cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r439569 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/access/types/ main/java/org/apache/cayenne/dba/ test/java/org/apache/art/ test/java/org/apache/art/auto/ test/java/org/apache/cayenne/access/ t...
Date Sat, 02 Sep 2006 10:07:42 GMT
Author: aadamchik
Date: Sat Sep  2 03:07:40 2006
New Revision: 439569

URL: http://svn.apache.org/viewvc?rev=439569&view=rev
Log:
CAY-647

Added:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BigIntegerType.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/BigDecimalEntity.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/BigIntegerEntity.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_BigDecimalEntity.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_BigIntegerEntity.java
Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/TypesMapping.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/NumericTypesTst.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/resources/testmap.map.xml

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BigIntegerType.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BigIntegerType.java?rev=439569&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BigIntegerType.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/BigIntegerType.java
Sat Sep  2 03:07:40 2006
@@ -0,0 +1,87 @@
+/*****************************************************************
+ *   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.types;
+
+import java.math.BigInteger;
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import org.apache.cayenne.dba.TypesMapping;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.validation.ValidationResult;
+
+/**
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+public class BigIntegerType implements ExtendedType {
+
+    public String getClassName() {
+        return BigInteger.class.getName();
+    }
+
+    public Object materializeObject(ResultSet rs, int index, int type) throws Exception {
+        Object object = rs.getObject(index);
+        if (rs.wasNull()) {
+            return null;
+        }
+
+        return new BigInteger(object.toString());
+    }
+
+    public Object materializeObject(CallableStatement rs, int index, int type)
+            throws Exception {
+        Object object = rs.getObject(index);
+        if (rs.wasNull()) {
+            return null;
+        }
+
+        return new BigInteger(object.toString());
+    }
+
+    public void setJdbcObject(
+            PreparedStatement statement,
+            Object value,
+            int pos,
+            int type,
+            int precision) throws Exception {
+
+        if (value == null) {
+            statement.setNull(pos, type);
+        }
+        else if (TypesMapping.isNumeric(type)) {
+            statement.setLong(pos, ((BigInteger) value).longValue());
+        }
+        else {
+            throw new IllegalArgumentException(
+                    "Can't map BigInteger to a non-numeric type: "
+                            + TypesMapping.getSqlNameByType(type));
+        }
+    }
+
+    public boolean validateProperty(
+            Object source,
+            String property,
+            Object value,
+            DbAttribute dbAttribute,
+            ValidationResult validationResult) {
+        return true;
+    }
+}

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java?rev=439569&r1=439568&r2=439569&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
Sat Sep  2 03:07:40 2006
@@ -32,6 +32,7 @@
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.trans.QualifierTranslator;
 import org.apache.cayenne.access.trans.QueryAssembler;
+import org.apache.cayenne.access.types.BigIntegerType;
 import org.apache.cayenne.access.types.BooleanType;
 import org.apache.cayenne.access.types.ByteArrayType;
 import org.apache.cayenne.access.types.CalendarType;
@@ -142,6 +143,8 @@
         // subclasses at once
         map.registerType(new CalendarType(GregorianCalendar.class));
         map.registerType(new CalendarType(Calendar.class));
+        
+        map.registerType(new BigIntegerType());
     }
 
     /**

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/TypesMapping.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/TypesMapping.java?rev=439569&r1=439568&r2=439569&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/TypesMapping.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/dba/TypesMapping.java
Sat Sep  2 03:07:40 2006
@@ -19,6 +19,7 @@
 
 package org.apache.cayenne.dba;
 
+import java.math.BigInteger;
 import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -369,6 +370,9 @@
         // check non-standard types
         if(Calendar.class.isAssignableFrom(javaClass)) {
             return Types.TIMESTAMP;
+        }
+        else if(BigInteger.class.isAssignableFrom(javaClass)) {
+            return Types.BIGINT;
         }
         
         while (javaClass != null) {

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/BigDecimalEntity.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/BigDecimalEntity.java?rev=439569&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/BigDecimalEntity.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/BigDecimalEntity.java
Sat Sep  2 03:07:40 2006
@@ -0,0 +1,10 @@
+package org.apache.art;
+
+import org.apache.art.auto._BigDecimalEntity;
+
+public class BigDecimalEntity extends _BigDecimalEntity {
+
+}
+
+
+

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/BigIntegerEntity.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/BigIntegerEntity.java?rev=439569&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/BigIntegerEntity.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/BigIntegerEntity.java
Sat Sep  2 03:07:40 2006
@@ -0,0 +1,10 @@
+package org.apache.art;
+
+import org.apache.art.auto._BigIntegerEntity;
+
+public class BigIntegerEntity extends _BigIntegerEntity {
+
+}
+
+
+

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_BigDecimalEntity.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_BigDecimalEntity.java?rev=439569&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_BigDecimalEntity.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_BigDecimalEntity.java
Sat Sep  2 03:07:40 2006
@@ -0,0 +1,22 @@
+package org.apache.art.auto;
+
+/** Class _BigDecimalEntity 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 class _BigDecimalEntity extends org.apache.cayenne.CayenneDataObject {
+
+    public static final String BIG_DECIMAL_FIELD_PROPERTY = "bigDecimalField";
+
+    public static final String ID_PK_COLUMN = "ID";
+
+    public void setBigDecimalField(java.math.BigDecimal bigDecimalField) {
+        writeProperty("bigDecimalField", bigDecimalField);
+    }
+    public java.math.BigDecimal getBigDecimalField() {
+        return (java.math.BigDecimal)readProperty("bigDecimalField");
+    }
+    
+    
+}

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_BigIntegerEntity.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_BigIntegerEntity.java?rev=439569&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_BigIntegerEntity.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_BigIntegerEntity.java
Sat Sep  2 03:07:40 2006
@@ -0,0 +1,22 @@
+package org.apache.art.auto;
+
+/** Class _BigIntegerEntity 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 class _BigIntegerEntity extends org.apache.cayenne.CayenneDataObject {
+
+    public static final String BIG_INTEGER_FIELD_PROPERTY = "bigIntegerField";
+
+    public static final String ID_PK_COLUMN = "ID";
+
+    public void setBigIntegerField(java.math.BigInteger bigIntegerField) {
+        writeProperty("bigIntegerField", bigIntegerField);
+    }
+    public java.math.BigInteger getBigIntegerField() {
+        return (java.math.BigInteger)readProperty("bigIntegerField");
+    }
+    
+    
+}

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/NumericTypesTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/NumericTypesTst.java?rev=439569&r1=439568&r2=439569&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/NumericTypesTst.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/NumericTypesTst.java
Sat Sep  2 03:07:40 2006
@@ -20,10 +20,13 @@
 package org.apache.cayenne.access;
 
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.art.BigDecimalEntity;
+import org.apache.art.BigIntegerEntity;
 import org.apache.art.BitTestEntity;
 import org.apache.art.BooleanTestEntity;
 import org.apache.art.DecimalPKTest1;
@@ -50,6 +53,42 @@
         context = createDataContext();
     }
 
+    public void testBigInteger() throws Exception {
+
+        BigIntegerEntity test = (BigIntegerEntity) context
+                .newObject(BigIntegerEntity.class);
+
+        BigInteger i = new BigInteger("1234567890");
+        test.setBigIntegerField(i);
+        context.commitChanges();
+
+        SelectQuery q = new SelectQuery(BigIntegerEntity.class);
+        BigIntegerEntity testRead = (BigIntegerEntity) context.performQuery(q).get(0);
+        assertNotNull(testRead.getBigIntegerField());
+        assertEquals(i, testRead.getBigIntegerField());
+
+        test.setBigIntegerField(null);
+        context.commitChanges();
+    }
+    
+    public void testBigDecimal() throws Exception {
+
+        BigDecimalEntity test = (BigDecimalEntity) context
+                .newObject(BigDecimalEntity.class);
+
+        BigDecimal i = new BigDecimal("1234567890.44");
+        test.setBigDecimalField(i);
+        context.commitChanges();
+
+        SelectQuery q = new SelectQuery(BigDecimalEntity.class);
+        BigDecimalEntity testRead = (BigDecimalEntity) context.performQuery(q).get(0);
+        assertNotNull(testRead.getBigDecimalField());
+        assertEquals(i, testRead.getBigDecimalField());
+
+        test.setBigDecimalField(null);
+        context.commitChanges();
+    }
+
     public void testShortInQualifier() throws Exception {
         createTestData("testShortInQualifier");
 
@@ -149,7 +188,9 @@
 
         // fetch true...
         Expression trueQ = ExpressionFactory.matchExp("booleanColumn", Boolean.TRUE);
-        List trueResult = context.performQuery(new SelectQuery(BooleanTestEntity.class, trueQ));
+        List trueResult = context.performQuery(new SelectQuery(
+                BooleanTestEntity.class,
+                trueQ));
         assertEquals(1, trueResult.size());
 
         BooleanTestEntity trueRefetched = (BooleanTestEntity) trueResult.get(0);
@@ -161,8 +202,9 @@
 
         // fetch false
         Expression falseQ = ExpressionFactory.matchExp("booleanColumn", Boolean.FALSE);
-        List falseResult = context
-                .performQuery(new SelectQuery(BooleanTestEntity.class, falseQ));
+        List falseResult = context.performQuery(new SelectQuery(
+                BooleanTestEntity.class,
+                falseQ));
         assertEquals(1, falseResult.size());
 
         BooleanTestEntity falseRefetched = (BooleanTestEntity) falseResult.get(0);

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/resources/testmap.map.xml
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/resources/testmap.map.xml?rev=439569&r1=439568&r2=439569&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/resources/testmap.map.xml (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/resources/testmap.map.xml Sat
Sep  2 03:07:40 2006
@@ -30,6 +30,14 @@
 		<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="BIGDECIMAL_ENTITY">
+		<db-attribute name="BIGDECIMAL_FIELD" type="NUMERIC"/>
+		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+	</db-entity>
+	<db-entity name="BIGINTEGER_ENTITY">
+		<db-attribute name="BIG_INTEGER_FIELD" type="BIGINT"/>
+		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+	</db-entity>
 	<db-entity name="BINARY_PK_TEST1">
 		<db-attribute name="BIN_ID" type="VARBINARY" isPrimaryKey="true" isMandatory="true"
length="32"/>
 		<db-attribute name="NAME" type="VARCHAR" length="10"/>
@@ -201,6 +209,12 @@
 	</obj-entity>
 	<obj-entity name="ArtistPaintingCounts" className="org.apache.art.ArtistPaintingCounts"
dbEntityName="ARTIST_ASSETS">
 		<obj-attribute name="paintingsCount" type="java.lang.Integer" db-attribute-path="PAINTINGS_COUNT"/>
+	</obj-entity>
+	<obj-entity name="BigDecimalEntity" className="org.apache.art.BigDecimalEntity" dbEntityName="BIGDECIMAL_ENTITY">
+		<obj-attribute name="bigDecimalField" type="java.math.BigDecimal" db-attribute-path="BIGDECIMAL_FIELD"/>
+	</obj-entity>
+	<obj-entity name="BigIntegerEntity" className="org.apache.art.BigIntegerEntity" dbEntityName="BIGINTEGER_ENTITY">
+		<obj-attribute name="bigIntegerField" type="java.math.BigInteger" db-attribute-path="BIG_INTEGER_FIELD"/>
 	</obj-entity>
 	<obj-entity name="BinaryPKTest1" className="org.apache.art.BinaryPKTest1" dbEntityName="BINARY_PK_TEST1">
 		<obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>



Mime
View raw message