Java Code Examples for org.apache.ddlutils.model.Table#getAutoIncrementColumns()

The following examples show how to use org.apache.ddlutils.model.Table#getAutoIncrementColumns() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InterbaseBuilder.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public String getSelectLastIdentityValues(Table table)
{
    Column[] columns = table.getAutoIncrementColumns();

    if (columns.length == 0)
    {
        return null;
    }
    else
    {
        StringBuilder result = new StringBuilder();

        result.append("SELECT ");
        for (int idx = 0; idx < columns.length; idx++)
        {
            result.append("GEN_ID(");
            result.append(getDelimitedIdentifier(getGeneratorName(table, columns[idx])));
            result.append(", 0)");
        }
        result.append(" FROM RDB$DATABASE");
        return result.toString();
    }
}
 
Example 2
Source File: Oracle10Builder.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void dropTable(Table table) throws IOException
{
	// The only difference to the Oracle 8/9 variant is the purge which prevents the
	// table from being moved to the recycle bin (which is new in Oracle 10)
    Column[] columns = table.getAutoIncrementColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        dropAutoIncrementTrigger(table, columns[idx]);
        dropAutoIncrementSequence(table, columns[idx]);
    }

    print("DROP TABLE ");
    printIdentifier(getTableName(table));
    print(" CASCADE CONSTRAINTS PURGE");
    printEndOfStatement();
}
 
Example 3
Source File: Oracle8Builder.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void createTable(Database database, Table table, Map parameters) throws IOException
{
    // lets create any sequences
    Column[] columns = table.getAutoIncrementColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        createAutoIncrementSequence(table, columns[idx]);
    }

    super.createTable(database, table, parameters);

    for (int idx = 0; idx < columns.length; idx++)
    {
        createAutoIncrementTrigger(table, columns[idx]);
    }
}
 
Example 4
Source File: FirebirdBuilder.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public String getSelectLastIdentityValues(Table table)
{
    Column[] columns = table.getAutoIncrementColumns();

    if (columns.length == 0)
    {
        return null;
    }
    else
    {
        StringBuilder result = new StringBuilder();

        result.append("SELECT ");
        for (int idx = 0; idx < columns.length; idx++)
        {
            result.append("GEN_ID(");
            result.append(getDelimitedIdentifier(getGeneratorName(table, columns[idx])));
            result.append(", 0)");
        }
        result.append(" FROM RDB$DATABASE");
        return result.toString();
    }
}
 
Example 5
Source File: Oracle8Builder.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void dropTable(Table table) throws IOException
{
    Column[] columns = table.getAutoIncrementColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        dropAutoIncrementTrigger(table, columns[idx]);
        dropAutoIncrementSequence(table, columns[idx]);
    }

    print("DROP TABLE ");
    printIdentifier(getTableName(table));
    print(" CASCADE CONSTRAINTS");
    printEndOfStatement();
}
 
Example 6
Source File: Oracle8Builder.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void createTable(Database database, Table table, Map parameters) throws IOException
{
    // lets create any sequences
    Column[] columns = table.getAutoIncrementColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        createAutoIncrementSequence(table, columns[idx]);
    }

    super.createTable(database, table, parameters);

    for (int idx = 0; idx < columns.length; idx++)
    {
        createAutoIncrementTrigger(table, columns[idx]);
    }
}
 
Example 7
Source File: InterbaseBuilder.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public String getSelectLastIdentityValues(Table table)
{
    Column[] columns = table.getAutoIncrementColumns();

    if (columns.length == 0)
    {
        return null;
    }
    else
    {
        StringBuilder result = new StringBuilder();

        result.append("SELECT ");
        for (int idx = 0; idx < columns.length; idx++)
        {
            result.append("GEN_ID(");
            result.append(getDelimitedIdentifier(getGeneratorName(table, columns[idx])));
            result.append(", 0)");
        }
        result.append(" FROM RDB$DATABASE");
        return result.toString();
    }
}
 
Example 8
Source File: SybasePlatform.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether we need to use identity override mode for the given table.
 * 
 * @param table The table
 * @return <code>true</code> if identity override mode is needed
 */
private boolean useIdentityOverrideFor(Table table)
{
    return isIdentityOverrideOn() &&
           getPlatformInfo().isIdentityOverrideAllowed() &&
           (table.getAutoIncrementColumns().length > 0);
}
 
Example 9
Source File: Oracle8Builder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public String getSelectLastIdentityValues(Table table)
{
    Column[] columns = table.getAutoIncrementColumns();

    if (columns.length > 0)
    {
        StringBuilder result = new StringBuilder();

        result.append("SELECT ");
        for (int idx = 0; idx < columns.length; idx++)
        {
            if (idx > 0)
            {
                result.append(",");
            }
            result.append(getDelimitedIdentifier(getConstraintName("seq", table, columns[idx].getName(), null)));
            result.append(".currval");
        }
        result.append(" FROM dual");
        return result.toString();
    }
    else
    {
        return null;
    }
}
 
Example 10
Source File: PostgreSqlBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public String getSelectLastIdentityValues(Table table)
{
    Column[] columns = table.getAutoIncrementColumns();

    if (columns.length == 0)
    {
        return null;
    }
    else
    {
        StringBuilder result = new StringBuilder();

        result.append("SELECT ");
        for (int idx = 0; idx < columns.length; idx++)
        {
            if (idx > 0)
            {
                result.append(", ");
            }
            result.append("currval('");
            result.append(getDelimitedIdentifier(getConstraintName(null, table, columns[idx].getName(), "seq")));
            result.append("') AS ");
            result.append(getDelimitedIdentifier(columns[idx].getName()));
        }
        return result.toString();
    }
}
 
