@Override protected String getFieldType(DField df) { String type = df.getType(); if ("boolean".equalsIgnoreCase(type)) return "char(1) check (" + df.getName() + " in(0,1))"; if ("time".equalsIgnoreCase(type)) return "TIMESTAMP"; if ("text".equalsIgnoreCase(type)) return "VARCHAR(4000)"; if ("bigint".equalsIgnoreCase(type)) return "NUMBER"; return type; }
@Override protected void appendField(StringBuilder sb, DField df) { appendFieldName(sb, df); sb.append(' ').append(getFieldType(df)); if (!df.isPrimaryKey()) { addDecorator(sb, df.isUnique(), " UNIQUE"); addDecorator(sb, df.isNotNull(), " NOT NULL"); } if (!Strings.isBlank(df.getDefaultValue())) sb.append(" DEFAULT ").append(df.getDefaultValue()); }
@Override public Sql makeDropSql(DTable td) { ComboSql sql = new ComboSql(); sql.add(Sqls.create("DROP TABLE " + td.getName())); for (DField df : td.getAutoIncreaments()) { sql.add(Sqls.create(gSQL(DSEQ, td.getName(), df.getName()))); // sql.addSQL(new ExecutableSql(gSQL(DTRI, td.getName(), // df.getName()))); } return sql; }
@Override public Sql makeCreateSql(DTable td) { ComboSql sql = new ComboSql(); // Make create table SQL StringBuilder sb = new StringBuilder("CREATE TABLE ").append(td.getName()).append('('); appendAllFields(td, sb); // Append PK Iterator<DField> dfIt = td.getPks().iterator(); if (dfIt.hasNext()) { String names = dfIt.next().getName(); while (dfIt.hasNext()) names += "," + dfIt.next(); sb.append(',').append(gSQL(CPK, td.getName(), names)); } sb.append(')'); sql.add(Sqls.create(sb.toString())); // For all auto increaments fields, create the sequance and trigger for (DField df : td.getAutoIncreaments()) { // create sequance; sql.add(Sqls.create(gSQL(CSEQ, td.getName(), df.getName()))); // create trigger; sql.add(Sqls.create(gSQL(CTRI, td.getName(), df.getName()))); } return sql; }
protected void appendFieldName(StringBuilder sb, DField df) { sb.append(df.getName()); }