use of com.developmentontheedge.be5.metadata.model.Project in project be5 by DevelopmentOnTheEdge.
the class EntityLocalizationsTest method testLocalizations.
@Test
public void testLocalizations() {
Project proj = new Project("test");
proj.getApplication().getLocalizations().addLocalization("de", "entity", Arrays.asList("@AllQueries", "topic"), "Hello", "Guten Tag");
Entity entity = new Entity("entity", proj.getApplication(), EntityType.TABLE);
DataElementUtils.save(entity);
DataElementUtils.save(new Query("testQuery", entity));
DataElementUtils.save(new Query("testQuery2", entity));
EntityLocalizations el = proj.getApplication().getLocalizations().get("de").get("entity");
Set<LocalizationRow> expected = StreamEx.of("testQuery", "testQuery2", "topic").map(topic -> new EntityLocalizations.LocalizationRow(topic, "Hello", "Guten Tag")).toSet();
assertEquals(expected, el.getRawRows());
assertEquals(expected, el.getRows());
el.remove("Hello", Collections.singleton("topic"));
expected = StreamEx.of("testQuery", "testQuery2").map(topic -> new EntityLocalizations.LocalizationRow(topic, "Hello", "Guten Tag")).toSet();
assertEquals(expected, el.getRawRows());
assertEquals(expected, el.getRows());
}
use of com.developmentontheedge.be5.metadata.model.Project in project be5 by DevelopmentOnTheEdge.
the class AppSync method readSchema.
private void readSchema() throws ExtendedSqlException, SQLException, ProcessInterruptedException {
getLog().info("Read database scheme ...");
long time = System.currentTimeMillis();
ProcessController controller = new NullLogger();
Rdbms rdbms = DatabaseUtils.getRdbms(connector);
DbmsSchemaReader schemaReader = rdbms.getSchemaReader();
defSchema = schemaReader.getDefaultSchema(sqlExecutor);
tableTypes = schemaReader.readTableNames(sqlExecutor, defSchema, controller);
columns = schemaReader.readColumns(sqlExecutor, defSchema, controller);
indices = schemaReader.readIndices(sqlExecutor, defSchema, controller);
if (debug) {
if (!warnings.isEmpty()) {
System.err.println(warnings.size() + " warning(s) during loading the project from " + sqlExecutor.getConnector().getConnectString());
Collections.sort(warnings);
for (String warning : warnings) {
System.err.println(warning);
}
}
}
getLog().info("comleted, " + (System.currentTimeMillis() - time) + "ms.");
}
use of com.developmentontheedge.be5.metadata.model.Project in project be5 by DevelopmentOnTheEdge.
the class AppSync method createEntities.
private void createEntities() throws ExtendedSqlException, SQLException {
Rdbms databaseSystem = DatabaseUtils.getRdbms(connector);
DbmsTypeManager typeManager = databaseSystem == null ? new DefaultTypeManager() : databaseSystem.getTypeManager();
boolean casePreserved = typeManager.normalizeIdentifierCase("aA").equals("aA");
entities = new ArrayList<>();
Project project = new Project("internal-db");
project.setDatabaseSystem(be5Project.getDatabaseSystem());
Module module = new Module("temp", project);
for (String table : tableTypes.keySet()) {
if (!"TABLE".equals(tableTypes.get(table.toLowerCase())))
continue;
List<SqlColumnInfo> columnInfos = columns.get(table.toLowerCase());
if (columnInfos == null)
continue;
Entity entity = new Entity(table, module, EntityType.TABLE);
entities.add(entity);
TableDef tableDef = new TableDef(entity);
for (SqlColumnInfo info : columnInfos) {
ColumnDef column = new ColumnDef(info.getName(), tableDef.getColumns());
column.setType(createColumnType(info));
typeManager.correctType(column.getType());
// PENDING
column.setPrimaryKey(info.getName().equalsIgnoreCase(entity.getPrimaryKey()));
column.setCanBeNull(info.isCanBeNull());
String defaultValue = info.getDefaultValue();
column.setAutoIncrement(info.isAutoIncrement());
if (!info.isAutoIncrement()) {
column.setDefaultValue(defaultValue);
}
if (column.isPrimaryKey() && typeManager.getKeyType().equals(typeManager.getTypeClause(column.getType()))) {
column.getType().setTypeName(SqlColumnType.TYPE_KEY);
}
// column.setOriginModuleName( module.getName() );
DataElementUtils.saveQuiet(column);
}
List<IndexInfo> indexInfos = indices.get(table.toLowerCase(Locale.ENGLISH));
if (indexInfos != null) {
INDEX: for (IndexInfo info : indexInfos) {
if (!casePreserved)
info.setName(info.getName().toUpperCase(Locale.ENGLISH));
IndexDef index = new IndexDef(info.getName(), tableDef.getIndices());
index.setUnique(info.isUnique());
for (String indexCol : info.getColumns()) {
IndexColumnDef indexColumnDef = IndexColumnDef.createFromString(indexCol, index);
if (tableDef.getColumns().get(indexColumnDef.getName()) == null) {
if (debug) {
warnings.add("Unsupported functional index found: " + index.getName() + " (problem is here: " + indexCol + "); skipped");
}
continue INDEX;
}
DataElementUtils.saveQuiet(indexColumnDef);
}
if (index.isUnique() && index.getSize() == 1) {
IndexColumnDef indexColumnDef = index.iterator().next();
if (!indexColumnDef.isFunctional()) {
if (index.getName().equalsIgnoreCase(table + "_pkey")) {
entity.setPrimaryKey(indexColumnDef.getName());
continue;
}
}
}
DataElementUtils.saveQuiet(index);
}
}
DataElementUtils.saveQuiet(tableDef);
}
if (sqlExecutor.getConnector().getType() != DbmsType.MYSQL)
return;
// For MySQL only now
for (Entity entity : entities) {
final String table = entity.getName();
if (!"VIEW".equalsIgnoreCase(tableTypes.get(table)))
continue;
String createTable;
ResultSet rs = sqlExecutor.executeNamedQuery("sql.getTableDefinition", table);
try {
if (!rs.next())
continue;
createTable = rs.getString(2);
} finally {
sqlExecutor.getConnector().close(rs);
}
int as = createTable.indexOf(" AS ");
if (as < 0)
continue;
createTable = createTable.substring(as + " AS ".length());
ViewDef def = new ViewDef(entity);
def.setDefinition(createTable);
DataElementUtils.saveQuiet(def);
}
}
use of com.developmentontheedge.be5.metadata.model.Project in project be5 by DevelopmentOnTheEdge.
the class AppValidate method loadModules.
private void loadModules() throws MojoFailureException {
LoadContext loadContext = new LoadContext();
// List<ProjectElementException> errors = new ArrayList<>();
try {
// final Project model = be5Project;
// List<Project> moduleProjects = ModuleLoader2.loadModules(model, logger, loadContext);
// errors.addAll( validateDeps(moduleProjects) );
// ModuleLoader2.mergeAllModules( model, moduleProjects, loadContext );
ModuleLoader2.mergeModules(be5Project, logger);
} catch (ProjectLoadException e) {
throw new MojoFailureException("Can not load project modules", e);
}
checkErrors(loadContext, "Modules have %d error(s)");
}
use of com.developmentontheedge.be5.metadata.model.Project in project be5 by DevelopmentOnTheEdge.
the class FreemarkerSqlHandler method execute.
public void execute(FreemarkerScript freemarkerScript) throws ProjectElementException, FreemarkerSqlException {
DataElementPath path = freemarkerScript.getCompletePath();
if (log != null) {
log.setOperationName("[>] " + path);
}
sqlExecutor.comment("Execute " + path);
Project project = freemarkerScript.getProject();
ResultToConsumerWriter out = new ResultToConsumerWriter(new MultiSqlConsumer(project.getDatabaseSystem().getType(), this));
FreemarkerUtils.mergeTemplateByPath(path.toString(), project.getContext(freemarkerScript), project.getConfiguration(), out);
for (int j = includeChain.size() - 1; j >= 0; j--) {
sqlExecutor.comment("End of included " + includeChain.get(j), false);
}
}
Aggregations