package org.hibernate.cfg;
import java.util.Map;
import javax.persistence.OrderColumn;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.mapping.Join;
public class IndexColumn extends Ejb3Column {
private int base;
public IndexColumn(
boolean isImplicit,
String sqlType,
int length,
int precision,
int scale,
String name,
boolean nullable,
boolean unique,
boolean insertable,
boolean updatable,
String secondaryTableName,
Map<String, Join> joins,
PropertyHolder propertyHolder,
MetadataBuildingContext buildingContext) {
super();
setImplicit( isImplicit );
setSqlType( sqlType );
setLength( length );
setPrecision( precision );
setScale( scale );
setLogicalColumnName( name );
setNullable( nullable );
setUnique( unique );
setInsertable( insertable );
setUpdatable( updatable );
setExplicitTableName( secondaryTableName );
setPropertyHolder( propertyHolder );
setJoins( joins );
setBuildingContext( buildingContext );
bind();
}
public int getBase() {
return base;
}
public void setBase(int base) {
this.base = base;
}
public static IndexColumn buildColumnFromAnnotation(
OrderColumn ann,
PropertyHolder propertyHolder,
PropertyData inferredData,
Map<String, Join> secondaryTables,
MetadataBuildingContext buildingContext) {
final IndexColumn column;
if ( ann != null ) {
final String sqlType = BinderHelper.isEmptyAnnotationValue( ann.columnDefinition() ) ? null : ann.columnDefinition();
final String name = BinderHelper.isEmptyAnnotationValue( ann.name() ) ? inferredData.getPropertyName() + "_ORDER" : ann.name();
column = new IndexColumn(
false,
sqlType,
0,
0,
0,
name,
ann.nullable(),
false,
ann.insertable(),
ann.updatable(),
null,
secondaryTables,
propertyHolder,
buildingContext
);
}
else {
column = new IndexColumn(
true,
null,
0,
0,
0,
null,
true,
false,
true,
true,
null,
null,
propertyHolder,
buildingContext
);
}
return column;
}
public static IndexColumn buildColumnFromAnnotation(
org.hibernate.annotations.IndexColumn ann,
PropertyHolder propertyHolder,
PropertyData inferredData,
MetadataBuildingContext buildingContext) {
final IndexColumn column;
if ( ann != null ) {
final String sqlType = BinderHelper.isEmptyAnnotationValue( ann.columnDefinition() ) ? null : ann.columnDefinition();
final String name = BinderHelper.isEmptyAnnotationValue( ann.name() ) ? inferredData.getPropertyName() : ann.name();
column = new IndexColumn(
false,
sqlType,
0,
0,
0,
name,
ann.nullable(),
false,
true,
true,
null,
null,
propertyHolder,
buildingContext
);
column.setBase( ann.base() );
}
else {
column = new IndexColumn(
true,
null,
0,
0,
0,
null,
true,
false,
true,
true,
null,
null,
propertyHolder,
buildingContext
);
}
return column;
}
}