Author: mikedd
Date: Tue May 20 03:51:42 2008
New Revision: 658197
URL: http://svn.apache.org/viewvc?rev=658197&view=rev
Log:
OPENJPA-213
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/PrecisionTestEntity.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestPrecisionMapping.java
(with props)
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=658197&r1=658196&r2=658197&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Tue May 20 03:51:42 2008
@@ -1499,7 +1499,7 @@
case JavaTypes.BIGDECIMAL:
if (storeLargeNumbersAsStrings)
return getPreferredType(Types.VARCHAR);
- return getPreferredType(Types.DOUBLE);
+ return getPreferredType(Types.NUMERIC);
case JavaTypes.NUMBER:
if (storeLargeNumbersAsStrings)
return getPreferredType(Types.VARCHAR);
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/PrecisionTestEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/PrecisionTestEntity.java?rev=658197&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/PrecisionTestEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/PrecisionTestEntity.java
Tue May 20 03:51:42 2008
@@ -0,0 +1,173 @@
+/*
+ * 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.openjpa.persistence.jdbc.mapping;
+
+import java.math.BigDecimal;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+@Entity
+public class PrecisionTestEntity {
+ @Id
+ @GeneratedValue
+ private int id;
+ @Version
+ private int version;
+
+ private double primDbl;
+ private Double dbl;
+ private BigDecimal bigDecimal;
+
+ @Column(precision = 10)
+ private double primDblPrecis;
+ @Column(precision = 10)
+ private Double dblPrecis;
+ @Column(precision = 10)
+ private BigDecimal bigDecimalPrecis;
+
+ @Column(scale = 10)
+ private double primDblScale;
+ @Column(scale = 10)
+ private Double dblScale;
+ @Column(scale = 10)
+ private BigDecimal bigDecimalScale;
+
+ @Column(precision = 10, scale = 10)
+ private double primDblPrecisScale;
+ @Column(precision = 10, scale = 10)
+ private Double dblPrecisScale;
+ @Column(precision = 10, scale = 10)
+ private BigDecimal bigDecimalPrecisScale;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getVersion() {
+ return version;
+ }
+
+ public void setVersion(int version) {
+ this.version = version;
+ }
+
+ public double getPrimDbl() {
+ return primDbl;
+ }
+
+ public void setPrimDbl(double primDbl) {
+ this.primDbl = primDbl;
+ }
+
+ public Double getDbl() {
+ return dbl;
+ }
+
+ public void setDbl(Double dbl) {
+ this.dbl = dbl;
+ }
+
+ public BigDecimal getBigDecimal() {
+ return bigDecimal;
+ }
+
+ public void setBigDecimal(BigDecimal bigDecimal) {
+ this.bigDecimal = bigDecimal;
+ }
+
+ public double getPrimDblPrecis() {
+ return primDblPrecis;
+ }
+
+ public void setPrimDblPrecis(double primDblPrecis) {
+ this.primDblPrecis = primDblPrecis;
+ }
+
+ public Double getDblPrecis() {
+ return dblPrecis;
+ }
+
+ public void setDblPrecis(Double dblPrecis) {
+ this.dblPrecis = dblPrecis;
+ }
+
+ public BigDecimal getBigDecimalPrecis() {
+ return bigDecimalPrecis;
+ }
+
+ public void setBigDecimalPrecis(BigDecimal bigDecimalPrecis) {
+ this.bigDecimalPrecis = bigDecimalPrecis;
+ }
+
+ public double getPrimDblScale() {
+ return primDblScale;
+ }
+
+ public void setPrimDblScale(double primDblScale) {
+ this.primDblScale = primDblScale;
+ }
+
+ public Double getDblScale() {
+ return dblScale;
+ }
+
+ public void setDblScale(Double dblScale) {
+ this.dblScale = dblScale;
+ }
+
+ public BigDecimal getBigDecimalScale() {
+ return bigDecimalScale;
+ }
+
+ public void setBigDecimalScale(BigDecimal bigDecimalScale) {
+ this.bigDecimalScale = bigDecimalScale;
+ }
+
+ public double getPrimDblPrecisScale() {
+ return primDblPrecisScale;
+ }
+
+ public void setPrimDblPrecisScale(double primDblPrecisScale) {
+ this.primDblPrecisScale = primDblPrecisScale;
+ }
+
+ public Double getDblPrecisScale() {
+ return dblPrecisScale;
+ }
+
+ public void setDblPrecisScale(Double dblPrecisScale) {
+ this.dblPrecisScale = dblPrecisScale;
+ }
+
+ public BigDecimal getBigDecimalPrecisScale() {
+ return bigDecimalPrecisScale;
+ }
+
+ public void setBigDecimalPrecisScale(BigDecimal bigDecimalPrecisScale) {
+ this.bigDecimalPrecisScale = bigDecimalPrecisScale;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/PrecisionTestEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestPrecisionMapping.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestPrecisionMapping.java?rev=658197&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestPrecisionMapping.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestPrecisionMapping.java
Tue May 20 03:51:42 2008
@@ -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.openjpa.persistence.jdbc.mapping;
+
+import java.sql.Types;
+
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestPrecisionMapping extends SingleEMFTestCase {
+
+ private static final String[] _DOUBLE_FIELDS =
+ { "primDbl", "dbl" };
+ private static final String _BIG_DECIMAL_FIELD = "bigDecimal";
+
+ public void setUp() {
+ setUp(PrecisionTestEntity.class);
+ }
+
+ public void testUnspecified() {
+ testDoubleMapping("", Types.DOUBLE,0,0);
+ testBigDecimalMapping("", Types.NUMERIC, 0, 0);
+ }
+
+ public void testPrecisionOnly() {
+ // testDoubleMapping("Precis", Types.NUMERIC, 10, 0);
+ testBigDecimalMapping("Precis", Types.NUMERIC, 10, 0);
+ }
+
+ public void testScaleOnly() {
+ // testDoubleMapping("Scale", Types.NUMERIC, 0 , 10);
+ testBigDecimalMapping("Scale", Types.NUMERIC, 0, 10);
+ }
+
+ public void testPrecisionAndScale() {
+// testDoubleMapping("PrecisScale", Types.NUMERIC,10,10);
+ testBigDecimalMapping("PrecisScale", Types.NUMERIC, 10, 10);
+ }
+
+ private void testBigDecimalMapping(String fieldSuffix, int expectedType,
+ int expectedPrecision, int expectedScale) {
+ ClassMapping mapping = getMapping(PrecisionTestEntity.class);
+ FieldMapping fm =
+ mapping.getFieldMapping(_BIG_DECIMAL_FIELD + fieldSuffix);
+
+ Column[] cols = fm.getColumns();
+ assertEquals(1, cols.length);
+ assertEquals(expectedType, cols[0].getType());
+ assertEquals(expectedPrecision, cols[0].getSize());
+ assertEquals(expectedScale, cols[0].getDecimalDigits());
+ }
+
+ private void testDoubleMapping(String fieldSuffix, int expectedType,
+ int expectedPrecision, int expectedScale) {
+ ClassMapping mapping = getMapping(PrecisionTestEntity.class);
+ FieldMapping fm;
+
+ for(String s : _DOUBLE_FIELDS) {
+ fm = mapping.getFieldMapping(s + fieldSuffix);
+
+ Column[] cols = fm.getColumns();
+ assertEquals(1, cols.length);
+ assertEquals(expectedType ,cols[0].getType());
+ assertEquals(expectedPrecision, cols[0].getSize());
+ assertEquals(expectedScale, cols[0].getDecimalDigits());
+ }
+ }
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestPrecisionMapping.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java?rev=658197&r1=658196&r2=658197&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
Tue May 20 03:51:42 2008
@@ -68,9 +68,32 @@
}
}
+ /**
+ * Get the class mapping for a given entity
+ *
+ * @param name
+ * The Entity's name.
+ *
+ * @return If the entity is a known type the ClassMapping for the Entity
+ * will be returned. Otherwise null
+ */
protected ClassMapping getMapping(String name) {
return (ClassMapping) emf.getConfiguration()
.getMetaDataRepositoryInstance().getMetaData(name,
getClass().getClassLoader(), true);
}
+
+ /**
+ * Get the class mapping for a given entity
+ *
+ * @param entityClass an entity class.
+ *
+ * @return If the entity is a known type the ClassMapping for the Entity
+ * will be returned. Otherwise null
+ */
+ protected ClassMapping getMapping(Class<?> entityClass) {
+ return (ClassMapping) emf.getConfiguration()
+ .getMetaDataRepositoryInstance().getMetaData(entityClass,
+ getClass().getClassLoader(), true);
+ }
}
|