use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKeyUnary.Column$ in project jaxdb by jaxdb.
the class OracleCompiler method triggers.
@Override
List<CreateStatement> triggers(final $Table table) {
final List<CreateStatement> statements = new ArrayList<>();
if (table.getColumn() != null) {
for (final $Column column : table.getColumn()) {
if (column instanceof $Integer) {
final $Integer type = ($Integer) column;
if (Generator.isAuto(type)) {
final String sequenceName = getSequenceName(table, type);
final String columnName = q(column.getName$().text());
statements.add(0, new CreateStatement("CREATE TRIGGER " + q(getTriggerName(table, type)) + " BEFORE INSERT ON " + q(table.getName$().text()) + " FOR EACH ROW WHEN (new." + columnName + " IS NULL) BEGIN SELECT " + q(sequenceName) + ".NEXTVAL INTO " + ":new." + columnName + " FROM dual; END;"));
}
}
}
}
statements.addAll(super.triggers(table));
return statements;
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKeyUnary.Column$ in project jaxdb by jaxdb.
the class OracleCompiler 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) {
for (final $Column column : table.getColumn()) {
if (column instanceof $Integer) {
final $Integer integer = ($Integer) column;
if (Generator.isAuto(integer)) {
final StringBuilder builder = new StringBuilder();
builder.append("CREATE SEQUENCE ").append(q(getSequenceName(table, integer)));
builder.append(" INCREMENT BY 1");
final String startWith = getAttr("default", integer);
if (startWith != null)
builder.append(" START WITH ").append(startWith);
final String max = getAttr("max", integer);
final Byte precision;
builder.append(" MAXVALUE ");
builder.append(max != null ? max : (precision = getPrecision(integer)) != null ? FastMath.longE10[precision] : Long.MAX_VALUE);
String min = getAttr("min", integer);
if (min == null)
min = startWith;
if (min != null)
builder.append(" MINVALUE ").append(min);
else
builder.append(" NOMINVALUE ");
builder.append(" CYCLE NOCACHE");
statements.add(0, new CreateStatement(builder.toString()));
}
}
}
}
statements.addAll(super.types(table, tableNameToEnumToOwner));
return statements;
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKeyUnary.Column$ 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.$ForeignKeyUnary.Column$ 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;
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKeyUnary.Column$ in project jaxdb by jaxdb.
the class DerbyDecompiler method makeCheck.
// TODO: This only supports single-column constraints
private static $CheckReference makeCheck(final String checkDefinition) {
final String[] terms = checkDefinition.substring(1, checkDefinition.length() - 1).split(" ");
$CheckReference check = null;
$CheckReference previousCheck = null;
for (int i = 0; i < terms.length; i += 3) {
final $CheckReference nextCheck = makeCheck(i == 0 ? null : terms[i++], Strings.trim(terms[i], '"'), terms[i + 1], terms[i + 2]);
if (previousCheck == null)
check = previousCheck = nextCheck;
else {
if (nextCheck instanceof $Table.Constraints.Check.And)
previousCheck.setAnd(nextCheck);
else if (nextCheck instanceof $Table.Constraints.Check.Or)
previousCheck.setOr(nextCheck);
else
throw new UnsupportedOperationException("Unsupported check type: " + nextCheck.getClass().getName());
previousCheck = nextCheck;
}
}
return check;
}
Aggregations