db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sheldon Ross <sr...@simmgene.com>
Subject Re: Criteria needs write permissions?
Date Thu, 12 Nov 2009 22:34:42 GMT
"So, people get confused when it seems like you can't use the DB objects
with more than one database connection.  But that's not true.  To use
more than one connection pool, you need to use the methods that take a
connection object."

In this case the query still fails even if you specify the connection.

The SqlBuilder assumes that the table name has been added to the dbMap at
the point where its crashing. But the table names only get added to the 
default dbMap.



Greg Monroe wrote:
> OK, I think I understand what's going on here.  It's really a semi-bug
> part but part a definitional issue.  This is because the term database 
> name/dbname actually has two meaning in Torque.  
>
> The first is the "schema database name", i.e. the name in your schema 
> XML.  This is used to group all the database schema's Metadata in the
> Database structure. 
>
> The second meaning for this is the "database connection pool name".  This
> is the name used in the runtime config to define the DB connection info.
>
> Unfortunately, for historical reasons, these two names are "tied" 
> together.  Mostly for convenience reasons... but there are a few cases 
> in the utility classes where a subquery or something needs to be done
> and the default DB name is used.
>
> So, people get confused when it seems like you can't use the DB objects
> with more than one database connection.  But that's not true.  To use
> more than one connection pool, you need to use the methods that take a
> connection object. 
>
> To get an alternate connection, you define this in your runtime with 
> a different name.  E.g. set up a different set of torque.dsfactory.
> properties.
>
> Then use the Torque.getConnection(String) to get a connection from this
> pool. 
>
> FWIW, I put forth a plan for Torque 4 to separate the connection pool
> name from the schema name.  This would require objects and criteria
> to track which pool they came from.
>   
>
>   
>> -----Original Message-----
>> From: Sheldon Ross [mailto:sross@simmgene.com]
>> Sent: Thursday, November 12, 2009 4:28 PM
>> To: Apache Torque Users List
>> Subject: Re: Criteria needs write permissions?
>>
>> Ok, I think this maybe a bug. After watching the addTable method in
>> DatabaseMap, It appears to add the table to the default database dbMap
>> even if the criteria is querying against a different database.
>>
>>
>> Sheldon Ross wrote:
>>     
>>> That would probably work, but It seems a little overkill. Do you know
>>> where the lazy loading happens?
>>> When I run with r/w connection, the dbmap tables hash does appear to
>>> load that way.
>>> However when I run the readonly connection, it just stays empty.
>>>
>>> Thanks
>>>
>>> Greg Monroe wrote:
>>>       
>>>> FWIW, the dbMap object get populated in a "lazy" manner by default.
>>>> However,
>>>> there is a way to force it to be fully loaded via a code call.  You
>>>> do this by calling:
>>>>
>>>> org.apache.torque.linkage.DefaultMapInit.init();
>>>>
>>>> Not that this class actually exists in the generated classes and not
>>>> in the Torque package.  This is because it provided a "known" class
>>>> that "knows" (via extension) the "user settable" om package.
>>>>
>>>>
>>>>         
>>>>> -----Original Message-----
>>>>> From: Sheldon Ross [mailto:sross@simmgene.com]
>>>>> Sent: Thursday, November 12, 2009 3:25 PM
>>>>> To: Apache Torque Users List
>>>>> Subject: Re: Criteria needs write permissions?
>>>>>
>>>>> The why is a good question, the table is not found. The tables
>>>>>           
>> hashmap
>>     
>>>>> in the dbMap appears to be empty.
>>>>> It of course is found when using the other db connection. It looks
>>>>>           
>> like
>>     
>>>>> I'm gonna have to dig for awhile.
>>>>>
>>>>> Thanks.
>>>>>
>>>>> Thomas Fischer wrote:
>>>>>
>>>>>           
>>>>>> The null ointer exception seems to come from reading the table or
>>>>>>
>>>>>>             
>>>>> column
>>>>>
>>>>>           
>>>>>> map. Can you put a breakpoint in SQLBuilder.java:497 and see whether
>>>>>>
>>>>>>             
>>>>> the
>>>>>
>>>>>           
>>>>>> table or the column cannot be found (and why it is not found)?
>>>>>>
>>>>>>     Thomas
>>>>>>
>>>>>>
>>>>>>
>>>>>>             
>>>>>>> Ok so I was trying to make our site a little safer from sql
>>>>>>>
>>>>>>>               
>>>>> injections,
>>>>>
>>>>>           
>>>>>>> so I made a database connection that connects with a user that
only
>>>>>>>
>>>>>>>               
>>>>> has
>>>>>
>>>>>           
>>>>>>> SELECT permissions. And edited Criteria like such
>>>>>>>
>>>>>>> public Criteria()
>>>>>>>     {
>>>>>>>         this(DEFAULT_CAPACITY);
>>>>>>>         this.setDbName("readonlydatabase");
>>>>>>>     }
>>>>>>>
>>>>>>> Now it seems to work for must things, but a couple queries fail
>>>>>>>               
>> with
>>     
>>>>>>> throws java.lang.Exception java.lang.NullPointerException
>>>>>>>     at org.apache.torque.util.SQLBuilder.processOrderBy
>>>>>>>
>>>>>>>
>>>>>>>               
>>>>>> (SQLBuilder.java:497)
>>>>>>
>>>>>>
>>>>>>             
>>>>>>>     at
>>>>>>>
>>>>>>>
>>>>>>>               
>> org.apache.torque.util.SQLBuilder.buildQueryClause(SQLBuilder.java:302)
>>     
>>>>>>>     at
>>>>>>>               
>> org.apache.torque.util.BasePeer.createQuery(BasePeer.java:730)
>>     
>>>>>>> This error disappears as soon as I let the criteria use a database
>>>>>>> connection with write privileges.
>>>>>>> I know the user that it connects with has select privileges on
>>>>>>>               
>> every
>>     
>>>>>>> public table in the database.
>>>>>>>
>>>>>>> Does criteria need update privileges to work or something?
>>>>>>>
>>>>>>> The query the criteria constructs work fine when I connect as
the
>>>>>>> readonly user and run it manually.
>>>>>>>
>>>>>>> Any thoughts?
>>>>>>>
>>>>>>> Thanks
>>>>>>>
>>>>>>> --
>>>>>>> Sheldon Ross
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> -------------------------------------------------------------------
>>>>>>>               
>> --
>>     
>>>>>>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>>>>>>> For additional commands, e-mail: torque-user-help@db.apache.org
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>               
>>>>>> --------------------------------------------------------------------
>>>>>>             
>> -
>>     
>>>>>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>>>>>> For additional commands, e-mail: torque-user-help@db.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>             
>>>>> --
>>>>> Sheldon Ross
>>>>> Software Development
>>>>> American Simmental Association
>>>>> sross@simmgene.com
>>>>> (406)587-4531 ext 102
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>>>>> For additional commands, e-mail: torque-user-help@db.apache.org
>>>>>
>>>>>           
>>>> DukeCE Privacy Statement:
>>>> Please be advised that this e-mail and any files transmitted with
>>>> it are confidential communication or may otherwise be privileged or
>>>> confidential and are intended solely for the individual or entity
>>>> to whom they are addressed. If you are not the intended recipient
>>>> you may not rely on the contents of this email or any attachments,
>>>> and we ask that you please not read, copy or retransmit this
>>>> communication, but reply to the sender and destroy the email, its
>>>> contents, and all copies thereof immediately. Any unauthorized
>>>> dissemination, distribution or copying of this communication is
>>>> strictly prohibited.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: torque-user-help@db.apache.org
>>>>
>>>>
>>>>
>>>>         
>> --
>> Sheldon Ross
>> Software Development
>> American Simmental Association
>> sross@simmgene.com
>> (406)587-4531 ext 102
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: torque-user-help@db.apache.org
>>     
>
> DukeCE Privacy Statement:
> Please be advised that this e-mail and any files transmitted with
> it are confidential communication or may otherwise be privileged or
> confidential and are intended solely for the individual or entity
> to whom they are addressed. If you are not the intended recipient
> you may not rely on the contents of this email or any attachments,
> and we ask that you please not read, copy or retransmit this
> communication, but reply to the sender and destroy the email, its
> contents, and all copies thereof immediately. Any unauthorized
> dissemination, distribution or copying of this communication is
> strictly prohibited.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>   

-- 
Sheldon Ross
Software Development
American Simmental Association
sross@simmgene.com
(406)587-4531 ext 102 


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message