You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2007/12/07 12:54:23 UTC
svn commit: r602075 - in
/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test:
java/org/apache/art/ java/org/apache/art/auto/
java/org/apache/cayenne/access/ java/org/apache/cayenne/unit/ resources/
Author: aadamchik
Date: Fri Dec 7 03:54:18 2007
New Revision: 602075
URL: http://svn.apache.org/viewvc?rev=602075&view=rev
Log:
Basic ExtendedType tests
Added:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/ExtendedTypeEntity.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/StringET1.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/StringET1ExtendedType.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_ExtendedTypeEntity.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSelectQueryExtendedTypeTest.java
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStack.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/DataSetFactory.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/ExtendedTypeEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/ExtendedTypeEntity.java?rev=602075&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/ExtendedTypeEntity.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/ExtendedTypeEntity.java Fri Dec 7 03:54:18 2007
@@ -0,0 +1,25 @@
+/*****************************************************************
+ * 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.art;
+
+import org.apache.art.auto._ExtendedTypeEntity;
+
+public class ExtendedTypeEntity extends _ExtendedTypeEntity {
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/StringET1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/StringET1.java?rev=602075&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/StringET1.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/StringET1.java Fri Dec 7 03:54:18 2007
@@ -0,0 +1,35 @@
+/*****************************************************************
+ * 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.art;
+
+/**
+ * A test extended type.
+ */
+public class StringET1 {
+
+ protected String string;
+
+ public StringET1(String string) {
+ this.string = string;
+ }
+
+ public String getString() {
+ return string;
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/StringET1ExtendedType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/StringET1ExtendedType.java?rev=602075&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/StringET1ExtendedType.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/StringET1ExtendedType.java Fri Dec 7 03:54:18 2007
@@ -0,0 +1,72 @@
+/*****************************************************************
+ * 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.art;
+
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import org.apache.cayenne.access.types.ExtendedType;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.validation.ValidationResult;
+
+public class StringET1ExtendedType implements ExtendedType {
+
+ public String getClassName() {
+ return StringET1.class.getName();
+ }
+
+ public Object materializeObject(ResultSet rs, int index, int type) throws Exception {
+ String string = rs.getString(index);
+ return string != null ? new StringET1(string) : null;
+ }
+
+ public Object materializeObject(CallableStatement rs, int index, int type)
+ throws Exception {
+ String string = rs.getString(index);
+ return string != null ? new StringET1(string) : null;
+ }
+
+ public void setJdbcObject(
+ PreparedStatement statement,
+ Object value,
+ int pos,
+ int type,
+ int precision) throws Exception {
+
+ if (value instanceof StringET1) {
+ statement.setString(pos, ((StringET1) value).getString());
+ }
+ else {
+ statement.setNull(pos, type);
+ }
+ }
+
+ /**
+ * @deprecated
+ */
+ public boolean validateProperty(
+ Object source,
+ String property,
+ Object value,
+ DbAttribute dbAttribute,
+ ValidationResult validationResult) {
+ return true;
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_ExtendedTypeEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_ExtendedTypeEntity.java?rev=602075&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_ExtendedTypeEntity.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/auto/_ExtendedTypeEntity.java Fri Dec 7 03:54:18 2007
@@ -0,0 +1,25 @@
+package org.apache.art.auto;
+
+import org.apache.art.StringET1;
+import org.apache.cayenne.CayenneDataObject;
+
+/**
+ * Class _ExtendedTypeEntity was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public abstract class _ExtendedTypeEntity extends CayenneDataObject {
+
+ public static final String NAME_PROPERTY = "name";
+
+ public static final String ID_PK_COLUMN = "ID";
+
+ public void setName(StringET1 name) {
+ writeProperty("name", name);
+ }
+ public StringET1 getName() {
+ return (StringET1)readProperty("name");
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSelectQueryExtendedTypeTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSelectQueryExtendedTypeTest.java?rev=602075&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSelectQueryExtendedTypeTest.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSelectQueryExtendedTypeTest.java Fri Dec 7 03:54:18 2007
@@ -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.access;
+
+import org.apache.art.ExtendedTypeEntity;
+import org.apache.art.StringET1;
+import org.apache.cayenne.query.SQLTemplate;
+import org.apache.cayenne.unit.CayenneCase;
+
+public class DataContextSelectQueryExtendedTypeTest extends CayenneCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ deleteTestData();
+ }
+
+ public void testStoreExtendedType() {
+ ExtendedTypeEntity e1 = createDataContext().newObject(ExtendedTypeEntity.class);
+ e1.setName(new StringET1("X"));
+ e1.getObjectContext().commitChanges();
+
+ SQLTemplate checkQ = new SQLTemplate(
+ ExtendedTypeEntity.class,
+ "SELECT * FROM EXTENDED_TYPE_TEST WHERE NAME = 'X'");
+ checkQ.setFetchingDataRows(true);
+ checkQ.setColumnNamesCapitalization(SQLTemplate.UPPERCASE_COLUMN_NAMES);
+ assertEquals(1, e1.getObjectContext().performQuery(checkQ).size());
+ }
+}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStack.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStack.java?rev=602075&r1=602074&r2=602075&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStack.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStack.java Fri Dec 7 03:54:18 2007
@@ -35,7 +35,7 @@
UnitTestDomain getDataDomain();
- void createTestData(Class testCase, String testName, Map parameters) throws Exception;
+ void createTestData(Class<?> testCase, String testName, Map parameters) throws Exception;
void deleteTestData() throws Exception;
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/DataSetFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/DataSetFactory.java?rev=602075&r1=602074&r2=602075&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/DataSetFactory.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/DataSetFactory.java Fri Dec 7 03:54:18 2007
@@ -33,5 +33,5 @@
/**
* Returns a query for creation of the data set.
*/
- Query getDataSetQuery(Class testCase, String testName, Map parameters);
+ Query getDataSetQuery(Class<?> testCase, String testName, Map parameters);
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java?rev=602075&r1=602074&r2=602075&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java Fri Dec 7 03:54:18 2007
@@ -19,9 +19,9 @@
package org.apache.cayenne.unit;
-import java.util.Iterator;
import java.util.Map;
+import org.apache.art.StringET1ExtendedType;
import org.apache.cayenne.access.DataDomain;
import org.apache.cayenne.access.DataNode;
import org.apache.cayenne.access.UnitTestDomain;
@@ -59,10 +59,11 @@
protected void initNode(DataMap map) throws Exception {
DataNode node = resources.newDataNode(map.getName());
+ // setup test extended types
+ node.getAdapter().getExtendedTypes().registerType(new StringET1ExtendedType());
+
// tweak mapping with a delegate
- Iterator procedures = map.getProcedures().iterator();
- while (procedures.hasNext()) {
- Procedure proc = (Procedure) procedures.next();
+ for (Procedure proc : map.getProcedures()) {
getAdapter(node).tweakProcedure(proc);
}
@@ -79,7 +80,6 @@
}
domain.addNode(node);
-
}
/**
@@ -89,7 +89,7 @@
return domain;
}
- public void createTestData(Class testCase, String testName, Map parameters)
+ public void createTestData(Class<?> testCase, String testName, Map parameters)
throws Exception {
Query query = dataSetFactory.getDataSetQuery(testCase, testName, parameters);
getDataDomain().onQuery(null, query);
@@ -99,18 +99,14 @@
* Deletes all data from the database tables mentioned in the DataMap.
*/
public void deleteTestData() throws Exception {
- Iterator it = domain.getDataNodes().iterator();
- while (it.hasNext()) {
- DataNode node = (DataNode) it.next();
+ for (DataNode node : domain.getDataNodes()) {
deleteTestData(node, node.getDataMaps().iterator().next());
}
}
/** Drops all test tables. */
public void dropSchema() throws Exception {
- Iterator it = domain.getDataNodes().iterator();
- while (it.hasNext()) {
- DataNode node = (DataNode) it.next();
+ for (DataNode node : domain.getDataNodes()) {
dropSchema(node, node.getDataMaps().iterator().next());
}
}
@@ -119,17 +115,13 @@
* Creates all test tables in the database.
*/
public void createSchema() throws Exception {
- Iterator it = domain.getDataNodes().iterator();
- while (it.hasNext()) {
- DataNode node = (DataNode) it.next();
+ for (DataNode node : domain.getDataNodes()) {
createSchema(node, node.getDataMaps().iterator().next());
}
}
public void dropPKSupport() throws Exception {
- Iterator it = domain.getDataNodes().iterator();
- while (it.hasNext()) {
- DataNode node = (DataNode) it.next();
+ for (DataNode node : domain.getDataNodes()) {
dropPKSupport(node, node.getDataMaps().iterator().next());
}
}
@@ -140,9 +132,7 @@
* primary key support.
*/
public void createPKSupport() throws Exception {
- Iterator it = domain.getDataNodes().iterator();
- while (it.hasNext()) {
- DataNode node = (DataNode) it.next();
+ for (DataNode node : domain.getDataNodes()) {
createPKSupport(node, node.getDataMaps().iterator().next());
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml?rev=602075&r1=602074&r2=602075&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml Fri Dec 7 03:54:18 2007
@@ -31,6 +31,11 @@
<db-attribute name="ARTIST_NAME" type="CHAR" isMandatory="true" length="254"/>
<db-attribute name="DATE_OF_BIRTH" type="DATE"/>
</db-entity>
+ <db-entity name="ARTIST_CT">
+ <db-attribute name="ARTIST_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+ <db-attribute name="ARTIST_NAME" type="CHAR" isMandatory="true" length="254"/>
+ <db-attribute name="DATE_OF_BIRTH" type="DATE"/>
+ </db-entity>
<db-entity name="ARTIST_EXHIBIT">
<db-attribute name="ARTIST_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
<db-attribute name="EXHIBIT_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
@@ -39,11 +44,6 @@
<db-attribute name="ARTIST_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
<db-attribute name="GROUP_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
</db-entity>
- <db-entity name="ARTIS_CT">
- <db-attribute name="ARTIST_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
- <db-attribute name="ARTIST_NAME" type="CHAR" isMandatory="true" length="254"/>
- <db-attribute name="DATE_OF_BIRTH" type="DATE"/>
- </db-entity>
<db-entity name="BIGDECIMAL_ENTITY">
<db-attribute name="BIGDECIMAL_FIELD" type="NUMERIC" length="12" scale="2"/>
<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
@@ -121,6 +121,10 @@
<db-attribute name="GALLERY_ID" type="INTEGER" isMandatory="true"/>
<db-attribute name="OPENING_DATE" type="TIMESTAMP" isMandatory="true"/>
</db-entity>
+ <db-entity name="EXTENDED_TYPE_TEST">
+ <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+ <db-attribute name="NAME" type="VARCHAR" length="200"/>
+ </db-entity>
<db-entity name="FLOAT_TEST">
<db-attribute name="FLOAT_COL" type="FLOAT"/>
<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
@@ -227,12 +231,7 @@
<obj-attribute name="artistName" type="java.lang.String" db-attribute-path="ARTIST_NAME"/>
<obj-attribute name="dateOfBirth" type="java.util.Date" db-attribute-path="DATE_OF_BIRTH"/>
</obj-entity>
- <obj-entity name="ArtistCallbackTest"
- className="org.apache.art.ArtistCallbackTest"
- dbEntityName="ARTIST_CT"
- exclude-superclass-listeners="true"
- exclude-default-listeners="true">
-
+ <obj-entity name="ArtistCallbackTest" className="org.apache.art.ArtistCallbackTest" dbEntityName="ARTIST_CT" exclude-superclass-listeners="true" exclude-default-listeners="true">
<obj-attribute name="artistName" type="java.lang.String"/>
<obj-attribute name="dateOfBirth" type="java.util.Date"/>
<entity-listener class="org.apache.art.EntityListenerObjEntity">
@@ -325,6 +324,9 @@
<obj-entity name="Exhibit" className="org.apache.art.Exhibit" dbEntityName="EXHIBIT">
<obj-attribute name="closingDate" type="java.util.Date" db-attribute-path="CLOSING_DATE"/>
<obj-attribute name="openingDate" type="java.util.Date" db-attribute-path="OPENING_DATE"/>
+ </obj-entity>
+ <obj-entity name="ExtendedTypeEntity" className="org.apache.art.ExtendedTypeEntity" dbEntityName="EXTENDED_TYPE_TEST">
+ <obj-attribute name="name" type="org.apache.art.StringET1" db-attribute-path="NAME"/>
</obj-entity>
<obj-entity name="Gallery" className="org.apache.art.Gallery" dbEntityName="GALLERY">
<obj-attribute name="galleryName" type="java.lang.String" db-attribute-path="GALLERY_NAME"/>