openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1342087 - in /openjpa/branches/2.2.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/
Date Wed, 23 May 2012 23:24:57 GMT
Author: hthomann
Date: Wed May 23 23:24:56 2012
New Revision: 1342087

URL: http://svn.apache.org/viewvc?rev=1342087&view=rev
Log:
OPENJPA-2139: Apply my lastest patch, which includes contributions added by Rick and Mark.

Modified:
    openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
    openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java

Modified: openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java?rev=1342087&r1=1342086&r2=1342087&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
(original)
+++ openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
Wed May 23 23:24:56 2012
@@ -51,7 +51,7 @@ import serp.util.Strings;
 public class MappingDefaultsImpl
     implements MappingDefaults, Configurable {
 
-    protected transient DBDictionary dict = null;
+    private transient DBDictionary dict = null;
     private String _baseClassStrategy = null;
     private String _subclassStrategy = null;
     private String _versionStrategy = null;
@@ -75,6 +75,17 @@ public class MappingDefaultsImpl
     private DBIdentifier _orderName = DBIdentifier.NULL;
     private DBIdentifier _nullIndName = DBIdentifier.NULL;
     private boolean _removeHungarianNotation = false;
+    private Configuration conf = null;
+
+    /**
+     * Convenient access to dictionary for mappings.
+     */
+    public DBDictionary getDBDictionary() {
+        if (dict == null) {
+            dict = ((JDBCConfiguration) conf).getDBDictionaryInstance();
+        }
+        return dict;
+    }
 
     public boolean isRemoveHungarianNotation() {
         return _removeHungarianNotation;
@@ -565,8 +576,10 @@ public class MappingDefaultsImpl
     public String getTableName(ClassMapping cls, Schema schema) {
         String name = Strings.getClassName(cls.getDescribedType()).
             replace(IdentifierUtil.DOLLAR_CHAR, IdentifierUtil.UNDERSCORE_CHAR);
-        if (!_defMissing)
-            name = dict.getValidTableName(name, schema);
+        if (!_defMissing && getDBDictionary() != null) {
+        	name = getDBDictionary().getValidTableName(name, schema);
+        }
+
         return name;
     }
 
@@ -585,8 +598,9 @@ public class MappingDefaultsImpl
             DBIdentifier tableName = DBIdentifier.truncate(table.getIdentifier(),5);
             sName = DBIdentifier.append(tableName, fm.getName());
         }
-        if (!_defMissing)
-            sName = dict.getValidTableName(sName, schema);
+        if (!_defMissing && getDBDictionary() != null){
+            sName = getDBDictionary().getValidTableName(sName, schema);
+        }
         return sName;
     }
 
@@ -608,9 +622,14 @@ public class MappingDefaultsImpl
         if (!_defMissing || _removeHungarianNotation)
         {
             DBIdentifier name = col.getIdentifier();
-            if (_removeHungarianNotation)
+            if (_removeHungarianNotation){
                 name = DBIdentifier.removeHungarianNotation(name);
-            DBIdentifier correctedName = dict.getValidColumnName(name, table);
+            }
+
+            DBIdentifier correctedName = name;
+            if (getDBDictionary() != null) {
+                correctedName = getDBDictionary().getValidColumnName(name, table);
+            }
             col.setIdentifier(correctedName);
             table.addCorrectedColumnName(correctedName, true);
         }
@@ -790,16 +809,24 @@ public class MappingDefaultsImpl
     }
 
     protected DBIdentifier getIndexName(DBIdentifier name, Table table, Column[] cols) {
+        DBIdentifier toReturn = null;
+
         // always use dict for index names because no spec mandates them
         // based on defaults
         DBIdentifier sName = name;
-        if (DBIdentifier.isNull(sName))
+        if (DBIdentifier.isNull(sName)){
             sName = cols[0].getIdentifier();
+        }
 
-        if (_removeHungarianNotation)
+        if (_removeHungarianNotation){
             sName = DBIdentifier.removeHungarianNotation(sName);
+        }
 
-        return dict.getValidIndexName(sName, table);
+        if (getDBDictionary() != null) {
+            toReturn = getDBDictionary().getValidIndexName(sName, table);        	
+        }
+        
+        return toReturn; 
     }
 
     /**
@@ -875,7 +902,7 @@ public class MappingDefaultsImpl
     ///////////////////////////////
 
     public void setConfiguration(Configuration conf) {
-        dict = ((JDBCConfiguration) conf).getDBDictionaryInstance();
+    	this.conf=conf;    	
     }
 
     public void startConfiguration() {

Modified: openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java?rev=1342087&r1=1342086&r2=1342087&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
(original)
+++ openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
Wed May 23 23:24:56 2012
@@ -130,6 +130,9 @@ public class MappingRepository extends M
      * Convenient access to dictionary for mappings.
      */
     public DBDictionary getDBDictionary() {
+        if (_dict == null) {
+            _dict = ((JDBCConfiguration) getConfiguration()).getDBDictionaryInstance();
+        }
         return _dict;
     }
 
