db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker/dirty DirtyTest.java
Date Fri, 16 Jul 2004 00:47:19 GMT
brianm      2004/07/15 17:47:19

  Modified:    src/java/org/apache/ojb/broker/query Criteria.java
                        SelectionCriteria.java ValueCriteria.java
               src/test/org/apache/ojb/broker/dirty DirtyTest.java
  Log:
  Change criteria to return self so that method invocations can be chained
  
  Revision  Changes    Path
  1.47      +86 -44    db-ojb/src/java/org/apache/ojb/broker/query/Criteria.java
  
  Index: Criteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/Criteria.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- Criteria.java	13 Jul 2004 11:37:57 -0000	1.46
  +++ Criteria.java	16 Jul 2004 00:47:19 -0000	1.47
  @@ -257,9 +257,10 @@
        * Set the type
        * @param type OR, AND, NONE
        */
  -    public void setType(int type)
  +    public Criteria setType(int type)
       {
           m_type = type;
  +        return this;
       }
   
       /**
  @@ -275,9 +276,10 @@
        * Set embraced
        * @param embraced true if criteria is to be surrounded by braces
        */
  -    public void setEmbraced(boolean embraced)
  +    public Criteria setEmbraced(boolean embraced)
       {
           m_embraced = embraced;
  +        return this;
       }
   
       /**
  @@ -287,9 +289,10 @@
        * @param  attribute   The field name to be used
        * @param  value       An object representing the value of the field
        */
  -    public void addEqualTo(String attribute, Object value)
  +    public Criteria addEqualTo(String attribute, Object value)
       {
   		addSelectionCriteria(ValueCriteria.buildEqualToCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -300,11 +303,12 @@
        * @param  column   The column name to be used without translation
        * @param  value    An object representing the value of the column
        */
  -    public void addColumnEqualTo(String column, Object value)
  +    public Criteria addColumnEqualTo(String column, Object value)
       {
   		SelectionCriteria c = ValueCriteria.buildEqualToCriteria(column, value, getUserAlias(column));
           c.setTranslateAttribute(false);
           addSelectionCriteria(c);
  +        return this;
       }
   
       /**
  @@ -315,11 +319,12 @@
        * @param  column       The column name to be used without translation
        * @param  fieldName    An object representing the value of the field
        */
  -    public void addColumnEqualToField(String column, Object fieldName)
  +    public Criteria addColumnEqualToField(String column, Object fieldName)
       {
   		SelectionCriteria c = FieldCriteria.buildEqualToCriteria(column, fieldName, getUserAlias(column));
           c.setTranslateAttribute(false);
           addSelectionCriteria(c);
  +        return this;
       }
   
       /**
  @@ -331,10 +336,11 @@
        * @param  attribute   The field name to be used
        * @param  fieldName   The field name to compare with
        */
  -    public void addEqualToField(String attribute, String fieldName)
  +    public Criteria addEqualToField(String attribute, String fieldName)
       {
   		FieldCriteria c = FieldCriteria.buildEqualToCriteria(attribute, fieldName, getUserAlias(attribute));
           addSelectionCriteria(c);
  +        return this;
       }
   
       /**
  @@ -346,10 +352,11 @@
        * @param  attribute   The field name to be used
        * @param  fieldName   The field name to compare with
        */
  -    public void addNotEqualToField(String attribute, String fieldName)
  +    public Criteria addNotEqualToField(String attribute, String fieldName)
       {
   		SelectionCriteria c = FieldCriteria.buildNotEqualToCriteria(attribute, fieldName, getUserAlias(attribute));
           addSelectionCriteria(c);
  +        return this;
       }
   
       /**
  @@ -361,11 +368,12 @@
        * @param  attribute   The field name to be used
        * @param  colName     The name of the column to compare with
        */
  -    public void addNotEqualToColumn(String attribute, String colName)
  +    public Criteria addNotEqualToColumn(String attribute, String colName)
       {
   		FieldCriteria c = FieldCriteria.buildNotEqualToCriteria(attribute, colName, getUserAlias(attribute));
           c.setTranslateField(false);
           addSelectionCriteria(c);
  +        return this;
       }
   
       /**
  @@ -377,11 +385,12 @@
        * @param  attribute   The field name to be used
        * @param  colName     The name of the column to compare with
        */
  -    public void addEqualToColumn(String attribute, String colName)
  +    public Criteria addEqualToColumn(String attribute, String colName)
       {
   		FieldCriteria c = FieldCriteria.buildEqualToCriteria(attribute, colName, getUserAlias(attribute));
           c.setTranslateField(false);
           addSelectionCriteria(c);
  +        return this;
       }
   
       /**
  @@ -391,9 +400,10 @@
        * @param  attribute   The field name to be used
        * @param  value       An object representing the value of the field
        */
  -    public void addGreaterOrEqualThan(Object attribute, Object value)
  +    public Criteria addGreaterOrEqualThan(Object attribute, Object value)
       {
   		addSelectionCriteria(ValueCriteria.buildNotLessCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -403,9 +413,10 @@
        * @param  attribute   The field name to be used
        * @param  value       The field name to compare with
        */
  -    public void addGreaterOrEqualThanField(String attribute, Object value)
  +    public Criteria addGreaterOrEqualThanField(String attribute, Object value)
       {
   		addSelectionCriteria(FieldCriteria.buildNotLessCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -415,9 +426,10 @@
        * @param  attribute   The field name to be used
        * @param  value       An object representing the value of the field
        */
  -    public void addLessOrEqualThan(Object attribute, Object value)
  +    public Criteria addLessOrEqualThan(Object attribute, Object value)
       {
   		addSelectionCriteria(ValueCriteria.buildNotGreaterCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -427,9 +439,10 @@
        * @param  attribute   The field name to be used
        * @param  value       The field name to compare with
        */
  -    public void addLessOrEqualThanField(String attribute, Object value)
  +    public Criteria addLessOrEqualThanField(String attribute, Object value)
       {
   		addSelectionCriteria(FieldCriteria.buildNotGreaterCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -440,9 +453,10 @@
        * @param  attribute   The field name to be used
        * @param  value       An object representing the value of the field
        */
  -    public void addLike(Object attribute, Object value)
  +    public Criteria addLike(Object attribute, Object value)
       {
   		addSelectionCriteria(ValueCriteria.buildLikeCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -453,9 +467,10 @@
        * @param  attribute   The field name to be used
        * @param  value       An object representing the value of the field
        */
  -    public void addNotLike(String attribute, Object value)
  +    public Criteria addNotLike(String attribute, Object value)
       {
   		addSelectionCriteria(ValueCriteria.buildNotLikeCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -465,9 +480,10 @@
        * @param  attribute   The field name to be used
        * @param  value       An object representing the value of the field
        */
  -    public void addNotEqualTo(Object attribute, Object value)
  +    public Criteria addNotEqualTo(Object attribute, Object value)
       {
   		addSelectionCriteria(ValueCriteria.buildNotEqualToCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -477,9 +493,10 @@
        * @param  attribute   The field name to be used
        * @param  value       An object representing the value of the field
        */
  -    public void addGreaterThan(Object attribute, Object value)
  +    public Criteria addGreaterThan(Object attribute, Object value)
       {
   		addSelectionCriteria(ValueCriteria.buildGreaterCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -489,9 +506,10 @@
        * @param  attribute   The field name to be used
        * @param  value       The field to compare with
        */
  -    public void addGreaterThanField(String attribute, Object value)
  +    public Criteria addGreaterThanField(String attribute, Object value)
       {
   		addSelectionCriteria(FieldCriteria.buildGreaterCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -501,9 +519,10 @@
        * @param  attribute   The field name to be used
        * @param  value       An object representing the value of the field
        */
  -    public void addLessThan(Object attribute, Object value)
  +    public Criteria addLessThan(Object attribute, Object value)
       {
   		addSelectionCriteria(ValueCriteria.buildLessCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -513,9 +532,10 @@
        * @param  attribute   The field name to be used
        * @param  value       The field to compare with
        */
  -    public void addLessThanField(String attribute, Object value)
  +    public Criteria addLessThanField(String attribute, Object value)
       {
   		addSelectionCriteria(FieldCriteria.buildLessCriteria(attribute, value, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -615,7 +635,7 @@
        * </pre>
        * @param pc criteria
        */
  -    public void addOrCriteria(Criteria pc)
  +    public Criteria addOrCriteria(Criteria pc)
       {
           if (!m_criteria.isEmpty())
           {
  @@ -629,6 +649,7 @@
               pc.setType(OR);
               addCriteria(pc);
           }
  +        return this;
       }
   
       /**
  @@ -637,9 +658,10 @@
        *
        * @param  attribute   The field name to be used
        */
  -    public void addIsNull(String attribute)
  +    public Criteria addIsNull(String attribute)
       {
   		addSelectionCriteria(ValueCriteria.buildNullCriteria(attribute, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -649,11 +671,12 @@
        *
        * @param  column   The column name to be used without translation
        */
  -    public void addColumnIsNull(String column)
  +    public Criteria addColumnIsNull(String column)
       {
   		SelectionCriteria c = ValueCriteria.buildNullCriteria(column, getUserAlias(column));
           c.setTranslateAttribute(false);
           addSelectionCriteria(c);
  +        return this;
       }
   
       /**
  @@ -662,9 +685,10 @@
        *
        * @param  attribute   The field name to be used
        */
  -    public void addNotNull(String attribute)
  +    public Criteria addNotNull(String attribute)
       {
   		addSelectionCriteria(ValueCriteria.buildNotNullCriteria(attribute, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -674,11 +698,12 @@
        *
        * @param  column   The column name to be used without translation
        */
  -    public void addColumnNotNull(String column)
  +    public Criteria addColumnNotNull(String column)
       {
   		SelectionCriteria c = ValueCriteria.buildNotNullCriteria(column, getUserAlias(column));
           c.setTranslateAttribute(false);
           addSelectionCriteria(c);
  +        return this;
       }
   
       /**
  @@ -689,9 +714,10 @@
        * @param  value1   The lower boundary
        * @param  value2   The upper boundary
        */
  -    public void addBetween(Object attribute, Object value1, Object value2)
  +    public Criteria addBetween(Object attribute, Object value1, Object value2)
       {
   		addSelectionCriteria(ValueCriteria.buildBeweenCriteria(attribute, value1, value2, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -702,9 +728,10 @@
        * @param  value1   The lower boundary
        * @param  value2   The upper boundary
        */
  -    public void addNotBetween(Object attribute, Object value1, Object value2)
  +    public Criteria addNotBetween(Object attribute, Object value1, Object value2)
       {
   		addSelectionCriteria(ValueCriteria.buildNotBeweenCriteria(attribute, value1, value2,
getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -716,7 +743,7 @@
        * @param  attribute   The field name to be used
        * @param  values   The value Collection
        */
  -    public void addIn(String attribute, Collection values)
  +    public Criteria addIn(String attribute, Collection values)
       {
           List list = splitInCriteria(attribute, values, false, IN_LIMIT);
           int index = 0;
  @@ -733,6 +760,7 @@
           }
   
           addAndCriteria(allInCritaria);
  +        return this;
       }
   
       /**
  @@ -745,7 +773,7 @@
        * @param  column   The column name to be used without translation
        * @param  values   The value Collection
        */
  -    public void addColumnIn(String column, Collection values)
  +    public Criteria addColumnIn(String column, Collection values)
       {
           List list = splitInCriteria(column, values, false, IN_LIMIT);
           int index = 0;
  @@ -764,6 +792,7 @@
           }
   
           addAndCriteria(allInCritaria);
  +        return this;
       }
       
       /**
  @@ -775,7 +804,7 @@
        * @param  attribute   The field name to be used
        * @param  values   The value Collection
        */
  -    public void addNotIn(String attribute, Collection values)
  +    public Criteria addNotIn(String attribute, Collection values)
       {
           List list = splitInCriteria(attribute, values, true, IN_LIMIT);
           int index = 0;
  @@ -786,6 +815,7 @@
               inCrit = (InCriteria) list.get(index);
               addSelectionCriteria(inCrit);
           }
  +        return this;
       }
   
       /**
  @@ -793,9 +823,10 @@
        * @param attribute The field name to be used
        * @param subQuery  The subQuery
        */
  -    public void addIn(Object attribute, Query subQuery)
  +    public Criteria addIn(Object attribute, Query subQuery)
       {
   		addSelectionCriteria(ValueCriteria.buildInCriteria(attribute, subQuery, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -803,9 +834,10 @@
        * @param attribute The field name to be used
        * @param subQuery  The subQuery
        */
  -    public void addNotIn(String attribute, Query subQuery)
  +    public Criteria addNotIn(String attribute, Query subQuery)
       {
   		addSelectionCriteria(ValueCriteria.buildNotInCriteria(attribute, subQuery, getUserAlias(attribute)));
  +        return this;
       }
   
       /**
  @@ -814,9 +846,10 @@
        *
        * @param  anSqlStatment   The free form SQL-Statement
        */
  -    public void addSql(String anSqlStatment)
  +    public Criteria addSql(String anSqlStatment)
       {
           addSelectionCriteria(new SqlCriteria(anSqlStatment));
  +        return this;
       }
   
       /**
  @@ -824,7 +857,7 @@
        *
        * @param  pc criteria
        */
  -    public void addAndCriteria(Criteria pc)
  +    public Criteria addAndCriteria(Criteria pc)
       {
           // by combining a second criteria by 'AND' the existing criteria needs to be enclosed
           // in parenthesis
  @@ -841,6 +874,7 @@
               pc.setType(AND);
               addCriteria(pc);
           }
  +        return this;
       }
   
       /**
  @@ -848,9 +882,10 @@
        *
        * @param subQuery sub-query
        */
  -    public void addExists(Query subQuery)
  +    public Criteria addExists(Query subQuery)
       {
           addSelectionCriteria(new ExistsCriteria(subQuery, false));
  +        return this;
       }
   
       /**
  @@ -858,9 +893,10 @@
        *
        * @param subQuery sub-query
        */
  -    public void addNotExists(Query subQuery)
  +    public Criteria addNotExists(Query subQuery)
       {
           addSelectionCriteria(new ExistsCriteria(subQuery, true));
  +        return this;
       }
   
       /**
  @@ -999,7 +1035,7 @@
   	/**
   	 * Retrieves or if necessary, creates a user alias to be used
   	 * by a child criteria 
  -	 * @param userAlias The alias to set
  +	 * @param attribute The alias to set
   	 */
   	private UserAlias getUserAlias(Object attribute)
   	{
  @@ -1028,7 +1064,7 @@
   	 * Sets the alias. Empty String is regarded as null.
   	 * @param alias The alias to set
   	 */
  -	public void setAlias(String alias)
  +	public Criteria setAlias(String alias)
   	{
   		if (alias == null || alias.trim().equals(""))
   		{
  @@ -1047,6 +1083,7 @@
   				((SelectionCriteria) m_criteria.elementAt(i)).setAlias(m_alias);
   			}
   		}
  +        return this;
   	}
   
   	/**
  @@ -1054,7 +1091,7 @@
   	 * @param alias The alias to set
   	 * @param aliasPath The path segment(s) to which the alias applies
   	 */
  -	public void setAlias(String alias, String aliasPath)
  +	public Criteria setAlias(String alias, String aliasPath)
   	{
   		if (alias == null || alias.trim().equals(""))
   		{
  @@ -1074,13 +1111,14 @@
   				((SelectionCriteria) m_criteria.elementAt(i)).setAlias(m_alias, aliasPath);
   			}
   		}
  +        return this;
   	}
   
   	/**
   	 * Sets the alias using a userAlias object. 
   	 * @param userAlias The alias to set
   	 */
  -	public void setAlias(UserAlias userAlias)
  +	public Criteria setAlias(UserAlias userAlias)
   	{
   		m_alias = userAlias.getName();
   
  @@ -1092,6 +1130,7 @@
   				((SelectionCriteria) m_criteria.elementAt(i)).setAlias(userAlias);
   			}
   		}
  +        return this;
   	}
   
   
  @@ -1162,9 +1201,10 @@
        * Flags the whole Criteria as negative.
        * @param negative The negative to set.
        */
  -    public void setNegative(boolean negative)
  +    public Criteria setNegative(boolean negative)
       {
           m_negative = negative;
  +        return this;
       }
   
   	/**
  @@ -1177,7 +1217,7 @@
   	 * @param aClass the Class ie: CdArticle
   	 * @see org.apache.ojb.broker.QueryTest#testInversePathExpression()
   	 */
  -	public void addPathClass(String aPath, Class aClass)
  +	public Criteria addPathClass(String aPath, Class aClass)
   	{
   		Object pathClasses = m_pathClasses.get(aPath);
   		if(pathClasses == null)
  @@ -1190,6 +1230,7 @@
   			hints.add(aClass);
   			m_pathClasses.put(aPath, hints);
   		}
  +        return this;
   	}
   
   	/**
  @@ -1204,11 +1245,12 @@
   	 * @see org.apache.ojb.broker.QueryTest#testInversePathExpression()
   	 * @see #addPathClass
   	 */
  -	public void setPathClass(String aPath, Class aClass)
  +	public Criteria setPathClass(String aPath, Class aClass)
   	{
   		List pathClasses = new ArrayList(1);
   		pathClasses.add(aClass);
   		m_pathClasses.put(aPath, pathClasses);
  +        return this;
   	}
   
   	/**
  
  
  
  1.18      +2 -6      db-ojb/src/java/org/apache/ojb/broker/query/SelectionCriteria.java
  
  Index: SelectionCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/SelectionCriteria.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SelectionCriteria.java	22 May 2004 08:37:23 -0000	1.17
  +++ SelectionCriteria.java	16 Jul 2004 00:47:19 -0000	1.18
  @@ -71,7 +71,6 @@
   	 *
   	 * @param anAttribute  column- or fieldName or a Query
   	 * @param aValue  the value to compare with
  -	 * @param negative  criteria is negated (ie NOT LIKE instead of LIKE)
   	 * @param alias  use alias to link anAttribute to
   	 */
   	SelectionCriteria(Object anAttribute, Object aValue, String alias)
  @@ -93,9 +92,7 @@
   	 *
   	 * @param anAttribute  column- or fieldName or a Query
   	 * @param aValue  the value to compare with
  -	 * @param negative  criteria is negated (ie NOT LIKE instead of LIKE)
  -	 * @param userAlias  userAlias to link anAttribute to
  -	 * @param dummy used so that subclass constructors calling with null
  +	 * @param aUserAlias  userAlias to link anAttribute to
   	 * parameters have an unambiguous signature
   	 */
   	SelectionCriteria(Object anAttribute, Object aValue, UserAlias aUserAlias)
  @@ -307,7 +304,6 @@
   	 *
   	 * @param aPath the path segment ie: allArticlesInGroup
   	 * @return a List o Class objects to be used in SqlStatment
  -	 * @see #addPathClass
   	 * @see org.apache.ojb.broker.QueryTest#testInversePathExpression()
   	 */
   	public List getClassesForPath(String aPath)
  
  
  
  1.9       +2 -2      db-ojb/src/java/org/apache/ojb/broker/query/ValueCriteria.java
  
  Index: ValueCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/ValueCriteria.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ValueCriteria.java	22 May 2004 08:37:23 -0000	1.8
  +++ ValueCriteria.java	16 Jul 2004 00:47:19 -0000	1.9
  @@ -173,7 +173,7 @@
   	 * @param anAttribute  column- or fieldName
   	 * @param aValue  the value to compare with
   	 * @param aClause the SQL compare clause (ie LIKE, = , IS NULL)
  -	 * @param aUserAliass userAlias to link anAttribute to
  +	 * @param aUserAlias userAlias to link anAttribute to
   	 */
   	ValueCriteria(Object anAttribute, Object aValue, String aClause, UserAlias aUserAlias)
   	{
  
  
  
  1.4       +8 -2      db-ojb/src/test/org/apache/ojb/broker/dirty/DirtyTest.java
  
  Index: DirtyTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/dirty/DirtyTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DirtyTest.java	8 Jul 2004 01:58:34 -0000	1.3
  +++ DirtyTest.java	16 Jul 2004 00:47:19 -0000	1.4
  @@ -4,14 +4,20 @@
   import org.apache.ojb.broker.Article;
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.InterfaceArticle;
  +import org.apache.ojb.broker.PersistenceAwarePerson;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.Person;
   import org.apache.ojb.broker.ProductGroupWithCollectionProxy;
  -import org.apache.ojb.broker.PersistenceAwarePerson;
  +import org.apache.ojb.broker.Role;
  +import org.apache.ojb.broker.Project;
  +import org.apache.ojb.broker.ProductGroup;
  +import org.apache.ojb.broker.ProductGroupWithRemovalAwareCollection;
  +import org.apache.ojb.broker.BookArticle;
   import org.apache.ojb.broker.core.proxy.CollectionProxy;
   import org.apache.ojb.broker.core.proxy.ProxyHelper;
   
   import java.util.List;
  +import java.util.HashSet;
   
   public class DirtyTest extends TestCase
   {
  @@ -79,7 +85,7 @@
           pg = (ProductGroupWithCollectionProxy) pb.getObjectByIdentity(new Identity(pg,
pb));
           List articles = pg.getAllArticlesInGroup();
           assertTrue(ProxyHelper.isCollectionProxy(articles));
  -        CollectionProxy proxy = (CollectionProxy)articles;
  +        CollectionProxy proxy = (CollectionProxy) articles;
           assertFalse(proxy.isLoaded());
           a = (InterfaceArticle) articles.get(0);
           a.setArticleName("new name");
  
  
  

---------------------------------------------------------------------
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