db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/odmg OQLTest.java
Date Wed, 09 Mar 2005 16:30:36 GMT
arminw      2005/03/09 08:30:36

  Modified:    src/test/org/apache/ojb/odmg/shared Tag: OJB_1_0_RELEASE
                        Article.java
               src/test/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        OQLTest.java
  Log:
  - update OQLTest
  - improve hashCode, equals, toString in Article
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.1   +40 -12    db-ojb/src/test/org/apache/ojb/odmg/shared/Article.java
  
  Index: Article.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/shared/Article.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- Article.java	22 Jun 2004 18:16:22 -0000	1.1
  +++ Article.java	9 Mar 2005 16:30:36 -0000	1.1.2.1
  @@ -1,6 +1,8 @@
   package org.apache.ojb.odmg.shared;
   
   import org.apache.ojb.odmg.shared.ProductGroup;
  +import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.commons.lang.builder.EqualsBuilder;
   
   
   /** Simple Article class is not derived from any base class nor does it implement any Interface,
  @@ -12,17 +14,20 @@
       /** return a string representaion of an article*/
       public String toString()
       {
  -        String group = "" + productGroupId;
  -        if (productGroup != null) group = productGroup.getName();
  -
  -        return "----\n" +
  -                "Article No:   " + articleId + "\n" +
  -                "Description:  " + articleName + "\n" +
  -                "ProductGroup: " + group + "\n" +
  -                "stock:        " + stock + "\n" +
  -                "price:        " + price + "\n" +
  -                "stock-value   " + getStockValue() + "\n";
  -
  +        return new ToStringBuilder(this)
  +                .append("articleId", articleId)
  +                .append("articleName", articleName)
  +                .append("productGroup", (productGroup != null ? productGroup.getName()
: null))
  +                .append("productGroupId", productGroupId)
  +                .append("isSelloutArticle", isSelloutArticle)
  +                .append("minimumStock", minimumStock)
  +                .append("orderedUnits", orderedUnits)
  +                .append("price", price)
  +                .append("orderedUnits", orderedUnits)
  +                .append("stock", stock)
  +                .append("supplierId", supplierId)
  +                .append("unit", unit)
  +                .toString();
       }
   
       /** maps to db-column "Artikel-Nr";INT;PrimaryKey*/
  @@ -196,12 +201,35 @@
       {
           if (obj instanceof Article)
           {
  -            return (this.articleId == ((Article) obj).articleId);
  +            Article other = ((Article) obj);
  +            return new EqualsBuilder()
  +                .append(articleId, other.articleId)
  +                .append(articleName, other.articleName)
  +                .append(productGroupId, other.productGroupId)
  +                .append(isSelloutArticle, other.isSelloutArticle)
  +                .append(minimumStock, other.minimumStock)
  +                .append(orderedUnits, other.orderedUnits)
  +                .append(price, other.price)
  +                .append(orderedUnits, other.orderedUnits)
  +                .append(stock, other.stock)
  +                .append(supplierId, other.supplierId)
  +                .append(unit, other.unit)
  +                .isEquals();
           }
           else
               return false;
       }
   
  +
  +    /* (non-Javadoc)
  +     * @see java.lang.Object#hashCode()
  +     */
  +    public int hashCode()
  +    {
  +        // Since we redefined equals, we have to redefine hashCode as well
  +        return articleId;
  +    }
  +
       /**
        * Gets the isSelloutArticle.
        * @return Returns a boolean
  
  
  
  No                   revision
  No                   revision
  1.16.2.3  +50 -2     db-ojb/src/test/org/apache/ojb/odmg/OQLTest.java
  
  Index: OQLTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/OQLTest.java,v
  retrieving revision 1.16.2.2
  retrieving revision 1.16.2.3
  diff -u -r1.16.2.2 -r1.16.2.3
  --- OQLTest.java	4 Dec 2004 14:01:08 -0000	1.16.2.2
  +++ OQLTest.java	9 Mar 2005 16:30:36 -0000	1.16.2.3
  @@ -253,8 +253,56 @@
   		query2.bind(new Integer(32));
   		List result2 = (List) query2.execute();
   
  -		assertEquals(result1.size(), result2.size());
  +//        System.out.println("#### OQLTest#testQueryBetween(): Size result_1=" + result1.size()
  +//                + ", size result_2=" + result2.size());
  +//        for(int i = 0; i < result1.size(); i++)
  +//        {
  +//            Article a = (Article) result1.get(i);
  +//            System.out.println("Article_Query_1: articles_in_group=" + a.getProductGroup().getAllArticlesInGroup().size()
  +//                    + " - " + a);
  +//        }
  +//
  +//        for(int i = 0; i < result2.size(); i++)
  +//        {
  +//            Article a = (Article) result2.get(i);
  +//            System.out.println("Article_Query_2: articles_in_group=" + a.getProductGroup().getAllArticlesInGroup().size()
  +//                    + " - " + a);
  +//        }
   		tx.commit();
  +
  +        tx.begin();
  +        OQLQuery query3 = odmg.newOQLQuery();
  +		query3.create("select Article from " + Article.class.getName() + " where articleId between
$1 and $2 order by articleId asc");
  +		query3.bind(new Integer(30));
  +		query3.bind(new Integer(32));
  +        List result3 = (List) query3.execute();
  +
  +        OQLQuery query4 = odmg.newOQLQuery();
  +		query4.create("select Article from " + Article.class.getName() + " where articleId between
30 and 32 order by articleId desc");
  +		List result4 = (List) query4.execute();
  +
  +//        for(int i = 0; i < result3.size(); i++)
  +//        {
  +//            Article a = (Article) result3.get(i);
  +//            System.out.println("Article_Query_3: articles_in_group=" + a.getProductGroup().getAllArticlesInGroup().size()
  +//                    + " - " + a);
  +//        }
  +//
  +//        for(int i = 0; i < result4.size(); i++)
  +//        {
  +//            Article a = (Article) result4.get(i);
  +//            System.out.println("Article_Query_4: articles_in_group=" + a.getProductGroup().getAllArticlesInGroup().size()
  +//                    + " - " + a);
  +//        }
  +        tx.commit();
  +
  +        assertEquals(result1.size(), result2.size());
  +        assertEquals(result1.size(), result3.size());
  +        assertEquals(result2.size(), result3.size());
  +        assertEquals(result1.size(), result4.size());
  +        assertEquals(result2.size(), result4.size());
  +        assertEquals(result1, result4);
  +        assertEquals(result2, result3);
   	}
   
   	public void testInListQuery() throws Exception
  
  
  

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