zhangjingl02 / activejdbc

Automatically exported from code.google.com/p/activejdbc
0 stars 0 forks source link

Expect Schema to be appended to all queries. However it seems to be done only #182

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set -Dactivejdbc.default.schema=scott
2. Fire a Model Query against User
3. You will see that the created SELECT query is 

What is the expected output? What do you see instead?
Expected:
SELECT * FROM ( SELECT t2.* FROM ( SELECT t.* FROM scott.users t  WHERE user_id 
= ? ) t2) WHERE ROWNUM <= 1
Actual:
SELECT * FROM ( SELECT t2.* FROM ( SELECT t.* FROM users t  WHERE user_id = ? ) 
t2) WHERE ROWNUM <= 1

What version of the product are you using? On what operating system?
1.4.5. (Windows 7)

Please provide any additional information below.
I looked into code and looks like the JVM parameter is used only for getting 
the Column Metadata in org.javalite.activejdbc.Registry.fetchMetaParams(...). 
Its not done in org.javalite.activejdbc.dialects.OracleDialect.formSelect(...)

First of all, I am also a huge fan of ActiveRecord and thought of doing 
something similar to that in Java and when I searched for any project already 
like this, I found yours. It looks awesome and I am using it rightaway. Its 
looks great. Thanks for bringing great things to OpenSource Community. However, 
in my company, all tables are done in a particular schema and there is no 
guarantee that PUBLIC synonyms would be properly created. Therefore this issue 
looks like a blocker for me unfortunately. Please do let me know if I am doing 
something wrong and should do more that just setting the JVM parameter 
-Dactivejdbc.default.schema.

Original issue reported on code.google.com by jve...@gmail.com on 30 Nov 2012 at 5:19

GoogleCodeExporter commented 9 years ago
you are correct, the schema is only sourced to collect metadata. 
It should be possible  though to augment all queries such that they prepend the 
schema to table name. However, I have two impediments. I no longer have Oracle 
instance to test against. The sever I ran it on crashed, and my fight to 
install Oracle XE ended up in Oracle winning (I failed to install :)). So, 
currently we are not even testing using Oracle. 
Second, I guess there needs to be a separate test for this case, with user 
logging onto one account, while getting data from tables in a different schema. 
If you can help in both of these cases, we can crack this together. 
Just writing code in a hope that it will work... is not my style ;)

thanks
igor

Original comment by i...@polevoy.org on 30 Nov 2012 at 7:46

GoogleCodeExporter commented 9 years ago
Thanks Igor for the confirmation. Sure. I would love to contribute. I will 
first get the code and try to understand your layers of separation. 

I am just curious to understand how others are using the schema argument just 
for the Column Metadata. They would require it even for the queries or for 
other DB actions...right? What is the point of getting properties of the 
Columns alone?

Original comment by jve...@gmail.com on 3 Dec 2012 at 2:05

GoogleCodeExporter commented 9 years ago
thanks! The schema argument is to get the metadata only. Apparently this is 
working for most people in multi-schema environment. When I designed AJ first 
in 2009, the primary target was Oracle, and we did have to work with multiple 
schemas, but the account we used had all aliases available. 
It appears that in JDBC implementations, you sometimes need schema and 
sometimes not, I guess this depends on driver.
In any case, the metadata is collected in ActiveJDBC so as to ensure you cannot 
set values on a model that  do not belong there. For instance if you have a 
table PEOPLE (first_name, last_name), then this:

person.set("age", 43);

will throw exception that will say that "age" is not defined, but also give you 
a list of attributes that are defined on this model (columns in table).
This can be easily traced from  Model.set(String, Object) method. 

Most queries are formed in the class DefaultDialect and subclasses, and maybe 
if we simply modify method MetaModels.getTableName(modelClass) we can add this 
enhancement. 

As you get familiar with code, keep on asking questions, I will help 

thanks
Igor

Original comment by i...@polevoy.org on 3 Dec 2012 at 2:24