@@ -825,6 +828,8 @@ public class MappingRepository extends M
      */
     protected FieldStrategy defaultStrategy(FieldMapping field,
         boolean installHandlers, boolean adapting) {
+        DBDictionary dict = getDBDictionary();    	
+
         // not persistent?
         if (field.getManagement() != FieldMetaData.MANAGE_PERSISTENT
             || field.isVersion())
@@ -842,7 +847,7 @@ public class MappingRepository extends M
         }
 
         if (field.isSerialized()) {
-            if (_dict.maxEmbeddedBlobSize != -1) {
+            if (dict != null && dict.maxEmbeddedBlobSize != -1) {
                 handler = defaultHandler(field, adapting);
                 if (handler != null) {
                     if (installHandlers)
@@ -865,7 +870,7 @@ public class MappingRepository extends M
         // check for known field strategies
         if (!field.isSerialized() && (field.getType() == byte[].class
             || field.getType() == Byte[].class)) {
-            if (_dict.maxEmbeddedBlobSize != -1) {
+            if (dict != null && dict.maxEmbeddedBlobSize != -1) {
                 handler = defaultHandler(field, adapting);
                 if (handler != null) {
                     if (installHandlers)
@@ -876,7 +881,7 @@ public class MappingRepository extends M
         } else if (!field.isSerialized()
             && (field.getType() == char[].class
             || field.getType() == Character[].class)) {
-            if (_dict.maxEmbeddedClobSize != -1 && isClob(field, false)) {
+            if (dict != null && dict.maxEmbeddedClobSize != -1 && isClob(field,
false)) {
                 handler = defaultHandler(field, adapting);
                 if (handler != null) {
                     if (installHandlers)
@@ -911,7 +916,7 @@ public class MappingRepository extends M
                 getLog().warn(_loc.get("no-field-strategy", field));
             field.setSerialized(true);
         }
-        if (_dict.maxEmbeddedBlobSize == -1) {
+        if (dict != null && dict.maxEmbeddedBlobSize == -1) {
             if (installHandlers)
                 field.setHandler(BlobValueHandler.getInstance());
             return new HandlerFieldStrategy();
@@ -937,7 +942,8 @@ public class MappingRepository extends M
             case JavaTypes.STRING:
                 if (!isClob(field, false))
                     return new StringFieldStrategy();
-                if (_dict.maxEmbeddedClobSize != -1)
+                DBDictionary dict = getDBDictionary();
+                if (dict != null && dict.maxEmbeddedClobSize != -1)
                     return new MaxEmbeddedClobFieldStrategy();
                 break;
             case JavaTypes.PC:
@@ -1285,9 +1291,12 @@ public class MappingRepository extends M
      * not take into account the named handler, if any.
      */
     protected ValueHandler defaultHandler(ValueMapping val, boolean adapting) {
+    	
+    	DBDictionary dict = getDBDictionary();
+    	
         if (val.isSerialized()) {
-            if (_dict.maxEmbeddedBlobSize != -1)
-                warnMaxEmbedded(val, _dict.maxEmbeddedBlobSize);
+            if (dict != null && dict.maxEmbeddedBlobSize != -1)
+                warnMaxEmbedded(val, dict.maxEmbeddedBlobSize);
             return BlobValueHandler.getInstance();
         }
 
@@ -1297,8 +1306,8 @@ public class MappingRepository extends M
 
         if (val.getType() == byte[].class 
             || val.getType() == Byte[].class) {
-            if (_dict.maxEmbeddedBlobSize != -1)
-                warnMaxEmbedded(val, _dict.maxEmbeddedBlobSize);
+            if (dict != null && dict.maxEmbeddedBlobSize != -1)
+                warnMaxEmbedded(val, dict.maxEmbeddedBlobSize);
             return ByteArrayValueHandler.getInstance();
         }
         if (val.getType() == char[].class
@@ -1377,12 +1386,13 @@ public class MappingRepository extends M
         Column col = (Column) cols.get(0);
         if (col.getSize() != -1 && col.getType() != Types.CLOB)
             return false;
-
-        if (_dict.getPreferredType(Types.CLOB) != Types.CLOB)
+        
+        DBDictionary dict = getDBDictionary();
+        if (dict != null && dict.getPreferredType(Types.CLOB) != Types.CLOB)
             return false;
 
-        if (warn && _dict.maxEmbeddedClobSize != -1)
-            warnMaxEmbedded(val, _dict.maxEmbeddedClobSize);
+        if (warn && dict != null && dict.maxEmbeddedClobSize != -1)
+            warnMaxEmbedded(val, dict.maxEmbeddedClobSize);
         return true;
     }
 
@@ -1507,7 +1517,6 @@ public class MappingRepository extends M
         super.endConfiguration();
 
         JDBCConfiguration conf = (JDBCConfiguration) getConfiguration();
-        _dict = conf.getDBDictionaryInstance();
         if (_defaults == null)
             _defaults = conf.getMappingDefaultsInstance();
         if (_schema != null && _schema instanceof Configurable) {

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?rev=1342087&r1=1342086&r2=1342087&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
Wed May 23 23:24:56 2012
@@ -612,8 +612,9 @@ public abstract class AbstractBrokerFact
             _readOnly = true;
 
             Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
-            if (log.isInfoEnabled())
+            if (log.isInfoEnabled()){
                 log.info(getFactoryInitializationBanner());
+            }
             if (log.isTraceEnabled()) {
                 Map<String,Object> props = _conf.toProperties(true);
                 String lineSep = J2DoPrivHelper.getLineSeparator();
@@ -651,6 +652,10 @@ public abstract class AbstractBrokerFact
             _conf.getBrokerFactoryEventManager().fireEvent(
                 new BrokerFactoryEvent(this,
                     BrokerFactoryEvent.BROKER_FACTORY_CREATED));
+        } catch (RuntimeException e) {
+            // if the db connection is not available we need to reset the state
+            _readOnly = false;
+            throw e;
         } finally {
             unlock();
         }

Modified: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java?rev=1342087&r1=1342086&r2=1342087&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
(original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
Wed May 23 23:24:56 2012
@@ -38,6 +38,7 @@ import org.apache.openjpa.jdbc.meta.stra
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.Schema;
 import org.apache.openjpa.jdbc.schema.Table;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
 import org.apache.openjpa.jdbc.sql.JoinSyntaxes;
 import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.meta.JavaTypes;
@@ -119,7 +120,7 @@ public class PersistenceMappingDefaults
         if (FlatClassStrategy.ALIAS.equals(strat))
             return new ValueMapDiscriminatorStrategy();
         if (VerticalClassStrategy.ALIAS.equals(strat)
-            && dict.joinSyntax != JoinSyntaxes.SYNTAX_TRADITIONAL)
+            && getDBDictionary() != null && getDBDictionary().joinSyntax
!= JoinSyntaxes.SYNTAX_TRADITIONAL)
             return new SubclassJoinDiscriminatorStrategy();
         return NoneDiscriminatorStrategy.getInstance();
     }
@@ -198,14 +199,18 @@ public class PersistenceMappingDefaults
             sName = DBIdentifier.newColumn(fm.getDefiningMapping().getTypeAlias());
         DBIdentifier targetName = ((Column) target).getIdentifier();
         DBIdentifier tempName = DBIdentifier.NULL;
-        if ((sName.length() + targetName.length()) >= dict.maxColumnNameLength)
+        DBDictionary dict = getDBDictionary();
+        if (dict != null && (sName.length() + targetName.length()) >= dict.maxColumnNameLength){
             tempName = DBIdentifier.truncate(sName, dict.maxColumnNameLength
                     - targetName.length() - 1);
+        }
         // suffix with '_' + target column
         if (DBIdentifier.isNull(tempName))
             tempName = sName;
         sName = DBIdentifier.combine(tempName, targetName.getName());
-        sName = dict.getValidColumnName(sName, foreign);
+        if (dict != null) {
+            sName = dict.getValidColumnName(sName, foreign);
+        }
         col.setIdentifier(sName);
     }
 
@@ -242,7 +247,9 @@ public class PersistenceMappingDefaults
                 sName = sName.combine(sName, ((Column)target).getIdentifier().getName());
 
                 // No need to check for uniqueness.
-                sName = dict.getValidColumnName(sName, local, false);
+                if(getDBDictionary() != null){
+                	sName = getDBDictionary().getValidColumnName(sName, local, false);
+                }
             }
             col.setIdentifier(sName);
         }



Mime
View raw message