cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [1/3] cayenne git commit: CAY-2191 and CAY-2188 - expressions in Property class - explicit type in Property class and factory methods - string and math functions from JPA standard with support for specific DBs - factory methods for new function call
Date Thu, 05 Jan 2017 12:33:22 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 50d4fbf50 -> 803166c03


http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLengthTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLengthTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLengthTest.java
new file mode 100644
index 0000000..dde6dc0
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLengthTest.java
@@ -0,0 +1,45 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.exp.parser;
+
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @since 4.0
+ */
+public class ASTLengthTest {
+
+    @Test
+    public void evaluateNode() throws Exception {
+        ASTObjPath path = new ASTObjPath("artistName");
+        ASTLength lower = new ASTLength(path);
+
+        Artist a = new Artist();
+        a.setArtistName("123456789");
+
+        Object res = lower.evaluateNode(a);
+        assertTrue(res instanceof Integer);
+        assertEquals(9, res);
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLocateTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLocateTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLocateTest.java
new file mode 100644
index 0000000..9c4090c
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLocateTest.java
@@ -0,0 +1,53 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.exp.parser;
+
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @since 4.0
+ */
+public class ASTLocateTest {
+
+    @Test
+    public void testEvaluateLocate() throws Exception {
+        ASTObjPath path = new ASTObjPath("artistName");
+        ASTScalar substr = new ASTScalar("678");
+        ASTScalar offset = new ASTScalar((Integer)5);
+        ASTLocate exp = new ASTLocate(substr, path, offset);
+
+        Artist a = new Artist();
+        a.setArtistName("1267834567890abc");
+
+        Object res = exp.evaluateNode(a);
+        assertTrue(res instanceof Integer);
+        assertEquals(9, res);
+
+        a.setArtistName("abcdefgh");
+        res = exp.evaluateNode(a);
+        assertTrue(res instanceof Integer);
+        assertEquals(0, res);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLowerTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLowerTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLowerTest.java
new file mode 100644
index 0000000..887e5b5
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTLowerTest.java
@@ -0,0 +1,46 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.exp.parser;
+
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @since 4.0
+ */
+public class ASTLowerTest {
+
+    @Test
+    public void testEvaluateLower() throws Exception {
+        ASTObjPath path = new ASTObjPath("artistName");
+        ASTLower lower = new ASTLower(path);
+
+        Artist a = new Artist();
+        a.setArtistName("AbCdEfG02X");
+
+        Object res = lower.evaluateNode(a);
+        assertTrue(res instanceof String);
+        assertEquals("abcdefg02x", res);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTModTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTModTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTModTest.java
new file mode 100644
index 0000000..fb014f6
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTModTest.java
@@ -0,0 +1,45 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.exp.parser;
+
+import org.apache.cayenne.testdo.table_primitives.TablePrimitives;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @since 4.0
+ */
+public class ASTModTest {
+
+    @Test
+    public void evaluateNode() throws Exception {
+        ASTObjPath path = new ASTObjPath("intColumn");
+        ASTMod mod = new ASTMod(path, new ASTScalar(3.0));
+
+        TablePrimitives a = new TablePrimitives();
+        a.setIntColumn(10);
+
+        Object res = mod.evaluateNode(a);
+        assertTrue(res instanceof Double);
+        assertEquals(1.0, res);
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSqrtTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSqrtTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSqrtTest.java
new file mode 100644
index 0000000..50dbf2f
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSqrtTest.java
@@ -0,0 +1,44 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.exp.parser;
+
+import org.apache.cayenne.testdo.table_primitives.TablePrimitives;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @since 4.0
+ */
+public class ASTSqrtTest {
+    @Test
+    public void evaluateNode() throws Exception {
+        ASTObjPath path = new ASTObjPath("intColumn");
+        ASTSqrt abs = new ASTSqrt(path);
+
+        TablePrimitives a = new TablePrimitives();
+        a.setIntColumn(9);
+
+        Object res = abs.evaluateNode(a);
+        assertTrue(res instanceof Double);
+        assertEquals(3.0, res);
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSubstringTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSubstringTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSubstringTest.java
new file mode 100644
index 0000000..ac51846
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTSubstringTest.java
@@ -0,0 +1,48 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.exp.parser;
+
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @since 4.0
+ */
+public class ASTSubstringTest {
+
+    @Test
+    public void testEvaluateSubstring() throws Exception {
+        ASTObjPath path = new ASTObjPath("artistName");
+        ASTScalar offset = new ASTScalar((Integer)2);
+        ASTScalar length = new ASTScalar((Integer)8);
+        ASTSubstring exp = new ASTSubstring(path, offset, length);
+
+        Artist a = new Artist();
+        a.setArtistName("1234567890xyz");
+
+        Object res = exp.evaluateNode(a);
+        assertTrue(res instanceof String);
+        assertEquals("34567890", res);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTTrimTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTTrimTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTTrimTest.java
new file mode 100644
index 0000000..6a45370
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTTrimTest.java
@@ -0,0 +1,45 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.exp.parser;
+
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @since 4.0
+ */
+public class ASTTrimTest {
+
+    @Test
+    public void testEvaluateTrim() throws Exception {
+        ASTObjPath path = new ASTObjPath("artistName");
+        ASTTrim trim = new ASTTrim(path);
+
+        Artist a = new Artist();
+        a.setArtistName("   \t\r\ntestArtist   \t\r\n");
+        Object res = trim.evaluateNode(a);
+        assertTrue(res instanceof String);
+        assertEquals("testArtist", res);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTUpperTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTUpperTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTUpperTest.java
new file mode 100644
index 0000000..6918041
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTUpperTest.java
@@ -0,0 +1,46 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.exp.parser;
+
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @since 4.0
+ */
+public class ASTUpperTest {
+
+    @Test
+    public void testEvaluateUpper() throws Exception {
+        ASTObjPath path = new ASTObjPath("artistName");
+        ASTUpper upper = new ASTUpper(path);
+
+        Artist a = new Artist();
+        a.setArtistName("abcDEFx981");
+
+        Object res = upper.evaluateNode(a);
+        assertTrue(res instanceof String);
+        assertEquals("ABCDEFX981", res);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-server/src/test/java/org/apache/cayenne/query/ObjectSelect_RunIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/ObjectSelect_RunIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/query/ObjectSelect_RunIT.java
index c10056f..92d54e7 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/ObjectSelect_RunIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/ObjectSelect_RunIT.java
@@ -33,12 +33,17 @@ import org.apache.cayenne.ResultIterator;
 import org.apache.cayenne.ResultIteratorCallback;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.FunctionExpressionFactory;
+import org.apache.cayenne.exp.Property;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 @UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
@@ -50,7 +55,8 @@ public class ObjectSelect_RunIT extends ServerCase {
 	@Inject
 	private DBHelper dbHelper;
 
-	protected void createArtistsDataSet() throws Exception {
+	@Before
+	public void createArtistsDataSet() throws Exception {
 		TableHelper tArtist = new TableHelper(dbHelper, "ARTIST");
 		tArtist.setColumns("ARTIST_ID", "ARTIST_NAME", "DATE_OF_BIRTH");
 
@@ -61,11 +67,15 @@ public class ObjectSelect_RunIT extends ServerCase {
 		}
 	}
 
+	@After
+	public void clearArtistsDataSet() throws Exception {
+		TableHelper tArtist = new TableHelper(dbHelper, "ARTIST");
+		tArtist.setColumns("ARTIST_ID", "ARTIST_NAME", "DATE_OF_BIRTH");
+		tArtist.deleteAll();
+	}
+
 	@Test
 	public void test_SelectObjects() throws Exception {
-
-		createArtistsDataSet();
-
 		List<Artist> result = ObjectSelect.query(Artist.class).select(context);
 		assertEquals(20, result.size());
 		assertThat(result.get(0), instanceOf(Artist.class));
@@ -77,8 +87,6 @@ public class ObjectSelect_RunIT extends ServerCase {
 
 	@Test
 	public void test_Iterate() throws Exception {
-		createArtistsDataSet();
-
 		final int[] count = new int[1];
 		ObjectSelect.query(Artist.class).iterate(context, new ResultIteratorCallback<Artist>()
{
 
@@ -94,8 +102,6 @@ public class ObjectSelect_RunIT extends ServerCase {
 
 	@Test
 	public void test_Iterator() throws Exception {
-		createArtistsDataSet();
-
 		try (ResultIterator<Artist> it = ObjectSelect.query(Artist.class).iterator(context))
{
 			int count = 0;
 
@@ -109,8 +115,6 @@ public class ObjectSelect_RunIT extends ServerCase {
 
 	@Test
 	public void test_BatchIterator() throws Exception {
-		createArtistsDataSet();
-
 		try (ResultBatchIterator<Artist> it = ObjectSelect.query(Artist.class).batchIterator(context,
5);) {
 			int count = 0;
 
@@ -125,9 +129,6 @@ public class ObjectSelect_RunIT extends ServerCase {
 
 	@Test
 	public void test_SelectDataRows() throws Exception {
-
-		createArtistsDataSet();
-
 		List<DataRow> result = ObjectSelect.dataRowQuery(Artist.class).select(context);
 		assertEquals(20, result.size());
 		assertThat(result.get(0), instanceOf(DataRow.class));
@@ -139,8 +140,6 @@ public class ObjectSelect_RunIT extends ServerCase {
 
 	@Test
 	public void test_SelectOne() throws Exception {
-		createArtistsDataSet();
-
 		Artist a = ObjectSelect.query(Artist.class).where(Artist.ARTIST_NAME.eq("artist13")).selectOne(context);
 		assertNotNull(a);
 		assertEquals("artist13", a.getArtistName());
@@ -148,20 +147,17 @@ public class ObjectSelect_RunIT extends ServerCase {
 
 	@Test
 	public void test_SelectOne_NoMatch() throws Exception {
-		Artist a = ObjectSelect.query(Artist.class).where(Artist.ARTIST_NAME.eq("artist13")).selectOne(context);
+		Artist a = ObjectSelect.query(Artist.class).where(Artist.ARTIST_NAME.eq("artist33")).selectOne(context);
 		assertNull(a);
 	}
 
 	@Test(expected = CayenneRuntimeException.class)
 	public void test_SelectOne_MoreThanOneMatch() throws Exception {
-		createArtistsDataSet();
 		ObjectSelect.query(Artist.class).where(Artist.ARTIST_NAME.like("artist%")).selectOne(context);
 	}
 
 	@Test
 	public void test_SelectFirst() throws Exception {
-		createArtistsDataSet();
-
 		Artist a = ObjectSelect.query(Artist.class).where(Artist.ARTIST_NAME.eq("artist13")).selectFirst(context);
 		assertNotNull(a);
 		assertEquals("artist13", a.getArtistName());
@@ -169,8 +165,6 @@ public class ObjectSelect_RunIT extends ServerCase {
 
 	@Test
 	public void test_SelectFirstByContext() throws Exception {
-		createArtistsDataSet();
-
 		ObjectSelect<Artist> q = ObjectSelect.query(Artist.class).where(Artist.ARTIST_NAME.eq("artist13"));
 		Artist a = context.selectFirst(q);
 		assertNotNull(a);
@@ -179,16 +173,34 @@ public class ObjectSelect_RunIT extends ServerCase {
 
 	@Test
 	public void test_SelectFirst_NoMatch() throws Exception {
-		Artist a = ObjectSelect.query(Artist.class).where(Artist.ARTIST_NAME.eq("artist13")).selectFirst(context);
+		Artist a = ObjectSelect.query(Artist.class).where(Artist.ARTIST_NAME.eq("artist33")).selectFirst(context);
 		assertNull(a);
 	}
 
 	@Test
 	public void test_SelectFirst_MoreThanOneMatch() throws Exception {
-		createArtistsDataSet();
+		Artist a = ObjectSelect.query(Artist.class).where(Artist.ARTIST_NAME.like("artist%"))
+				.orderBy("db:ARTIST_ID").selectFirst(context);
+		assertNotNull(a);
+		assertEquals("artist1", a.getArtistName());
+	}
 
-		Artist a = ObjectSelect.query(Artist.class).where(Artist.ARTIST_NAME.like("artist%")).orderBy("db:ARTIST_ID")
-				.selectFirst(context);
+	@Test
+	public void test_SelectFirst_TrimInWhere() throws Exception {
+		Expression exp = FunctionExpressionFactory.trimExp(Artist.ARTIST_NAME.path());
+		Property<String> trimmedName = Property.create("trimmed", exp, String.class);
+		Artist a = ObjectSelect.query(Artist.class).where(trimmedName.likeIgnoreCase("artist%"))
+				.orderBy("db:ARTIST_ID").selectFirst(context);
+		assertNotNull(a);
+		assertEquals("artist1", a.getArtistName());
+	}
+
+	@Test
+	public void test_SelectFirst_SubstringInWhere() throws Exception {
+		Expression exp = FunctionExpressionFactory.substringExp(Artist.ARTIST_NAME.path(), 2, 3);
+		Property<String> substrName = Property.create("substr", exp, String.class);
+		Artist a = ObjectSelect.query(Artist.class).where(substrName.eq("rti"))
+				.orderBy("db:ARTIST_ID").selectFirst(context);
 		assertNotNull(a);
 		assertEquals("artist1", a.getArtistName());
 	}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-tools/src/main/java/org/apache/cayenne/gen/StringUtils.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/gen/StringUtils.java b/cayenne-tools/src/main/java/org/apache/cayenne/gen/StringUtils.java
index 5473142..cc27627 100644
--- a/cayenne-tools/src/main/java/org/apache/cayenne/gen/StringUtils.java
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/gen/StringUtils.java
@@ -162,4 +162,28 @@ public class StringUtils {
             return str + "s";
         }
     }
+
+    /**
+     * <p>
+     * Strip generic definition from string
+     * </p>
+     * <p>For example: List&gt;Integer&lt; == List</p>
+     * @since 4.0
+     */
+    public String stripGeneric(String str) {
+        if(str == null) {
+            return null;
+        }
+        int start = str.indexOf('<');
+        if(start == -1) {
+            return str;
+        }
+        int end = str.lastIndexOf('>');
+        if(end == -1) {
+            return str;
+        } else if(end == str.length() - 1) {
+            return str.substring(0, start);
+        }
+        return str.substring(0, start) + str.substring(end+1);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm b/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm
index f7c1c9d..f8c9cbe 100644
--- a/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm
+++ b/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm
@@ -76,19 +76,21 @@ public abstract class ${superClassName} extends ${baseClassName} {
 #end
 ## Create Properties
 #foreach( $attr in ${object.DeclaredAttributes} )
-    public static final Property<$importUtils.formatJavaType(${attr.Type}, false)>
${stringUtils.capitalizedAsConstant($attr.Name)} = new Property<>("${attr.Name}");
+    #set ( $type = "$importUtils.formatJavaType(${attr.Type}, false)" )
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($attr.Name)}
= Property.create("${attr.Name}", ${stringUtils.stripGeneric($type)}.class);
 #end
 #foreach( $rel in ${object.DeclaredRelationships} )
 #if( $rel.ToMany )
 #if ( ${rel.CollectionType} == "java.util.Map")
     #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)),
$importUtils.formatJavaType($rel.TargetEntity.ClientClassName)>" )
-    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= new Property<>("${rel.Name}");
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= Property.create("${rel.Name}", ${stringUtils.stripGeneric($type)}.class);
 #else
     #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClientClassName)>"
)
-    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= new Property<>("${rel.Name}");
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= Property.create("${rel.Name}", ${stringUtils.stripGeneric($type)}.class);
 #end
 #else
-    public static final Property<$importUtils.formatJavaType(${rel.TargetEntity.ClientClassName})>
${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<>("${rel.Name}");
+    #set( $type = "$importUtils.formatJavaType(${rel.TargetEntity.ClassName})" )
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= Property.create("${rel.Name}", ${stringUtils.stripGeneric($type)}.class);
 #end
 #end
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-tools/src/main/resources/templates/v1_2/embeddable-singleclass.vm
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/resources/templates/v1_2/embeddable-singleclass.vm b/cayenne-tools/src/main/resources/templates/v1_2/embeddable-singleclass.vm
index b40c9ff..a30dcec 100644
--- a/cayenne-tools/src/main/resources/templates/v1_2/embeddable-singleclass.vm
+++ b/cayenne-tools/src/main/resources/templates/v1_2/embeddable-singleclass.vm
@@ -57,7 +57,8 @@ public abstract class ${subClassName} extends ${baseClassName} {
 #end
 ## Create Properties
 #foreach( $attr in ${object.Attributes} )
-    public static final Property<$importUtils.formatJavaType(${attr.Type}, false)>
${stringUtils.capitalizedAsConstant($attr.Name)} = new Property<$importUtils.formatJavaType(${attr.Type},
false)>("${attr.Name}");
+    #set ( $type = "$importUtils.formatJavaType(${attr.Type}, false)" )
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($attr.Name)}
= Property.create("${attr.Name}", ${stringUtils.stripGeneric($type)}.class);
 #end
 
     // special properties injected by Cayenne

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-tools/src/main/resources/templates/v1_2/embeddable-superclass.vm
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/resources/templates/v1_2/embeddable-superclass.vm b/cayenne-tools/src/main/resources/templates/v1_2/embeddable-superclass.vm
index f4de6c7..95e39dc 100644
--- a/cayenne-tools/src/main/resources/templates/v1_2/embeddable-superclass.vm
+++ b/cayenne-tools/src/main/resources/templates/v1_2/embeddable-superclass.vm
@@ -63,7 +63,8 @@ public abstract class ${superClassName} extends ${baseClassName} {
 #end
 ## Create Properties
 #foreach( $attr in ${object.Attributes} )
-    public static final Property<$importUtils.formatJavaType(${attr.Type}, false)>
${stringUtils.capitalizedAsConstant($attr.Name)} = new Property<>("${attr.Name}");
+    #set ( $type = "$importUtils.formatJavaType(${attr.Type}, false)" )
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($attr.Name)}
= Property.create("${attr.Name}", ${stringUtils.stripGeneric($type)}.class);
 #end
 
     // special properties injected by Cayenne

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-tools/src/main/resources/templates/v1_2/singleclass.vm
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/resources/templates/v1_2/singleclass.vm b/cayenne-tools/src/main/resources/templates/v1_2/singleclass.vm
index 2d83cfd..53c6aa7 100644
--- a/cayenne-tools/src/main/resources/templates/v1_2/singleclass.vm
+++ b/cayenne-tools/src/main/resources/templates/v1_2/singleclass.vm
@@ -72,19 +72,21 @@ public#if("true" == "${object.isAbstract()}") abstract#end class ${subClassName}
 
 ## Create Properties
 #foreach( $attr in ${object.DeclaredAttributes} )
-    public static final Property<$importUtils.formatJavaType(${attr.Type}, false)>
${stringUtils.capitalizedAsConstant($attr.Name)} = new Property<>("${attr.Name}");
+    #set ( $type = "$importUtils.formatJavaType(${attr.Type}, false)" )
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($attr.Name)}
= Property.create("${attr.Name}", ${stringUtils.stripGeneric($type)}.class);
 #end
 #foreach( $rel in ${object.DeclaredRelationships} )
 #if( $rel.ToMany )
 #if ( ${rel.CollectionType} == "java.util.Map")
     #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)),
$importUtils.formatJavaType($rel.TargetEntity.ClassName)>" )
-    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= new Property<>("${rel.Name}");
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= Property.create("${rel.Name}", ${stringUtils.stripGeneric($type)}.class);
 #else
     #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClassName)>"
)
-    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= new Property<>("${rel.Name}");
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= Property.create("${rel.Name}", ${stringUtils.stripGeneric($type)}.class);
 #end
 #else
-    public static final Property<$importUtils.formatJavaType(${rel.TargetEntity.ClassName})>
${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<>("${rel.Name}");
+    #set( $type = "$importUtils.formatJavaType(${rel.TargetEntity.ClassName})" )
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= Property.create("${rel.Name}", ${stringUtils.stripGeneric($type)}.class);
 #end
 #end
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm b/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm
index 9934a96..7857189 100644
--- a/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm
+++ b/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm
@@ -77,19 +77,21 @@ public abstract class ${superClassName} extends ${baseClassName} {
 
 ## Create Properties
 #foreach( $attr in ${object.DeclaredAttributes} )
-    public static final Property<$importUtils.formatJavaType(${attr.Type}, false)>
${stringUtils.capitalizedAsConstant($attr.Name)} = new Property<>("${attr.Name}");
+    #set ( $type = "$importUtils.formatJavaType(${attr.Type}, false)")
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($attr.Name)}
= Property.create("${attr.Name}", ${stringUtils.stripGeneric($type)}.class);
 #end
 #foreach( $rel in ${object.DeclaredRelationships} )
 #if( $rel.ToMany )
 #if ( ${rel.CollectionType} == "java.util.Map")
     #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)),
$importUtils.formatJavaType($rel.TargetEntity.ClassName)>" )
-    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= new Property<>("${rel.Name}");
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= Property.create("${rel.Name}", ${stringUtils.stripGeneric($type)}.class);
 #else
     #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClassName)>"
)
-    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= new Property<>("${rel.Name}");
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= Property.create("${rel.Name}", ${stringUtils.stripGeneric($type)}.class);
 #end
 #else
-    public static final Property<$importUtils.formatJavaType(${rel.TargetEntity.ClassName})>
${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<>("${rel.Name}");
+    #set( $type = "$importUtils.formatJavaType(${rel.TargetEntity.ClassName})" )
+    public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)}
= Property.create("${rel.Name}", ${stringUtils.stripGeneric($type)}.class);
 #end
 #end
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/cayenne-tools/src/test/java/org/apache/cayenne/gen/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/gen/StringUtilsTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/gen/StringUtilsTest.java
index 1fe187e..a11ba2f 100644
--- a/cayenne-tools/src/test/java/org/apache/cayenne/gen/StringUtilsTest.java
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/gen/StringUtilsTest.java
@@ -98,4 +98,13 @@ public class StringUtilsTest {
         assertEquals(expected, stringUtils.capitalizedAsConstant("abCe"));
     }
 
+    @Test
+    public void testStripGeneric() throws Exception {
+        assertEquals("List", stringUtils.stripGeneric("List"));
+        assertEquals("List", stringUtils.stripGeneric("List<Integer>"));
+        assertEquals("List", stringUtils.stripGeneric("List<List<Map<Integer,List<String>>>>"));
+        assertEquals("List123", stringUtils.stripGeneric("List<List<Map<Integer,List<String>>>>123"));
+        assertEquals("List<Integer", stringUtils.stripGeneric("List<Integer"));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/803166c0/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
b/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
index bd8068f..734e93c 100644
--- a/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
+++ b/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
@@ -70,7 +70,7 @@ public class CayenneGeneratorMojoTest extends AbstractMojoTestCase {
         assertFalse(excludedEntity.exists());
 
         String content = FileUtils.readFileToString(superTestEntity);
-        assertTrue(content.contains("public static final Property<List<TestRelEntity>>
ADDITIONAL_REL = new Property<>(\"additionalRel\");"));
+        assertTrue(content.contains("public static final Property<List<TestRelEntity>>
ADDITIONAL_REL = Property.create(\"additionalRel\", List.class);"));
         assertTrue(content.contains("public void addToAdditionalRel(TestRelEntity obj)"));
         assertTrue(content.contains("public void removeFromAdditionalRel(TestRelEntity obj)"));
 


Mime
View raw message