openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwsut...@apache.org
Subject svn commit: r562986 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/ openjpa-persistence-jd...
Date Sun, 05 Aug 2007 23:30:12 GMT
Author: kwsutter
Date: Sun Aug  5 16:30:08 2007
New Revision: 562986

URL: http://svn.apache.org/viewvc?view=rev&rev=562986
Log:
OPENJPA-281.  Committing the patch that I posted earlier this week.  These changes do the
proper eager loading of @Basic types.  Along with a new testcase and updated AllFieldTypes.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestBasicAnnotation.java
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/AllFieldTypes.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java?view=diff&rev=562986&r1=562985&r2=562986
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
Sun Aug  5 16:30:08 2007
@@ -483,7 +483,8 @@
         _val.resolve(MODE_MAPPING_INIT);
         _key.resolve(MODE_MAPPING_INIT);
         _val.resolve(MODE_MAPPING_INIT);
-        _strategy.initialize();
+        if (_strategy != null)
+            _strategy.initialize();
     }
 
     public void copy(FieldMetaData fmd) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java?view=diff&rev=562986&r1=562985&r2=562986
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
Sun Aug  5 16:30:08 2007
@@ -1009,7 +1009,8 @@
         if (handler instanceof ValueHandler)
             return (ValueHandler) handler;
 
-        if (val.getType() == byte[].class) {
+        if (val.getType() == byte[].class 
+            || val.getType() == Byte[].class) {
             if (_dict.maxEmbeddedBlobSize != -1)
                 warnMaxEmbedded(val, _dict.maxEmbeddedBlobSize);
             return ByteArrayValueHandler.getInstance();

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java?view=diff&rev=562986&r1=562985&r2=562986
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
Sun Aug  5 16:30:08 2007
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.io.Serializable;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
@@ -170,6 +171,10 @@
     private String _extString = null;
     private Map _extValues = Collections.EMPTY_MAP;
     private Map _fieldValues = Collections.EMPTY_MAP;
+    private Boolean _enumField = null;
+    private Boolean _lobField = null;
+    private Boolean _serializableField = null;
+    private boolean _generated = false;
 
     // Members aren't serializable. Use a proxy that can provide a Member
     // to avoid writing the full Externalizable implementation.
@@ -590,7 +595,17 @@
                 switch (getTypeCode()) {
                     case JavaTypes.OBJECT:
                     case JavaTypes.PC:
+                        if (isSerializable() || isEnum())
+                            _dfg = DFG_TRUE;
+                        else
+                            _dfg = DFG_FALSE;
+                        break;
                     case JavaTypes.ARRAY:
+                        if (isLobArray())
+                            _dfg = DFG_TRUE;
+                        else
+                            _dfg = DFG_FALSE;
+                        break;
                     case JavaTypes.COLLECTION:
                     case JavaTypes.MAP:
                     case JavaTypes.PC_UNTYPED:
@@ -604,6 +619,38 @@
         return (_dfg & DFG_TRUE) > 0;
     }
 
+    private boolean isEnum() {
+        if (_enumField == null) {
+            Class dt = getDeclaredType();
+            _enumField = dt.isEnum() ? Boolean.TRUE : Boolean.FALSE;
+        }
+        return _enumField.booleanValue();
+    }
+
+    private boolean isSerializable() {
+        if (_serializableField == null) {
+            Class dt = getDeclaredType();
+            if (Serializable.class.isAssignableFrom(dt))
+                _serializableField = Boolean.TRUE;
+            else
+                _serializableField = Boolean.FALSE;
+        }
+        return _serializableField.booleanValue();
+    }
+
+    private boolean isLobArray() {
+        // check for byte[], Byte[], char[], Character[]
+        if (_lobField == null) {
+            Class dt = getDeclaredType();
+            if (dt == byte[].class || dt == Byte[].class ||
+                dt == char[].class || dt == Character[].class)
+                _lobField = Boolean.TRUE;
+            else
+                _lobField = Boolean.FALSE;
+        }
+        return _lobField.booleanValue();
+    }
+
     /**
      * Whether this field is in the default fetch group.
      */
@@ -1732,6 +1779,10 @@
         _fieldValues = Collections.EMPTY_MAP;
         _primKey = field.isPrimaryKey();
         _backingMember = field._backingMember;
+        _enumField = field._enumField;
+        _lobField = field._lobField;
+        _serializableField = field._serializableField;
+        _generated = field._generated;
 
         // embedded fields can't be versions
         if (_owner.getEmbeddingMetaData() == null && _version == null)
@@ -1995,5 +2046,13 @@
             if (!isField)
                 out.writeObject(((Method) _member).getParameterTypes());
         }
+    }
+
+    public boolean is_generated() {
+        return _generated;
+    }
+
+    public void set_generated(boolean _generated) {
+        this._generated = _generated;
     }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/AllFieldTypes.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/AllFieldTypes.java?view=diff&rev=562986&r1=562985&r2=562986
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/AllFieldTypes.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/AllFieldTypes.java
Sun Aug  5 16:30:08 2007
@@ -18,16 +18,24 @@
  */
 package org.apache.openjpa.persistence.simple;
 
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Set;
 import javax.persistence.Entity;
