private ISqlJetTableDef alterTableSafe(final SqlJetAlterTableDef alterTableDef) throws SqlJetException {
assert (null != alterTableDef);
String tableName = alterTableDef.getTableName();
String newTableName = alterTableDef.getNewTableName();
ISqlJetColumnDef newColumnDef = alterTableDef.getNewColumnDef();
if (null == tableName) {
throw new SqlJetException(SqlJetErrorCode.MISUSE, "Table name isn't defined");
}
if (null == newTableName && null == newColumnDef) {
throw new SqlJetException(SqlJetErrorCode.MISUSE, "Not defined any altering");
}
boolean renameTable = false;
if (null != newTableName) {
renameTable = true;
} else {
newTableName = tableName;
}
if (renameTable && tableDefs.containsKey(newTableName)) {
throw new SqlJetException(SqlJetErrorCode.MISUSE,
String.format("Table \"%s\" already exists", newTableName));
}
final SqlJetTableDef tableDef = (SqlJetTableDef) tableDefs.get(tableName);
if (null == tableDef) {
throw new SqlJetException(SqlJetErrorCode.MISUSE, String.format("Table \"%s\" not found", tableName));
}
List<ISqlJetColumnDef> columns = tableDef.getColumns();
if (null != newColumnDef) {
final String fieldName = newColumnDef.getName();
if (tableDef.getColumn(fieldName) != null) {
throw new SqlJetException(SqlJetErrorCode.MISUSE, String.format(
"Field \"%s\" already exists in table \"%s\"", fieldName, tableName));
}
final List<ISqlJetColumnConstraint> constraints = newColumnDef.getConstraints();
if (null != constraints && 0 != constraints.size()) {
boolean notNull = false;
boolean defaultValue = false;
for (final ISqlJetColumnConstraint constraint : constraints) {
if (constraint instanceof ISqlJetColumnNotNull) {