db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/query QueryByCriteria.java Criteria.java SelectionCriteria.java
Date Mon, 24 Mar 2003 20:09:55 GMT
brj         2003/03/24 12:09:53

  Modified:    src/java/org/apache/ojb/broker/query QueryByCriteria.java
                        Criteria.java SelectionCriteria.java
  Log:
  support access to query from selection criteria
  
  Revision  Changes    Path
  1.11      +12 -3     db-ojb/src/java/org/apache/ojb/broker/query/QueryByCriteria.java
  
  Index: QueryByCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/QueryByCriteria.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- QueryByCriteria.java	15 Mar 2003 16:22:11 -0000	1.10
  +++ QueryByCriteria.java	24 Mar 2003 20:09:51 -0000	1.11
  @@ -105,8 +105,9 @@
       {
           super (targetClass);
           
  -        m_criteria = whereCriteria;
  -        m_havingCriteria = havingCriteria;
  +        setCriteria(whereCriteria);
  +        setHavingCriteria(havingCriteria);
  +
           m_distinct = distinct;
           m_pathClasses = new HashMap();
           m_groupby = new ArrayList();
  @@ -286,6 +287,10 @@
   	public void setCriteria(Criteria criteria)
   	{
   		m_criteria = criteria;
  +        if (m_criteria != null)
  +        {
  +            m_criteria.setQuery(this);
  +        }
   	}
   
   	/**
  @@ -295,6 +300,10 @@
   	public void setHavingCriteria(Criteria havingCriteria)
   	{
   		m_havingCriteria = havingCriteria;
  +        if (m_havingCriteria != null)
  +        {
  +            m_havingCriteria.setQuery(this);
  +        }
   	}
   
       /**
  
  
  
  1.27      +107 -52   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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- Criteria.java	20 Mar 2003 20:48:20 -0000	1.26
  +++ Criteria.java	24 Mar 2003 20:09:52 -0000	1.27
  @@ -87,9 +87,9 @@
   	public final static int OR = 0;
   	public final static int AND = 1;
   	public final static int NONE = 9;
  -	private Vector criteria;
  -	private int type;
  -	private boolean embraced;
  +	private Vector m_criteria;
  +	private int m_type;
  +	private boolean m_embraced;
   
   	// holding CriteriaFields for orderBy and groupBy
   	private List orderby = null;
  @@ -100,18 +100,21 @@
   	private String m_alias = null;
   
   	protected static final int IN_LIMIT = getSqlInLimit();
  +    
  +    private QueryByCriteria m_query;
  +    private Criteria m_parentCriteria;
   
   	/**
   	 * Constructor declaration
   	 */
   	public Criteria()
   	{
  -		criteria = new Vector();
  +		m_criteria = new Vector();
   		groupby = new ArrayList();
   		orderby = new ArrayList();
   		prefetchedRelationships = new ArrayList();
  -		type = NONE;
  -		embraced = false;
  +		m_type = NONE;
  +		m_embraced = false;
   	}
   
   	/**
  @@ -121,7 +124,7 @@
   	public Criteria(SelectionCriteria aSelectionCriteria)
   	{
   		this();
  -		criteria.addElement(aSelectionCriteria);
  +		m_criteria.addElement(aSelectionCriteria);
   	}
   
   	/**
  @@ -131,7 +134,7 @@
   	{
   		Criteria copy = new Criteria();
   
  -		copy.criteria = this.criteria;
  +		copy.m_criteria = this.m_criteria;
   		if (includeGroupBy)
   		{
   			copy.groupby = this.groupby;
  @@ -148,6 +151,18 @@
   		return copy;
   	}
   
  +    protected void addSelectionCriteria(SelectionCriteria selectionCrit)
  +    {
  +        selectionCrit.setCriteria(this);
  +        m_criteria.addElement(selectionCrit);
  +    }
  +
  +    protected void addCriteria(Criteria crit)
  +    {
  +        crit.setParentCriteria(this);
  +        m_criteria.addElement(crit);
  +    }
  +    
   	/**
   	 * Answer a List of InCriteria based on values, each InCriteria
   	 * contains only inLimit values
  @@ -199,7 +214,7 @@
   	 */
   	protected Vector getCriteria()
   	{
  -		return criteria;
  +		return m_criteria;
   	}
   
   	/**
  @@ -208,7 +223,7 @@
   	 */
   	public int getType()
   	{
  -		return type;
  +		return m_type;
   	}
   
   	/**
  @@ -217,7 +232,7 @@
   	 */
   	public void setType(int type)
   	{
  -		this.type = type;
  +		this.m_type = type;
   	}
   
   	/**
  @@ -226,7 +241,7 @@
   	 */
   	public boolean isEmbraced()
   	{
  -		return embraced;
  +		return m_embraced;
   	}
   
   	/**
  @@ -235,7 +250,7 @@
   	 */
   	public void setEmbraced(boolean embraced)
   	{
  -		this.embraced = embraced;
  +		this.m_embraced = embraced;
   	}
   
   	/**
  @@ -247,7 +262,7 @@
   	 */
   	public void addEqualTo(String attribute, Object value)
   	{
  -		criteria.addElement(new EqualToCriteria(attribute, value, false, getAlias()));
  +		addSelectionCriteria(new EqualToCriteria(attribute, value, false, getAlias()));
   	}
   
       /**
  @@ -262,7 +277,7 @@
       {
           SelectionCriteria c = new EqualToCriteria(column, value, false, getAlias());
           c.setTranslateAttribute(false);      
  -        criteria.addElement(c);
  +        addSelectionCriteria(c);
       }
   
       /**
  @@ -277,7 +292,7 @@
       {
           SelectionCriteria c = new EqualToFieldCriteria(column, fieldName, false, getAlias());
           c.setTranslateAttribute(false);      
  -        criteria.addElement(c);
  +        addSelectionCriteria(c);
       }
   
   	/**
  @@ -335,7 +350,7 @@
   	public void addEqualToField(String attribute, String fieldName)
   	{
   		SelectionCriteria c = new EqualToFieldCriteria(attribute, fieldName, false, getAlias());
  -		criteria.addElement(c);
  +		addSelectionCriteria(c);
   	}
   
   	/**
  @@ -350,7 +365,7 @@
   	public void addNotEqualToField(String attribute, String fieldName)
   	{
   		SelectionCriteria c = new EqualToFieldCriteria(attribute, fieldName, true, getAlias());
  -		criteria.addElement(c);
  +		addSelectionCriteria(c);
   	}
   
   	/**
  @@ -366,7 +381,7 @@
   	{
           FieldCriteria c = new EqualToFieldCriteria(attribute, colName, true, getAlias());
           c.setTranslateField(false);
  -		criteria.addElement(c);
  +		addSelectionCriteria(c);
   	}
   
   	/**
  @@ -382,7 +397,7 @@
   	{
   		FieldCriteria c = new EqualToFieldCriteria(attribute, colName, false, getAlias());
           c.setTranslateField(false);
  -		criteria.addElement(c);
  +		addSelectionCriteria(c);
   	}
   
   	/**
  @@ -394,7 +409,7 @@
   	 */
   	public void addGreaterOrEqualThan(String attribute, Object value)
   	{
  -		criteria.addElement(new LessThanCriteria(attribute, value, true, getAlias()));
  +		addSelectionCriteria(new LessThanCriteria(attribute, value, true, getAlias()));
   	}
   
   	/**
  @@ -406,7 +421,7 @@
   	 */
   	public void addGreaterOrEqualThanField(String attribute, Object value)
   	{
  -		criteria.addElement(new LessThanFieldCriteria(attribute, value, true, getAlias()));
  +		addSelectionCriteria(new LessThanFieldCriteria(attribute, value, true, getAlias()));
   	}
   
   	/**
  @@ -418,7 +433,7 @@
   	 */
   	public void addLessOrEqualThan(String attribute, Object value)
   	{
  -		criteria.addElement(new GreaterThanCriteria(attribute, value, true, getAlias()));
  +		addSelectionCriteria(new GreaterThanCriteria(attribute, value, true, getAlias()));
   	}
   
   	/**
  @@ -430,7 +445,7 @@
   	 */
   	public void addLessOrEqualThanField(String attribute, Object value)
   	{
  -		criteria.addElement(new GreaterThanFieldCriteria(attribute, value, true, getAlias()));
  +		addSelectionCriteria(new GreaterThanFieldCriteria(attribute, value, true, getAlias()));
   	}
   
   	/**
  @@ -464,7 +479,7 @@
   			pattern = null;
   		}
   
  -		criteria.addElement(new LikeCriteria(attribute, pattern, false, getAlias()));
  +		addSelectionCriteria(new LikeCriteria(attribute, pattern, false, getAlias()));
   	}
   
   	/**
  @@ -488,7 +503,7 @@
   			pattern = null;
   		}
   
  -		criteria.addElement(new LikeCriteria(attribute, pattern, true, getAlias()));
  +		addSelectionCriteria(new LikeCriteria(attribute, pattern, true, getAlias()));
   	}
   
   	/**
  @@ -500,7 +515,7 @@
   	 */
   	public void addNotEqualTo(String attribute, Object value)
   	{
  -		criteria.addElement(new EqualToCriteria(attribute, value, true, getAlias()));
  +		addSelectionCriteria(new EqualToCriteria(attribute, value, true, getAlias()));
   	}
   
   	/**
  @@ -512,7 +527,7 @@
   	 */
   	public void addGreaterThan(String attribute, Object value)
   	{
  -		criteria.addElement(new GreaterThanCriteria(attribute, value, false, getAlias()));
  +		addSelectionCriteria(new GreaterThanCriteria(attribute, value, false, getAlias()));
   	}
   
   	/**
  @@ -524,7 +539,7 @@
   	 */
   	public void addGreaterThanField(String attribute, Object value)
   	{
  -		criteria.addElement(new GreaterThanFieldCriteria(attribute, value, false, getAlias()));
  +		addSelectionCriteria(new GreaterThanFieldCriteria(attribute, value, false, getAlias()));
   	}
   
   	/**
  @@ -536,7 +551,7 @@
   	 */
   	public void addLessThan(String attribute, Object value)
   	{
  -		criteria.addElement(new LessThanCriteria(attribute, value, false, getAlias()));
  +		addSelectionCriteria(new LessThanCriteria(attribute, value, false, getAlias()));
   	}
   
   	/**
  @@ -548,7 +563,7 @@
   	 */
   	public void addLessThanField(String attribute, Object value)
   	{
  -		criteria.addElement(new LessThanFieldCriteria(attribute, value, false, getAlias()));
  +		addSelectionCriteria(new LessThanFieldCriteria(attribute, value, false, getAlias()));
   	}
   
   	/**
  @@ -649,17 +664,17 @@
   	 */
   	public void addOrCriteria(Criteria pc)
   	{
  -		if (!criteria.isEmpty())
  +		if (!m_criteria.isEmpty())
   		{
   			pc.setEmbraced(true);
   			pc.setType(OR);
  -			criteria.addElement(pc);
  +			addCriteria(pc);
   		}
   		else
   		{
   			setEmbraced(false);
   			setType(NONE); // root object
  -			criteria = pc.getCriteria();
  +			m_criteria = pc.getCriteria();
   
   			orderby.addAll(pc._getOrderby());
   			groupby.addAll(pc._getGroupby());
  @@ -674,7 +689,7 @@
   	 */
   	public void addIsNull(String attribute)
   	{
  -		criteria.addElement(new NullCriteria(attribute, false, getAlias()));
  +		addSelectionCriteria(new NullCriteria(attribute, false, getAlias()));
   	}
   
   	/**
  @@ -685,7 +700,7 @@
   	 */
   	public void addNotNull(String attribute)
   	{
  -		criteria.addElement(new NullCriteria(attribute, true, getAlias()));
  +		addSelectionCriteria(new NullCriteria(attribute, true, getAlias()));
   	}
   
   	/**
  @@ -698,7 +713,7 @@
   	 */
   	public void addBetween(String attribute, Object value1, Object value2)
   	{
  -		criteria.addElement(new BetweenCriteria(attribute, value1, value2, false, getAlias()));
  +		addSelectionCriteria(new BetweenCriteria(attribute, value1, value2, false, getAlias()));
   	}
   
   	/**
  @@ -711,7 +726,7 @@
   	 */
   	public void addNotBetween(String attribute, Object value1, Object value2)
   	{
  -		criteria.addElement(new BetweenCriteria(attribute, value1, value2, true, getAlias()));
  +		addSelectionCriteria(new BetweenCriteria(attribute, value1, value2, true, getAlias()));
   	}
   
   	/**
  @@ -760,7 +775,7 @@
   		for (index = 0; index < list.size(); index++)
   		{
   			inCrit = (InCriteria) list.get(index);
  -			criteria.addElement(inCrit);
  +			addSelectionCriteria(inCrit);
   		}
   	}
   
  @@ -771,7 +786,7 @@
   	 */
   	public void addIn(String attribute, Query subQuery)
   	{
  -		criteria.addElement(new InCriteria(attribute, subQuery, false, getAlias()));
  +		addSelectionCriteria(new InCriteria(attribute, subQuery, false, getAlias()));
   	}
   
   	/**
  @@ -781,7 +796,7 @@
   	 */
   	public void addNotIn(String attribute, Query subQuery)
   	{
  -		criteria.addElement(new InCriteria(attribute, subQuery, true, getAlias()));
  +		addSelectionCriteria(new InCriteria(attribute, subQuery, true, getAlias()));
   	}
   
   	/**
  @@ -792,7 +807,7 @@
   	 */
   	public void addSql(String anSqlStatment)
   	{
  -		criteria.addElement(new SqlCriteria(anSqlStatment));
  +		addSelectionCriteria(new SqlCriteria(anSqlStatment));
   	}
   
   	/**
  @@ -804,18 +819,18 @@
   	{
   		// by combining a second criteria by 'AND' the existing criteria needs to be enclosed
   		// in parenthesis
  -		if (!criteria.isEmpty())
  +		if (!m_criteria.isEmpty())
   		{
   			this.setEmbraced(true);
   			pc.setEmbraced(true);
   			pc.setType(AND);
  -			criteria.addElement(pc);
  +			addCriteria(pc);
   		}
   		else
   		{
   			setEmbraced(false);
   			setType(NONE); // root object
  -			criteria = pc.getCriteria();
  +			m_criteria = pc.getCriteria();
   
   			orderby.addAll(pc._getOrderby());
   			groupby.addAll(pc._getGroupby());
  @@ -829,7 +844,7 @@
   	 */
   	public void addExists(Query subQuery)
   	{
  -		criteria.addElement(new ExistsCriteria(subQuery, false));
  +		addSelectionCriteria(new ExistsCriteria(subQuery, false));
   	}
   
   	/**
  @@ -839,7 +854,7 @@
   	 */
   	public void addNotExists(Query subQuery)
   	{
  -		criteria.addElement(new ExistsCriteria(subQuery, true));
  +		addSelectionCriteria(new ExistsCriteria(subQuery, true));
   	}
   
   	/**
  @@ -848,7 +863,7 @@
   	 */
   	public boolean isEmpty()
   	{
  -		return criteria.isEmpty();
  +		return m_criteria.isEmpty();
   	}
   
   	/**
  @@ -982,13 +997,53 @@
           }
           
   		// propagate to SelectionCriteria,not to Criteria
  -		for (int i = 0; i < criteria.size(); i++)
  +		for (int i = 0; i < m_criteria.size(); i++)
   		{
  -			if (!(criteria.elementAt(i) instanceof Criteria))
  +			if (!(m_criteria.elementAt(i) instanceof Criteria))
   			{
  -				((SelectionCriteria) criteria.elementAt(i)).setAlias(m_alias);
  +				((SelectionCriteria) m_criteria.elementAt(i)).setAlias(m_alias);
   			}
   		}
  +	}
  +
  +	/**
  +	 * @return
  +	 */
  +	public QueryByCriteria getQuery()
  +	{
  +        if (getParentCriteria() != null)
  +        {
  +            return getParentCriteria().getQuery();
  +        }
  +        else
  +        {
  +            return m_query;
  +        }
  +        
  +	}
  +
  +	/**
  +	 * @param query
  +	 */
  +	void setQuery(QueryByCriteria query)
  +	{
  +		m_query = query;
  +	}
  +
  +	/**
  +	 * @return
  +	 */
  +	public Criteria getParentCriteria()
  +	{
  +		return m_parentCriteria;
  +	}
  +
  +	/**
  +	 * @param criteria
  +	 */
  +	void setParentCriteria(Criteria criteria)
  +	{
  +		m_parentCriteria = criteria;
   	}
   
   }
  
  
  
  1.10      +30 -1     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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SelectionCriteria.java	20 Mar 2003 20:50:47 -0000	1.9
  +++ SelectionCriteria.java	24 Mar 2003 20:09:52 -0000	1.10
  @@ -86,6 +86,8 @@
       // BRJ: indicate whether attribute name should be translated into column name
       private boolean m_translateAttribute = true;
   
  +    private Criteria m_criteria;
  +    
   	/**
   	 * Constructor declaration
   	 *
  @@ -236,4 +238,31 @@
   		m_translateAttribute = b;
   	}
   
  +	/**
  +	 * @return
  +	 */
  +	public Criteria getCriteria()
  +	{
  +		return m_criteria;
  +	}
  +
  +	/**
  +	 * @param criteria
  +	 */
  +	void setCriteria(Criteria criteria)
  +	{
  +		m_criteria = criteria;
  +	}
  +
  +    public QueryByCriteria getQuery()
  +    {
  +        if (getQuery() != null)
  +        {
  +            return getCriteria().getQuery();
  +        }
  +        else
  +        {
  +            return null;
  +        }
  +    }
   }
  
  
  

Mime
View raw message