You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2003/08/04 08:24:31 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/odmg/oql oql-ojb.g OQLParser.java

arminw      2003/08/03 23:24:31

  Modified:    src/java/org/apache/ojb/odmg/oql oql-ojb.g OQLParser.java
  Log:
  don't use PBF.defaultPersistenceBroker call,
  it's not guaranteed that we have one.
  Use MetadataManager instead.
  
  Revision  Changes    Path
  1.20      +24 -26    db-ojb/src/java/org/apache/ojb/odmg/oql/oql-ojb.g
  
  Index: oql-ojb.g
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/oql/oql-ojb.g,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- oql-ojb.g	4 Aug 2003 00:03:02 -0000	1.19
  +++ oql-ojb.g	4 Aug 2003 06:24:31 -0000	1.20
  @@ -335,27 +335,27 @@
       ;
   
   
  -selectQuery returns [QueryByCriteria query = null] : 
  +selectQuery returns [QueryByCriteria query = null] :
   
  -        { 
  -            Class clazz = null; 
  -            Criteria criteria = new Criteria(); 
  -            String[] projectionAttrs; 
  -            boolean distinct = false; 
  -        } 
  -
  -        "select" 
  -
  -        ( 
  -            options { 
  -                warnWhenFollowAmbig = false; 
  -            } : 
  -
  -            "distinct" 
  -            { 
  -                 distinct = true; 
  -            } 
  -        )? 
  +        {
  +            Class clazz = null;
  +            Criteria criteria = new Criteria();
  +            String[] projectionAttrs;
  +            boolean distinct = false;
  +        }
  +
  +        "select"
  +
  +        (
  +            options {
  +                warnWhenFollowAmbig = false;
  +            } :
  +
  +            "distinct"
  +            {
  +                 distinct = true;
  +            }
  +        )?
   
           projectionAttrs = projectionAttributes
   
  @@ -370,9 +370,7 @@
                   }
                   else
                   {
  -                	PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -                    ClassDescriptor cld = broker.getClassDescriptor(clazz);
  -                    broker.close();
  +                    ClassDescriptor cld = MetadataManager.getInstance().getRepository().getDescriptorFor(clazz);
                       for (int i = 0; i < projectionAttrs.length; i++)
                       {
                           projectionAttrs[i] = projectionAttrs[i].substring(projectionAttrs[i].indexOf('.') + 1);
  @@ -398,9 +396,9 @@
           }
           ( "order" "by" orderClause[query] )?
   
  -        ( "prefetch" prefetchClause[query] )? 
  +        ( "prefetch" prefetchClause[query] )?
   
  -    ; 
  +    ;
   
   
   existsQuery returns [Query query = null] :
  @@ -637,7 +635,7 @@
           }
       ;
   
  -    
  +
   
   betweenExpr[Criteria criteria] :
   
  
  
  
  1.17      +151 -153  db-ojb/src/java/org/apache/ojb/odmg/oql/OQLParser.java
  
  Index: OQLParser.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/oql/OQLParser.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- OQLParser.java	4 Aug 2003 06:06:25 -0000	1.16
  +++ OQLParser.java	4 Aug 2003 06:24:31 -0000	1.17
  @@ -63,8 +63,8 @@
   
   	public final Query  buildQuery() throws RecognitionException, TokenStreamException {
   		Query query = null;
  -		
  -		
  +
  +
   		try {      // for error handling
   			query=selectQuery();
   			{
  @@ -76,7 +76,7 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
   		}
   		catch (RecognitionException ex) {
  @@ -86,32 +86,32 @@
   		}
   		return query;
   	}
  -	
  +
   	public final QueryByCriteria  selectQuery() throws RecognitionException, TokenStreamException {
   		QueryByCriteria query = null;
  -		
  -		
  +
  +
   		try {      // for error handling
  -			
  -			Class clazz = null; 
  -			Criteria criteria = new Criteria(); 
  -			String[] projectionAttrs; 
  -			boolean distinct = false; 
  -			
  +
  +			Class clazz = null;
  +			Criteria criteria = new Criteria();
  +			String[] projectionAttrs;
  +			boolean distinct = false;
  +
   			match(LITERAL_select);
   			{
   			if ((LA(1)==LITERAL_distinct)) {
   				match(LITERAL_distinct);
  -				
  -				distinct = true; 
  -				
  +
  +				distinct = true;
  +
   			}
   			else if ((LA(1)==TOK_STAR||LA(1)==Identifier)) {
   			}
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
   			projectionAttrs=projectionAttributes();
   			match(LITERAL_from);
  @@ -126,9 +126,9 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
  -			
  +
   			if (clazz != null)
   			{
   			if (projectionAttrs[0].indexOf('.') < 0)
  @@ -137,17 +137,15 @@
   			}
   			else
   			{
  -				PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -			ClassDescriptor cld = broker.getClassDescriptor(clazz);
  -			broker.close();
  +            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 =
  @@ -162,7 +160,7 @@
   			}
   			}
   			}
  -			
  +
   			{
   			if ((LA(1)==LITERAL_order)) {
   				match(LITERAL_order);
  @@ -174,7 +172,7 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
   			{
   			if ((LA(1)==LITERAL_prefetch)) {
  @@ -186,7 +184,7 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
   		}
   		catch (RecognitionException ex) {
  @@ -196,26 +194,26 @@
   		}
   		return query;
   	}
  -	
  +
   	public final String[]  projectionAttributes() throws RecognitionException, TokenStreamException {
   		String[] projectionAttrs = null;
  -		
  +
   		Token  id = null;
   		Token  id1 = null;
  -		
  +
   		try {      // for error handling
  -			
  +
   			String first = null;
   			ArrayList list = null;
  -			
  +
   			{
   			if ((LA(1)==Identifier)) {
   				id = LT(1);
   				match(Identifier);
   				{
  -				
  +
   				first = id.getText();
  -				
  +
   				}
   				{
   				_loop79:
  @@ -225,20 +223,20 @@
   						id1 = LT(1);
   						match(Identifier);
   						{
  -						
  +
   						if (list == null)
   						{
   						list = new ArrayList();
   						list.add(first);
   						}
   						list.add(id1.getText());
  -						
  +
   						}
   					}
   					else {
   						break _loop79;
   					}
  -					
  +
   				} while (true);
   				}
   			}
  @@ -248,9 +246,9 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
  -			
  +
   			if (list == null)
   			{
   			projectionAttrs = new String[] {first};
  @@ -259,8 +257,8 @@
   			{
   			projectionAttrs = (String[]) list.toArray(new String[list.size()]);
   			}
  -			
  -			
  +
  +
   		}
   		catch (RecognitionException ex) {
   			reportError(ex);
  @@ -269,22 +267,22 @@
   		}
   		return projectionAttrs;
   	}
  -	
  +
   	public final Class  fromClause() throws RecognitionException, TokenStreamException {
   		Class clazz = null;
  -		
  +
   		Token  id = null;
  -		
  +
   		try {      // for error handling
   			id = LT(1);
   			match(Identifier);
  -			
  +
   			try {
   			clazz = Class.forName(id.getText(), true,
   			Thread.currentThread().getContextClassLoader());
   			} catch (Exception e) {
   			}
  -			
  +
   		}
   		catch (RecognitionException ex) {
   			reportError(ex);
  @@ -293,12 +291,12 @@
   		}
   		return clazz;
   	}
  -	
  +
   	public final void whereClause(
   		Criteria criteria
   	) throws RecognitionException, TokenStreamException {
  -		
  -		
  +
  +
   		try {      // for error handling
   			orExpr(criteria);
   		}
  @@ -308,12 +306,12 @@
   			consumeUntil(_tokenSet_6);
   		}
   	}
  -	
  +
   	public final void orderClause(
   		QueryByCriteria query
   	) throws RecognitionException, TokenStreamException {
  -		
  -		
  +
  +
   		try {      // for error handling
   			sortCriterion(query);
   			{
  @@ -326,7 +324,7 @@
   				else {
   					break _loop82;
   				}
  -				
  +
   			} while (true);
   			}
   		}
  @@ -336,12 +334,12 @@
   			consumeUntil(_tokenSet_2);
   		}
   	}
  -	
  +
   	public final void prefetchClause(
   		QueryByCriteria query
   	) throws RecognitionException, TokenStreamException {
  -		
  -		
  +
  +
   		try {      // for error handling
   			prefetchCriterion(query);
   			{
  @@ -354,7 +352,7 @@
   				else {
   					break _loop88;
   				}
  -				
  +
   			} while (true);
   			}
   		}
  @@ -364,16 +362,16 @@
   			consumeUntil(_tokenSet_3);
   		}
   	}
  -	
  +
   	public final Query  existsQuery() throws RecognitionException, TokenStreamException {
   		Query query = null;
  -		
  -		
  +
  +
   		try {      // for error handling
  -			
  +
   			Class clazz = null;
   			Criteria criteria = new Criteria();
  -			
  +
   			match(LITERAL_exists);
   			projectionAttributes();
   			match(LITERAL_in);
  @@ -388,13 +386,13 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
  -			
  +
   			if (clazz != null) {
   			query = QueryFactory.newQuery(clazz, criteria);
   			}
  -					
  +
   		}
   		catch (RecognitionException ex) {
   			reportError(ex);
  @@ -403,12 +401,12 @@
   		}
   		return query;
   	}
  -	
  +
   	public final void orExpr(
   		Criteria criteria
   	) throws RecognitionException, TokenStreamException {
  -		
  -		
  +
  +
   		try {      // for error handling
   			andExpr(criteria);
   			{
  @@ -423,7 +421,7 @@
   				else {
   					break _loop92;
   				}
  -				
  +
   			} while (true);
   			}
   		}
  @@ -433,13 +431,13 @@
   			consumeUntil(_tokenSet_6);
   		}
   	}
  -	
  +
   	public final void sortCriterion(
   		QueryByCriteria query
   	) throws RecognitionException, TokenStreamException {
  -		
  +
   		Token  id = null;
  -		
  +
   		try {      // for error handling
   			boolean descending = false;
   			id = LT(1);
  @@ -458,7 +456,7 @@
   				else {
   					throw new NoViableAltException(LT(1), getFilename());
   				}
  -				
  +
   				}
   			}
   			else if ((_tokenSet_9.member(LA(1)))) {
  @@ -466,15 +464,15 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
  -			
  +
   			if (descending) {
   			query.addOrderByDescending(id.getText());
   			} else {
   			query.addOrderByAscending(id.getText());
   			}
  -			
  +
   		}
   		catch (RecognitionException ex) {
   			reportError(ex);
  @@ -482,19 +480,19 @@
   			consumeUntil(_tokenSet_9);
   		}
   	}
  -	
  +
   	public final void prefetchCriterion(
   		QueryByCriteria query
   	) throws RecognitionException, TokenStreamException {
  -		
  +
   		Token  id = null;
  -		
  +
   		try {      // for error handling
   			id = LT(1);
   			match(Identifier);
  -			
  +
   			query.addPrefetchedRelationship(id.getText());
  -			
  +
   		}
   		catch (RecognitionException ex) {
   			reportError(ex);
  @@ -502,12 +500,12 @@
   			consumeUntil(_tokenSet_10);
   		}
   	}
  -	
  +
   	public final void andExpr(
   		Criteria criteria
   	) throws RecognitionException, TokenStreamException {
  -		
  -		
  +
  +
   		try {      // for error handling
   			quantifierExpr(criteria);
   			{
  @@ -522,7 +520,7 @@
   				else {
   					break _loop95;
   				}
  -				
  +
   			} while (true);
   			}
   		}
  @@ -532,12 +530,12 @@
   			consumeUntil(_tokenSet_6);
   		}
   	}
  -	
  +
   	public final void quantifierExpr(
   		Criteria criteria
   	) throws RecognitionException, TokenStreamException {
  -		
  -		
  +
  +
   		try {      // for error handling
   			switch ( LA(1)) {
   			case TOK_LPAREN:
  @@ -583,17 +581,17 @@
   			consumeUntil(_tokenSet_6);
   		}
   	}
  -	
  +
   	public final void equalityExpr(
   		Criteria criteria
   	) throws RecognitionException, TokenStreamException {
  -		
  +
   		Token  id = null;
  -		
  +
   		try {      // for error handling
  -			
  +
   				Object value = null;
  -			
  +
   			id = LT(1);
   			match(Identifier);
   			{
  @@ -614,7 +612,7 @@
   				else {
   					throw new NoViableAltException(LT(1), getFilename());
   				}
  -				
  +
   				}
   				break;
   			}
  @@ -633,7 +631,7 @@
   				else {
   					throw new NoViableAltException(LT(1), getFilename());
   				}
  -				
  +
   				}
   				break;
   			}
  @@ -652,7 +650,7 @@
   				else {
   					throw new NoViableAltException(LT(1), getFilename());
   				}
  -				
  +
   				}
   				break;
   			}
  @@ -698,18 +696,18 @@
   			consumeUntil(_tokenSet_6);
   		}
   	}
  -	
  +
   	public final void likeExpr(
   		Criteria criteria
   	) throws RecognitionException, TokenStreamException {
  -		
  +
   		Token  id = null;
  -		
  +
   		try {      // for error handling
  -			
  +
   			boolean negative = false;
   			Object value = null;
  -			
  +
   			id = LT(1);
   			match(Identifier);
   			{
  @@ -722,17 +720,17 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
   			match(LITERAL_like);
   			value=literal();
  -			
  +
   			if (negative) {
   			criteria.addNotLike(id.getText(), value);
   			} else {
   			criteria.addLike(id.getText(), value);
   			}
  -			
  +
   		}
   		catch (RecognitionException ex) {
   			reportError(ex);
  @@ -740,13 +738,13 @@
   			consumeUntil(_tokenSet_6);
   		}
   	}
  -	
  +
   	public final void undefinedExpr(
   		Criteria criteria
   	) throws RecognitionException, TokenStreamException {
  -		
  +
   		Token  id = null;
  -		
  +
   		try {      // for error handling
   			boolean negative = false;
   			{
  @@ -761,19 +759,19 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
   			match(TOK_LPAREN);
   			id = LT(1);
   			match(Identifier);
   			match(TOK_RPAREN);
  -			
  +
   			if (negative) {
   			criteria.addNotNull(id.getText());
   			} else {
   			criteria.addIsNull(id.getText());
   			}
  -			
  +
   		}
   		catch (RecognitionException ex) {
   			reportError(ex);
  @@ -781,19 +779,19 @@
   			consumeUntil(_tokenSet_6);
   		}
   	}
  -	
  +
   	public final void betweenExpr(
   		Criteria criteria
   	) throws RecognitionException, TokenStreamException {
  -		
  +
   		Token  id = null;
  -		
  +
   		try {      // for error handling
  -			
  +
   			boolean negative = false;
   			Object lower = null;
   			Object upper = null;
  -			
  +
   			id = LT(1);
   			match(Identifier);
   			{
  @@ -806,19 +804,19 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
   			match(LITERAL_between);
   			lower=literal();
   			match(LITERAL_and);
   			upper=literal();
  -			
  +
   			if (negative) {
   			criteria.addNotBetween(id.getText(), lower, upper);
   			} else {
   			criteria.addBetween(id.getText(), lower, upper);
   			}
  -			
  +
   		}
   		catch (RecognitionException ex) {
   			reportError(ex);
  @@ -826,18 +824,18 @@
   			consumeUntil(_tokenSet_6);
   		}
   	}
  -	
  +
   	public final void inExpr(
   		Criteria criteria
   	) throws RecognitionException, TokenStreamException {
  -		
  +
   		Token  id = null;
  -		
  +
   		try {      // for error handling
  -			
  +
   				 boolean negative = false;
   				 Collection coll;
  -			
  +
   			id = LT(1);
   			match(Identifier);
   			{
  @@ -850,7 +848,7 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
   			match(LITERAL_in);
   			{
  @@ -862,16 +860,16 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
   			coll=argList();
  -			
  +
   			if (negative) {
   			criteria.addNotIn(id.getText(), coll);
   			} else {
   			criteria.addIn(id.getText(), coll);
   			}
  -			
  +
   		}
   		catch (RecognitionException ex) {
   			reportError(ex);
  @@ -879,17 +877,17 @@
   			consumeUntil(_tokenSet_6);
   		}
   	}
  -	
  +
   	public final void existsExpr(
   		Criteria criteria
   	) throws RecognitionException, TokenStreamException {
  -		
  -		
  +
  +
   		try {      // for error handling
  -			
  +
   			Query subQuery = null;
   			boolean negative = false;
  -			
  +
   			{
   			if ((LA(1)==LITERAL_not)) {
   				match(LITERAL_not);
  @@ -900,7 +898,7 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
   			{
   			if ((LA(1)==LITERAL_exists) && (LA(2)==TOK_LPAREN)) {
  @@ -915,15 +913,15 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
  -			
  +
   			if (negative) {
   			criteria.addNotExists(subQuery);
   			} else {
   			criteria.addExists(subQuery);
   			}
  -			
  +
   		}
   		catch (RecognitionException ex) {
   			reportError(ex);
  @@ -931,10 +929,10 @@
   			consumeUntil(_tokenSet_6);
   		}
   	}
  -	
  +
   	public final Object  literal() throws RecognitionException, TokenStreamException {
   		Object value = null;
  -		
  +
   		Token  tokInt = null;
   		Token  tokADbl = null;
   		Token  tokEDbl = null;
  @@ -943,7 +941,7 @@
   		Token  tokDate = null;
   		Token  tokTime = null;
   		Token  tokTs = null;
  -		
  +
   		try {      // for error handling
   			switch ( LA(1)) {
   			case TOK_DOLLAR:
  @@ -969,7 +967,7 @@
   			{
   				tokInt = LT(1);
   				match(TOK_UNSIGNED_INTEGER);
  -				
  +
   					try
   					{
   						value = Integer.valueOf(tokInt.getText());
  @@ -978,7 +976,7 @@
   					{
   						value = Long.valueOf(tokInt.getText());
   					}
  -				
  +
   				break;
   			}
   			case TOK_APPROXIMATE_NUMERIC_LITERAL:
  @@ -1046,16 +1044,16 @@
   		}
   		return value;
   	}
  -	
  +
   	public final Collection  argList() throws RecognitionException, TokenStreamException {
   		Collection coll = null;
  -		
  -		
  +
  +
   		try {      // for error handling
  -			
  +
   					Collection temp = new Vector();
   				    Object val;
  -				
  +
   			match(TOK_LPAREN);
   			{
   			if ((_tokenSet_14.member(LA(1)))) {
  @@ -1072,7 +1070,7 @@
   					else {
   						break _loop119;
   					}
  -					
  +
   				} while (true);
   				}
   			}
  @@ -1081,12 +1079,12 @@
   			else {
   				throw new NoViableAltException(LT(1), getFilename());
   			}
  -			
  +
   			}
   			match(TOK_RPAREN);
  -			
  +
   					if (!temp.isEmpty()) {coll = temp;}
  -					
  +
   		}
   		catch (RecognitionException ex) {
   			reportError(ex);
  @@ -1095,8 +1093,8 @@
   		}
   		return coll;
   	}
  -	
  -	
  +
  +
   	public static final String[] _tokenNames = {
   		"<0>",
   		"EOF",
  @@ -1162,7 +1160,7 @@
   		"\"time\"",
   		"\"timestamp\""
   	};
  -	
  +
   	private static final long _tokenSet_0_data_[] = { 2L, 0L };
   	public static final BitSet _tokenSet_0 = new BitSet(_tokenSet_0_data_);
   	private static final long _tokenSet_1_data_[] = { 21990232555666L, 0L };
  @@ -1195,5 +1193,5 @@
   	public static final BitSet _tokenSet_14 = new BitSet(_tokenSet_14_data_);
   	private static final long _tokenSet_15_data_[] = { 1710840092819666L, 0L };
   	public static final BitSet _tokenSet_15 = new BitSet(_tokenSet_15_data_);
  -	
  +
   	}
  
  
  

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