Search in sources :

Example 11 with DialectException

use of com.github.drinkjava2.jdialects.DialectException in project jDialects by drinkjava2.

the class DDLCreateUtils method checkAndInsertToNotRepeatSeq.

/**
 * if name not found, add <br/>
 * If name same, but other fields different, throw exception </br>
 * If name same, and other field same, ignore </br>
 */
protected static void checkAndInsertToNotRepeatSeq(Set<SequenceIdGenerator> notRepeatedSeq, SequenceIdGenerator seq) {
    DialectException.assureNotEmpty(seq.getName(), "SequenceGen name can not be empty");
    DialectException.assureNotEmpty(seq.getSequenceName(), "sequenceName can not be empty of \"" + seq.getName() + "\"");
    boolean canAdd = true;
    for (SequenceIdGenerator not : notRepeatedSeq) {
        if (seq.getName().equals(not.getName())) {
            canAdd = false;
            if (!(seq.getSequenceName().equals(not.getSequenceName()) && seq.getInitialValue().equals(not.getInitialValue()) && seq.getAllocationSize().equals(not.getAllocationSize())))
                throw new DialectException("In one or more tableModel, duplicated SequenceIdGenerator name '" + seq.getName() + "' but different value of sequenceName/initialValue/allocationSize setting");
        } else {
            if (seq.getSequenceName().equals(not.getSequenceName()))
                throw new DialectException("In one or more tableModel, duplicated SequenceName '" + seq.getSequenceName() + "' found for '" + seq.getName() + "' and '" + not.getName() + "'");
        }
    }
    if (canAdd)
        notRepeatedSeq.add(seq);
}
Also used : SequenceIdGenerator(com.github.drinkjava2.jdialects.id.SequenceIdGenerator)

Example 12 with DialectException

use of com.github.drinkjava2.jdialects.DialectException in project jDialects by drinkjava2.

the class DDLDropUtils method toDropDDL.

/**
 * Transfer tables to drop DDL and without format it
 */
public static String[] toDropDDL(Dialect dialect, TableModel... tables) {
    // resultList store mixed drop DDL + drop Ojbects
    List<Object> objectResultList = new ArrayList<Object>();
    for (TableModel table : tables) transferTableToObjectList(dialect, table, objectResultList);
    boolean hasAutoIdGenerator = false;
    for (TableModel table : tables) {
        for (ColumnModel column : table.getColumns()) if (GenerationType.AUTO.equals(column.getIdGenerationType())) {
            hasAutoIdGenerator = true;
            break;
        }
        for (IdGenerator idGens : table.getIdGenerators()) if (hasAutoIdGenerator || idGens.dependOnAutoIdGenerator()) {
            hasAutoIdGenerator = true;
            break;
        }
    }
    List<String> stringResultList = new ArrayList<String>();
    List<TableIdGenerator> tbGeneratorList = new ArrayList<TableIdGenerator>();
    List<SequenceIdGenerator> sequenceList = new ArrayList<SequenceIdGenerator>();
    List<FKeyModel> fKeyConstraintList = new ArrayList<FKeyModel>();
    for (Object strOrObj : objectResultList) {
        if (!StrUtils.isEmpty(strOrObj)) {
            if (strOrObj instanceof String)
                stringResultList.add((String) strOrObj);
            else if (strOrObj instanceof TableIdGenerator)
                tbGeneratorList.add((TableIdGenerator) strOrObj);
            else if (strOrObj instanceof SequenceIdGenerator)
                sequenceList.add((SequenceIdGenerator) strOrObj);
            else if (strOrObj instanceof FKeyModel)
                fKeyConstraintList.add((FKeyModel) strOrObj);
        }
    }
    if (hasAutoIdGenerator) {
        IdGenerator realIdGen = AutoIdGenerator.INSTANCE.getSequenceOrTableIdGenerator(dialect);
        if (realIdGen instanceof TableIdGenerator)
            tbGeneratorList.add((TableIdGenerator) realIdGen);
        else if (realIdGen instanceof SequenceIdGenerator)
            sequenceList.add((SequenceIdGenerator) realIdGen);
        else
            throw new DialectException("Unknow exception happen for realIdGen, please report this bug");
    }
    buildDropSequenceDDL(dialect, stringResultList, sequenceList);
    buildDropTableGeneratorDDL(dialect, stringResultList, tbGeneratorList);
    outputDropFKeyConstraintDDL(dialect, stringResultList, fKeyConstraintList);
    String[] result = stringResultList.toArray(new String[stringResultList.size()]);
    if (Dialect.getGlobalAllowShowSql())
        Dialect.logger.info("Drop DDL:\r" + StrUtils.arrayToString(result, "\r"));
    return result;
}
Also used : ArrayList(java.util.ArrayList) TableIdGenerator(com.github.drinkjava2.jdialects.id.TableIdGenerator) AutoIdGenerator(com.github.drinkjava2.jdialects.id.AutoIdGenerator) SequenceIdGenerator(com.github.drinkjava2.jdialects.id.SequenceIdGenerator) IdGenerator(com.github.drinkjava2.jdialects.id.IdGenerator) TableIdGenerator(com.github.drinkjava2.jdialects.id.TableIdGenerator) SequenceIdGenerator(com.github.drinkjava2.jdialects.id.SequenceIdGenerator) ColumnModel(com.github.drinkjava2.jdialects.model.ColumnModel) TableModel(com.github.drinkjava2.jdialects.model.TableModel) FKeyModel(com.github.drinkjava2.jdialects.model.FKeyModel)

