-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBX-2390: Create a JBoss Tools adaptation layer in Hibernate Tools
- Create interface 'org.hibernate.tool.orm.jbt.wrp.ColumnWrapper' - Change class 'org.hibernate.tool.orm.jbt.wrp.ColumnWrapper' into 'org.hibernate.tool.orm.jbt.wrp.DelegatingColumnWrapperImpl' that extends Column and implemnts ColumnWrapper - Modify method 'org.hibernate.tool.orm.jbt.wrp.DelegatingTableWrapperImpl# getPrimaryKey()' to wrap the resulting PrimaryKey value - Modify method 'org.hibernate.tool.orm.jbt.wrp.DelegatingTableWrapperImpl#getColumnIterator()' to wrap the resulting columns - Modify 'next()' method in return value of 'org.hibernate.tool.orm.jbt.wrp.DelegatingTableWrapperImpl#getForeignKeyIterator()' and wrap the resulting ForeignKey instance - Modify interface method 'org.hibernate.tool.orm.jbt.wrp.TypeWrapperFactory.TypeWrapper#getAssociatedEntityName()' - Handle 'getType' case in 'org.hibernate.tool.orm.jbt.wrp.ValueWrapperFactory.ValueWrapperInvocationHandler#invoke(...)' - Modify method 'org.hibernate.tool.orm.jbt.wrp.WrapperFactory#createColumnWrapper(String)' - Modify test cases in class 'org.hibernate.tool.orm.jbt.wrp.ColumnWrapperTest' - Modify test case 'org.hibernate.tool.orm.jbt.wrp.TypeWrapperTest#testGetAssociatedEntityName()' - Modify test case 'org.hibernate.tool.orm.jbt.wrp.WrapperFactoryTest#testCreateColumnWrapper()' Signed-off-by: Koen Aers <[email protected]>
- Loading branch information
Showing
13 changed files
with
306 additions
and
100 deletions.
There are no files selected for viewing
89 changes: 17 additions & 72 deletions
89
jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ColumnWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,26 @@ | ||
package org.hibernate.tool.orm.jbt.wrp; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.hibernate.boot.Metadata; | ||
import org.hibernate.boot.internal.MetadataImpl; | ||
import org.hibernate.cfg.AvailableSettings; | ||
import org.hibernate.cfg.Configuration; | ||
import org.hibernate.dialect.Dialect; | ||
import org.hibernate.engine.jdbc.dialect.spi.DialectFactory; | ||
import org.hibernate.mapping.Column; | ||
import org.hibernate.mapping.Value; | ||
import org.hibernate.tool.orm.jbt.util.MetadataHelper; | ||
import org.hibernate.type.spi.TypeConfiguration; | ||
|
||
public class ColumnWrapper extends Column { | ||
|
||
private static final int DEFAULT_LENGTH = 255; | ||
private static final int DEFAULT_PRECISION = 19; | ||
private static final int DEFAULT_SCALE = 2; | ||
|
||
public ColumnWrapper(String name) { | ||
super(name); | ||
} | ||
|
||
public String getSqlType(Configuration configuration) { | ||
Metadata metadata = MetadataHelper.getMetadata(configuration); | ||
TypeConfiguration tc = ((MetadataImpl)metadata).getTypeConfiguration(); | ||
return super.getSqlType(tc, buildDialect(configuration), metadata); | ||
} | ||
|
||
public Long getLength() { | ||
Long length = super.getLength(); | ||
return length == null ? Integer.MIN_VALUE : length.longValue(); | ||
} | ||
|
||
public int getDefaultLength() { | ||
return DEFAULT_LENGTH; | ||
} | ||
|
||
public Integer getPrecision() { | ||
Integer precision = super.getPrecision(); | ||
return precision == null ? Integer.MIN_VALUE : precision.intValue(); | ||
} | ||
|
||
public int getDefaultPrecision() { | ||
return DEFAULT_PRECISION; | ||
} | ||
|
||
public Integer getScale() { | ||
Integer scale = super.getScale(); | ||
return scale == null ? Integer.MIN_VALUE : scale.intValue(); | ||
} | ||
|
||
public int getDefaultScale() { | ||
return DEFAULT_SCALE; | ||
} | ||
|
||
@Override | ||
public Value getValue() { | ||
Value val = super.getValue(); | ||
if (val != null) { | ||
val = ValueWrapperFactory.createValueWrapper(val); | ||
} | ||
return val; | ||
} | ||
|
||
private Dialect buildDialect(Configuration configuration) { | ||
Map<String, Object> dialectPropertyMap = new HashMap<String, Object>(); | ||
dialectPropertyMap.put( | ||
AvailableSettings.DIALECT, | ||
configuration.getProperty(AvailableSettings.DIALECT)); | ||
DialectFactory df = configuration | ||
.getStandardServiceRegistryBuilder() | ||
.build() | ||
.getService(DialectFactory.class); | ||
return df.buildDialect(dialectPropertyMap, null); | ||
} | ||
public interface ColumnWrapper extends Wrapper { | ||
|
||
@Override Column getWrappedObject(); | ||
String getName(); | ||
Integer getSqlTypeCode(); | ||
String getSqlType(); | ||
Long getLength(); | ||
int getDefaultLength(); | ||
Integer getPrecision(); | ||
int getDefaultPrecision(); | ||
Integer getScale(); | ||
int getDefaultScale(); | ||
boolean isNullable(); | ||
Value getValue(); | ||
boolean isUnique(); | ||
String getSqlType(Configuration configuration); | ||
void setSqlType(String sqlType); | ||
|
||
} |
136 changes: 136 additions & 0 deletions
136
jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/DelegatingColumnWrapperImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package org.hibernate.tool.orm.jbt.wrp; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.hibernate.boot.Metadata; | ||
import org.hibernate.boot.internal.MetadataImpl; | ||
import org.hibernate.cfg.AvailableSettings; | ||
import org.hibernate.cfg.Configuration; | ||
import org.hibernate.dialect.Dialect; | ||
import org.hibernate.engine.jdbc.dialect.spi.DialectFactory; | ||
import org.hibernate.mapping.Column; | ||
import org.hibernate.mapping.Value; | ||
import org.hibernate.tool.orm.jbt.util.MetadataHelper; | ||
import org.hibernate.type.spi.TypeConfiguration; | ||
|
||
public class DelegatingColumnWrapperImpl extends Column implements ColumnWrapper { | ||
|
||
private static final int DEFAULT_LENGTH = 255; | ||
private static final int DEFAULT_PRECISION = 19; | ||
private static final int DEFAULT_SCALE = 2; | ||
|
||
private Column delegate = null; | ||
|
||
public DelegatingColumnWrapperImpl(Column c) { | ||
delegate = c; | ||
} | ||
|
||
@Override | ||
public Column getWrappedObject() { | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public String getSqlType(Configuration configuration) { | ||
Metadata metadata = MetadataHelper.getMetadata(configuration); | ||
TypeConfiguration tc = ((MetadataImpl)metadata).getTypeConfiguration(); | ||
return delegate.getSqlType(tc, buildDialect(configuration), metadata); | ||
} | ||
|
||
@Override | ||
public Long getLength() { | ||
Long length = delegate.getLength(); | ||
return length == null ? Integer.MIN_VALUE : length.longValue(); | ||
} | ||
|
||
@Override | ||
public int getDefaultLength() { | ||
return DEFAULT_LENGTH; | ||
} | ||
|
||
@Override | ||
public Integer getPrecision() { | ||
Integer precision = delegate.getPrecision(); | ||
return precision == null ? Integer.MIN_VALUE : precision.intValue(); | ||
} | ||
|
||
@Override | ||
public int getDefaultPrecision() { | ||
return DEFAULT_PRECISION; | ||
} | ||
|
||
@Override | ||
public Integer getScale() { | ||
Integer scale = delegate.getScale(); | ||
return scale == null ? Integer.MIN_VALUE : scale.intValue(); | ||
} | ||
|
||
@Override | ||
public int getDefaultScale() { | ||
return DEFAULT_SCALE; | ||
} | ||
|
||
@Override | ||
public Value getValue() { | ||
Value val = delegate.getValue(); | ||
if (val != null) { | ||
val = ValueWrapperFactory.createValueWrapper(val); | ||
} | ||
return val; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return delegate.getName(); | ||
} | ||
|
||
@Override | ||
public Integer getSqlTypeCode() { | ||
return delegate.getSqlTypeCode(); | ||
} | ||
|
||
@Override | ||
public String getSqlType() { | ||
return delegate.getSqlType(); | ||
} | ||
|
||
@Override | ||
public boolean isNullable() { | ||
return delegate.isNullable(); | ||
} | ||
|
||
@Override | ||
public boolean isUnique() { | ||
return delegate.isUnique(); | ||
} | ||
|
||
@Override | ||
public void setSqlType(String sqlType) { | ||
delegate.setSqlType(sqlType); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (!(o instanceof DelegatingColumnWrapperImpl)) { | ||
return false; | ||
} else { | ||
return ((DelegatingColumnWrapperImpl)o).getWrappedObject().equals(delegate); | ||
} | ||
} | ||
|
||
|
||
private Dialect buildDialect(Configuration configuration) { | ||
Map<String, Object> dialectPropertyMap = new HashMap<String, Object>(); | ||
dialectPropertyMap.put( | ||
AvailableSettings.DIALECT, | ||
configuration.getProperty(AvailableSettings.DIALECT)); | ||
DialectFactory df = configuration | ||
.getStandardServiceRegistryBuilder() | ||
.build() | ||
.getService(DialectFactory.class); | ||
return df.buildDialect(dialectPropertyMap, null); | ||
} | ||
|
||
|
||
} |
48 changes: 48 additions & 0 deletions
48
jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/DelegatingForeignKeyWrapperImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.hibernate.tool.orm.jbt.wrp; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import org.hibernate.mapping.Column; | ||
import org.hibernate.mapping.ForeignKey; | ||
import org.hibernate.mapping.Table; | ||
|
||
public class DelegatingForeignKeyWrapperImpl extends ForeignKey implements ForeignKeyWrapper { | ||
|
||
private ForeignKey delegate = null; | ||
|
||
public DelegatingForeignKeyWrapperImpl(ForeignKey fk) { | ||
delegate = fk; | ||
} | ||
|
||
@Override | ||
public ForeignKey getWrappedObject() { | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public Iterator<Column> columnIterator() { | ||
return delegate.getColumns().iterator(); | ||
} | ||
|
||
@Override | ||
public Table getReferencedTable() { | ||
Table result = delegate.getReferencedTable(); | ||
return result == null ? null : new DelegatingTableWrapperImpl(result); | ||
} | ||
|
||
@Override | ||
public boolean isReferenceToPrimaryKey() { | ||
return delegate.isReferenceToPrimaryKey(); | ||
} | ||
|
||
@Override | ||
public List<Column> getReferencedColumns() { | ||
return delegate.getReferencedColumns(); | ||
} | ||
|
||
@Override | ||
public boolean containsColumn(Column column) { | ||
return delegate.containsColumn(column); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/DelegatingPrimaryKeyWrapperImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.hibernate.tool.orm.jbt.wrp; | ||
|
||
import java.util.Iterator; | ||
|
||
import org.hibernate.mapping.Column; | ||
import org.hibernate.mapping.PrimaryKey; | ||
|
||
public class DelegatingPrimaryKeyWrapperImpl extends PrimaryKey implements PrimaryKeyWrapper { | ||
|
||
private PrimaryKey delegate = null; | ||
|
||
public DelegatingPrimaryKeyWrapperImpl(PrimaryKey pk) { | ||
super(pk.getTable()); | ||
delegate = pk; | ||
} | ||
|
||
@Override | ||
public PrimaryKey getWrappedObject() { | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public Iterator<Column> columnIterator() { | ||
return delegate.getColumns().iterator(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ForeignKeyWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.hibernate.tool.orm.jbt.wrp; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import org.hibernate.mapping.Column; | ||
import org.hibernate.mapping.ForeignKey; | ||
import org.hibernate.mapping.Table; | ||
|
||
public interface ForeignKeyWrapper extends Wrapper { | ||
|
||
@Override ForeignKey getWrappedObject(); | ||
Table getReferencedTable(); | ||
Iterator<Column> columnIterator(); | ||
boolean isReferenceToPrimaryKey(); | ||
List<Column> getReferencedColumns(); | ||
boolean containsColumn(Column column); | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/PrimaryKeyWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.hibernate.tool.orm.jbt.wrp; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import org.hibernate.mapping.Column; | ||
import org.hibernate.mapping.PrimaryKey; | ||
import org.hibernate.mapping.Table; | ||
|
||
public interface PrimaryKeyWrapper extends Wrapper { | ||
|
||
@Override PrimaryKey getWrappedObject(); | ||
void addColumn(Column column); | ||
int getColumnSpan(); | ||
List<Column> getColumns(); | ||
Column getColumn(int i); | ||
Table getTable(); | ||
boolean containsColumn(Column column); | ||
Iterator<Column> columnIterator(); | ||
String getName(); | ||
|
||
} |
Oops, something went wrong.