use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int in project jaxdb by jaxdb.
the class Compiler method $default.
String $default(final $Column column) {
if (column instanceof $Char) {
final $Char type = ($Char) column;
if (type.getDefault$() == null)
return null;
if (type.getDefault$().text().length() > type.getLength$().text())
throw new IllegalArgumentException(type.name().getPrefix() + ":" + type.name().getLocalPart() + " column '" + column.getName$().text() + "' DEFAULT '" + type.getDefault$().text() + "' is longer than declared LENGTH(" + type.getLength$().text() + ")");
return "'" + type.getDefault$().text() + "'";
}
if (column instanceof $Binary) {
final $Binary type = ($Binary) column;
if (type.getDefault$() == null)
return null;
if (type.getDefault$().text().getBytes().length > type.getLength$().text())
throw new IllegalArgumentException(type.name().getPrefix() + ":" + type.name().getLocalPart() + " column '" + column.getName$().text() + "' DEFAULT '" + type.getDefault$().text() + "' is longer than declared LENGTH " + type.getLength$().text());
return compileBinary(type.getDefault$().text().toString());
}
if (column instanceof $Integer) {
final Number _default;
final Byte precision;
final Number min;
final Number max;
if (column instanceof $Tinyint) {
final $Tinyint type = ($Tinyint) column;
_default = type.getDefault$() == null ? null : type.getDefault$().text();
precision = type.getPrecision$() == null ? null : type.getPrecision$().text();
min = type.getMin$() == null ? null : type.getMin$().text();
max = type.getMax$() == null ? null : type.getMax$().text();
} else if (column instanceof $Smallint) {
final $Smallint type = ($Smallint) column;
_default = type.getDefault$() == null ? null : type.getDefault$().text();
precision = type.getPrecision$() == null ? null : type.getPrecision$().text();
min = type.getMin$() == null ? null : type.getMin$().text();
max = type.getMax$() == null ? null : type.getMax$().text();
} else if (column instanceof $Int) {
final $Int type = ($Int) column;
_default = type.getDefault$() == null ? null : type.getDefault$().text();
precision = type.getPrecision$() == null ? null : type.getPrecision$().text();
min = type.getMin$() == null ? null : type.getMin$().text();
max = type.getMax$() == null ? null : type.getMax$().text();
} else if (column instanceof $Bigint) {
final $Bigint type = ($Bigint) column;
_default = type.getDefault$() == null ? null : type.getDefault$().text();
precision = type.getPrecision$() == null ? null : type.getPrecision$().text();
min = type.getMin$() == null ? null : type.getMin$().text();
max = type.getMax$() == null ? null : type.getMax$().text();
} else {
throw new UnsupportedOperationException("Unsupported type: " + column.getClass().getName());
}
if (_default == null)
return null;
checkNumericDefault(column, precision == null ? null : Integer.valueOf(precision), _default, min, max);
return String.valueOf(_default);
}
if (column instanceof $Float) {
final $Float type = ($Float) column;
if (type.getDefault$() == null)
return null;
checkNumericDefault(type, null, type.getDefault$().text(), type.getMin$() == null ? null : type.getMin$().text(), type.getMax$() == null ? null : type.getMax$().text());
return type.getDefault$().text().toString();
}
if (column instanceof $Double) {
final $Double type = ($Double) column;
if (type.getDefault$() == null)
return null;
checkNumericDefault(type, null, type.getDefault$().text(), type.getMin$() == null ? null : type.getMin$().text(), type.getMax$() == null ? null : type.getMax$().text());
return type.getDefault$().text().toString();
}
if (column instanceof $Decimal) {
final $Decimal type = ($Decimal) column;
if (type.getDefault$() == null)
return null;
checkNumericDefault(type, type.getPrecision$() == null ? null : type.getPrecision$().text(), type.getDefault$().text(), type.getMin$() == null ? null : type.getMin$().text(), type.getMax$() == null ? null : type.getMax$().text());
return type.getDefault$().text().toString();
}
if (column instanceof $Date) {
final $Date type = ($Date) column;
return type.getDefault$() == null ? null : compileDate(type.getDefault$().text());
}
if (column instanceof $Time) {
final $Time type = ($Time) column;
return type.getDefault$() == null ? null : compileTime(type.getDefault$().text());
}
if (column instanceof $Datetime) {
final $Datetime type = ($Datetime) column;
return type.getDefault$() == null ? null : compileDateTime(type.getDefault$().text());
}
if (column instanceof $Boolean) {
final $Boolean type = ($Boolean) column;
return type.getDefault$() == null ? null : type.getDefault$().text().toString();
}
if (column instanceof $Enum) {
final $Enum type = ($Enum) column;
return type.getDefault$() == null ? null : "'" + type.getDefault$().text() + "'";
}
if (column instanceof $Clob || column instanceof $Blob)
return null;
throw new UnsupportedOperationException("Unknown type: " + column.getClass().getName());
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int in project jaxdb by jaxdb.
the class Compiler method indexes.
List<CreateStatement> indexes(final $Table table, final Map<String, ColumnRef> columnNameToColumn) {
final List<CreateStatement> statements = new ArrayList<>();
if (table.getIndexes() != null) {
for (final $Table.Indexes.Index index : table.getIndexes().getIndex()) {
final List<$Named> columns = index.getColumn();
final int[] columnIndexes = new int[columns.size()];
for (int c = 0, len = columns.size(); c < len; ++c) {
final $Named column = columns.get(c);
columnIndexes[c] = columnNameToColumn.get(column.getName$().text()).index;
}
final CreateStatement createIndex = createIndex(index.getUnique$() != null && index.getUnique$().text(), getIndexName(table, index, columnIndexes), index.getType$(), table.getName$().text(), index.getColumn().toArray(new $Named[index.getColumn().size()]));
if (createIndex != null)
statements.add(createIndex);
}
}
if (table.getColumn() != null) {
final List<$Column> columns = table.getColumn();
for (int c = 0, len = columns.size(); c < len; ++c) {
final $Column column = columns.get(c);
if (column.getIndex() != null) {
final CreateStatement createIndex = createIndex(column.getIndex().getUnique$() != null && column.getIndex().getUnique$().text(), getIndexName(table, column.getIndex(), c), column.getIndex().getType$(), table.getName$().text(), column);
if (createIndex != null)
statements.add(createIndex);
}
}
}
return statements;
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int in project jaxdb by jaxdb.
the class DerbyDecompiler method makeColumn.
@Override
$Column makeColumn(final String columnName, final String typeName, final long size, final int decimalDigits, final String _default, final Boolean nullable, final Boolean autoIncrement) {
final $Column column;
if ("BIGINT".equals(typeName)) {
final $Bigint type = newColumn($Bigint.class);
// type.setPrecision$(new $Bigint.Precision$((byte)size));
if (_default != null && !"GENERATED_BY_DEFAULT".equals(_default))
type.setDefault$(new $Bigint.Default$(Long.valueOf(getDefault(_default))));
if (autoIncrement != null && autoIncrement)
type.setGenerateOnInsert$(new $Bigint.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
column = type;
} else if ("CHAR () FOR BIT DATA".equals(typeName) || "VARCHAR () FOR BIT DATA".equals(typeName)) {
final $Binary type = newColumn($Binary.class);
if (typeName.startsWith("VARCHAR"))
type.setVarying$(new $Binary.Varying$(true));
type.setLength$(new $Binary.Length$(size));
column = type;
} else if ("BLOB".equals(typeName)) {
final $Blob type = newColumn($Blob.class);
type.setLength$(new $Blob.Length$(size));
column = type;
} else if ("BOOLEAN".equals(typeName)) {
final $Boolean type = newColumn($Boolean.class);
if (_default != null)
type.setDefault$(new $Boolean.Default$(Boolean.valueOf(_default)));
column = type;
} else if ("VARCHAR".equals(typeName) || "CHAR".equals(typeName)) {
final $Char type = newColumn($Char.class);
if ("VARCHAR".equals(typeName))
type.setVarying$(new $Char.Varying$(true));
type.setLength$(new $Char.Length$(size));
if (_default != null)
type.setDefault$(new $Char.Default$(_default.substring(1, _default.length() - 1)));
column = type;
} else if ("CLOB".equals(typeName)) {
final $Clob type = newColumn($Clob.class);
type.setLength$(new $Clob.Length$(size));
column = type;
} else if ("DATE".equals(typeName)) {
final $Date type = newColumn($Date.class);
if (_default != null)
type.setDefault$(new $Date.Default$(_default.substring(1, _default.length() - 1)));
column = type;
} else if ("TIMESTAMP".equals(typeName)) {
final $Datetime type = newColumn($Datetime.class);
// type.setPrecision$(new $Datetime.Precision$((byte)size));
if (_default != null)
type.setDefault$(new $Datetime.Default$(_default.substring(1, _default.length() - 1)));
column = type;
} else if ("DECIMAL".equals(typeName)) {
final int precision = (int) size;
final $Decimal type = newColumn($Decimal.class);
type.setPrecision$(new $Decimal.Precision$(precision));
type.setScale$(new $Decimal.Scale$(decimalDigits));
if (_default != null)
type.setDefault$(new $Decimal.Default$(new BigDecimal(_default)));
column = type;
} else if ("DOUBLE".equals(typeName)) {
final $Double type = newColumn($Double.class);
if (_default != null)
type.setDefault$(new $Double.Default$(Double.valueOf(_default)));
column = type;
} else // }
if ("FLOAT".equals(typeName)) {
final $Float type = newColumn($Float.class);
if (_default != null)
type.setDefault$(new $Float.Default$(Float.valueOf(_default)));
column = type;
} else if ("INTEGER".equals(typeName)) {
final $Int type = newColumn($Int.class);
type.setPrecision$(new $Int.Precision$((byte) size));
if (_default != null && !"GENERATED_BY_DEFAULT".equals(_default))
type.setDefault$(new $Int.Default$(Integer.valueOf(getDefault(_default))));
if (autoIncrement != null && autoIncrement)
type.setGenerateOnInsert$(new $Int.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
column = type;
} else if ("SMALLINT".equals(typeName)) {
final $Smallint type = newColumn($Smallint.class);
type.setPrecision$(new $Smallint.Precision$((byte) size));
if (_default != null && !"GENERATED_BY_DEFAULT".equals(_default))
type.setDefault$(new $Smallint.Default$(Short.valueOf(getDefault(_default))));
if (autoIncrement != null && autoIncrement)
type.setGenerateOnInsert$(new $Smallint.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
column = type;
} else if ("TIME".equals(typeName)) {
final $Time type = newColumn($Time.class);
type.setPrecision$(new $Time.Precision$((byte) size));
if (_default != null)
type.setDefault$(new $Time.Default$(_default.substring(1, _default.length() - 1)));
column = type;
} else // else if ("TINYINT".equals(typeName)) {
// final $Tinyint type = newColumn($Tinyint.class);
// type.setPrecision$(new $Tinyint.Precision$((byte)size));
// if (_default != null && !"GENERATED_BY_DEFAULT".equals(_default))
// type.setDefault$(new $Tinyint.setDefault$(new BigInteger(getDefault(_default))));
//
// if (autoIncrement != null && autoIncrement)
// type.GenerateOnInsert$(new $Integer.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
//
// column = type;
// }
{
throw new UnsupportedOperationException("Unsupported column type: " + typeName);
}
column.setName$(new $Column.Name$(columnName));
if (nullable != null && !nullable)
column.setNull$(new $Column.Null$(false));
return column;
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int in project jaxdb by jaxdb.
the class PostgreSQLCompiler method types.
@Override
List<CreateStatement> types(final $Table table, final Map<String, Map<String, String>> tableNameToEnumToOwner) {
final List<CreateStatement> statements = new ArrayList<>();
if (table.getColumn() != null) {
StringBuilder sql = null;
for (final $Column column : table.getColumn()) {
if (column instanceof $Enum) {
final $Enum type = ($Enum) column;
if (sql == null)
sql = new StringBuilder();
else
sql.setLength(0);
sql.append("CREATE TYPE ").append(q(Dialect.getTypeName(type, tableNameToEnumToOwner))).append(" AS ENUM (");
if (type.getValues$() != null) {
final List<String> enums = Dialect.parseEnum(type.getValues$().text());
final Iterator<String> iterator = enums.iterator();
for (int i = 0; iterator.hasNext(); ++i) {
if (i > 0)
sql.append(", ");
sql.append('\'').append(iterator.next()).append('\'');
}
}
statements.add(0, new CreateStatement(sql.append(')').toString()));
} else if (column instanceof $Integer) {
final $Integer integer = ($Integer) column;
if (Generator.isAuto(integer)) {
final StringBuilder builder = new StringBuilder("CREATE SEQUENCE " + q(getSequenceName(table, integer)));
final String min = getAttr("min", integer);
if (min != null)
builder.append(" MINVALUE ").append(min);
final String max = getAttr("max", integer);
if (max != null)
builder.append(" MAXVALUE ").append(max);
final String _default = getAttr("default", integer);
if (_default != null)
builder.append(" START ").append(_default);
builder.append(" CYCLE");
statements.add(0, new CreateStatement(builder.toString()));
}
}
}
}
statements.addAll(super.types(table, tableNameToEnumToOwner));
return statements;
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int in project jaxdb by jaxdb.
the class SQLiteCompiler method $autoIncrement.
@Override
String $autoIncrement(final LinkedHashSet<CreateStatement> alterStatements, final $Table table, final $Integer column) {
if (!Generator.isAuto(column))
return null;
final $Columns primaryKey;
if (table.getConstraints() == null || (primaryKey = table.getConstraints().getPrimaryKey()) == null) {
if (logger.isWarnEnabled())
logger.warn("AUTO_INCREMENT is only allowed on an INT PRIMARY KEY -- Ignoring AUTO_INCREMENT spec.");
return null;
}
if (primaryKey.getColumn().size() > 1) {
if (logger.isWarnEnabled())
logger.warn("AUTO_INCREMENT is not allowed for tables with composite primary keys -- Ignoring AUTO_INCREMENT spec.");
return null;
}
for (final $Named primaryColumn : primaryKey.getColumn()) {
if (primaryColumn.getName$().text().equals(column.getName$().text())) {
final String min = getAttr("min", column);
if (min != null && logger.isWarnEnabled())
logger.warn("AUTO_INCREMENT does not consider min=\"" + min + "\" -- Ignoring min spec.");
final String max = getAttr("max", column);
if (max != null && logger.isWarnEnabled())
logger.warn("AUTO_INCREMENT does not consider max=\"" + max + "\" -- Ignoring max spec.");
final String _default = getAttr("default", column);
if (_default != null && logger.isWarnEnabled())
logger.warn("AUTO_INCREMENT does not consider default=\"" + _default + "\" -- Ignoring default spec.");
return "PRIMARY KEY";
}
}
if (logger.isWarnEnabled())
logger.warn("AUTO_INCREMENT is only allowed on an INT PRIMARY KEY -- Ignoring AUTO_INCREMENT spec.");
return null;
}
Aggregations