db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clóvis Wichoski <clovis_wicho...@uol.com.br>
Subject Re: OQL grammar changes
Date Tue, 29 Jun 2004 15:10:21 GMT
Hi Thomas,

I changed the ojb-oql.g to support case sensitive OQL reserved words 
(SELECT,FROM,etc..) and to support alias and multiple class in FROM 
clause, note that the support for multiple class is only for OQL syntax, 
because the implementation of multiple class select must be a more research.
Then now supported syntax OQL are:

SELECT obj FROM myapp.Person
select obj from myapp.Person obj
select obj from myapp.Person obj, myapp.Person obj2

Regards

Clóvis

follow are the diff:

Index: src/java/org/apache/ojb/odmg/oql/oql-ojb.g
===================================================================
RCS file: 
/home/cvspublic/db-ojb/src/java/org/apache/ojb/odmg/oql/oql-ojb.g,v
retrieving revision 1.23
diff -r1.23 oql-ojb.g
70,71c70,71
<  * Modifications done by Ch. Rath & Th. Mahler & S. Harris
<  *
---
 >  * Modifications done by Ch. Rath & Th. Mahler & S. Harris & C. Wichoski
 >  *
94c94
<     caseSensitiveLiterals=true;
---
 >     caseSensitiveLiterals=false; //for compat with others OQL
342a343
 >             Object[] classes = null;
345a347,348
 >             boolean isAliasFrom = false;
 >             int qtyClassFrom = 0;
363c366
<         "from" clazz = fromClause
---
 >         "from" classes = fromClause
366c369
<             if (clazz != null)
---
 >             if (classes != null)
368c371,373
<                 if (projectionAttrs[0].indexOf('.') < 0)
---
 >                 isAliasFrom = 
((Boolean)classes[classes.length-1]).booleanValue();
 >                 qtyClassFrom = (classes.length-1) / ( isAliasFrom ? 2 
: 1);
 >                 if (qtyClassFrom == 1)
370c375,406
<                     query = QueryFactory.newQuery(clazz, criteria, 
distinct);
---
 >                     clazz = (Class)classes[0];
 >                     if (clazz != null)
 >                     {
 >                         if (projectionAttrs[0].indexOf('.') < 0)
 >                         {
 >                             query = QueryFactory.newQuery(clazz, 
criteria, distinct);
 >                         }
 >                         else
 >                         {
 >                             ClassDescriptor cld = 
MetadataManager.getInstance().getRepository().getDescriptorFor(clazz);
 >                             for (int i = 0; i < 
projectionAttrs.length; i++)
 >                             {
 >                                 projectionAttrs[i] = 
projectionAttrs[i].substring(projectionAttrs[i].indexOf('.') + 1);
 >                             }
 >        
 >                             ArrayList descs = 
cld.getAttributeDescriptorsForPath(projectionAttrs[0]);
 >                             int pathLen = descs.size();
 >        
 >                             if ((pathLen > 0) && (descs.get(pathLen - 
1) instanceof ObjectReferenceDescriptor))
 >                             {
 >                                 ObjectReferenceDescriptor ord =
 >                                         ((ObjectReferenceDescriptor) 
descs.get(pathLen - 1));
 >                                 query = QueryFactory.newQuery(clazz, 
criteria, distinct);
 >                                 
query.setObjectProjectionAttribute(projectionAttrs[0],
 >                                                                    
ord.getItemClass());
 >                             }
 >                             else
 >                             {
 >                                 query = 
QueryFactory.newReportQuery(clazz, projectionAttrs, criteria, distinct);
 >                             }
 >                         }
 >                     }
374,394c410,413
<                     ClassDescriptor cld = 
MetadataManager.getInstance().getRepository().getDescriptorFor(clazz);
<                     for (int i = 0; i < projectionAttrs.length; i++)
<                     {
<                         projectionAttrs[i] = 
projectionAttrs[i].substring(projectionAttrs[i].indexOf('.') + 1);
<                     }
<
<                     ArrayList descs = 
cld.getAttributeDescriptorsForPath(projectionAttrs[0]);
<                     int pathLen = descs.size();
<
<                     if ((pathLen > 0) && (descs.get(pathLen - 1) 
instanceof ObjectReferenceDescriptor))
<                     {
<                         ObjectReferenceDescriptor ord =
<                                 ((ObjectReferenceDescriptor) 
descs.get(pathLen - 1));
<                         query = QueryFactory.newQuery(clazz, criteria, 
distinct);
<                         
query.setObjectProjectionAttribute(projectionAttrs[0],
<                                                            
ord.getItemClass());
<                     }
<                     else
<                     {
<                         query = QueryFactory.newReportQuery(clazz, 
projectionAttrs, criteria, distinct);
<                     }
---
 >                     /**
 >                     * @TODO: make a Query from multiple class maybe 
create a
 >                     *        SQL statement based on classes, or what?
 >                     **/
