You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Lachlan Deck <la...@gmail.com> on 2008/06/10 08:26:29 UTC

NamedQuery / SQLTemplate keyPath validation

Hi there,

(question related to ROP)

say I've got an Expression (whether complex or otherwise) and I want  
to utilise that Expression in a NamedQuery or SQLTemplate... what's  
the easiest way to transform the expression to an sql equivalent  
string? (i.e., such that, e.g.,, boolean values are transformed from  
say true to 1 (if using an int column), dates are formatted  
appropriately etc, comparison operators are transformed (e.g., != to  
<>) etc.

I see that there's a QueryAssembler and QualifierTranslator etc, but  
what I'm looking for, I guess, is a something like  
expression.toSQLString(baseEntity).

Any suggestions?

Thanks.

with regards,
--

Lachlan Deck


Re: NamedQuery / SQLTemplate keyPath validation

Posted by Lachlan Deck <la...@gmail.com>.
Hi Laurent,

thanks, I'll keep that in mind if we get stuck...

with regards,
--

Lachlan Deck




Re: NamedQuery / SQLTemplate keyPath validation

Posted by Laurent Marchal <lm...@smaeur.com>.
Hi !

We are using Cayenne version 3.0 M4, and we had this problem too.
Our need was to fetch lighweight objects than persistent objects, we 
called Descriptors.

So we created a complex SQLTemplate query with Outer/Left joins ...etc, 
but we needed to append to this SQLTemplate string an Expression.
(To filter the query on user rights for example)

We tried EJBQL, but we found some JOINS limitations, and a bug : an 
"inExpr" transformated to EJBQL that was not working.
http://www.nabble.com/Pb-to-cast-Expression-to-ejbql-string-td16083997.html

So we found a way to append Expressions to SQLTemplate :

	/**
	 * Transform a given Expression to a string for SQLTemplate statement.
	 * @param rootClass (Class<?>)
	 * @param exp (Expression)
	 * @return String
	 */
	public static String transformExpressionToSQLTemplateString(ObjectContext context, Class<?> rootClass, Expression exp) 
	{
		if (exp != null && rootClass != null) 
		{
			//Transform expression
			String expString = CayenneUtil.getObjEntity(context, rootClass).translateToDbPath(exp).toString();
			String dbTableName = CayenneUtil.getDbEntityName(context, rootClass);
			dbTableName += SystemConstants.DOT;
			
			//remove all db: prefixes
			expString = expString.replaceAll("db:", dbTableName);
			expString = expString.replaceAll("\"", "'");
			
			return expString;
		}
		
		return null;
	}
	
	/**
	 * This will add to the given SQLTemplate string its WHERE statement.
	 * @param SQLTemplateStatement
	 * @param exp Expression;
	 * @return String - the entire SQLTemplate statement string.
	 */
	public static String addExpressionToSQLTemplate(ObjectContext context, String sqlTemplateStatement, Expression exp, Class<?> classRootForExpression) {
		String sqlStatement = sqlTemplateStatement;
		//Transform expression
		String expString = CayenneUtil.transformExpressionToSQLTemplateString(context, classRootForExpression, exp);
		
		//Add the statement to the current sql template query model
		if (expString != null) {
			
			if (sqlStatement.contains(SQLTemplateConstants.WHERE)) {
				sqlStatement += SQLTemplateConstants.AND + "(" + expString + ")";
			} else {
				sqlStatement += SQLTemplateConstants.WHERE + "(" + expString + ")";
			}
		}
		
		return sqlStatement;
	}


I know that it's not very clean, but we had hard deadlines in our 
project, and  we needed something which work quickly.
We use this system everywhere in our Descriptors Factories, i can post 
some code if needed.

Regards.

Laurent Marchal.

Lachlan Deck wrote:
> Hi there,
>
> (question related to ROP)
>
> say I've got an Expression (whether complex or otherwise) and I want 
> to utilise that Expression in a NamedQuery or SQLTemplate... what's 
> the easiest way to transform the expression to an sql equivalent 
> string? (i.e., such that, e.g.,, boolean values are transformed from 
> say true to 1 (if using an int column), dates are formatted 
> appropriately etc, comparison operators are transformed (e.g., != to 
> <>) etc.
>
> I see that there's a QueryAssembler and QualifierTranslator etc, but 
> what I'm looking for, I guess, is a something like 
> expression.toSQLString(baseEntity).
>
> Any suggestions?
>
> Thanks.
>
> with regards,
> -- 
>
> Lachlan Deck
>
>
>
>

-- 

Laurent Marchal

SMA Europe
www.smaeur.com <http://www.smaeur.com>
lmarchal@smaeur.com <ma...@smaeur.com>
Tel : +33 3 83 15 25 76

Re: NamedQuery / SQLTemplate keyPath validation

Posted by Andrus Adamchik <an...@objectstyle.org>.
But maybe I misunderstood your goal with that? What about "kePath  
validation" in the subject?

Andrus

On Jun 10, 2008, at 10:12 AM, Andrus Adamchik wrote:

> Hi Lachlan,
>
> there is nothing there that would let you do that outside the  
> context of query execution. One reason why we never pursued such  
> functionality is because ... well, such context is needed:
>
> * you need a place to stick joins as you walk the expression path
> * you need a way to match bound variables against "?" in prepared  
> statement (we don't do conversion from Date to String for instance,  
> as there is no sane way to do that for all databases; we let JDBC  
> driver handle bindings)
> * you need access to specific DbAdapter to generate correct SQL and  
> correctly process bindings.
>
> The closest thing to what you describe is a procedure of translation  
> of an EJBQL query (which is logically, but not semantically is a  
> close analog of SelectQuery) to SQLTemplate. It is also done in the  
> context of query execution, but with some effort it can probably be  
> converted to a standalone SQLTemplate without execution.
>
> Andrus
>
>
> On Jun 10, 2008, at 9:26 AM, Lachlan Deck wrote:
>> Hi there,
>>
>> (question related to ROP)
>>
>> say I've got an Expression (whether complex or otherwise) and I  
>> want to utilise that Expression in a NamedQuery or SQLTemplate...  
>> what's the easiest way to transform the expression to an sql  
>> equivalent string? (i.e., such that, e.g.,, boolean values are  
>> transformed from say true to 1 (if using an int column), dates are  
>> formatted appropriately etc, comparison operators are transformed  
>> (e.g., != to <>) etc.
>>
>> I see that there's a QueryAssembler and QualifierTranslator etc,  
>> but what I'm looking for, I guess, is a something like  
>> expression.toSQLString(baseEntity).
>>
>> Any suggestions?
>>
>> Thanks.
>>
>> with regards,
>> --
>>
>> Lachlan Deck
>>
>>
>
>


Re: NamedQuery / SQLTemplate keyPath validation

Posted by Lachlan Deck <la...@gmail.com>.
On 10/06/2008, at 5:52 PM, Lachlan Deck wrote:

> Hi Andrus,
>
> On 10/06/2008, at 5:37 PM, Andrus Adamchik wrote:
>
>> On Jun 10, 2008, at 10:31 AM, Lachlan Deck wrote:
>>
>>> Perhaps I should describe what I'm actually doing. All I need is a  
>>> way to get a count of a select query (without having to fault in  
>>> all the related objects). So is there a way to trigger that, in  
>>> order to just get a count back, with a SelectQuery without going  
>>> the sqltemplate or namedquery route?
>>
>> I think EJBQL route is the way to go for aggregate object queries.  
>> In fact Expression has 'toEJBQLString' method, but you may not even  
>> care about it.

Actually, I may indeed care... to to tweak your example are you saying  
I could do this...

>> EJBQLQuery countQuery = new EJBQLQuery("SELECT count(a) FROM Artist  
>> a WHERE a.artistName like 'A%'");

Expression expression; // assume exists
EJBQLQuery countQuery = new EJBQLQuery("SELECT count(*) FROM Artist a  
WHERE " + expression.toEJBQLString("a"));

Is that the intention?

with regards,
--

Lachlan Deck


Re: NamedQuery / SQLTemplate keyPath validation

Posted by Lachlan Deck <la...@gmail.com>.
On 10/06/2008, at 6:02 PM, Andrus Adamchik wrote:

> Unlike SQLTemplate, EJBQL operates in object terms, abstracted from  
> SQL (this is why I said earlier that it is similar to SelectQuery).  
> So it is free from the constraints that I mentioned and you can do  
> something like this:
>
> String ejbql = "SELECT count(a) FROM Artist a WHERE " +  
> expression.toEJBQLString("a");

Just sent my email with this question exactly... thanks!

with regards,
--

Lachlan Deck




Re: NamedQuery / SQLTemplate keyPath validation

Posted by Andrus Adamchik <an...@objectstyle.org>.
IIRC no... But I think we should.

Andrus

On Jun 10, 2008, at 11:09 AM, Lachlan Deck wrote:

> On 10/06/2008, at 6:02 PM, Andrus Adamchik wrote:
>
>> Unlike SQLTemplate, EJBQL operates in object terms, abstracted from  
>> SQL (this is why I said earlier that it is similar to SelectQuery).  
>> So it is free from the constraints that I mentioned and you can do  
>> something like this:
>>
>> String ejbql = "SELECT count(a) FROM Artist a WHERE " +  
>> expression.toEJBQLString("a");
>
> One more clarification...
>
> I assume restricting qualifiers are not auto-applied?
>
> Thanks again
>
> with regards,
> --
>
> Lachlan Deck
>


Re: NamedQuery / SQLTemplate keyPath validation

Posted by Lachlan Deck <la...@gmail.com>.
On 10/06/2008, at 6:02 PM, Andrus Adamchik wrote:

> Unlike SQLTemplate, EJBQL operates in object terms, abstracted from  
> SQL (this is why I said earlier that it is similar to SelectQuery).  
> So it is free from the constraints that I mentioned and you can do  
> something like this:
>
> String ejbql = "SELECT count(a) FROM Artist a WHERE " +  
> expression.toEJBQLString("a");

One more clarification...

I assume restricting qualifiers are not auto-applied?

Thanks again

with regards,
--

Lachlan Deck

Re: NamedQuery / SQLTemplate keyPath validation

Posted by Andrus Adamchik <an...@objectstyle.org>.
Unlike SQLTemplate, EJBQL operates in object terms, abstracted from  
SQL (this is why I said earlier that it is similar to SelectQuery). So  
it is free from the constraints that I mentioned and you can do  
something like this:

   String ejbql = "SELECT count(a) FROM Artist a WHERE " +  
expression.toEJBQLString("a");

Andrus


On Jun 10, 2008, at 10:52 AM, Lachlan Deck wrote:

> Hi Andrus,
>
> On 10/06/2008, at 5:37 PM, Andrus Adamchik wrote:
>
>> On Jun 10, 2008, at 10:31 AM, Lachlan Deck wrote:
>>
>>> Perhaps I should describe what I'm actually doing. All I need is a  
>>> way to get a count of a select query (without having to fault in  
>>> all the related objects). So is there a way to trigger that, in  
>>> order to just get a count back, with a SelectQuery without going  
>>> the sqltemplate or namedquery route?
>>
>> I think EJBQL route is the way to go for aggregate object queries.  
>> In fact Expression has 'toEJBQLString' method, but you may not even  
>> care about it. Anyways here is an example:
>>
>> EJBQLQuery countQuery = new EJBQLQuery("SELECT count(a) FROM Artist  
>> a WHERE a.artistName like 'A%'");
>
> The problem is that we have a list controller that's doing its  
> select given the combination of various Expressions. These  
> expressions get broken out (at points) in order to obtain a relevant  
> count via some other query. So I don't have the option of  
> constructing the where clause as simply as above (or, in other  
> words, by hand).
>
> i.e., will EJBQLQuery cope with an expression.toString() where clause?
>
> with regards,
> --
>
> Lachlan Deck
>
>
>
>


Re: NamedQuery / SQLTemplate keyPath validation

Posted by Lachlan Deck <la...@gmail.com>.
Hi Andrus,

On 10/06/2008, at 5:37 PM, Andrus Adamchik wrote:

> On Jun 10, 2008, at 10:31 AM, Lachlan Deck wrote:
>
>> Perhaps I should describe what I'm actually doing. All I need is a  
>> way to get a count of a select query (without having to fault in  
>> all the related objects). So is there a way to trigger that, in  
>> order to just get a count back, with a SelectQuery without going  
>> the sqltemplate or namedquery route?
>
> I think EJBQL route is the way to go for aggregate object queries.  
> In fact Expression has 'toEJBQLString' method, but you may not even  
> care about it. Anyways here is an example:
>
> EJBQLQuery countQuery = new EJBQLQuery("SELECT count(a) FROM Artist  
> a WHERE a.artistName like 'A%'");

The problem is that we have a list controller that's doing its select  
given the combination of various Expressions. These expressions get  
broken out (at points) in order to obtain a relevant count via some  
other query. So I don't have the option of constructing the where  
clause as simply as above (or, in other words, by hand).

i.e., will EJBQLQuery cope with an expression.toString() where clause?

with regards,
--

Lachlan Deck




Re: NamedQuery / SQLTemplate keyPath validation

Posted by Lachlan Deck <la...@gmail.com>.
https://issues.apache.org/cayenne/browse/CAY-1072

Thanks again...

On 10/06/2008, at 6:33 PM, Andrus Adamchik wrote:

>
> On Jun 10, 2008, at 11:29 AM, Lachlan Deck wrote:
>
>> Do you need a task?
>
> Sure. I'd appreciate that.
>
> Andrus

with regards,
--

Lachlan Deck




Re: NamedQuery / SQLTemplate keyPath validation

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Jun 10, 2008, at 11:29 AM, Lachlan Deck wrote:

> Do you need a task?

Sure. I'd appreciate that.

Andrus

Re: NamedQuery / SQLTemplate keyPath validation

Posted by Lachlan Deck <la...@gmail.com>.
On 10/06/2008, at 6:19 PM, Andrus Adamchik wrote:

> I need to test it with ROP... Probably a bug, but also likely easy  
> to fix.

Same problem with using getContext().perform[Generic]Query also.

Caused by: java.lang.IllegalStateException: Serialized class  
org.apache.cayenne.query.SQLResultSetMapping must implement  
java.io.Serializable

Do you need a task?

with regards,
--

Lachlan Deck




Re: NamedQuery / SQLTemplate keyPath validation

Posted by Andrus Adamchik <an...@objectstyle.org>.
I need to test it with ROP... Probably a bug, but also likely easy to  
fix.

Andrus

On Jun 10, 2008, at 11:17 AM, Lachlan Deck wrote:

> On 10/06/2008, at 5:37 PM, Andrus Adamchik wrote:
>
>> On Jun 10, 2008, at 10:31 AM, Lachlan Deck wrote:
>>
>>> Perhaps I should describe what I'm actually doing. All I need is a  
>>> way to get a count of a select query (without having to fault in  
>>> all the related objects). So is there a way to trigger that, in  
>>> order to just get a count back, with a SelectQuery without going  
>>> the sqltemplate or namedquery route?
>>
>> I think EJBQL route is the way to go for aggregate object queries.  
>> In fact Expression has 'toEJBQLString' method, but you may not even  
>> care about it. Anyways here is an example:
>>
>> EJBQLQuery countQuery = new EJBQLQuery("SELECT count(a) FROM Artist  
>> a WHERE a.artistName like 'A%'");
>> Number count = (Number) DataObjectUtils.objectForQuery(countQuery);
>
> Okay, so I've got this...
> public int allRecordsCount(Expression e) {
> 	ObjEntity entity =  
> getContext().getEntityResolver().lookupObjEntity(getObjectClass());
> 	Expression qualifier = null;
> 	<...>
> 	String ejbqlWhereString = qualifier == null ? "" : " WHERE " +  
> qualifier.toEJBQL("a");
> 	String ejbqlQueryString = "SELECT count(a) FROM " +  
> entity.getName() + " a" + ejbqlWhereString;
> 	EJBQLQuery ejbqlQuery = new EJBQLQuery(ejbqlQueryString);
> 	Number count = (Number)  
> DataObjectUtils.objectForQuery(getContext(), ejbqlQuery);
> 	return count.intValue();
> }
>
> But I'm getting this exception. Any ideas?
>
> org.apache.cayenne.CayenneRuntimeException: [v.3.0-SNAPSHOT May 14  
> 2008 22:35:23] Remote error. URL - http://delish.ish.com.au:8181/angel-server-cayenne 
> ; CAUSE - Serialized class  
> org.apache.cayenne.query.SQLResultSetMapping must implement  
> java.io.Serializable
>     [java] 	at  
> org 
> .apache 
> .cayenne 
> .remote 
> .hessian.HessianConnection.doSendMessage(HessianConnection.java:147)
>     [java] 	at  
> org 
> .apache 
> .cayenne.remote.BaseConnection.sendMessage(BaseConnection.java:73)
>     [java] 	at  
> org.apache.cayenne.remote.ClientChannel.send(ClientChannel.java:281)
>     [java] 	at  
> org.apache.cayenne.remote.ClientChannel.onQuery(ClientChannel.java: 
> 113)
>     [java] 	at  
> org 
> .apache 
> .cayenne 
> .util 
> .ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:317)
>     [java] 	at  
> org 
> .apache 
> .cayenne 
> .util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java: 
> 96)
>     [java] 	at  
> org.apache.cayenne.CayenneContext.onQuery(CayenneContext.java:340)
>     [java] 	at  
> org.apache.cayenne.CayenneContext.performQuery(CayenneContext.java: 
> 328)
>     [java] 	at  
> ish.oncourse.cayenne.CayenneContext.performQuery(CayenneContext.java: 
> 292)
>     [java] 	at  
> org 
> .apache.cayenne.DataObjectUtils.objectForQuery(DataObjectUtils.java: 
> 274)
>     [java] 	at  
> ish 
> .oncourse 
> .controller.ListController.allRecordsCount(ListController.java:482)
>
> with regards,
> --
>
> Lachlan Deck
>


Re: NamedQuery / SQLTemplate keyPath validation

Posted by Lachlan Deck <la...@gmail.com>.
On 10/06/2008, at 5:37 PM, Andrus Adamchik wrote:

> On Jun 10, 2008, at 10:31 AM, Lachlan Deck wrote:
>
>> Perhaps I should describe what I'm actually doing. All I need is a  
>> way to get a count of a select query (without having to fault in  
>> all the related objects). So is there a way to trigger that, in  
>> order to just get a count back, with a SelectQuery without going  
>> the sqltemplate or namedquery route?
>
> I think EJBQL route is the way to go for aggregate object queries.  
> In fact Expression has 'toEJBQLString' method, but you may not even  
> care about it. Anyways here is an example:
>
> EJBQLQuery countQuery = new EJBQLQuery("SELECT count(a) FROM Artist  
> a WHERE a.artistName like 'A%'");
> Number count = (Number) DataObjectUtils.objectForQuery(countQuery);

Okay, so I've got this...
public int allRecordsCount(Expression e) {
	ObjEntity entity =  
getContext().getEntityResolver().lookupObjEntity(getObjectClass());
	Expression qualifier = null;
	<...>
	String ejbqlWhereString = qualifier == null ? "" : " WHERE " +  
qualifier.toEJBQL("a");
	String ejbqlQueryString = "SELECT count(a) FROM " + entity.getName()  
+ " a" + ejbqlWhereString;
	EJBQLQuery ejbqlQuery = new EJBQLQuery(ejbqlQueryString);
	Number count = (Number) DataObjectUtils.objectForQuery(getContext(),  
ejbqlQuery);
	return count.intValue();
}

But I'm getting this exception. Any ideas?

org.apache.cayenne.CayenneRuntimeException: [v.3.0-SNAPSHOT May 14  
2008 22:35:23] Remote error. URL - http://delish.ish.com.au:8181/angel-server-cayenne 
; CAUSE - Serialized class  
org.apache.cayenne.query.SQLResultSetMapping must implement  
java.io.Serializable
      [java] 	at  
org 
.apache 
.cayenne 
.remote.hessian.HessianConnection.doSendMessage(HessianConnection.java: 
147)
      [java] 	at  
org 
.apache.cayenne.remote.BaseConnection.sendMessage(BaseConnection.java: 
73)
      [java] 	at  
org.apache.cayenne.remote.ClientChannel.send(ClientChannel.java:281)
      [java] 	at  
org.apache.cayenne.remote.ClientChannel.onQuery(ClientChannel.java:113)
      [java] 	at  
org 
.apache 
.cayenne 
.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java: 
317)
      [java] 	at  
org 
.apache 
.cayenne 
.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
      [java] 	at  
org.apache.cayenne.CayenneContext.onQuery(CayenneContext.java:340)
      [java] 	at  
org.apache.cayenne.CayenneContext.performQuery(CayenneContext.java:328)
      [java] 	at  
ish.oncourse.cayenne.CayenneContext.performQuery(CayenneContext.java: 
292)
      [java] 	at  
org.apache.cayenne.DataObjectUtils.objectForQuery(DataObjectUtils.java: 
274)
      [java] 	at  
ish 
.oncourse 
.controller.ListController.allRecordsCount(ListController.java:482)

with regards,
--

Lachlan Deck

Re: NamedQuery / SQLTemplate keyPath validation

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Jun 10, 2008, at 10:31 AM, Lachlan Deck wrote:

> Perhaps I should describe what I'm actually doing. All I need is a  
> way to get a count of a select query (without having to fault in all  
> the related objects). So is there a way to trigger that, in order to  
> just get a count back, with a SelectQuery without going the  
> sqltemplate or namedquery route?

I think EJBQL route is the way to go for aggregate object queries. In  
fact Expression has 'toEJBQLString' method, but you may not even care  
about it. Anyways here is an example:

  EJBQLQuery countQuery = new EJBQLQuery("SELECT count(a) FROM Artist  
a WHERE a.artistName like 'A%'");
  Number count = (Number) DataObjectUtils.objectForQuery(countQuery);

Andrus



Re: NamedQuery / SQLTemplate keyPath validation

Posted by Lachlan Deck <la...@gmail.com>.
Hi Andrus,

thanks for the reply...

On 10/06/2008, at 5:12 PM, Andrus Adamchik wrote:

> there is nothing there that would let you do that outside the  
> context of query execution. One reason why we never pursued such  
> functionality is because ... well, such context is needed:
>
> * you need a place to stick joins as you walk the expression path
> * you need a way to match bound variables against "?" in prepared  
> statement (we don't do conversion from Date to String for instance,  
> as there is no sane way to do that for all databases; we let JDBC  
> driver handle bindings)
> * you need access to specific DbAdapter to generate correct SQL and  
> correctly process bindings.

okay.

Perhaps I should describe what I'm actually doing. All I need is a way  
to get a count of a select query (without having to fault in all the  
related objects). So is there a way to trigger that, in order to just  
get a count back, with a SelectQuery without going the sqltemplate or  
namedquery route?

> The closest thing to what you describe is a procedure of translation  
> of an EJBQL query (which is logically, but not semantically is a  
> close analog of SelectQuery) to SQLTemplate. It is also done in the  
> context of query execution, but with some effort it can probably be  
> converted to a standalone SQLTemplate without execution.

Would that help here?

Sorry the subject was misleading... I ended up changing the body from  
its original - where I was finding that foreign keys in the expression  
were being validated and it was throwing an exception because they  
weren't public members... but that's another (albeit related) topic.

with regards,
--

Lachlan Deck

Re: NamedQuery / SQLTemplate keyPath validation

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Lachlan,

there is nothing there that would let you do that outside the context  
of query execution. One reason why we never pursued such functionality  
is because ... well, such context is needed:

* you need a place to stick joins as you walk the expression path
* you need a way to match bound variables against "?" in prepared  
statement (we don't do conversion from Date to String for instance, as  
there is no sane way to do that for all databases; we let JDBC driver  
handle bindings)
* you need access to specific DbAdapter to generate correct SQL and  
correctly process bindings.

The closest thing to what you describe is a procedure of translation  
of an EJBQL query (which is logically, but not semantically is a close  
analog of SelectQuery) to SQLTemplate. It is also done in the context  
of query execution, but with some effort it can probably be converted  
to a standalone SQLTemplate without execution.

Andrus


On Jun 10, 2008, at 9:26 AM, Lachlan Deck wrote:
> Hi there,
>
> (question related to ROP)
>
> say I've got an Expression (whether complex or otherwise) and I want  
> to utilise that Expression in a NamedQuery or SQLTemplate... what's  
> the easiest way to transform the expression to an sql equivalent  
> string? (i.e., such that, e.g.,, boolean values are transformed from  
> say true to 1 (if using an int column), dates are formatted  
> appropriately etc, comparison operators are transformed (e.g., != to  
> <>) etc.
>
> I see that there's a QueryAssembler and QualifierTranslator etc, but  
> what I'm looking for, I guess, is a something like  
> expression.toSQLString(baseEntity).
>
> Any suggestions?
>
> Thanks.
>
> with regards,
> --
>
> Lachlan Deck
>
>


Re: NamedQuery / SQLTemplate keyPath validation

Posted by Marcin Skladaniec <ma...@ish.com.au>.
Sorry everyone, I sent my last message to the list by mistake...

Marcin

On 11/06/2008, at 7:58 AM, Marcin Skladaniec wrote:

> there is no simple way, see what I did in allRecordsCount in  
> ListController. Yo wont translate IN statement and other easily though
> Marcin
>
> On 10/06/2008, at 4:26 PM, Lachlan Deck wrote:
>
>> Hi there,
>>
>> (question related to ROP)
>>
>> say I've got an Expression (whether complex or otherwise) and I  
>> want to utilise that Expression in a NamedQuery or SQLTemplate...  
>> what's the easiest way to transform the expression to an sql  
>> equivalent string? (i.e., such that, e.g.,, boolean values are  
>> transformed from say true to 1 (if using an int column), dates are  
>> formatted appropriately etc, comparison operators are transformed  
>> (e.g., != to <>) etc.
>>
>> I see that there's a QueryAssembler and QualifierTranslator etc,  
>> but what I'm looking for, I guess, is a something like  
>> expression.toSQLString(baseEntity).
>>
>> Any suggestions?
>>
>> Thanks.
>>
>> with regards,
>> --
>>
>> Lachlan Deck
>>
>


Re: NamedQuery / SQLTemplate keyPath validation

Posted by Marcin Skladaniec <ma...@ish.com.au>.
there is no simple way, see what I did in allRecordsCount in  
ListController. Yo wont translate IN statement and other easily though
Marcin

On 10/06/2008, at 4:26 PM, Lachlan Deck wrote:

> Hi there,
>
> (question related to ROP)
>
> say I've got an Expression (whether complex or otherwise) and I want  
> to utilise that Expression in a NamedQuery or SQLTemplate... what's  
> the easiest way to transform the expression to an sql equivalent  
> string? (i.e., such that, e.g.,, boolean values are transformed from  
> say true to 1 (if using an int column), dates are formatted  
> appropriately etc, comparison operators are transformed (e.g., != to  
> <>) etc.
>
> I see that there's a QueryAssembler and QualifierTranslator etc, but  
> what I'm looking for, I guess, is a something like  
> expression.toSQLString(baseEntity).
>
> Any suggestions?
>
> Thanks.
>
> with regards,
> --
>
> Lachlan Deck
>