Example 13 with DialectException

use of com.github.drinkjava2.jdialects.DialectException in project jDialects by drinkjava2.

the class DDLCreateUtils method checkAndInsertToNotRepeatTable.

/**
 * if name not found, add <br/>
 * If name same, but other fields different, throw exception </br>
 * If name same, and other field same, ignore </br>
 */
protected static void checkAndInsertToNotRepeatTable(Set<TableIdGenerator> notRepeatedSeq, TableIdGenerator tab) {
    DialectException.assureNotEmpty(tab.getName(), "TableGen name can not be empty");
    DialectException.assureNotEmpty(tab.getTable(), "TableGen tableName can not be empty of \"" + tab.getName() + "\"");
    DialectException.assureNotEmpty(tab.getPkColumnName(), "TableGen pkColumnName can not be empty of \"" + tab.getName() + "\"");
    DialectException.assureNotEmpty(tab.getPkColumnValue(), "TableGen pkColumnValue can not be empty of \"" + tab.getName() + "\"");
    DialectException.assureNotEmpty(tab.getValueColumnName(), "TableGen valueColumnName can not be empty of \"" + tab.getName() + "\"");
    boolean canAdd = true;
    for (TableIdGenerator not : notRepeatedSeq) {
        if (tab.getName().equals(not.getName())) {
            canAdd = false;
            if (!(tab.getTable().equals(not.getTable()) && tab.getPkColumnName().equals(not.getPkColumnName()) && tab.getPkColumnValue().equals(not.getPkColumnValue()) && tab.getValueColumnName().equals(not.getValueColumnName()) && tab.getInitialValue().equals(not.getInitialValue()) && tab.getAllocationSize().equals(not.getAllocationSize())))
                throw new DialectException("In one or more tableModel, duplicated TableIdGenerator name '" + tab.getName() + "' but different value of table/pKColumnName/pkColumnValue/valueColumnName/initialValue/allocationSize setting");
        }
    }
    if (canAdd)
        notRepeatedSeq.add(tab);
}
Also used : TableIdGenerator(com.github.drinkjava2.jdialects.id.TableIdGenerator)

Aggregations

DialectException (com.github.drinkjava2.jdialects.DialectException)6 TableModel (com.github.drinkjava2.jdialects.model.TableModel)5 Dialect (com.github.drinkjava2.jdialects.Dialect)4 DB2400Dialect (com.github.drinkjava2.jdialects.Dialect.DB2400Dialect)4 DB2Dialect (com.github.drinkjava2.jdialects.Dialect.DB2Dialect)4 DerbyDialect (com.github.drinkjava2.jdialects.Dialect.DerbyDialect)4 DerbyTenFiveDialect (com.github.drinkjava2.jdialects.Dialect.DerbyTenFiveDialect)4 DerbyTenSevenDialect (com.github.drinkjava2.jdialects.Dialect.DerbyTenSevenDialect)4 DerbyTenSixDialect (com.github.drinkjava2.jdialects.Dialect.DerbyTenSixDialect)4 H2Dialect (com.github.drinkjava2.jdialects.Dialect.H2Dialect)4 HSQLDialect (com.github.drinkjava2.jdialects.Dialect.HSQLDialect)4 InformixDialect (com.github.drinkjava2.jdialects.Dialect.InformixDialect)4 IngresDialect (com.github.drinkjava2.jdialects.Dialect.IngresDialect)4 Oracle10gDialect (com.github.drinkjava2.jdialects.Dialect.Oracle10gDialect)4 Oracle8iDialect (com.github.drinkjava2.jdialects.Dialect.Oracle8iDialect)4 Oracle9iDialect (com.github.drinkjava2.jdialects.Dialect.Oracle9iDialect)4 PostgreSQL81Dialect (com.github.drinkjava2.jdialects.Dialect.PostgreSQL81Dialect)4 PostgreSQL82Dialect (com.github.drinkjava2.jdialects.Dialect.PostgreSQL82Dialect)4 PostgreSQL9Dialect (com.github.drinkjava2.jdialects.Dialect.PostgreSQL9Dialect)4 PostgresPlusDialect (com.github.drinkjava2.jdialects.Dialect.PostgresPlusDialect)4