OPENJPA-2139: Reverting previous changes to 2.0.x as we've found further considerartion/design is needed.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.0.x@1350014 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Heath Thomann 2012-06-13 20:53:51 +00:00
parent 4ce857e119
commit 135e7c78fa
4 changed files with 30 additions and 78 deletions

View File

@ -51,7 +51,7 @@ import serp.util.Strings;
public class MappingDefaultsImpl public class MappingDefaultsImpl
implements MappingDefaults, Configurable { implements MappingDefaults, Configurable {
private transient DBDictionary dict = null; protected transient DBDictionary dict = null;
private String _baseClassStrategy = null; private String _baseClassStrategy = null;
private String _subclassStrategy = null; private String _subclassStrategy = null;
private String _versionStrategy = null; private String _versionStrategy = null;
@ -75,17 +75,6 @@ public class MappingDefaultsImpl
private DBIdentifier _orderName = DBIdentifier.NULL; private DBIdentifier _orderName = DBIdentifier.NULL;
private DBIdentifier _nullIndName = DBIdentifier.NULL; private DBIdentifier _nullIndName = DBIdentifier.NULL;
private boolean _removeHungarianNotation = false; 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() { public boolean isRemoveHungarianNotation() {
return _removeHungarianNotation; return _removeHungarianNotation;
@ -576,10 +565,8 @@ public class MappingDefaultsImpl
public String getTableName(ClassMapping cls, Schema schema) { public String getTableName(ClassMapping cls, Schema schema) {
String name = Strings.getClassName(cls.getDescribedType()). String name = Strings.getClassName(cls.getDescribedType()).
replace(IdentifierUtil.DOLLAR_CHAR, IdentifierUtil.UNDERSCORE_CHAR); replace(IdentifierUtil.DOLLAR_CHAR, IdentifierUtil.UNDERSCORE_CHAR);
if (!_defMissing && getDBDictionary() != null) { if (!_defMissing)
name = getDBDictionary().getValidTableName(name, schema); name = dict.getValidTableName(name, schema);
}
return name; return name;
} }
@ -598,9 +585,8 @@ public class MappingDefaultsImpl
DBIdentifier tableName = DBIdentifier.truncate(table.getIdentifier(),5); DBIdentifier tableName = DBIdentifier.truncate(table.getIdentifier(),5);
sName = DBIdentifier.append(tableName, fm.getName()); sName = DBIdentifier.append(tableName, fm.getName());
} }
if (!_defMissing && getDBDictionary() != null){ if (!_defMissing)
sName = getDBDictionary().getValidTableName(sName, schema); sName = dict.getValidTableName(sName, schema);
}
return sName; return sName;
} }
@ -622,14 +608,9 @@ public class MappingDefaultsImpl
if (!_defMissing || _removeHungarianNotation) if (!_defMissing || _removeHungarianNotation)
{ {
DBIdentifier name = col.getIdentifier(); DBIdentifier name = col.getIdentifier();
if (_removeHungarianNotation){ if (_removeHungarianNotation)
name = DBIdentifier.removeHungarianNotation(name); name = DBIdentifier.removeHungarianNotation(name);
} DBIdentifier correctedName = dict.getValidColumnName(name, table);
DBIdentifier correctedName = name;
if (getDBDictionary() != null) {
correctedName = getDBDictionary().getValidColumnName(name, table);
}
col.setIdentifier(correctedName); col.setIdentifier(correctedName);
table.addCorrectedColumnName(correctedName, true); table.addCorrectedColumnName(correctedName, true);
} }
@ -809,24 +790,16 @@ public class MappingDefaultsImpl
} }
protected DBIdentifier getIndexName(DBIdentifier name, Table table, Column[] cols) { protected DBIdentifier getIndexName(DBIdentifier name, Table table, Column[] cols) {
DBIdentifier toReturn = null;
// always use dict for index names because no spec mandates them // always use dict for index names because no spec mandates them
// based on defaults // based on defaults
DBIdentifier sName = name; DBIdentifier sName = name;
if (DBIdentifier.isNull(sName)){ if (DBIdentifier.isNull(sName))
sName = cols[0].getIdentifier(); sName = cols[0].getIdentifier();
}
if (_removeHungarianNotation){ if (_removeHungarianNotation)
sName = DBIdentifier.removeHungarianNotation(sName); sName = DBIdentifier.removeHungarianNotation(sName);
}
if (getDBDictionary() != null) { return dict.getValidIndexName(sName, table);
toReturn = getDBDictionary().getValidIndexName(sName, table);
}
return toReturn;
} }
/** /**
@ -902,7 +875,7 @@ public class MappingDefaultsImpl
/////////////////////////////// ///////////////////////////////
public void setConfiguration(Configuration conf) { public void setConfiguration(Configuration conf) {
this.conf=conf; dict = ((JDBCConfiguration) conf).getDBDictionaryInstance();
} }
public void startConfiguration() { public void startConfiguration() {

View File

@ -130,9 +130,6 @@ public class MappingRepository extends MetaDataRepository {
* Convenient access to dictionary for mappings. * Convenient access to dictionary for mappings.
*/ */
public DBDictionary getDBDictionary() { public DBDictionary getDBDictionary() {
if (_dict == null) {
_dict = ((JDBCConfiguration) getConfiguration()).getDBDictionaryInstance();
}
return _dict; return _dict;
} }
@ -828,8 +825,6 @@ public class MappingRepository extends MetaDataRepository {
*/ */
protected FieldStrategy defaultStrategy(FieldMapping field, protected FieldStrategy defaultStrategy(FieldMapping field,
boolean installHandlers, boolean adapting) { boolean installHandlers, boolean adapting) {
DBDictionary dict = getDBDictionary();
// not persistent? // not persistent?
if (field.getManagement() != FieldMetaData.MANAGE_PERSISTENT if (field.getManagement() != FieldMetaData.MANAGE_PERSISTENT
|| field.isVersion()) || field.isVersion())
@ -847,7 +842,7 @@ public class MappingRepository extends MetaDataRepository {
} }
if (field.isSerialized()) { if (field.isSerialized()) {
if (dict != null && dict.maxEmbeddedBlobSize != -1) if (_dict.maxEmbeddedBlobSize != -1)
return new MaxEmbeddedBlobFieldStrategy(); return new MaxEmbeddedBlobFieldStrategy();
} else { } else {
// check for mapped strategy // check for mapped strategy
@ -864,12 +859,12 @@ public class MappingRepository extends MetaDataRepository {
// check for known field strategies // check for known field strategies
if (!field.isSerialized() && (field.getType() == byte[].class if (!field.isSerialized() && (field.getType() == byte[].class
|| field.getType() == Byte[].class)) { || field.getType() == Byte[].class)) {
if (dict != null && dict.maxEmbeddedBlobSize != -1) if (_dict.maxEmbeddedBlobSize != -1)
return new MaxEmbeddedByteArrayFieldStrategy(); return new MaxEmbeddedByteArrayFieldStrategy();
} else if (!field.isSerialized() } else if (!field.isSerialized()
&& (field.getType() == char[].class && (field.getType() == char[].class
|| field.getType() == Character[].class)) { || field.getType() == Character[].class)) {
if (dict != null && dict.maxEmbeddedClobSize != -1 && isClob(field, false)) if (_dict.maxEmbeddedClobSize != -1 && isClob(field, false))
return new MaxEmbeddedCharArrayFieldStrategy(); return new MaxEmbeddedCharArrayFieldStrategy();
} else if (!field.isSerialized()) { } else if (!field.isSerialized()) {
FieldStrategy strat = defaultTypeStrategy(field, installHandlers, FieldStrategy strat = defaultTypeStrategy(field, installHandlers,
@ -892,7 +887,7 @@ public class MappingRepository extends MetaDataRepository {
getLog().warn(_loc.get("no-field-strategy", field)); getLog().warn(_loc.get("no-field-strategy", field));
field.setSerialized(true); field.setSerialized(true);
} }
if (dict != null && dict.maxEmbeddedBlobSize == -1) { if (_dict.maxEmbeddedBlobSize == -1) {
if (installHandlers) if (installHandlers)
field.setHandler(BlobValueHandler.getInstance()); field.setHandler(BlobValueHandler.getInstance());
return new HandlerFieldStrategy(); return new HandlerFieldStrategy();
@ -918,8 +913,7 @@ public class MappingRepository extends MetaDataRepository {
case JavaTypes.STRING: case JavaTypes.STRING:
if (!isClob(field, false)) if (!isClob(field, false))
return new StringFieldStrategy(); return new StringFieldStrategy();
DBDictionary dict = getDBDictionary(); if (_dict.maxEmbeddedClobSize != -1)
if (dict != null && dict.maxEmbeddedClobSize != -1)
return new MaxEmbeddedClobFieldStrategy(); return new MaxEmbeddedClobFieldStrategy();
break; break;
case JavaTypes.PC: case JavaTypes.PC:
@ -1267,12 +1261,9 @@ public class MappingRepository extends MetaDataRepository {
* not take into account the named handler, if any. * not take into account the named handler, if any.
*/ */
protected ValueHandler defaultHandler(ValueMapping val, boolean adapting) { protected ValueHandler defaultHandler(ValueMapping val, boolean adapting) {
DBDictionary dict = getDBDictionary();
if (val.isSerialized()) { if (val.isSerialized()) {
if (dict != null && dict.maxEmbeddedBlobSize != -1) if (_dict.maxEmbeddedBlobSize != -1)
warnMaxEmbedded(val, dict.maxEmbeddedBlobSize); warnMaxEmbedded(val, _dict.maxEmbeddedBlobSize);
return BlobValueHandler.getInstance(); return BlobValueHandler.getInstance();
} }
@ -1282,8 +1273,8 @@ public class MappingRepository extends MetaDataRepository {
if (val.getType() == byte[].class if (val.getType() == byte[].class
|| val.getType() == Byte[].class) { || val.getType() == Byte[].class) {
if (dict != null && dict.maxEmbeddedBlobSize != -1) if (_dict.maxEmbeddedBlobSize != -1)
warnMaxEmbedded(val, dict.maxEmbeddedBlobSize); warnMaxEmbedded(val, _dict.maxEmbeddedBlobSize);
return ByteArrayValueHandler.getInstance(); return ByteArrayValueHandler.getInstance();
} }
if (val.getType() == char[].class if (val.getType() == char[].class
@ -1362,13 +1353,12 @@ public class MappingRepository extends MetaDataRepository {
Column col = (Column) cols.get(0); Column col = (Column) cols.get(0);
if (col.getSize() != -1 && col.getType() != Types.CLOB) if (col.getSize() != -1 && col.getType() != Types.CLOB)
return false; return false;
DBDictionary dict = getDBDictionary(); if (_dict.getPreferredType(Types.CLOB) != Types.CLOB)
if (dict != null && dict.getPreferredType(Types.CLOB) != Types.CLOB)
return false; return false;
if (warn && dict != null && dict.maxEmbeddedClobSize != -1) if (warn && _dict.maxEmbeddedClobSize != -1)
warnMaxEmbedded(val, dict.maxEmbeddedClobSize); warnMaxEmbedded(val, _dict.maxEmbeddedClobSize);
return true; return true;
} }
@ -1496,6 +1486,7 @@ public class MappingRepository extends MetaDataRepository {
super.endConfiguration(); super.endConfiguration();
JDBCConfiguration conf = (JDBCConfiguration) getConfiguration(); JDBCConfiguration conf = (JDBCConfiguration) getConfiguration();
_dict = conf.getDBDictionaryInstance();
if (_defaults == null) if (_defaults == null)
_defaults = conf.getMappingDefaultsInstance(); _defaults = conf.getMappingDefaultsInstance();
if (_schema != null && _schema instanceof Configurable) { if (_schema != null && _schema instanceof Configurable) {

View File

@ -615,9 +615,8 @@ public abstract class AbstractBrokerFactory
_readOnly = true; _readOnly = true;
Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME); Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
if (log.isInfoEnabled()){ if (log.isInfoEnabled())
log.info(getFactoryInitializationBanner()); log.info(getFactoryInitializationBanner());
}
if (log.isTraceEnabled()) { if (log.isTraceEnabled()) {
Map<String,Object> props = _conf.toProperties(true); Map<String,Object> props = _conf.toProperties(true);
String lineSep = J2DoPrivHelper.getLineSeparator(); String lineSep = J2DoPrivHelper.getLineSeparator();
@ -653,10 +652,6 @@ public abstract class AbstractBrokerFactory
_conf.getBrokerFactoryEventManager().fireEvent( _conf.getBrokerFactoryEventManager().fireEvent(
new BrokerFactoryEvent(this, new BrokerFactoryEvent(this,
BrokerFactoryEvent.BROKER_FACTORY_CREATED)); 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 { } finally {
unlock(); unlock();
} }

View File

@ -38,7 +38,6 @@ import org.apache.openjpa.jdbc.meta.strats.VerticalClassStrategy;
import org.apache.openjpa.jdbc.schema.Column; import org.apache.openjpa.jdbc.schema.Column;
import org.apache.openjpa.jdbc.schema.Schema; import org.apache.openjpa.jdbc.schema.Schema;
import org.apache.openjpa.jdbc.schema.Table; 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.jdbc.sql.JoinSyntaxes;
import org.apache.openjpa.meta.FieldMetaData; import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.JavaTypes; import org.apache.openjpa.meta.JavaTypes;
@ -120,7 +119,7 @@ public class PersistenceMappingDefaults
if (FlatClassStrategy.ALIAS.equals(strat)) if (FlatClassStrategy.ALIAS.equals(strat))
return new ValueMapDiscriminatorStrategy(); return new ValueMapDiscriminatorStrategy();
if (VerticalClassStrategy.ALIAS.equals(strat) if (VerticalClassStrategy.ALIAS.equals(strat)
&& getDBDictionary() != null && getDBDictionary().joinSyntax != JoinSyntaxes.SYNTAX_TRADITIONAL) && dict.joinSyntax != JoinSyntaxes.SYNTAX_TRADITIONAL)
return new SubclassJoinDiscriminatorStrategy(); return new SubclassJoinDiscriminatorStrategy();
return NoneDiscriminatorStrategy.getInstance(); return NoneDiscriminatorStrategy.getInstance();
} }
@ -199,18 +198,14 @@ public class PersistenceMappingDefaults
sName = DBIdentifier.newColumn(fm.getDefiningMapping().getTypeAlias()); sName = DBIdentifier.newColumn(fm.getDefiningMapping().getTypeAlias());
DBIdentifier targetName = ((Column) target).getIdentifier(); DBIdentifier targetName = ((Column) target).getIdentifier();
DBIdentifier tempName = DBIdentifier.NULL; DBIdentifier tempName = DBIdentifier.NULL;
DBDictionary dict = getDBDictionary(); if ((sName.length() + targetName.length()) >= dict.maxColumnNameLength)
if (dict != null && (sName.length() + targetName.length()) >= dict.maxColumnNameLength){
tempName = DBIdentifier.truncate(sName, dict.maxColumnNameLength tempName = DBIdentifier.truncate(sName, dict.maxColumnNameLength
- targetName.length() - 1); - targetName.length() - 1);
}
// suffix with '_' + target column // suffix with '_' + target column
if (DBIdentifier.isNull(tempName)) if (DBIdentifier.isNull(tempName))
tempName = sName; tempName = sName;
sName = DBIdentifier.combine(tempName, targetName.getName()); sName = DBIdentifier.combine(tempName, targetName.getName());
if (dict != null) { sName = dict.getValidColumnName(sName, foreign);
sName = dict.getValidColumnName(sName, foreign);
}
col.setIdentifier(sName); col.setIdentifier(sName);
} }
@ -247,9 +242,7 @@ public class PersistenceMappingDefaults
sName = sName.combine(sName, ((Column)target).getIdentifier().getName()); sName = sName.combine(sName, ((Column)target).getIdentifier().getName());
// No need to check for uniqueness. // No need to check for uniqueness.
if(getDBDictionary() != null){ sName = dict.getValidColumnName(sName, local, false);
sName = getDBDictionary().getValidColumnName(sName, local, false);
}
} }
col.setIdentifier(sName); col.setIdentifier(sName);
} }