You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by ht...@apache.org on 2012/05/23 07:34:41 UTC
svn commit: r1341751 - in /openjpa/branches/1.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/
Author: hthomann
Date: Wed May 23 05:34:40 2012
New Revision: 1341751
URL: http://svn.apache.org/viewvc?rev=1341751&view=rev
Log:
OPENJPA-2139: Apply my lastest patch, which includes contributions added by Rick and Mark.
Modified:
openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java?rev=1341751&r1=1341750&r2=1341751&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java (original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java Wed May 23 05:34:40 2012
@@ -48,7 +48,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;
@@ -72,7 +72,18 @@ public class MappingDefaultsImpl
private String _orderName = null;
private String _nullIndName = 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;
}
@@ -512,8 +523,9 @@ public class MappingDefaultsImpl
public String getTableName(ClassMapping cls, Schema schema) {
String name = Strings.getClassName(cls.getDescribedType()).
replace('$', '_');
- if (!_defMissing)
- name = dict.getValidTableName(name, schema);
+ if (!_defMissing && getDBDictionary() != null) {
+ name = getDBDictionary().getValidTableName(name, schema);
+ }
return name;
}
@@ -526,8 +538,9 @@ public class MappingDefaultsImpl
tableName = tableName.substring(0, 5);
name = tableName + "_" + name;
}
- if (!_defMissing)
- name = dict.getValidTableName(name, schema);
+ if (!_defMissing && getDBDictionary() != null){
+ name = getDBDictionary().getValidTableName(name, schema);
+ }
return name;
}
@@ -549,9 +562,13 @@ public class MappingDefaultsImpl
if (!_defMissing || _removeHungarianNotation)
{
String name = col.getName();
- if (_removeHungarianNotation)
+ if (_removeHungarianNotation) {
name = removeHungarianNotation(name);
- col.setName(dict.getValidColumnName(name, table));
+ }
+
+ if (getDBDictionary() != null) {
+ col.setName(getDBDictionary().getValidColumnName(name, table));
+ }
}
}
@@ -703,15 +720,23 @@ public class MappingDefaultsImpl
* Generate an index name.
*/
protected String getIndexName(String name, Table table, Column[] cols) {
+ String toReturn = null;
+
// always use dict for index names because no spec mandates them
// based on defaults
- if (name == null)
+ if (name == null) {
name = cols[0].getName();
+ }
- if (_removeHungarianNotation)
+ if (_removeHungarianNotation){
name = removeHungarianNotation(name);
-
- return dict.getValidIndexName(name, table);
+ }
+
+ if (getDBDictionary() != null) {
+ toReturn = getDBDictionary().getValidIndexName(name, table);
+ }
+
+ return toReturn;
}
public Index getIndex(ValueMapping vm, String name, Table table,
@@ -764,7 +789,7 @@ public class MappingDefaultsImpl
///////////////////////////////
public void setConfiguration(Configuration conf) {
- dict = ((JDBCConfiguration) conf).getDBDictionaryInstance();
+ this.conf=conf;
}
public void startConfiguration() {
Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java?rev=1341751&r1=1341750&r2=1341751&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java (original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java Wed May 23 05:34:40 2012
@@ -123,6 +123,9 @@ public class MappingRepository
* Convenient access to dictionary for mappings.
*/
public DBDictionary getDBDictionary() {
+ if (_dict == null) {
+ _dict = ((JDBCConfiguration) getConfiguration()).getDBDictionaryInstance();
+ }
return _dict;
}
@@ -824,6 +827,8 @@ public class MappingRepository
*/
protected FieldStrategy defaultStrategy(FieldMapping field,
boolean installHandlers, boolean adapting) {
+ DBDictionary dict = getDBDictionary();
+
// not persistent?
if (field.getManagement() != field.MANAGE_PERSISTENT
|| field.isVersion())
@@ -841,7 +846,7 @@ public class MappingRepository
}
if (field.isSerialized()) {
- if (_dict.maxEmbeddedBlobSize != -1)
+ if (dict != null && dict.maxEmbeddedBlobSize != -1)
return new MaxEmbeddedBlobFieldStrategy();
} else {
// check for mapped strategy
@@ -858,12 +863,12 @@ public class MappingRepository
// 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)
return new MaxEmbeddedByteArrayFieldStrategy();
} 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))
return new MaxEmbeddedCharArrayFieldStrategy();
} else if (!field.isSerialized()) {
FieldStrategy strat = defaultTypeStrategy(field, installHandlers,
@@ -886,7 +891,7 @@ public class MappingRepository
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();
@@ -912,7 +917,8 @@ public class MappingRepository
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:
@@ -1116,9 +1122,11 @@ public class MappingRepository
* 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();
}
@@ -1128,8 +1136,8 @@ public class MappingRepository
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
@@ -1208,12 +1216,13 @@ public class MappingRepository
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;
}
@@ -1341,7 +1350,6 @@ public class MappingRepository
super.endConfiguration();
JDBCConfiguration conf = (JDBCConfiguration) getConfiguration();
- _dict = conf.getDBDictionaryInstance();
if (_defaults == null)
_defaults = conf.getMappingDefaultsInstance();
if (_schema != null && _schema instanceof Configurable) {
Modified: openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?rev=1341751&r1=1341750&r2=1341751&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java (original)
+++ openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java Wed May 23 05:34:40 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 props = _conf.toProperties(true);
String lineSep = J2DoPrivHelper.getLineSeparator();
@@ -650,6 +651,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/1.2.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java?rev=1341751&r1=1341750&r2=1341751&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java (original)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java Wed May 23 05:34:40 2012
@@ -34,8 +34,10 @@ 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.JavaTypes;
+
import serp.util.Strings;
/**
@@ -111,7 +113,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();
}
@@ -158,14 +160,18 @@ public class PersistenceMappingDefaults
name = fm.getDefiningMapping().getTypeAlias();
String targetName = ((Column) target).getName();
String tempName = null;
- if ((name.length() + targetName.length()) >= dict.maxColumnNameLength)
+ DBDictionary dict = getDBDictionary();
+ if (dict != null && (name.length() + targetName.length()) >= dict.maxColumnNameLength){
tempName = name.substring(0, dict.maxColumnNameLength
- targetName.length() - 1);
+ }
// suffix with '_' + target column
if (tempName == null)
tempName = name;
name = tempName + "_" + targetName;
- name = dict.getValidColumnName(name, foreign);
+ if (dict != null){
+ name = dict.getValidColumnName(name, foreign);
+ }
col.setName(name);
}
@@ -193,7 +199,9 @@ public class PersistenceMappingDefaults
name = name + "_" + ((Column) target).getName();
// No need to check for uniqueness.
- name = dict.getValidColumnName(name, local, false);
+ if (getDBDictionary() != null){
+ name = getDBDictionary().getValidColumnName(name, local, false);
+ }
col.setName(name);
}
}