+import javax.persistence.Version;
 
 import org.apache.openjpa.persistence.PersistentCollection;
 
 @Entity
 public class AllFieldTypes {
-
+    
+    public static enum EnumType {Value1, Value2};
+    
+    // @Basic types
     private short shortField;
     private int intField;
     private boolean booleanField;
@@ -36,8 +44,30 @@
     private char charField;
     private double doubleField;
     private byte byteField;
+    private Short wShortField;
+    private Integer wIntegerField;
+    private Boolean wBooleanField;
+    private Long wLongField;
+    private Float wFloatField;
+    private Character wCharacterField;
+    private Double wDoubleField;
+    private Byte wByteField;
+    private BigInteger bigIntegerField;
+    private BigDecimal bigDecimalField;
     private String stringField;
     private Date dateField;
+    private Calendar calendarField;
+    private java.sql.Date sqlDateField;
+    private java.sql.Time sqlTimeField;
+    private java.sql.Timestamp sqlTimestampField;
+    private byte[] byteLob;
+    private Byte[] wByteLob;
+    private char[] charLob;
+    private Character[] wCharacterLob;
+    private EnumType enumField;
+    private Serializable serializableField;
+    
+    // Additional types
     private Set<String> setOfStrings = new HashSet<String>();
     private String[] arrayOfStrings;
 
@@ -147,5 +177,166 @@
     public int[] getArrayOfInts() {
         return arrayOfInts;
     }
+
+    public BigDecimal getBigDecimalField() {
+        return bigDecimalField;
+    }
+
+    public void setBigDecimalField(BigDecimal bigDecimalField) {
+        this.bigDecimalField = bigDecimalField;
+    }
+
+    public BigInteger getBigIntegerField() {
+        return bigIntegerField;
+    }
+
+    public void setBigIntegerField(BigInteger bigIntegerField) {
+        this.bigIntegerField = bigIntegerField;
+    }
+
+    public byte[] getByteLob() {
+        return byteLob;
+    }
+
+    public void setByteLob(byte[] byteLob) {
+        this.byteLob = byteLob;
+    }
+
+    public Calendar getCalendarField() {
+        return calendarField;
+    }
+
+    public void setCalendarField(Calendar calendarField) {
+        this.calendarField = calendarField;
+    }
+
+    public char[] getCharLob() {
+        return charLob;
+    }
+
+    public void setCharLob(char[] charLob) {
+        this.charLob = charLob;
+    }
+
+    public EnumType getEnumField() {
+        return enumField;
+    }
+
+    public void setEnumField(EnumType enumField) {
+        this.enumField = enumField;
+    }
+
+    public Serializable getSerializableField() {
+        return serializableField;
+    }
+
+    public void setSerializableField(Serializable serializableField) {
+        this.serializableField = serializableField;
+    }
+
+    public java.sql.Date getSqlDateField() {
+        return sqlDateField;
+    }
+
+    public void setSqlDateField(java.sql.Date sqlDateField) {
+        this.sqlDateField = sqlDateField;
+    }
+
+    public java.sql.Time getSqlTimeField() {
+        return sqlTimeField;
+    }
+
+    public void setSqlTimeField(java.sql.Time sqlTimeField) {
+        this.sqlTimeField = sqlTimeField;
+    }
+
+    public java.sql.Timestamp getSqlTimestampField() {
+        return sqlTimestampField;
+    }
+
+    public void setSqlTimestampField(java.sql.Timestamp sqlTimestampField) {
+        this.sqlTimestampField = sqlTimestampField;
+    }
+
+    public Boolean getWBooleanField() {
+        return wBooleanField;
+    }
+
+    public void setWBooleanField(Boolean booleanField) {
+        wBooleanField = booleanField;
+    }
+
+    public Byte getWByteField() {
+        return wByteField;
+    }
+
+    public void setWByteField(Byte byteField) {
+        wByteField = byteField;
+    }
+
+    public Byte[] getWByteLob() {
+        return wByteLob;
+    }
+
+    public void setWByteLob(Byte[] byteLob) {
+        wByteLob = byteLob;
+    }
+
+    public Character getWCharacterField() {
+        return wCharacterField;
+    }
+
+    public void setWCharacterField(Character characterField) {
+        wCharacterField = characterField;
+    }
+
+    public Character[] getWCharacterLob() {
+        return wCharacterLob;
+    }
+
+    public void setWCharacterLob(Character[] characterLob) {
+        wCharacterLob = characterLob;
+    }
+
+    public Double getWDoubleField() {
+        return wDoubleField;
+    }
+
+    public void setWDoubleField(Double doubleField) {
+        wDoubleField = doubleField;
+    }
+
+    public Float getWFloatField() {
+        return wFloatField;
+    }
+
+    public void setWFloatField(Float floatField) {
+        wFloatField = floatField;
+    }
+
+    public Integer getWIntegerField() {
+        return wIntegerField;
+    }
+
+    public void setWIntegerField(Integer integerField) {
+        wIntegerField = integerField;
+    }
+
+    public Long getWLongField() {
+        return wLongField;
+    }
+
+    public void setWLongField(Long longField) {
+        wLongField = longField;
+    }
+
+    public Short getWShortField() {
+        return wShortField;
+    }
+
+    public void setWShortField(Short shortField) {
+        wShortField = shortField;
+    }
+
 }
 

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestBasicAnnotation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestBasicAnnotation.java?view=auto&rev=562986
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestBasicAnnotation.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestBasicAnnotation.java
Sun Aug  5 16:30:08 2007
@@ -0,0 +1,92 @@
+/*
+ * 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.simple;
+
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.Date;
+
+import javax.persistence.EntityManager;
+
+import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * Simple test case to test the default values associated with the @Basic 
+ * annotation.
+ *
+ * @author Kevin Sutter
+ */
+public class TestBasicAnnotation
+    extends SingleEMFTestCase {
+
+    public void setUp() {
+        setUp(CLEAR_TABLES, AllFieldTypes.class);
+    }
+
+    public void testEagerFetchType() {
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        AllFieldTypes aft = new AllFieldTypes();
+        
+        // Initialize a sampling of the types
+        aft.setBigDecimalField(new BigDecimal(1));
+        aft.setBooleanField(false);
+        aft.setByteLob(new byte[1]);
+        aft.setCalendarField(Calendar.getInstance());
+        aft.setDateField(new Date());
+        aft.setEnumField(AllFieldTypes.EnumType.Value1);
+        aft.setSerializableField(new Date());
+        aft.setSqlTimestampField(new java.sql.Timestamp(
+                System.currentTimeMillis()));
+        aft.setStringField("aft");
+        aft.setWByteLob(new Byte[1]);
+        aft.setWDoubleField(new Double(1));
+        
+        em.persist(aft);
+        em.getTransaction().commit();
+        em.clear();
+        
+        AllFieldTypes aftQuery = (AllFieldTypes)em.createQuery
+            ("select x from AllFieldTypes x where x.stringField = 'aft'").
+            getSingleResult();
+        em.clear();  // ensure detached
+        assertFalse(em.contains(aftQuery));
+        
+        // assert that the sampling of fields are not null
+        assertNotNull(aftQuery.getBigDecimalField());
+        assertNotNull(aftQuery.getBooleanField());
+        assertNotNull(aftQuery.getByteLob());
+        assertNotNull(aftQuery.getCalendarField());
+        assertNotNull(aftQuery.getDateField());
+        assertNotNull(aftQuery.getEnumField());
+        assertNotNull(aftQuery.getSerializableField());
+        assertNotNull(aftQuery.getSqlTimestampField());
+        assertNotNull(aftQuery.getStringField());
+        assertNotNull(aftQuery.getWByteLob());
+        assertNotNull(aftQuery.getWDoubleField());
+        
+        em.close();
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(TestBasicAnnotation.class);
+    }
+}
+

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml?view=diff&rev=562986&r1=562985&r2=562986
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
Sun Aug  5 16:30:08 2007
@@ -39,9 +39,18 @@
     </entity>
     <entity name="XmlOverride" class="XmlOverrideEntity">
     	<attributes>
-	    <basic name="name" optional="true"></basic>
-	    <basic name="description" optional="false"></basic>
+	    	<basic name="name" optional="true"></basic>
+	    	<basic name="description" optional="false"></basic>
     	</attributes>
+    </entity>
+    <entity name="AllFieldTypes" 
+        	class="org.apache.openjpa.persistence.simple.AllFieldTypes">
+    	<attributes>
+			<basic name="byteLob" fetch="EAGER"> 
+				<column name="BYTELOB"/>
+				<lob/>
+			</basic>
+		</attributes>
     </entity>
 </entity-mappings>
 



Mime
View raw message