use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class DefaultDataBaseBuilder method buildColumn.
protected void buildColumn(DatabaseMetaData metaData, TableContainer owner, NativeTypesLibrary nativeTypesLibrary, AbstractTable table, ResultSet rs) throws SQLException {
if (table instanceof View) {
return;
}
String columnName = rs.getString(4);
Column column = CreationUtils.createColumn(table, columnName);
// TODO optimize search
String columnType = rs.getString(6);
int columnSize = rs.getInt(7);
int decimalDigits = rs.getInt(9);
TypeInstance typeInstance = createTypeInstance(nativeTypesLibrary, columnType, columnSize, decimalDigits);
column.setType(typeInstance);
String defaultValue = rs.getString(13);
if (defaultValue == null || defaultValue.length() == 0) {
defaultValue = "";
}
column.setDefaultValue(defaultValue.trim());
if (rs.getMetaData().getColumnCount() >= 23) {
column.setAutoincrement("YES".equals(rs.getString(23)));
}
String columnComments = getRealComments(getColumnComments(metaData, rs, owner.getName(), table.getName(), columnName));
if (columnComments == null || columnComments.length() == 0) {
column.setComments(null);
} else {
column.setComments(columnComments);
}
String isNullableValue = rs.getString(18);
boolean isNullable = false;
// Fix Oracle compatibility
if (isNullableValue.equals("YES")) {
isNullable = true;
} else if (isNullableValue.equals("NO")) {
isNullable = false;
} else {
isNullable = rs.getBoolean(18);
}
column.setNullable(isNullable);
buildColumnConstraint(metaData, owner, column);
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class OracleDataBaseBuilder method createTypeInstance.
@Override
protected TypeInstance createTypeInstance(NativeTypesLibrary nativeTypesLibrary, String columnType, int columnSize, int decimalDigits) {
TypeInstance typeInstance = super.createTypeInstance(nativeTypesLibrary, columnType, columnSize, decimalDigits);
if ("NUMBER".equals(columnType) && columnSize == 0 && decimalDigits == -127) {
typeInstance.setLength(38);
typeInstance.setPrecision(0);
}
return typeInstance;
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class SQLServerDataBaseBuilder method buildColumn.
@Override
protected void buildColumn(DatabaseMetaData metaData, TableContainer owner, NativeTypesLibrary nativeTypesLibrary, AbstractTable table, ResultSet rs) throws SQLException {
String columnName = rs.getString(4);
Column column = CreationUtils.createColumn(table, columnName);
String columnType = rs.getString(6);
int indexIdentity = columnType.indexOf("identity");
Identity identity = null;
if (indexIdentity != -1) {
identity = getIdentity(columnType);
columnType = columnType.substring(0, indexIdentity).trim();
}
int columnSize = rs.getInt(7);
int decimalDigits = rs.getInt(9);
TypeInstance typeInstance = createTypeInstance(nativeTypesLibrary, columnType, columnSize, decimalDigits);
column.setType(typeInstance);
if (identity != null) {
// buildSequence(owner, table, column, identity);
column.setAutoincrement(true);
}
String defaultValue = rs.getString(13);
if (defaultValue == null || defaultValue.length() == 0) {
defaultValue = "";
}
column.setDefaultValue(defaultValue.trim());
String columnComments = getRealComments(getColumnComments(metaData, rs, owner.getName(), table.getName(), columnName));
if (columnComments == null || columnComments.length() == 0) {
column.setComments(null);
} else {
column.setComments(columnComments);
}
String isNullableValue = rs.getString(18);
boolean isNullable = false;
// Fix Oracle compatibility
if (isNullableValue.equals("YES")) {
isNullable = true;
} else if (isNullableValue.equals("NO")) {
isNullable = false;
} else {
isNullable = rs.getBoolean(18);
}
column.setNullable(isNullable);
buildColumnConstraint(metaData, owner, column);
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class ColumnServicesTest method testColumnLengthENUM.
@Test
public void testColumnLengthENUM() {
Column col = (Column) EcoreUtil.create(DatabasePackage.Literals.COLUMN);
TypeInstance type = (TypeInstance) EcoreUtil.create(TypesLibraryPackage.Literals.TYPE_INSTANCE);
NativeType nType = (NativeType) EcoreUtil.create(TypesLibraryPackage.Literals.NATIVE_TYPE);
col.setType(type);
type.setNativeType(nType);
nType.setSpec(NativeTypeKind.ENUM);
assertEquals("", new ColumnServices().typeLength(col));
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class ColumnServices method typeName.
/**
* Returns the name of the column's type.
*
* @param column
* @return the name of the column's type.
*/
public String typeName(Column column) {
final String res;
Type type = column.getType();
if (type instanceof UserDefinedTypeRef) {
res = ((UserDefinedTypeRef) type).getType().getName();
} else if (type instanceof TypeInstance) {
res = ((TypeInstance) type).getNativeType().getName();
} else {
res = "no name found";
}
return res;
}
Aggregations