use of org.jumpmind.db.model.Database in project symmetric-ds by JumpMind.
the class AbstractSymmetricDialect method dropTablesAndDatabaseObjects.
public void dropTablesAndDatabaseObjects() {
Database modelFromDatabase = readSymmetricSchemaFromDatabase();
platform.dropDatabase(modelFromDatabase, true);
dropRequiredDatabaseObjects();
}
use of org.jumpmind.db.model.Database in project symmetric-ds by JumpMind.
the class DatabaseXmlUtil method read.
/*
* Reads the database model given by the reader.
*
* @param reader The reader that returns the model XML
*
* @return The database model
*/
public static Database read(Reader reader, boolean validate) {
try {
boolean done = false;
Database database = null;
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
parser.setInput(reader);
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT && !done) {
switch(eventType) {
case XmlPullParser.START_DOCUMENT:
database = new Database();
break;
case XmlPullParser.START_TAG:
String name = parser.getName();
if (name.equalsIgnoreCase("database")) {
for (int i = 0; i < parser.getAttributeCount(); i++) {
String attributeName = parser.getAttributeName(i);
String attributeValue = parser.getAttributeValue(i);
if (attributeName.equalsIgnoreCase("name")) {
database.setName(attributeValue);
} else if (attributeName.equalsIgnoreCase("catalog")) {
database.setCatalog(attributeValue);
} else if (attributeName.equalsIgnoreCase("schema")) {
database.setSchema(attributeValue);
}
}
} else if (name.equalsIgnoreCase("table")) {
Table table = nextTable(parser, database.getCatalog(), database.getSchema());
if (table != null) {
database.addTable(table);
}
}
break;
case XmlPullParser.END_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("database")) {
done = true;
}
break;
}
eventType = parser.next();
}
if (validate) {
database.initialize();
}
return database;
} catch (XmlPullParserException e) {
throw new IoException(e);
} catch (IOException e) {
throw new IoException(e);
}
}
use of org.jumpmind.db.model.Database in project symmetric-ds by JumpMind.
the class AbstractDatabasePlatform method dropTables.
public void dropTables(boolean continueOnError, Table... tables) {
Database db = new Database();
for (Table table : tables) {
db.addTable(table);
}
dropDatabase(db, continueOnError);
}
use of org.jumpmind.db.model.Database in project symmetric-ds by JumpMind.
the class AbstractDatabasePlatform method checkSymTablePermissions.
public List<PermissionResult> checkSymTablePermissions(PermissionType... permissionTypes) {
List<PermissionResult> results = new ArrayList<PermissionResult>();
Database database = new Database();
PermissionResult createResult = getCreateSymTablePermission(database);
PermissionResult createTriggerResult = getCreateSymTriggerPermission();
PermissionResult dropTriggerResult = getDropSymTriggerPermission();
boolean drop = false;
for (PermissionType permissionType : permissionTypes) {
switch(permissionType) {
case CREATE_TABLE:
results.add(createResult);
break;
case ALTER_TABLE:
PermissionResult alterResult = getAlterSymTablePermission(database);
results.add(alterResult);
break;
case CREATE_TRIGGER:
results.add(createTriggerResult);
break;
case DROP_TRIGGER:
results.add(dropTriggerResult);
break;
case EXECUTE:
PermissionResult executeResult = getExecuteSymPermission();
results.add(executeResult);
break;
case DROP_TABLE:
drop = true;
break;
case CREATE_FUNCTION:
PermissionResult createFunctionResult = getCreateSymFunctionPermission();
results.add(createFunctionResult);
break;
case CREATE_ROUTINE:
PermissionResult createRoutineResult = getCreateSymRoutinePermission();
results.add(createRoutineResult);
break;
}
}
PermissionResult dropPermission = getDropSymTablePermission();
if (drop) {
results.add(dropPermission);
}
return results;
}
use of org.jumpmind.db.model.Database in project symmetric-ds by JumpMind.
the class AbstractDatabasePlatform method alterTables.
public void alterTables(boolean continueOnError, Table... desiredTables) {
Database currentDatabase = new Database();
Database desiredDatabase = new Database();
StringBuilder tablesProcessed = new StringBuilder();
for (Table table : desiredTables) {
tablesProcessed.append(table.getFullyQualifiedTableName());
tablesProcessed.append(", ");
desiredDatabase.addTable(table);
Table currentTable = ddlReader.readTable(table.getCatalog(), table.getSchema(), table.getName());
if (currentTable != null) {
currentDatabase.addTable(currentTable);
}
}
if (tablesProcessed.length() > 1) {
tablesProcessed.replace(tablesProcessed.length() - 2, tablesProcessed.length(), "");
}
String alterSql = ddlBuilder.alterDatabase(currentDatabase, desiredDatabase);
if (StringUtils.isNotBlank(alterSql.trim())) {
log.info("Running alter sql:\n{}", alterSql);
String delimiter = getDdlBuilder().getDatabaseInfo().getSqlCommandDelimiter();
new SqlScript(alterSql, getSqlTemplate(), !continueOnError, false, false, delimiter, null).execute(getDatabaseInfo().isRequiresAutoCommitForDdl());
} else {
log.info("Tables up to date. No alters found for {}", tablesProcessed);
}
}
Aggregations