Author: max.andersen(a)jboss.com
Date: 2009-02-25 23:33:15 -0500 (Wed, 25 Feb 2009)
New Revision: 16034
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideRepository.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
Log:
remove java 5 code
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideRepository.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideRepository.java 2009-02-25
14:35:32 UTC (rev 16033)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideRepository.java 2009-02-26
04:33:15 UTC (rev 16034)
@@ -31,12 +31,12 @@
public class OverrideRepository {
final private static Log log = LogFactory.getLog( OverrideRepository.class );
-
+
final private transient XMLHelper xmlHelper;
final private transient EntityResolver entityResolver;
final private Map typeMappings; // from sqltypes to list of SQLTypeMapping
-
+
final private List tableFilters;
final private List tables;
@@ -53,9 +53,9 @@
final private Map primaryKeyColumnsForTable;
final private Set excludedColumns;
-
+
final private Map tableToClassName;
-
+
final private List schemaSelections;
final private Map propertyNameForPrimaryKey;
@@ -69,14 +69,14 @@
final private Map foreignKeyInverseExclude;
final private Map foreignKeyToOneExclude;
-
+
final private Map foreignKeyToEntityInfo;
final private Map foreignKeyToInverseEntityInfo;
final private Map tableMetaAttributes; // TI -> MultiMap of SimpleMetaAttributes
final private Map columnMetaAttributes;
-
+
//private String defaultCatalog;
//private String defaultSchema;
@@ -108,7 +108,7 @@
foreignKeyToEntityInfo = new HashMap();
foreignKeyToInverseEntityInfo = new HashMap();
}
-
+
public OverrideRepository addFile(File xmlFile) {
log.info( "Override file: " + xmlFile.getPath() );
try {
@@ -118,10 +118,10 @@
log.error( "Could not configure overrides from file: " + xmlFile.getPath(),
e );
throw new MappingException( "Could not configure overrides from file: " +
xmlFile.getPath(), e );
}
- return this;
-
+ return this;
+
}
-
+
/**
* Read override from an application resource trying different classloaders.
* This method will try to load the resource first from the thread context
@@ -140,7 +140,7 @@
}
}
-
+
public OverrideRepository addInputStream(InputStream xmlInputStream) throws
MappingException {
try {
List errors = new ArrayList();
@@ -173,7 +173,7 @@
private String getPreferredHibernateType(int sqlType, int length, int precision, int
scale, boolean nullable) {
List l = (List) typeMappings.get(new TypeMappingKey(sqlType,length) );
-
+
if(l == null) { // if no precise length match found, then try to find matching unknown
length matches
l = (List) typeMappings.get(new TypeMappingKey(sqlType,SQLTypeMapping.UNKNOWN_LENGTH)
);
}
@@ -188,12 +188,12 @@
if(element.getJDBCType()!=sqlType) return null;
if(element.match(sqlType, length, precision, scale, nullable) ) {
return element.getHibernateType();
- }
- }
+ }
+ }
}
return null;
}
-
+
public OverrideRepository addTypeMapping(SQLTypeMapping sqltype) {
TypeMappingKey key = new TypeMappingKey(sqltype);
List list = (List) typeMappings.get(key);
@@ -201,20 +201,20 @@
list = new ArrayList();
typeMappings.put(key, list);
}
- list.add(sqltype);
+ list.add(sqltype);
return this;
}
-
+
static class TypeMappingKey {
-
+
int type;
int length;
-
+
TypeMappingKey(SQLTypeMapping mpa) {
type = mpa.getJDBCType();
length = mpa.getLength();
}
-
+
public TypeMappingKey(int sqlType, int length) {
this.type = sqlType;
this.length = length;
@@ -224,15 +224,15 @@
if(obj==null) return false;
if(!(obj instanceof TypeMappingKey)) return false;
TypeMappingKey other = (TypeMappingKey) obj;
-
-
+
+
return type==other.type && length==other.length;
}
-
+
public int hashCode() {
return (type + length) % 17;
}
-
+
public String toString() {
return this.getClass() + "(type:" + type + ", length:" + length +
")";
}
@@ -247,13 +247,13 @@
return value;
}
}
- return null;
+ return null;
}
protected boolean excludeTable(TableIdentifier identifier) {
Iterator iterator = tableFilters.iterator();
boolean hasInclude = false;
-
+
while(iterator.hasNext() ) {
TableFilter tf = (TableFilter) iterator.next();
Boolean value = tf.exclude(identifier);
@@ -264,7 +264,7 @@
hasInclude = true;
}
}
-
+
// can probably be simplified - but like this to be very explicit ;)
if(hasInclude) {
return true; // exclude all by default when at least one include specified
@@ -276,26 +276,26 @@
public void addTableFilter(TableFilter filter) {
tableFilters.add(filter);
}
-
- public ReverseEngineeringStrategy
getReverseEngineeringStrategy(ReverseEngineeringStrategy delegate) {
+
+ public ReverseEngineeringStrategy
getReverseEngineeringStrategy(ReverseEngineeringStrategy delegate) {
return new DelegatingReverseEngineeringStrategy(delegate) {
-
+
public boolean excludeTable(TableIdentifier ti) {
return OverrideRepository.this.excludeTable(ti);
}
-
+
public Map tableToMetaAttributes(TableIdentifier tableIdentifier) {
- return OverrideRepository.this.tableToMetaAttributes(tableIdentifier);
+ return OverrideRepository.this.tableToMetaAttributes(tableIdentifier);
}
-
+
public Map columnToMetaAttributes(TableIdentifier tableIdentifier, String column) {
- return OverrideRepository.this.columnToMetaAttributes(tableIdentifier,
column);
+ return OverrideRepository.this.columnToMetaAttributes(tableIdentifier, column);
}
-
+
public boolean excludeColumn(TableIdentifier identifier, String columnName) {
return excludedColumns.contains(TABLECOLUMN_KEY_FACTORY.newInstance(identifier,
columnName));
}
-
+
public String tableToCompositeIdName(TableIdentifier identifier) {
String result = (String) compositeIdNameForTable.get(identifier);
if(result==null) {
@@ -311,7 +311,7 @@
return schemaSelections;
}
}
-
+
public String columnToHibernateTypeName(TableIdentifier table, String columnName, int
sqlType, int length, int precision, int scale, boolean nullable, boolean
generatedIdentifier) {
String result = null;
String location = "";
@@ -319,7 +319,7 @@
if(table!=null) {
location = Table.qualify(table.getCatalog(), table.getSchema(), table.getName() ) +
"." + columnName;
} else {
-
+
location += " Column: " + columnName + info;
}
if(table!=null && columnName!=null) {
@@ -329,20 +329,20 @@
return result;
}
}
-
+
result = OverrideRepository.this.getPreferredHibernateType(sqlType, length,
precision, scale, nullable);
if(result==null) {
return super.columnToHibernateTypeName(table, columnName, sqlType, length,
precision, scale, nullable, generatedIdentifier);
- }
- else {
- log.debug("<type-mapping> found for [" + location + info + "]
to [" + result + "]");
+ }
+ else {
+ log.debug("<type-mapping> found for [" + location + info + "]
to [" + result + "]");
return result;
}
}
-
+
public String tableToClassName(TableIdentifier tableIdentifier) {
String className = (String) tableToClassName.get(tableIdentifier);
-
+
if(className!=null) {
if(className.indexOf( "." )>=0) {
return className;
@@ -354,19 +354,19 @@
return StringHelper.qualify(packageName, className);
}
}
- }
-
+ }
+
String packageName = getPackageName(tableIdentifier);
if(packageName==null) {
return super.tableToClassName(tableIdentifier);
- }
+ }
else {
String string = super.tableToClassName(tableIdentifier);
if(string==null) return null;
- return StringHelper.qualify(packageName, StringHelper.unqualify(string));
+ return StringHelper.qualify(packageName, StringHelper.unqualify(string));
}
}
-
+
public List getForeignKeys(TableIdentifier referencedTable) {
List list = (List) foreignKeys.get(referencedTable);
if(list==null) {
@@ -375,7 +375,7 @@
return list;
}
}
-
+
public String columnToPropertyName(TableIdentifier table, String column) {
String result = (String)
propertyNameForColumn.get(TABLECOLUMN_KEY_FACTORY.newInstance(table, column));
if(result==null) {
@@ -384,7 +384,7 @@
return result;
}
}
-
+
public String tableToIdentifierPropertyName(TableIdentifier tableIdentifier) {
String result = (String) propertyNameForPrimaryKey.get(tableIdentifier);
if(result==null) {
@@ -393,35 +393,35 @@
return result;
}
}
-
+
public String getTableIdentifierStrategyName(TableIdentifier tableIdentifier) {
String result = (String) identifierStrategyForTable.get(tableIdentifier);
if(result==null) {
- return super.getTableIdentifierStrategyName( tableIdentifier );
+ return super.getTableIdentifierStrategyName( tableIdentifier );
} else {
log.debug("tableIdentifierStrategy for " + tableIdentifier + " ->
'" + result + "'");
return result;
}
}
-
+
public Properties getTableIdentifierProperties(TableIdentifier tableIdentifier) {
Properties result = (Properties) identifierPropertiesForTable.get(tableIdentifier);
if(result==null) {
- return super.getTableIdentifierProperties( tableIdentifier );
+ return super.getTableIdentifierProperties( tableIdentifier );
} else {
return result;
}
}
-
+
public List getPrimaryKeyColumnNames(TableIdentifier tableIdentifier) {
List result = (List) primaryKeyColumnsForTable.get(tableIdentifier);
if(result==null) {
- return super.getPrimaryKeyColumnNames(tableIdentifier);
+ return super.getPrimaryKeyColumnNames(tableIdentifier);
} else {
return result;
}
}
-
+
public String foreignKeyToEntityName(String keyname, TableIdentifier fromTable, List
fromColumnNames, TableIdentifier referencedTable, List referencedColumnNames, boolean
uniqueReference) {
String property = (String) foreignKeyToOneName.get(keyname);
if(property==null) {
@@ -430,13 +430,13 @@
return property;
}
}
-
- @Override
+
+
public String foreignKeyToInverseEntityName(String keyname,
TableIdentifier fromTable, List fromColumnNames,
TableIdentifier referencedTable,
List referencedColumnNames, boolean uniqueReference) {
-
+
String property = (String) foreignKeyToInverseName.get(keyname);
if(property==null) {
return super.foreignKeyToInverseEntityName(keyname, fromTable, fromColumnNames,
referencedTable, referencedColumnNames, uniqueReference);
@@ -444,7 +444,7 @@
return property;
}
}
-
+
public String foreignKeyToCollectionName(String keyname, TableIdentifier fromTable,
List fromColumns, TableIdentifier referencedTable, List referencedColumns, boolean
uniqueReference) {
String property = (String) foreignKeyToInverseName.get(keyname);
if(property==null) {
@@ -453,7 +453,7 @@
return property;
}
}
-
+
public boolean excludeForeignKeyAsCollection(String keyname, TableIdentifier
fromTable, List fromColumns, TableIdentifier referencedTable, List referencedColumns) {
Boolean bool = (Boolean) foreignKeyInverseExclude.get(keyname);
if(bool!=null) {
@@ -463,7 +463,7 @@
referencedTable, referencedColumns );
}
}
-
+
public boolean excludeForeignKeyAsManytoOne(String keyname, TableIdentifier fromTable,
List fromColumns, TableIdentifier referencedTable, List referencedColumns) {
Boolean bool = (Boolean) foreignKeyToOneExclude.get(keyname);
if(bool!=null) {
@@ -473,8 +473,8 @@
referencedTable, referencedColumns );
}
}
-
-
+
+
public AssociationInfo foreignKeyToInverseAssociationInfo(ForeignKey foreignKey) {
AssociationInfo fkei = (AssociationInfo)
foreignKeyToInverseEntityInfo.get(foreignKey.getName());
if(fkei!=null) {
@@ -483,7 +483,7 @@
return super.foreignKeyToInverseAssociationInfo(foreignKey);
}
}
-
+
public AssociationInfo foreignKeyToAssociationInfo(ForeignKey foreignKey) {
AssociationInfo fkei = (AssociationInfo)
foreignKeyToEntityInfo.get(foreignKey.getName());
if(fkei!=null) {
@@ -492,7 +492,7 @@
return super.foreignKeyToAssociationInfo(foreignKey);
}
}
- };
+ };
}
protected Map columnToMetaAttributes(TableIdentifier tableIdentifier, String column) {
@@ -500,7 +500,7 @@
if(specific!=null && !specific.isEmpty()) {
return toMetaAttributes(specific);
}
-
+
return null;
}
@@ -514,13 +514,13 @@
if(general!=null && !general.isEmpty()) {
return toMetaAttributes(general);
}
-
+
return null;
-
+
/* inheritance not defined yet
if(specific==null) { specific = Collections.EMPTY_MAP; }
if(general==null) { general = Collections.EMPTY_MAP; }
-
+
MultiMap map = MetaAttributeBinder.mergeMetaMaps( specific, general );
*/
/*
@@ -533,7 +533,7 @@
}
private Map findGeneralAttributes(TableIdentifier identifier) {
- Iterator iterator = tableFilters.iterator();
+ Iterator iterator = tableFilters.iterator();
while(iterator.hasNext() ) {
TableFilter tf = (TableFilter) iterator.next();
Map value = tf.getMetaAttributes(identifier);
@@ -546,16 +546,16 @@
private Map toMetaAttributes(Map value) {
Map result = new HashMap();
-
+
Set set = value.entrySet();
for (Iterator iter = set.iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String name = (String) entry.getKey();
List values = (List) entry.getValue();
-
- result.put(name, MetaAttributeBinder.toRealMetaAttribute(name, values));
+
+ result.put(name, MetaAttributeBinder.toRealMetaAttribute(name, values));
}
-
+
return result;
}
@@ -573,20 +573,20 @@
existing = new ArrayList();
foreignKeys.put(identifier, existing);
}
- existing.add( fk );
+ existing.add( fk );
}
-
+
tables.add(table);
-
+
if(StringHelper.isNotEmpty(wantedClassName)) {
tableToClassName.put(TableIdentifier.create(table), wantedClassName);
}
}
-
+
private static final TableColumnKeyFactory TABLECOLUMN_KEY_FACTORY;
static {
- TABLECOLUMN_KEY_FACTORY = (TableColumnKeyFactory)
KeyFactory.create(TableColumnKeyFactory.class);
+ TABLECOLUMN_KEY_FACTORY = (TableColumnKeyFactory)
KeyFactory.create(TableColumnKeyFactory.class);
}
static interface TableColumnKeyFactory {
@@ -598,11 +598,11 @@
typeForColumn.put(TABLECOLUMN_KEY_FACTORY.newInstance(identifier, columnName), type);
}
}
-
+
public void setExcludedColumn(TableIdentifier tableIdentifier, String columnName) {
- excludedColumns.add(TABLECOLUMN_KEY_FACTORY.newInstance(tableIdentifier,
columnName));
+ excludedColumns.add(TABLECOLUMN_KEY_FACTORY.newInstance(tableIdentifier, columnName));
}
-
+
public void setPropertyNameForColumn(TableIdentifier identifier, String columnName,
String property) {
if(StringHelper.isNotEmpty(property)) {
propertyNameForColumn.put(TABLECOLUMN_KEY_FACTORY.newInstance(identifier, columnName),
property);
@@ -614,17 +614,17 @@
final TableIdentifier tid = TableIdentifier.create(table);
identifierStrategyForTable.put(tid, identifierClass);
identifierPropertiesForTable.put(tid, params);
- }
+ }
}
public void addPrimaryKeyNamesForTable(Table table, List boundColumnNames, String
propertyName, String compositeIdName) {
- TableIdentifier tableIdentifier = TableIdentifier.create(table);
+ TableIdentifier tableIdentifier = TableIdentifier.create(table);
if(boundColumnNames!=null && !boundColumnNames.isEmpty()) {
primaryKeyColumnsForTable.put(tableIdentifier, boundColumnNames);
}
if(StringHelper.isNotEmpty(propertyName)) {
propertyNameForPrimaryKey.put(tableIdentifier, propertyName);
- }
+ }
if(StringHelper.isNotEmpty(compositeIdName)) {
compositeIdNameForTable.put(tableIdentifier, compositeIdName);
}
@@ -643,14 +643,14 @@
}
/**
- * Both sides of the FK are important,
+ * Both sides of the FK are important,
* the owning side can generate a toOne (ManyToOne or OneToOne), we call this side
foreignKeyToOne
* the inverse side can generate a OneToMany OR a OneToOne (in case we have a pure
bidirectional OneToOne, we call this side foreignKeyToInverse
*/
public void addForeignKeyInfo(String constraintName, String toOneProperty, Boolean
excludeToOne, String inverseProperty, Boolean excludeInverse, AssociationInfo
associationInfo, AssociationInfo inverseAssociationInfo) {
if(StringHelper.isNotEmpty(toOneProperty)) {
foreignKeyToOneName.put(constraintName, toOneProperty);
- }
+ }
if(StringHelper.isNotEmpty(inverseProperty)) {
foreignKeyToInverseName.put(constraintName, inverseProperty);
}
@@ -666,24 +666,24 @@
if(inverseAssociationInfo!=null) {
foreignKeyToInverseEntityInfo.put(constraintName, inverseAssociationInfo);
}
-
+
}
public void addMetaAttributeInfo(Table table, Map map) {
if(map!=null && !map.isEmpty()) {
tableMetaAttributes.put(TableIdentifier.create(table), map);
}
-
+
}
public void addMetaAttributeInfo(TableIdentifier tableIdentifier, String name, MultiMap
map) {
if(map!=null && !map.isEmpty()) {
columnMetaAttributes.put(TABLECOLUMN_KEY_FACTORY.newInstance( tableIdentifier, name ),
map);
}
-
+
}
-
-
-
+
+
+
}
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java 2009-02-25
14:35:32 UTC (rev 16033)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java 2009-02-26
04:33:15 UTC (rev 16034)
@@ -124,7 +124,7 @@
return getAllPropertiesIterator(clazz);
}
-
+
public Iterator getAllPropertiesIterator(PersistentClass pc) {
List properties = new ArrayList();
List iterators = new ArrayList();
@@ -142,29 +142,29 @@
}*/
}
-
+
// iterators.add( pc.getPropertyIterator() );
// Need to skip <properties> element which are defined via "embedded"
components
// Best if we could return an intelligent iterator, but for now we just iterate
explicitly.
- Iterator pit = pc.getPropertyIterator();
+ Iterator pit = pc.getPropertyIterator();
while(pit.hasNext())
{
Property element = (Property) pit.next();
- if ( element.getValue() instanceof Component
+ if ( element.getValue() instanceof Component
&& element.getPropertyAccessorName().equals( "embedded" )) {
Component component = (Component) element.getValue();
// need to "explode" property to get proper sequence in java code.
Iterator embeddedProperty = component.getPropertyIterator();
while(embeddedProperty.hasNext()) {
properties.add(embeddedProperty.next());
- }
+ }
} else {
properties.add(element);
}
}
-
+
iterators.add( properties.iterator() );
-
+
Iterator[] it = (Iterator[]) iterators.toArray( new Iterator[iterators.size()] );
return new SkipBackRefPropertyIterator( new JoinedIterator( it ) );
}
@@ -177,7 +177,7 @@
public boolean hasIdentifierProperty() {
return clazz.hasIdentifierProperty() && clazz instanceof RootClass;
}
-
+
public Property getIdentifierProperty() {
return clazz.getIdentifierProperty();
}
@@ -200,20 +200,20 @@
}
AnnotationBuilder constraint = AnnotationBuilder.createAnnotation(
importType("javax.persistence.UniqueConstraint") );
constraint.addQuotedAttributes( "columnNames", new
IteratorTransformer(key.getColumnIterator()) {
- public Object transform(Object object) {
+ public Object transform(Object object) {
return ((Column)object).getName();
}
});
cons.add( constraint.getResult() );
}
-
+
AnnotationBuilder builder = AnnotationBuilder.createAnnotation(
"dummyAnnotation" );
builder.addAttributes( "dummyAttribute", cons.iterator() );
String attributeAsString = builder.getAttributeAsString( "dummyAttribute" );
return attributeAsString==null?"":attributeAsString;
}
-
+
public String generateAnnIdGenerator() {
KeyValue identifier = clazz.getIdentifier();
String strategy = null;
@@ -231,11 +231,11 @@
AnnotationBuilder builder = AnnotationBuilder.createAnnotation(
importType("javax.persistence.Id") );
idResult.append(builder.getResult());
idResult.append(" ");
-
+
boolean isGenericGenerator = false; //TODO: how to handle generic now??
if ( !"assigned".equals( strategy ) ) {
-
- if ( !"native".equals( strategy ) ) {
+
+ if ( !"native".equals( strategy ) ) {
if ( "identity".equals( strategy ) ) {
builder.resetAnnotation( importType("javax.persistence.GeneratedValue")
);
builder.addAttribute( "strategy",
staticImport("javax.persistence.GenerationType", "IDENTITY" ) );
@@ -245,8 +245,8 @@
builder.resetAnnotation( importType("javax.persistence.GeneratedValue")
)
.addAttribute( "strategy",
staticImport("javax.persistence.GenerationType", "SEQUENCE" ) )
.addQuotedAttribute( "generator", "generator" );
- idResult.append(builder.getResult());
-
+ idResult.append(builder.getResult());
+
builder.resetAnnotation(
importType("javax.persistence.SequenceGenerator") )
.addQuotedAttribute( "name", "generator" ) // TODO:
shouldn't this be unique, e.g. entityName + sequenceName (or just sequencename) ?
.addQuotedAttribute( "sequenceName", properties.getProperty(
org.hibernate.id.SequenceGenerator.SEQUENCE, null ) );
@@ -265,7 +265,7 @@
builder.resetAnnotation( importType("javax.persistence.GeneratedValue")
);
builder.addQuotedAttribute( "generator", "generator" );
idResult.append(builder.getResult());
- }
+ }
} else {
builder.resetAnnotation( importType("javax.persistence.GeneratedValue")
);
idResult.append(builder.getResult());
@@ -275,18 +275,18 @@
builder.resetAnnotation(
importType("org.hibernate.annotations.GenericGenerator") )
.addQuotedAttribute( "name", "generator" )
.addQuotedAttribute( "strategy", strategy);
-
+
List params = new ArrayList();
//wholeString.append( "parameters = { " );
if ( properties != null ) {
Enumeration propNames = properties.propertyNames();
while ( propNames.hasMoreElements() ) {
-
+
String propertyName = (String) propNames.nextElement();
AnnotationBuilder parameter = AnnotationBuilder.createAnnotation(
importType("org.hibernate.annotations.Parameter") )
.addQuotedAttribute( "name", propertyName )
.addQuotedAttribute( "value", properties.getProperty( propertyName )
);
- params.add( parameter );
+ params.add( parameter );
}
}
builder.addAttributes( "parameters", params.iterator() );
@@ -295,27 +295,27 @@
wholeString.append( idResult );
}
return wholeString.toString();
- }
+ }
private void buildAnnTableGenerator(StringBuffer wholeString, Properties properties) {
-
+
AnnotationBuilder builder = AnnotationBuilder.createAnnotation(
importType("javax.persistence.TableGenerator") );
builder.addQuotedAttribute( "name", "generator" );
builder.addQuotedAttribute( "table", properties.getProperty(
"generatorTableName", "hibernate_sequences" ) );
if ( ! isPropertyDefault( PersistentIdentifierGenerator.CATALOG, properties ) ) {
- builder.addQuotedAttribute( "catalog", properties.getProperty(
PersistentIdentifierGenerator.CATALOG, "") );
+ builder.addQuotedAttribute( "catalog", properties.getProperty(
PersistentIdentifierGenerator.CATALOG, "") );
}
if ( ! isPropertyDefault( PersistentIdentifierGenerator.SCHEMA, properties ) ) {
- builder.addQuotedAttribute( "schema", properties.getProperty(
PersistentIdentifierGenerator.SCHEMA, "") );
+ builder.addQuotedAttribute( "schema", properties.getProperty(
PersistentIdentifierGenerator.SCHEMA, "") );
}
if (! isPropertyDefault( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, properties ) ) {
- builder.addQuotedAttribute( "pkColumnValue", properties.getProperty(
MultipleHiLoPerTableGenerator.PK_VALUE_NAME, "") );
+ builder.addQuotedAttribute( "pkColumnValue", properties.getProperty(
MultipleHiLoPerTableGenerator.PK_VALUE_NAME, "") );
}
if ( ! isPropertyDefault( MultipleHiLoPerTableGenerator.MAX_LO, properties,
"50" ) ) {
builder.addAttribute( "allocationSize", properties.getProperty(
MultipleHiLoPerTableGenerator.MAX_LO, "50" ) );
}
if (! isPropertyDefault( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, properties ) )
{
- builder.addQuotedAttribute( "pkColumnName", properties.getProperty(
MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, "") );
+ builder.addQuotedAttribute( "pkColumnName", properties.getProperty(
MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, "") );
}
if (! isPropertyDefault( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, properties )
) {
builder.addQuotedAttribute( "valueColumnName", properties.getProperty(
MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, "") );
@@ -348,7 +348,7 @@
span = property.getColumnSpan();
columnIterator = property.getColumnIterator();
}
-
+
if(property.getValue() instanceof ToOne) {
String referencedEntityName = ((ToOne)property.getValue()).getReferencedEntityName();
PersistentClass target = cfg.getClassMapping(referencedEntityName);
@@ -381,7 +381,7 @@
if(referencedColumnsIterator!=null) {
referencedColumn = (Selectable) referencedColumnsIterator.next();
}
-
+
if ( selectable.isFormula() ) {
//TODO formula in multicolumns not supported by annotations
//annotations.append("/* TODO formula in multicolumns not supported by
annotations */");
@@ -409,27 +409,27 @@
if(referencedColumn!=null) {
annotations.append(", referencedColumnName=\"" ).append(
referencedColumn.getText() ).append( "\"" );
}
-
- appendCommonColumnInfo(annotations, column, insertable, updatable);
+
+ appendCommonColumnInfo(annotations, column, insertable, updatable);
//TODO support secondary table
annotations.append( ")" );
}
- }
-
+ }
+
public String[] getCascadeTypes(Property property) {
StringTokenizer st = new StringTokenizer( property.getCascade(), ", ", false
);
List types = new ArrayList();
while ( st.hasMoreElements() ) {
String element = ( (String) st.nextElement() ).toLowerCase();
if ( "persist".equals( element ) ) {
- types.add(importType( "javax.persistence.CascadeType" ) +
".PERSIST");
+ types.add(importType( "javax.persistence.CascadeType" ) +
".PERSIST");
}
else if ( "merge".equals( element ) ) {
types.add(importType( "javax.persistence.CascadeType") +
".MERGE");
}
else if ( "delete".equals( element ) ) {
types.add(importType( "javax.persistence.CascadeType") +
".REMOVE");
- }
+ }
else if ( "refresh".equals( element ) ) {
types.add(importType( "javax.persistence.CascadeType") +
".REFRESH");
}
@@ -448,51 +448,51 @@
buffer.append(getHibernateCascadeTypeAnnotation(property));
return buffer.toString();
}
-
+
public boolean isSharedPkBasedOneToOne(OneToOne oneToOne){
Iterator joinColumnsIt = oneToOne.getColumnIterator();
Set joinColumns = new HashSet();
while ( joinColumnsIt.hasNext() ) {
joinColumns.add( joinColumnsIt.next() );
}
-
+
if ( joinColumns.size() == 0 )
return false;
-
- Iterator<Column> idColumnsIt = getIdentifierProperty().getColumnIterator();
+
+ Iterator idColumnsIt = getIdentifierProperty().getColumnIterator();
Set idColumns = new HashSet();
while ( idColumnsIt.hasNext() ) {
if (!joinColumns.contains(idColumnsIt.next()) )
return false;
}
-
+
return true;
}
-
+
public String generateOneToOneAnnotation(Property property, Configuration cfg) {
OneToOne oneToOne = (OneToOne)property.getValue();
-
+
boolean pkIsAlsoFk = isSharedPkBasedOneToOne(oneToOne);
-
+
AnnotationBuilder ab = AnnotationBuilder.createAnnotation(
importType("javax.persistence.OneToOne") )
.addAttribute( "cascade", getCascadeTypes(property))
.addAttribute( "fetch", getFetchType(property));
-
+
if ( oneToOne.getForeignKeyType().equals(ForeignKeyDirection.FOREIGN_KEY_TO_PARENT) ){
ab.addQuotedAttribute("mappedBy", getOneToOneMappedBy(cfg, oneToOne));
}
-
+
StringBuffer buffer = new StringBuffer(ab.getResult());
buffer.append(getHibernateCascadeTypeAnnotation(property));
-
+
if ( pkIsAlsoFk &&
oneToOne.getForeignKeyType().equals(ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT) ){
AnnotationBuilder ab1 = AnnotationBuilder.createAnnotation(
importType("javax.persistence.PrimaryKeyJoinColumn") );
buffer.append(ab1.getResult());
}
-
+
return buffer.toString();
}
-
+
public String getHibernateCascadeTypeAnnotation(Property property) {
StringTokenizer st = new StringTokenizer( property.getCascade(), ", ", false
);
String cascadeType = null;
@@ -572,10 +572,10 @@
ab.addAttribute( "fetch", getFetchType (property) );
if ( collection.isInverse() ) {
mappedBy = getOneToManyMappedBy( cfg, collection );
- ab.addQuotedAttribute( "mappedBy", mappedBy );
+ ab.addQuotedAttribute( "mappedBy", mappedBy );
}
annotation.append( ab.getResult() );
-
+
if (mappedBy == null) annotation.append("\n").append(
generateJoinColumnsAnnotation(property, cfg) );
}
else {
@@ -585,17 +585,17 @@
AnnotationBuilder ab = AnnotationBuilder.createAnnotation( importType(
"javax.persistence.ManyToMany") );
ab.addAttribute( "cascade", getCascadeTypes( property ) );
ab.addAttribute( "fetch", getFetchType (property) );
-
+
if ( collection.isInverse() ) {
mappedBy = getManyToManyMappedBy( cfg, collection );
- ab.addQuotedAttribute( "mappedBy", mappedBy );
+ ab.addQuotedAttribute( "mappedBy", mappedBy );
}
annotation.append(ab.getResult());
if (mappedBy == null) {
annotation.append("\n @");
annotation.append( importType( "javax.persistence.JoinTable") ).append(
"(name=\"" );
Table table = collection.getCollectionTable();
-
+
annotation.append( table.getName() );
annotation.append( "\"" );
if ( StringHelper.isNotEmpty( table.getSchema() ) ) {
@@ -711,7 +711,7 @@
}
return mappedBy;
}
-
+
private String getOneToOneMappedBy(Configuration cfg, OneToOne oneToOne) {
String mappedBy;
Iterator joinColumnsIt = oneToOne.getColumnIterator();
@@ -723,13 +723,13 @@
String referencedPropertyName = oneToOne.getReferencedPropertyName();
if ( referencedPropertyName != null )
return referencedPropertyName;
-
+
Iterator properties = pc.getPropertyClosureIterator();
//TODO we should check the table too
boolean isOtherSide = false;
mappedBy = "unresolved";
-
-
+
+
while ( ! isOtherSide && properties.hasNext() ) {
Property oneProperty = (Property) properties.next();
Value manyValue = oneProperty.getValue();
@@ -753,15 +753,15 @@
}
return mappedBy;
}
-
+
public boolean isSubclass() {
- return clazz.getSuperclass()!=null;
+ return clazz.getSuperclass()!=null;
}
-
+
public List getPropertyClosureForFullConstructor() {
return getPropertyClosureForFullConstructor(clazz);
}
-
+
protected List getPropertyClosureForFullConstructor(PersistentClass pc) {
List l = new ArrayList(getPropertyClosureForSuperclassFullConstructor( pc ));
l.addAll(getPropertiesForFullConstructor( pc ));
@@ -771,10 +771,10 @@
public List getPropertiesForFullConstructor() {
return getPropertiesForFullConstructor(clazz);
}
-
+
protected List getPropertiesForFullConstructor(PersistentClass pc) {
List result = new ArrayList();
-
+
for ( Iterator myFields = getAllPropertiesIterator(pc); myFields.hasNext() ; ) {
Property field = (Property) myFields.next();
// TODO: if(!field.isGenerated() ) ) {
@@ -787,17 +787,17 @@
} else if(isFormula(field)) {
continue;
} else {
- result.add( field );
+ result.add( field );
}
}
-
+
return result;
}
private boolean isFormula(Property field) {
Value value = field.getValue();
- boolean foundFormula = false;
-
+ boolean foundFormula = false;
+
if(value!=null && value.getColumnSpan()>0) {
Iterator columnIterator = value.getColumnIterator();
while ( columnIterator.hasNext() ) {
@@ -817,7 +817,7 @@
public List getPropertyClosureForSuperclassFullConstructor() {
return getPropertyClosureForSuperclassFullConstructor(clazz);
}
-
+
public List getPropertyClosureForSuperclassFullConstructor(PersistentClass pc) {
List result = new ArrayList();
if ( pc.getSuperclass() != null ) {
@@ -830,12 +830,12 @@
return result;
}
-
-
+
+
public List getPropertyClosureForMinimalConstructor() {
return getPropertyClosureForMinimalConstructor(clazz);
}
-
+
protected List getPropertyClosureForMinimalConstructor(PersistentClass pc) {
List l = new ArrayList(getPropertyClosureForSuperclassMinConstructor( pc ));
l.addAll(getPropertiesForMinimalConstructor( pc ));
@@ -845,25 +845,25 @@
public List getPropertiesForMinimalConstructor() {
return getPropertiesForMinimalConstructor(clazz);
}
-
+
protected List getPropertiesForMinimalConstructor(PersistentClass pc) {
List result = new ArrayList();
-
+
for ( Iterator myFields = getAllPropertiesIterator(pc); myFields.hasNext() ; ) {
Property property = (Property) myFields.next();
if(property.equals(pc.getIdentifierProperty())) {
if(isAssignedIdentifier(pc, property)) {
result.add(property);
} else {
- continue;
- }
+ continue;
+ }
} else if (property.equals(pc.getVersion())) {
continue; // the version property should not be in the result.
} else if( isRequiredInConstructor(property) ) {
result.add(property);
- }
+ }
}
-
+
return result;
}
@@ -874,7 +874,7 @@
if("assigned".equals(sv.getIdentifierGeneratorStrategy())) {
return true;
}
- }
+ }
}
return false;
}
@@ -882,7 +882,7 @@
public List getPropertyClosureForSuperclassMinimalConstructor() {
return getPropertyClosureForSuperclassMinConstructor(clazz);
}
-
+
protected List getPropertyClosureForSuperclassMinConstructor(PersistentClass pc) {
List result = new ArrayList();
if ( pc.getSuperclass() != null ) {
@@ -895,22 +895,22 @@
return result;
}
-
+
public POJOClass getSuperClass(){
if (!isSubclass())
return null;
return new EntityPOJOClass(clazz.getSuperclass(),c2j);
}
-
+
public String toString() {
return "Entity: " +
(clazz==null?"<none>":clazz.getEntityName());
}
-
+
public boolean hasVersionProperty() {
return clazz.isVersioned() && clazz instanceof RootClass;
}
-
+
/*
* @see org.hibernate.tool.hbm2x.pojo.POJOClass#getVersionProperty()
*/
@@ -918,7 +918,7 @@
{
return clazz.getVersion();
}
-
+
static public abstract class IteratorTransformer implements Iterator {
private Iterator delegate;
@@ -926,7 +926,7 @@
public IteratorTransformer(Iterator delegate) {
this.delegate = delegate;
}
-
+
public boolean hasNext() {
return delegate.hasNext();
}
@@ -938,8 +938,8 @@
public abstract Object transform(Object object);
public void remove() {
- delegate.remove();
- }
+ delegate.remove();
+ }
}
-
+
}