Example 11
Source File: FirebirdBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void createTable(Database database, Table table, Map parameters) throws IOException
{
    super.createTable(database, table, parameters);

    // creating generator and trigger for auto-increment
    Column[] columns = table.getAutoIncrementColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        writeAutoIncrementCreateStmts(database, table, columns[idx]);
    }
}
 
Example 12
Source File: PostgreSqlBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void dropTable(Table table) throws IOException
{ 
    print("DROP TABLE ");
    printIdentifier(getTableName(table));
    print(" CASCADE");
    printEndOfStatement();

    Column[] columns = table.getAutoIncrementColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        dropAutoIncrementSequence(table, columns[idx]);
    }
}
 
Example 13
Source File: FirebirdBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void dropTable(Table table) throws IOException
{
    // dropping generators for auto-increment
    Column[] columns = table.getAutoIncrementColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        writeAutoIncrementDropStmts(table, columns[idx]);
    }
    super.dropTable(table);
}
 
Example 14
Source File: SybaseBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void copyData(Table sourceTable, Table targetTable) throws IOException
{
    // We need to turn on identity override except when the identity column was added to the column
    Column[] targetAutoIncrCols   = targetTable.getAutoIncrementColumns();
    boolean  needIdentityOverride = false;

    if (targetAutoIncrCols.length > 0)
    {
        needIdentityOverride = true;
        // Sybase only allows for one identity column per table
        if (sourceTable.findColumn(targetAutoIncrCols[0].getName(), getPlatform().isDelimitedIdentifierModeOn()) == null)
        {
            needIdentityOverride = false;
        }
    }
    if (needIdentityOverride)
    {
        print(getEnableIdentityOverrideSql(targetTable));
        printEndOfStatement();
    }
    super.copyData(sourceTable, targetTable);
    if (needIdentityOverride)
    {
        print(getDisableIdentityOverrideSql(targetTable));
        printEndOfStatement();
    }
}
 
Example 15
Source File: SybaseBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void copyData(Table sourceTable, Table targetTable) throws IOException
{
    // We need to turn on identity override except when the identity column was added to the column
    Column[] targetAutoIncrCols   = targetTable.getAutoIncrementColumns();
    boolean  needIdentityOverride = false;

    if (targetAutoIncrCols.length > 0)
    {
        needIdentityOverride = true;
        // Sybase only allows for one identity column per table
        if (sourceTable.findColumn(targetAutoIncrCols[0].getName(), getPlatform().isDelimitedIdentifierModeOn()) == null)
        {
            needIdentityOverride = false;
        }
    }
    if (needIdentityOverride)
    {
        print(getEnableIdentityOverrideSql(targetTable));
        printEndOfStatement();
    }
    super.copyData(sourceTable, targetTable);
    if (needIdentityOverride)
    {
        print(getDisableIdentityOverrideSql(targetTable));
        printEndOfStatement();
    }
}
 
Example 16
Source File: MSSqlBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void copyData(Table sourceTable, Table targetTable) throws IOException
{
    // Sql Server per default does not allow us to insert values explicitly into
    // identity columns. However, we can change this behavior
    // We need to this only if
    // - there is a column in both tables that is auto increment only in the target table, or
    // - there is a column in both tables that is auto increment in both tables
    Column[] targetIdentityColumns = targetTable.getAutoIncrementColumns();

    // Sql Server allows only one identity column, so let's take a shortcut here
    boolean needToAllowIdentityInsert = (targetIdentityColumns.length > 0) &&
                                        (sourceTable.findColumn(targetIdentityColumns[0].getName(), getPlatform().isDelimitedIdentifierModeOn()) != null);

    if (needToAllowIdentityInsert)
    {
        print("SET IDENTITY_INSERT ");
        printIdentifier(getTableName(targetTable));
        print(" ON");
        printEndOfStatement();
    }
    super.copyData(sourceTable, targetTable);
    // We have to turn it off ASAP because it can be on only for one table per session
    if (needToAllowIdentityInsert)
    {
        print("SET IDENTITY_INSERT ");
        printIdentifier(getTableName(targetTable));
        print(" OFF");
        printEndOfStatement();
    }
}
 
Example 17
Source File: MckoiBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void createTable(Database database, Table table, Map parameters) throws IOException
{
    // we use sequences instead of the UNIQUEKEY function because this way
    // we can read their values back
    Column[] columns = table.getAutoIncrementColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        createAutoIncrementSequence(table, columns[idx]);
    }

    super.createTable(database, table, parameters);
}
 
Example 18
Source File: MySqlBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * Normally mysql will return the LAST_INSERT_ID as the column name for the inserted id.
 * Since ddlutils expects the real column name of the field that is autoincrementing, the
 * column has an alias of that column name.
 */
public String getSelectLastIdentityValues(Table table)
{
    String autoIncrementKeyName = "";
    if (table.getAutoIncrementColumns().length > 0)
    {
        autoIncrementKeyName = table.getAutoIncrementColumns()[0].getName();
    }
    return "SELECT LAST_INSERT_ID() " + autoIncrementKeyName;
}
 
Example 19
Source File: InterbaseBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void createTable(Database database, Table table, Map parameters) throws IOException
{
    super.createTable(database, table, parameters);

    // creating generator and trigger for auto-increment
    Column[] columns = table.getAutoIncrementColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        writeAutoIncrementCreateStmts(database, table, columns[idx]);
    }
}
 
Example 20
Source File: SqlServerDialect.java    From DataLink with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasAutoIncrementNotKeyColumns(String schemaName, String tableName) {
    Table table = findTable(schemaName, tableName);
    Column[] columns = table.getAutoIncrementColumns();
    boolean flag = false;
    if (columns != null) {
        for (Column column : columns) {
            if (!column.isPrimaryKey()) {
                flag = true;
                break;
            }
        }
    }
    return flag;
}