mirror of https://github.com/apache/openjpa.git
OpenJPA-179 store defaultSchemaName in ClassMapping
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@525006 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
10bdc61b91
commit
f023f58562
|
@ -21,6 +21,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
||||
import org.apache.openjpa.jdbc.schema.Column;
|
||||
import org.apache.openjpa.jdbc.schema.ColumnIO;
|
||||
|
@ -69,6 +70,7 @@ public abstract class MappingInfo
|
|||
private boolean _canFK = true;
|
||||
private int _join = JOIN_NONE;
|
||||
private ColumnIO _io = null;
|
||||
private String _defaultSchemaName = null;
|
||||
|
||||
/**
|
||||
* Mapping strategy name.
|
||||
|
@ -439,6 +441,9 @@ public abstract class MappingInfo
|
|||
if (schema == null) {
|
||||
schemaName = Schemas.getNewTableSchema((JDBCConfiguration)
|
||||
repos.getConfiguration());
|
||||
if(StringUtils.isEmpty(schemaName)) {
|
||||
schemaName = _defaultSchemaName;
|
||||
}
|
||||
schema = group.getSchema(schemaName);
|
||||
if (schema == null)
|
||||
schema = group.addSchema(schemaName);
|
||||
|
@ -1764,4 +1769,12 @@ public abstract class MappingInfo
|
|||
public void populate(Table local, Table foreign, Column col,
|
||||
Object target, boolean inverse, int pos, int cols);
|
||||
}
|
||||
|
||||
public String getDefaultSchemaName() {
|
||||
return _defaultSchemaName;
|
||||
}
|
||||
|
||||
public void setDefaultSchemaName(String schemaName) {
|
||||
_defaultSchemaName = schemaName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package org.apache.openjpa.persistence.jdbc;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.openjpa.jdbc.meta.ClassMapping;
|
||||
import org.apache.openjpa.jdbc.meta.Discriminator;
|
||||
import org.apache.openjpa.jdbc.meta.FieldMapping;
|
||||
|
@ -114,17 +115,31 @@ public class PersistenceMappingDefaults
|
|||
|
||||
@Override
|
||||
public String getTableName(ClassMapping cls, Schema schema) {
|
||||
String name = "";
|
||||
|
||||
if(StringUtils.isNotEmpty(schema.getName())) {
|
||||
name +=schema.getName() + '.';
|
||||
}
|
||||
|
||||
if (cls.getTypeAlias() != null)
|
||||
return cls.getTypeAlias();
|
||||
name += cls.getTypeAlias();
|
||||
|
||||
else
|
||||
return Strings.getClassName(
|
||||
cls.getDescribedType()).replace('$', '_');
|
||||
name += Strings.getClassName(cls.getDescribedType()).replace('$',
|
||||
'_');
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableName(FieldMapping fm, Schema schema) {
|
||||
String name = "";
|
||||
if(StringUtils.isNotEmpty(schema.getName())) {
|
||||
name +=schema.getName() + '.';
|
||||
}
|
||||
|
||||
// base name is table of defining type + '_'
|
||||
String name = fm.getDefiningMapping().getTable().getName() + "_";
|
||||
name += fm.getDefiningMapping().getTable().getName() + "_";
|
||||
|
||||
// if this is an assocation table, spec says to suffix with table of
|
||||
// the related type. spec doesn't cover other cases; we're going to
|
||||
|
|
|
@ -50,6 +50,7 @@ import org.apache.openjpa.lib.util.Localizer;
|
|||
import org.apache.openjpa.meta.ClassMetaData;
|
||||
import org.apache.openjpa.meta.FieldMetaData;
|
||||
import org.apache.openjpa.meta.JavaTypes;
|
||||
import org.apache.openjpa.meta.MetaDataRepository;
|
||||
import org.apache.openjpa.persistence.XMLPersistenceMetaDataParser;
|
||||
import static org.apache.openjpa.persistence.jdbc.MappingTag.*;
|
||||
|
||||
|
@ -910,4 +911,18 @@ public class XMLPersistenceMappingParser
|
|||
TRUE,
|
||||
FALSE
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void endClass(String elem)
|
||||
throws SAXException {
|
||||
if (StringUtils.isNotEmpty(_schema)) {
|
||||
Class cls = classForName(currentClassName());
|
||||
|
||||
MetaDataRepository repos = getRepository();
|
||||
ClassMapping meta = (ClassMapping) repos.getCachedMetaData(cls);
|
||||
|
||||
meta.getMappingInfo().setDefaultSchemaName(_schema);
|
||||
}
|
||||
super.endClass(elem);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue