Search in sources :

Example 1 with DdlException

use of org.jumpmind.db.platform.DdlException in project symmetric-ds by JumpMind.

the class AddColumnChange method apply.

/**
     * {@inheritDoc}
     */
public void apply(Database database, boolean caseSensitive) {
    Column newColumn = null;
    try {
        newColumn = (Column) _newColumn.clone();
    } catch (CloneNotSupportedException ex) {
        throw new DdlException(ex);
    }
    Table table = database.findTable(getChangedTable().getName(), caseSensitive);
    if ((_previousColumn != null) && (_nextColumn != null)) {
        int idx = table.getColumnIndex(_previousColumn) + 1;
        table.addColumn(idx, newColumn);
    } else {
        table.addColumn(newColumn);
    }
}
Also used : DdlException(org.jumpmind.db.platform.DdlException) Table(org.jumpmind.db.model.Table) Column(org.jumpmind.db.model.Column)

Example 2 with DdlException

use of org.jumpmind.db.platform.DdlException in project symmetric-ds by JumpMind.

the class AddForeignKeyChange method apply.

/**
     * {@inheritDoc}
     */
public void apply(Database database, boolean caseSensitive) {
    ForeignKey newFK = null;
    try {
        newFK = (ForeignKey) _newForeignKey.clone();
        newFK.setForeignTable(database.findTable(_newForeignKey.getForeignTableName(), caseSensitive));
    } catch (CloneNotSupportedException ex) {
        throw new DdlException(ex);
    }
    database.findTable(getChangedTable().getName()).addForeignKey(newFK);
}
Also used : DdlException(org.jumpmind.db.platform.DdlException) ForeignKey(org.jumpmind.db.model.ForeignKey)

Example 3 with DdlException

use of org.jumpmind.db.platform.DdlException in project symmetric-ds by JumpMind.

the class CallbackClosure method execute.

/**
     * {@inheritDoc}
     */
public void execute(Object obj) throws DdlException {
    LinkedList queue = new LinkedList();
    queue.add(obj.getClass());
    while (!queue.isEmpty()) {
        Class type = (Class) queue.removeFirst();
        Method callback = (Method) _callbacks.get(type);
        if (callback != null) {
            try {
                _parameters[_callbackTypePos] = obj;
                callback.invoke(_callee, _parameters);
                return;
            } catch (InvocationTargetException ex) {
                throw new DdlException(ex.getTargetException());
            } catch (IllegalAccessException ex) {
                throw new DdlException(ex);
            }
        }
        if ((type.getSuperclass() != null) && !type.getSuperclass().equals(Object.class)) {
            queue.add(type.getSuperclass());
        }
        Class[] baseInterfaces = type.getInterfaces();
        if (baseInterfaces != null) {
            for (int idx = 0; idx < baseInterfaces.length; idx++) {
                queue.add(baseInterfaces[idx]);
            }
        }
    }
}
Also used : DdlException(org.jumpmind.db.platform.DdlException) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with DdlException

use of org.jumpmind.db.platform.DdlException in project symmetric-ds by JumpMind.

the class MsSqlDdlReader method existsPKWithName.

/*
     * Determines whether there is a pk for the table with the given name.
     * 
     * @param metaData The database metadata
     * 
     * @param table The table
     * 
     * @param name The pk name
     * 
     * @return <code>true</code> if there is such a pk
     */
private boolean existsPKWithName(DatabaseMetaDataWrapper metaData, Table table, String name) {
    try {
        ResultSet pks = metaData.getPrimaryKeys(table.getName());
        boolean found = false;
        while (pks.next() && !found) {
            if (name.equals(pks.getString("PK_NAME"))) {
                found = true;
            }
        }
        pks.close();
        return found;
    } catch (SQLException ex) {
        throw new DdlException(ex);
    }
}
Also used : DdlException(org.jumpmind.db.platform.DdlException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Example 5 with DdlException

use of org.jumpmind.db.platform.DdlException in project symmetric-ds by JumpMind.

the class AddIndexChange method apply.

/**
     * {@inheritDoc}
     */
public void apply(Database database, boolean caseSensitive) {
    IIndex newIndex = null;
    try {
        newIndex = (IIndex) _newIndex.clone();
    } catch (CloneNotSupportedException ex) {
        throw new DdlException(ex);
    }
    database.findTable(getChangedTable().getName(), caseSensitive).addIndex(newIndex);
}
Also used : IIndex(org.jumpmind.db.model.IIndex) DdlException(org.jumpmind.db.platform.DdlException)

Aggregations

DdlException (org.jumpmind.db.platform.DdlException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 Column (org.jumpmind.db.model.Column)1 ForeignKey (org.jumpmind.db.model.ForeignKey)1 IIndex (org.jumpmind.db.model.IIndex)1 Table (org.jumpmind.db.model.Table)1