use of com.developmentontheedge.be5.metadata.model.DdlElement in project be5 by DevelopmentOnTheEdge.
the class AppDb method execute.
private void execute(final Module module) throws ProjectElementException {
boolean started = false;
for (Entity entity : module.getOrCreateEntityCollection().getAvailableElements()) {
DdlElement scheme = entity.getScheme();
if (scheme instanceof TableDef) {
if (scheme.withoutDbScheme()) {
if (!started) {
logger.setOperationName("[A] " + module.getCompletePath());
started = true;
}
processDdl(scheme);
createdTables++;
} else {
logger.setOperationName("Skip table with schema: " + scheme.getEntityName());
}
}
}
// Define views after tables as there might be dependencies
for (Entity entity : module.getOrCreateEntityCollection().getAvailableElements()) {
DdlElement scheme = entity.getScheme();
if (scheme instanceof ViewDef) {
if (scheme.withoutDbScheme()) {
if (!started) {
logger.setOperationName("[A] " + module.getCompletePath());
started = true;
}
processDdl(scheme);
createdViews++;
} else {
logger.setOperationName("Skip table with schema: " + scheme.getEntityName());
}
}
}
}
use of com.developmentontheedge.be5.metadata.model.DdlElement in project be5 by DevelopmentOnTheEdge.
the class AppValidate method checkDdl.
private void checkDdl() throws MojoFailureException {
if (ddlPath != null) {
Entity entity = be5Project.getEntity(ddlPath);
if (entity == null) {
throw new MojoFailureException("Invalid entity: " + ddlPath);
}
DdlElement scheme = entity.getScheme();
if (scheme == null) {
throw new MojoFailureException("Entity has no scheme: " + ddlPath);
}
getLog().info("DDL: " + scheme.getDdl().replaceAll("\n", System.lineSeparator()));
}
}
use of com.developmentontheedge.be5.metadata.model.DdlElement in project be5 by DevelopmentOnTheEdge.
the class TableDef method getDangerousDiffStatements.
@Override
public String getDangerousDiffStatements(DdlElement other, SqlExecutor sql) throws ExtendedSqlException {
if (other == null || (sql != null && sql.isEmpty(getEntityName()))) {
return "";
}
if (!(other instanceof TableDef))
return other.getDropDdl();
TableDef def = (TableDef) ((TableDef) other).clone(other.getOrigin(), other.getName());
DbmsTypeManager typeManager = getProject().getDatabaseSystem().getTypeManager();
String diff = getColumnsDiff(def, typeManager, true, sql);
if (diff == null)
return getDropDdl();
return diff;
}
use of com.developmentontheedge.be5.metadata.model.DdlElement in project be5 by DevelopmentOnTheEdge.
the class AppDb method processDdl.
private void processDdl(final DdlElement tableDef) throws ProjectElementException {
try {
final String generatedQuery = tableDef.getDdl();
sql.executeMultiple(generatedQuery);
} catch (Exception e) {
throw new ProjectElementException(tableDef, e);
}
}
use of com.developmentontheedge.be5.metadata.model.DdlElement in project be5 by DevelopmentOnTheEdge.
the class AppSync method getDdlStatements.
// /////////////////////////////////////////////////////////////////////////
// Synchronization
//
protected String getDdlStatements(boolean dangerousOnly) throws ExtendedSqlException {
Map<String, DdlElement> oldSchemes = new HashMap<>();
Map<String, DdlElement> newSchemes = new HashMap<>();
for (Module module : be5Project.getModulesAndApplication()) {
for (Entity entity : module.getEntities()) {
DdlElement scheme = entity.isAvailable() ? entity.getScheme() : null;
if (scheme != null) {
String normalizedName = entity.getName().toLowerCase();
newSchemes.put(normalizedName, scheme);
}
}
}
for (Entity entity : entities) {
DdlElement scheme = entity.isAvailable() ? entity.getScheme() : null;
if (scheme != null) {
String normalizedName = entity.getName().toLowerCase();
oldSchemes.put(normalizedName, scheme);
}
}
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, DdlElement> entity : newSchemes.entrySet()) {
DdlElement oldScheme = oldSchemes.get(entity.getKey());
DdlElement newScheme = entity.getValue();
if (newScheme.withoutDbScheme()) {
if (!dangerousOnly) {
// PENDING - list of other type
// warnings.addAll(newScheme.getWarnings());
}
if (oldScheme == null) {
if (!dangerousOnly) {
sb.append(newScheme.getCreateDdl());
}
continue;
}
if (newScheme.equals(oldScheme) || newScheme.getDiffDdl(oldScheme, null).isEmpty())
continue;
// PENDING
if (oldScheme instanceof TableDef && newScheme instanceof TableDef)
fixPrimaryKey((TableDef) oldScheme, (TableDef) newScheme);
sb.append(dangerousOnly ? newScheme.getDangerousDiffStatements(oldScheme, sqlExecutor) : newScheme.getDiffDdl(oldScheme, sqlExecutor));
} else {
System.out.println("Skip table with schema: " + newScheme.getEntityName());
}
}
return sb.toString();
}
Aggregations