Firebird domain as Rails type - ruby-on-rails

I am working on a patch for a firebird rails adapter. My goal is to make it possible to define a column as the type boolean if the domain of the column has a defined name.
I found the SqlTypeMetadata class which I am using to create FirebirdColumns in the method fetch_type_metadata in the module SchemaStatements.
But it seems that this is used only after the data is fetched so it doesn't use the defined true/false values in the query. So, right now, I am looking for a way to tell ActiveRecord the type of a column on an adapter basis. I read the files schema_definitions and schema_statements several times in case I am missing something but I couldn't find a method there... .
Where is a method that I can overwrite to make the typecasting correct?

Firebird doesn't communicate information about the domain of a column in the bind information of a prepared query. It only communicates the basic underlying datatype information. So if you have defined a domain X with underlying type CHAR(1), then Firebird will communicate it as a CHAR(1), not as X.
There is no option to obtain the domain, except by querying the metadata tables for additional information. So, what you want to achieve is either not possible, or at least it will be complicated.

Related

SEGW entity type without key

I am trying to create a OData service that returns user parameters found in the databasde usr05. Those can be accessed by the ABAP statement:
GET PARAMETER ID 'XXX' FIELD YYY.
This means, that basically do not need a key value.
In SEGW it is impossible to create an entity type without one though.
The solution of course could be a dummy key field, that is simply ignored in the backend implementation.
Does anyone know a better solution?
Thanks in advance,
Eric
it is not a shame it is by design and follows the OData specification.
Every entity type must have a key.
What you can try to use instead is to use a property that is based on a so called complex type within an entity type that is used for your users.
The latter should have a key.
Like the complex type address that is used in the entity type Supplier
https://services.odata.org/OData/OData.svc/$metadata

rename domain class, groovy and grails reverse engineering

How do a rename a domain class while reverse engineering or after reverse engineering.
i generated class using reverse engineering in Groovy and Grails.
the domain class name was AgentTable. I want to rename it as Agent. When i renamed the domain class using IntelliJ (right click - refactor - rename), it renamed the AgentTable to Agent whereever it was used. but when i start the server (run the app), giving error
"nested exception is org.hibernate.HibernateException: Missing table: agent"
I have to do this for few domain class. is it anyway i can give an alternative name while reverse engineering the domain classes.
or after domain class was created how do i rename it without this error.
Look into your database the name of the table it created for the agent. Once you know the name of the table add the following in your new domain
static mapping = {
table "table-name-here"
}
While it works I would not recommend #elixir 's approach.
In my opinion the mapping is not supposed to be used for renames. This is also how I understand the official documentation.
In the example they use it to map Person onto the 'people' table, not because of a rename but because of a semantic reason. Tables are typically named after the plural form. Here is a nice answer on another question regarding this. In the project I am working on the domain object 'User' is mapped to the table 'users'. You can not use the table name 'user' as it is an SQL statement.
Assumptions and clarifications:
In my experience Grails maps the domain name to the table name after these rules (example domain name 'MyExampleDomain':
separate the domain name by capital letters (My Example Domain)
lower case all (my example domain)
replace spaces with underlines (my_example_domain)
Following this your Domain Class 'AgentTable' has a table 'agent_table' in your respective database. After your rename Grails even tells you what it wants:
nested exception is org.hibernate.HibernateException: Missing table: agent
It wants to look up values in a table called 'agent' but it can not find it. The refactor function of IntelliJ does not rename the functions, so it will miss out on the database.
Luckily we know exactly what values it wants - the values previously found in 'agent_table'.
So why create this confusion with remapping domains and table names when we could just rename the table and be done with it?
The solution:
Execute an SQL script like this on your database:
ALTER TABLE <old_domain_name> RENAME TO <new_domain_name>;
The names are of course in their "table-form".
This simply renames your table to match the expected format in Grails. When restarting everything should be fine.
However you do not need to use rename. You could also create a whole new table, build it the way the domain objects wants it to be and then migrate the data. See section 'Problems with this approach' for information on when to use what.
Problems with this approach:
As always, tinkering with information a program depends on (and even generated itself) will often have some dire consequences if you aren't careful.
For example we have to pay attention to keys. If your domain object has a relation to other objects it will hold them in the table via foreign keys. Depending on how you chose to migrate the information in the table you might have deleted these foreign keys connections. You will have to add them via a separate SQL statement. When you choose to recreate the table this will happen for sure. Renaming it should keep the keys.
Another one are column names. If you choose to rename attributes you will also have to rename the columns via SQL. You will also have to remember the foreign keys other tables might have on the table you are renaming. RENAME did this automatically for me, but you should double check.
Why you should still stick with this approach:
Remapping domain objects to the tables with old names is bound to create code smell and confusion. Do you really want to remember these mappings in your head? And more importantly: do you really expect other people to have to work with this?
The best case is if people can't even tell if this object has ever had a different name and changing the database is the best way I know to achieve this.

NHibernate - Updating only specified object properties identified at runtime

I'm trying to implement a very granular security module in an ASP.NET MVC 3 app where only certain users can edit certain columns on records in a table. I can imagine that the update SQL statement's list of columns would only include the columns that the user had the right to change. The thing is, I'm planning to use an ORM like NHibernate. I'm wondering if NHibernate provides a way to determine at runtime which properties of a model should be part of an Update. Or is my only option to, on the POST method, get the model again from the database, set only the properties that the user is allowed to set then finally Save the model. Also, is this a good way to handle my requirement of of granular security?
Would dynamic-update and dynamic-insert be enough?
dynamic-update (optional, defaults to false): Specifies that UPDATE SQL should be generated at runtime and contain only those columns whose values have changed.
dynamic-insert (optional, defaults to false): Specifies that INSERT SQL should be generated at runtime and contain only the columns whose values are not null.
Otherwise it might be possible with events or interceptors, but I've never used them so I don't know exactly.

Entity Framework, Oracle, DevArt, Context#ExecuteStoreQuery: System.Int32 constructed as System.Double?

I have an Entity-class having a Property of type Int32: on generating DDL using DevArt for ORACLE a NUMBER(10) column is generated. Reading and writing instances works flawlessly.
However, on fetching instances of this Entity-class sending a custom query to ExecuteStoreQuery on the ObjectContext this Property seems to be returned as System.Double, as such constructing the instances fails.
Can I hint DevArt to construct System.Int32?
Thank you.
Bart
The reason is the fact that OracleDataReader, which is used in the ExecuteStoreQuery method, has type mapping different from the one used in the Entity Framework provider.
I recommend you to use NumberMappings, I suppose you will need to map Number(10) to Int32: Number Mappings=((NUMBER,10,10,System.Int32). These changes should be persisted to the model connection string (they are duplicating the default EF mapping rules, it is necessary for the OracleDataReader from ExecuteStoreQuery).
Please let us know if the problem persists.

MVC using Linq to Entity w/ sql encryption

Currently i am using sql encryption and would like to continue using it through Linq. I have all my CRUD stored proc's wired up to the table in order to handle the encryption/decryption on the backend. Problem is my database model see's a field type of varbinary(max) which is used for the sql encryption storage. The retrieval sp for this table does the decryption thus returning a string value. How does one get around this. Seems like the model needs to recognize a string in place of the varbinary but i am unsure of how to handle this.
Thanks in advance.
So change the table mapping to a view mapping in the database model?
Off the top of my head, some choices:
Edit the ssdl manually.
Make a view and map that (you don't need to actually use it for anything but mapping).

Resources