409a429
 >             Object[] classes = null;
410a431,432
 >             boolean isAliasFrom = false;
 >             int qtyClassFrom = 0;
418c440
<         "in" clazz = fromClause
---
 >         "in" classes = fromClause
421,422c443,457
<             if (clazz != null) {
<                 query = QueryFactory.newQuery(clazz, criteria);
---
 >             isAliasFrom = 
((Boolean)classes[classes.length-1]).booleanValue();
 >             qtyClassFrom = (classes.length-1) / ( isAliasFrom ? 2 : 1);
 >             if (qtyClassFrom == 1)
 >             {
 >                 clazz = (Class)classes[0];
 >                 if (clazz != null) {
 >                     query = QueryFactory.newQuery(clazz, criteria);
 >                 }
 >             }
 >             else
 >             {
 >                 /**
 >                 * @TODO: make a Query from multiple class maybe create a
 >                 *        SQL statement based on classes, or what?
 >                 **/
427,429c462
< fromClause returns [Class clazz = null] :
<
<         id:Identifier
---
 > fromClause returns [Object[] classes = null] :
431,433c464,551
<             try {
<                 clazz = ClassHelper.getClass(id.getText());
<             } catch (Exception e) {
---
 >             Class firstClass = null;
 >             String firstLabel = null;
 >             Class clazz = null;
 >             String label = null;
 >             ArrayList list = null;
 >             Boolean isAlias = Boolean.FALSE;
 >         }
 >    
 >         (
 >             id:Identifier
 >             (
 >                 {
 >                     try
 >                     {
 >                         firstClass = ClassHelper.getClass(id.getText());
 >                     } catch (Exception e) {
 >                     }
 >                 }
 >             )
 >             (
 >                 lb:Identifier
 >                 (
 >                     {
 >                         isAlias = Boolean.TRUE;
 >                         firstLabel = lb.getText();
 >                     }
 >                 )
 >             )?
 >    
 >             (
 >                 TOK_COMMA
 >                 id2:Identifier
 >                 (
 >                     {
 >                         try
 >                         {
 >                             clazz = ClassHelper.getClass(id2.getText());;
 >                         } catch (Exception e) {
 >                         }
 >                     }
 >                 )
 >                 (
 >                     lb2:Identifier
 >                     (
 >                         {
 >                             label = lb2.getText();
 >                         }
 >                     )
 >                 )?
 >                 {
 >                     //this because don't need create List for single 
class FROM
 >                     if (list == null)
 >                     {
 >                         list = new ArrayList();
 >                         list.add(firstClass);
 >                         if (firstLabel != null)
 >                         {
 >                             list.add(firstLabel);
 >                         }
 >                     }
 >                     list.add(clazz);
 >                     if (label != null)
 >                     {
 >                         list.add(label);
 >                     }
 >                     label = null;
 >                     clazz = null;
 >                 }
 >             )*
 >         )
 >    
 >         {
 >             if (list == null)
 >             {
 >                 //Te last position indicates if had or no Alias
 >                 if (firstLabel == null)
 >                 {
 >                     classes = new Object[] {firstClass,isAlias};
 >                 }
 >                 else
 >                 {
 >                     classes = new Object[] 
{firstClass,firstLabel,isAlias};
 >                 }
 >             }
 >             else
 >             {
 >                 list.add(isAlias);
 >                 classes = (Object[]) list.toArray(new 
Object[list.size()]);
434a553
 >    




Thomas Dudziak wrote:

> Clóvis Wichoski wrote:
>
>> Hi devs,
>>
>> I'm migrating from Castor, then here we use OQLs like this
>>
>> select obj from myapp.Person obj where name="Joseph"
>>
>> but on OJB this isn't supported, then in past I created a wrapper of 
>> OQL for TopLink and created my own grammar based on oql-ojb.g
>> that supports the follow syntax:
>>
>> select obj.name NAME, obj.rule RULE from myapp.Person obj
>> select obj from myapp.Person obj where name="Joseph"
>> select obj from myapp.Person
>>
>> This includes support for Castor like OQLs, works with current ojb 
>> OQLs, and starts OQL to returns Fields from ReportQuery,
>>
>> I think that this is usefull for the OJB OQL support, then my 
>> question is I need to change oql-ojb.g and sends the diffs, to 
>> contribute, or send my changed oql.g to you for explore, and patch?
>
>
> Yes, please send the diff. We were planning to have a look at the OQL 
> grammar anyway in the not-so-far future, as some things are missing yet.
>
> Tom
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>



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


Mime
View raw message