jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r658855 - in /jackrabbit/trunk/jackrabbit-ocm/src: main/java/org/apache/jackrabbit/ocm/query/impl/ test/java/org/apache/jackrabbit/ocm/manager/query/
Date Wed, 21 May 2008 20:42:52 GMT
Author: clombart
Date: Wed May 21 13:42:52 2008
New Revision: 658855

URL: http://svn.apache.org/viewvc?rev=658855&view=rev
Log:
Fix for JCR-1286. 

Modified:
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationAtomicQueryTest.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterAtomicQueryTest.java

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java?rev=658855&r1=658854&r2=658855&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/FilterImpl.java
Wed May 21 13:42:52 2008
@@ -26,7 +26,9 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.jackrabbit.ocm.manager.atomictypeconverter.AtomicTypeConverter;
 import org.apache.jackrabbit.ocm.mapper.model.ClassDescriptor;
+import org.apache.jackrabbit.ocm.mapper.model.FieldDescriptor;
 import org.apache.jackrabbit.ocm.query.Filter;
+import org.apache.jackrabbit.ocm.reflection.ReflectionUtils;
 
 /**
  * {@link org.apache.jackrabbit.ocm.query.Filter}
@@ -113,9 +115,9 @@
      */
     public Filter addBetween(String fieldAttributeName, Object value1, Object value2) {
         String jcrExpression = "( @" + this.getJcrFieldName(fieldAttributeName) + " >=
"
-            + this.getStringValue(value1)
+            + this.getStringValue(fieldAttributeName, value1)
             + " and @" + this.getJcrFieldName(fieldAttributeName) + " <= "
-            + this.getStringValue(value2) + ")";
+            + this.getStringValue(fieldAttributeName, value2) + ")";
 
         addExpression(jcrExpression);
 
@@ -127,7 +129,7 @@
      */
     public Filter addEqualTo(String fieldAttributeName, Object value) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " = "
-            + this.getStringValue(value);
+            + this.getStringValue(fieldAttributeName, value);
         addExpression(jcrExpression);
 
         return this;
@@ -138,7 +140,7 @@
      */
     public Filter addGreaterOrEqualThan(String fieldAttributeName, Object value) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " >= "
-            + this.getStringValue(value);
+            + this.getStringValue(fieldAttributeName, value);
         addExpression(jcrExpression);
 
         return this;
@@ -149,7 +151,7 @@
      */
     public Filter addGreaterThan(String fieldAttributeName, Object value) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " > "
-            + this.getStringValue(value);
+            + this.getStringValue(fieldAttributeName, value);
         addExpression(jcrExpression);
 
         return this;
@@ -160,7 +162,7 @@
      */
     public Filter addLessOrEqualThan(String fieldAttributeName, Object value) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " <= "
-            + this.getStringValue(value);
+            + this.getStringValue(fieldAttributeName, value);
         addExpression(jcrExpression);
 
         return this;
@@ -171,7 +173,7 @@
      */
     public Filter addLessThan(String fieldAttributeName, Object value) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " < "
-            + this.getStringValue(value);
+            + this.getStringValue(fieldAttributeName, value);
         addExpression(jcrExpression);
 
         return this;
@@ -193,7 +195,7 @@
      */
     public Filter addNotEqualTo(String fieldAttributeName, Object value) {
         String jcrExpression = "@" + this.getJcrFieldName(fieldAttributeName) + " != "
-            + this.getStringValue(value);
+            + this.getStringValue(fieldAttributeName, value);
         addExpression(jcrExpression);
 
         return this;
@@ -228,7 +230,7 @@
         {
     	   if ( null == jcrExpression || "".equals(jcrExpression) )
     	   {
-    		   jcrExpression =    ((FilterImpl) filter).getJcrExpression() ;    		
+    		   jcrExpression =    ((FilterImpl) filter).getJcrExpression() ;
     	   }
     	   else
     	   {
@@ -247,7 +249,7 @@
         {
      	   if ( null == jcrExpression || "".equals(jcrExpression) )
     	   {
-    		   jcrExpression =    ((FilterImpl) filter).getJcrExpression() ;    		
+    		   jcrExpression =    ((FilterImpl) filter).getJcrExpression() ;
     	   }
     	   else
     	   {
@@ -274,10 +276,30 @@
 
     }
 
-    private String getStringValue(Object value) {
-        AtomicTypeConverter atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters.get(
-                value.getClass());
-
+    private String getStringValue(String fieldName, Object value) {
+    	FieldDescriptor fieldDescriptor = classDescriptor.getFieldDescriptor(fieldName);
+    	AtomicTypeConverter atomicTypeConverter = null ;
+    	// if the attribute is a simple field (primitive data type or wrapper class)
+    	if (fieldDescriptor != null)
+    	{
+	    	String fieldConverterName = fieldDescriptor.getConverter();
+
+	    	// if a field converter is set in the mapping, use this one
+	    	if ( fieldConverterName != null )
+	    	{
+	    		atomicTypeConverter = (AtomicTypeConverter) ReflectionUtils.newInstance(fieldConverterName);
+	    	}
+	    	// else use a default converter in function of the attribute type
+	    	else
+	    	{
+	    		atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters.get(value.getClass());
+	    	}
+    	}
+    	// else it could be a collection (for example, it is a multivalue property)
+    	else
+    	{
+    		atomicTypeConverter = (AtomicTypeConverter) atomicTypeConverters.get(value.getClass());
+    	}
         return atomicTypeConverter.getXPathQueryValue(valueFactory, value);
     }
 

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java?rev=658855&r1=658854&r2=658855&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/query/impl/QueryManagerImpl.java
Wed May 21 13:42:52 2008
@@ -22,7 +22,10 @@
 
 import javax.jcr.ValueFactory;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.jackrabbit.ocm.manager.ManagerConstant;
+import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl;
 import org.apache.jackrabbit.ocm.mapper.Mapper;
 import org.apache.jackrabbit.ocm.mapper.model.ClassDescriptor;
 import org.apache.jackrabbit.ocm.query.Filter;
@@ -31,6 +34,8 @@
 
 public class QueryManagerImpl implements QueryManager {
 
+	private final static Log log = LogFactory.getLog(ObjectContentManagerImpl.class);
+
 	private Mapper mapper;
     private Map atomicTypeConverters;
     private ValueFactory valueFactory;
@@ -85,6 +90,7 @@
 
         // Add order by
         jcrExp += ((QueryImpl) query).getOrderByExpression();
+        log.debug(jcrExp);
 
         return jcrExp;
 
@@ -118,11 +124,11 @@
         String jcrNodeType = classDescriptor.getJcrType();
         if (jcrNodeType == null || jcrNodeType.equals(""))
         	{
-           return ManagerConstant.NT_UNSTRUCTURED;	
+           return ManagerConstant.NT_UNSTRUCTURED;
         	}
         else
         {
-           return jcrNodeType;	
+           return jcrNodeType;
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationAtomicQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationAtomicQueryTest.java?rev=658855&r1=658854&r2=658855&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationAtomicQueryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationAtomicQueryTest.java
Wed May 21 13:42:52 2008
@@ -44,7 +44,7 @@
 {
 	private final static Log log = LogFactory.getLog(AnnotationAtomicQueryTest.class);
 	private Date date = new Date();
-	
+
 	/**
 	 * <p>Defines the test case name for junit.</p>
 	 * @param testName The test case name.
@@ -52,7 +52,7 @@
 	public AnnotationAtomicQueryTest(String testName) throws Exception
 	{
 		super(testName);
-		
+
 	}
 
 	public static Test suite()
@@ -60,28 +60,33 @@
 		// All methods starting with "test" will be executed in the test suite.
 		return new RepositoryLifecycleTestSetup(new TestSuite(AnnotationAtomicQueryTest.class));
 	}
-	
+
+	protected void setUp() throws Exception
+	{
+		super.setUp();
+		this.importData(date);
+	}
+
 	public void testQueryAtomicFields()
 	{
 
 		try
 		{
-			
-			this.importData(date);
+
 			ObjectContentManager ocm = this.getObjectContentManager();
-			
+
 			// Test Boolean value
 			QueryManager queryManager = this.getQueryManager();
 			Filter filter = queryManager.createFilter(Atomic.class);
 			filter.addEqualTo("booleanObject", new Boolean(true));
 			Query query = queryManager.createQuery(filter);
-			
+
 			long start = System.currentTimeMillis();
 			Collection result = ocm.getObjects(query);
 			System.out.println("getObjects  : " + (System.currentTimeMillis() - start));
-			
+
 			assertTrue("Invalid number of objects - should be = 50", result.size() == 50);
-			
+
 			filter = queryManager.createFilter(Atomic.class);
 			filter.addEqualTo("booleanPrimitive", new Boolean(false));
 			query = queryManager.createQuery(filter);
@@ -90,32 +95,32 @@
 			result = ocm.getObjects(query);
 			System.out.println("getObjects 2 : " + (System.currentTimeMillis() - start));
 			assertTrue("Invalid number of objects - should be = 0", result.size() == 0);
-			
-			
+
+
 			// Test int value
 			filter = queryManager.createFilter(Atomic.class);
 			filter.addBetween("integerObject", new Integer(0), new Integer(500));
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 5", result.size() == 5);
-			
+
 			filter = queryManager.createFilter(Atomic.class);
 			filter.addLessOrEqualThan("intPrimitive", new Integer(236));
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 36", result.size() == 36);
 
-			
+
 			//Test Date & Calendar
 			filter = queryManager.createFilter(Atomic.class);
 			Calendar calendar = Calendar.getInstance();
 			calendar.set(2012, Calendar.DECEMBER, 01);
 			filter.addLessThan("calendar", calendar);
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
 
 			filter = queryManager.createFilter(Atomic.class);
@@ -123,55 +128,55 @@
 			calendar.set(1975, Calendar.DECEMBER, 01);
 			filter.addLessThan("calendar", calendar);
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);
-			
-			filter = queryManager.createFilter(Atomic.class);			
+
+			filter = queryManager.createFilter(Atomic.class);
 			filter.addEqualTo("date", date);
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
 
-			filter = queryManager.createFilter(Atomic.class);			
+			filter = queryManager.createFilter(Atomic.class);
 			filter.addBetween("date", date, new Date());
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
 
-			filter = queryManager.createFilter(Atomic.class);			
+			filter = queryManager.createFilter(Atomic.class);
 			filter.addGreaterThan("date", date);
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);
 
 			// Test contains method
-			filter = queryManager.createFilter(Atomic.class);			
+			filter = queryManager.createFilter(Atomic.class);
 			filter.addContains(".", "JCR");
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 50 ", result.size() == 50);
-			
-			filter = queryManager.createFilter(Atomic.class);			
+
+			filter = queryManager.createFilter(Atomic.class);
 			filter.addContains("string", "JCR");
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 50 ", result.size() == 50);
-			
-			filter = queryManager.createFilter(Atomic.class);			
+
+			filter = queryManager.createFilter(Atomic.class);
 			filter.addContains("string", "ocm");
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);
 
 
-			
+
 		}
 		catch (Exception e)
 		{
@@ -181,13 +186,30 @@
 
 	}
 
+	public void testQueryAtomicFieldsWithConverter()
+	{
+		ObjectContentManager ocm = this.getObjectContentManager();
+
+		// Test Boolean value
+		QueryManager queryManager = this.getQueryManager();
+		Filter filter = queryManager.createFilter(Atomic.class);
+		filter.addEqualTo("int2boolean", new Boolean(true));
+		Query query = queryManager.createQuery(filter);
+
+		long start = System.currentTimeMillis();
+		Collection result = ocm.getObjects(query);
+		System.out.println("getObjects  : " + (System.currentTimeMillis() - start));
+
+		assertEquals(50, result.size());
+	}
+
 	private void importData(Date date)
 	{
 		try
 		{
 
 			ObjectContentManager ocm = getObjectContentManager();
-			
+
 			for (int i = 1; i <= 100; i++)
 			{
 				Atomic a = new Atomic();
@@ -195,7 +217,7 @@
 				a.setBooleanObject(new Boolean(i%2==0));
 				a.setBooleanPrimitive(true);
 				a.setIntegerObject(new Integer(100 * i));
-				a.setIntPrimitive(200 + i);				
+				a.setIntPrimitive(200 + i);
 				a.setDate(date);
 				Calendar calendar = Calendar.getInstance();
 				calendar.set(1976, 4, 20, 15, 40);
@@ -207,18 +229,20 @@
 				if ((i % 2) == 0)
 				{
 					a.setString("Test String JCR " + i);
-				     a.setByteArray("This is small object stored in a JCR repository".getBytes());
-				     a.setInputStream(new ByteArrayInputStream("Test inputstream".getBytes()));
+				    a.setByteArray("This is small object stored in a JCR repository".getBytes());
+				    a.setInputStream(new ByteArrayInputStream("Test inputstream".getBytes()));
+				    a.setInt2boolean(true);
 				}
 				else
 				{
 					 a.setByteArray("This is small object stored in the ocm repository".getBytes());
 					 a.setInputStream(new ByteArrayInputStream("Another Stream".getBytes()));
 					 a.setString("Test String " + i);
+					 a.setInt2boolean(false);
 				}
 				ocm.insert(a);
-				
-				
+
+
 			}
 			ocm.save();
 
@@ -230,5 +254,6 @@
 		}
 
 	}
-	
+
+
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterAtomicQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterAtomicQueryTest.java?rev=658855&r1=658854&r2=658855&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterAtomicQueryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/DigesterAtomicQueryTest.java
Wed May 21 13:42:52 2008
@@ -44,7 +44,7 @@
 {
 	private final static Log log = LogFactory.getLog(DigesterAtomicQueryTest.class);
 	private Date date = new Date();
-	
+
 	/**
 	 * <p>Defines the test case name for junit.</p>
 	 * @param testName The test case name.
@@ -52,7 +52,7 @@
 	public DigesterAtomicQueryTest(String testName) throws Exception
 	{
 		super(testName);
-		
+
 	}
 
 	public static Test suite()
@@ -60,28 +60,33 @@
 		// All methods starting with "test" will be executed in the test suite.
 		return new RepositoryLifecycleTestSetup(new TestSuite(DigesterAtomicQueryTest.class));
 	}
-		
+
+	protected void setUp() throws Exception
+	{
+		super.setUp();
+		this.importData(date);
+	}
+
 	public void testQueryAtomicFields()
 	{
 
 		try
 		{
-			
-			this.importData(date);
+
 			ObjectContentManager ocm = this.getObjectContentManager();
-			
+
 			// Test Boolean value
 			QueryManager queryManager = this.getQueryManager();
 			Filter filter = queryManager.createFilter(Atomic.class);
 			filter.addEqualTo("booleanObject", new Boolean(true));
 			Query query = queryManager.createQuery(filter);
-			
+
 			long start = System.currentTimeMillis();
 			Collection result = ocm.getObjects(query);
 			System.out.println("getObjects  : " + (System.currentTimeMillis() - start));
-			
+
 			assertTrue("Invalid number of objects - should be = 50", result.size() == 50);
-			
+
 			filter = queryManager.createFilter(Atomic.class);
 			filter.addEqualTo("booleanPrimitive", new Boolean(false));
 			query = queryManager.createQuery(filter);
@@ -90,32 +95,32 @@
 			result = ocm.getObjects(query);
 			System.out.println("getObjects 2 : " + (System.currentTimeMillis() - start));
 			assertTrue("Invalid number of objects - should be = 0", result.size() == 0);
-			
-			
+
+
 			// Test int value
 			filter = queryManager.createFilter(Atomic.class);
 			filter.addBetween("integerObject", new Integer(0), new Integer(500));
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 5", result.size() == 5);
-			
+
 			filter = queryManager.createFilter(Atomic.class);
 			filter.addLessOrEqualThan("intPrimitive", new Integer(236));
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 36", result.size() == 36);
 
-			
+
 			//Test Date & Calendar
 			filter = queryManager.createFilter(Atomic.class);
 			Calendar calendar = Calendar.getInstance();
 			calendar.set(2012, Calendar.DECEMBER, 01);
 			filter.addLessThan("calendar", calendar);
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
 
 			filter = queryManager.createFilter(Atomic.class);
@@ -123,55 +128,55 @@
 			calendar.set(1975, Calendar.DECEMBER, 01);
 			filter.addLessThan("calendar", calendar);
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);
-			
-			filter = queryManager.createFilter(Atomic.class);			
+
+			filter = queryManager.createFilter(Atomic.class);
 			filter.addEqualTo("date", date);
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
 
-			filter = queryManager.createFilter(Atomic.class);			
+			filter = queryManager.createFilter(Atomic.class);
 			filter.addBetween("date", date, new Date());
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 100 ", result.size() == 100);
 
-			filter = queryManager.createFilter(Atomic.class);			
+			filter = queryManager.createFilter(Atomic.class);
 			filter.addGreaterThan("date", date);
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);
 
 			// Test contains method
-			filter = queryManager.createFilter(Atomic.class);			
+			filter = queryManager.createFilter(Atomic.class);
 			filter.addContains(".", "JCR");
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 50 ", result.size() == 50);
-			
-			filter = queryManager.createFilter(Atomic.class);			
+
+			filter = queryManager.createFilter(Atomic.class);
 			filter.addContains("string", "JCR");
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 50 ", result.size() == 50);
-			
-			filter = queryManager.createFilter(Atomic.class);			
+
+			filter = queryManager.createFilter(Atomic.class);
 			filter.addContains("string", "ocm");
 			query = queryManager.createQuery(filter);
-			
-			result = ocm.getObjects(query);			
+
+			result = ocm.getObjects(query);
 			assertTrue("Invalid number of objects - should be = 0 ", result.size() == 0);
 
 
-			
+
 		}
 		catch (Exception e)
 		{
@@ -181,13 +186,30 @@
 
 	}
 
+	public void testQueryAtomicFieldsWithConverter()
+	{
+		ObjectContentManager ocm = this.getObjectContentManager();
+
+		// Test Boolean value
+		QueryManager queryManager = this.getQueryManager();
+		Filter filter = queryManager.createFilter(Atomic.class);
+		filter.addEqualTo("int2boolean", new Boolean(true));
+		Query query = queryManager.createQuery(filter);
+
+		long start = System.currentTimeMillis();
+		Collection result = ocm.getObjects(query);
+		System.out.println("getObjects  : " + (System.currentTimeMillis() - start));
+
+		assertEquals(50, result.size());
+	}
+
 	private void importData(Date date)
 	{
 		try
 		{
 
 			ObjectContentManager ocm = getObjectContentManager();
-			
+
 			for (int i = 1; i <= 100; i++)
 			{
 				Atomic a = new Atomic();
@@ -195,7 +217,7 @@
 				a.setBooleanObject(new Boolean(i%2==0));
 				a.setBooleanPrimitive(true);
 				a.setIntegerObject(new Integer(100 * i));
-				a.setIntPrimitive(200 + i);				
+				a.setIntPrimitive(200 + i);
 				a.setDate(date);
 				Calendar calendar = Calendar.getInstance();
 				calendar.set(1976, 4, 20, 15, 40);
@@ -206,19 +228,21 @@
 				a.setTimestamp(new Timestamp(now));
 				if ((i % 2) == 0)
 				{
-					a.setString("Test String JCR " + i);
+					 a.setString("Test String JCR " + i);
 				     a.setByteArray("This is small object stored in a JCR repository".getBytes());
 				     a.setInputStream(new ByteArrayInputStream("Test inputstream".getBytes()));
+				     a.setInt2boolean(true);
 				}
 				else
 				{
 					 a.setByteArray("This is small object stored in the ocm repository".getBytes());
 					 a.setInputStream(new ByteArrayInputStream("Another Stream".getBytes()));
 					 a.setString("Test String " + i);
+					 a.setInt2boolean(false);
 				}
 				ocm.insert(a);
-				
-				
+
+
 			}
 			ocm.save();
 
@@ -230,5 +254,5 @@
 		}
 
 	}
-	
+
 }
\ No newline at end of file



Mime
View raw message