use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class OracleSchemaReader method readIndices.
@Override
public Map<String, List<IndexInfo>> readIndices(SqlExecutor sql, String defSchema, ProcessController controller) throws SQLException, ProcessInterruptedException {
DbmsConnector connector = sql.getConnector();
Map<String, List<IndexInfo>> result = new HashMap<>();
ResultSet rs = connector.executeQuery("SELECT " + "i.table_name,i.index_name,ic.column_name,i.uniqueness " + "FROM user_indexes i " + "JOIN user_ind_columns ic ON i.index_name=ic.index_name " + "JOIN entities e ON (UPPER(e.name)=i.table_name) " + "ORDER BY i.table_name,i.index_name,ic.column_position");
try {
IndexInfo curIndex = null;
String lastTable = null;
while (rs.next()) {
String tableName = rs.getString(1).toLowerCase();
String indexName = rs.getString(2);
if (!tableName.equals(lastTable) || curIndex == null || !curIndex.getName().equals(indexName)) {
List<IndexInfo> list = result.get(tableName);
if (list == null) {
list = new ArrayList<>();
result.put(tableName, list);
}
curIndex = new IndexInfo();
lastTable = tableName;
list.add(curIndex);
curIndex.setName(indexName);
curIndex.setUnique("UNIQUE".equals(rs.getString(4)));
}
String column = rs.getString(3);
curIndex.addColumn(column);
}
} finally {
connector.close(rs);
}
// Read functional indices separately
// as this query contains streaming column which is read slowly
rs = connector.executeQuery("SELECT " + "i.table_name,i.index_name,ic.column_position,c.data_default " + "FROM user_indexes i " + "JOIN user_ind_columns ic ON i.index_name=ic.index_name " + "JOIN entities e ON (UPPER(e.name)=i.table_name) " + "JOIN user_tab_cols c ON (c.column_name=ic.column_name AND c.table_name=ic.table_name) " + "WHERE c.virtual_column='YES' " + "ORDER BY i.table_name,i.index_name,ic.column_position");
try {
while (rs.next()) {
// Read streaming column at first
String defaultValue = rs.getString(4);
String tableName = rs.getString(1).toLowerCase();
String indexName = rs.getString(2);
int pos = rs.getInt(3) - 1;
List<IndexInfo> list = result.get(tableName);
if (list == null)
continue;
for (IndexInfo indexInfo : list) {
if (indexInfo.getName().equals(indexName)) {
defaultValue = GENERIC_REF_INDEX_PATTERN.matcher(defaultValue).replaceFirst("generic($2)");
defaultValue = UPPER_INDEX_PATTERN.matcher(defaultValue).replaceFirst("upper($1)");
defaultValue = LOWER_INDEX_PATTERN.matcher(defaultValue).replaceFirst("lower($1)");
indexInfo.getColumns().set(pos, defaultValue);
}
}
}
} finally {
connector.close(rs);
}
return result;
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class YamlDeserializer method readQuery.
public static Query readQuery(final LoadContext loadContext, final String queryName, final Map<String, Object> content, final Entity entity) {
YamlDeserializer yamlDeserializer = new YamlDeserializer(loadContext);
yamlDeserializer.setProject(entity.getProject());
EntityDeserializer entityDeserializer = yamlDeserializer.new EntityDeserializer();
try {
return entityDeserializer.readQuery(queryName, content, entity);
} catch (ReadException e) {
Query query = new Query(queryName, entity);
loadContext.addWarning(e.attachElement(query));
return query;
}
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class YamlDeserializer method readCustomizations.
/**
* Used with customizations (module), entity, query, operation and static page.
*/
@SuppressWarnings("unchecked")
private void readCustomizations(final Map<String, Object> serialized, final BeVectorCollection<?> target, boolean replace) {
if (project == null)
throw new IllegalStateException();
final Map<String, Object> serializedCustomizations = (Map<String, Object>) serialized.get("customizations");
if (serializedCustomizations == null || serializedCustomizations.isEmpty())
return;
final BeVectorCollection<PageCustomization> customizations = replace ? new PageCustomizations(target) : target.getOrCreateCollection(PageCustomization.CUSTOMIZATIONS_COLLECTION, PageCustomization.class);
try {
for (final String name : serializedCustomizations.keySet()) {
final Map<String, Object> content = (Map<String, Object>) serializedCustomizations.get(name);
final List<String> splitted = StreamEx.split(name, "\\.").toList();
final String type;
final String domain;
if (splitted.size() == 1) {
type = "";
domain = splitted.get(0);
} else {
type = splitted.get(splitted.size() - 1);
splitted.remove(splitted.size() - 1);
domain = String.join(".", splitted);
}
final PageCustomization customization = new PageCustomization(type, domain, customizations);
customization.setCode((String) content.get(TAG_CODE));
customization.setOriginModuleName(project.getProjectOrigin());
DataElementUtils.saveQuiet(customization);
}
} catch (Exception e) {
loadContext.addWarning(new ReadException(e, target, project.getLocation()));
}
if (replace)
DataElementUtils.save(customizations);
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class MassChangeTest method testMassChange.
@Test
public void testMassChange() {
Project project = new Project("test");
Entity entity = new Entity("entity", project.getApplication(), EntityType.TABLE);
DataElementUtils.save(entity);
Query queryToChange = new Query("queryToChange", entity);
DataElementUtils.save(queryToChange);
Query query = new Query("query", entity);
DataElementUtils.save(query);
MassChange mc = new MassChange("Query[name*=\"Change\"]", project.getApplication().getMassChangeCollection(), Collections.singletonMap("type", QueryType.D2));
assertEquals("type", mc.getPropertiesString());
assertEquals("Query[name*=Change]", mc.getSelectorString());
DataElementUtils.save(mc);
assertEquals(QueryType.D1, queryToChange.getType());
assertEquals(QueryType.D1, query.getType());
LoadContext context = new LoadContext();
project.applyMassChanges(context);
context.check();
assertEquals(QueryType.D2, entity.getQueries().get("queryToChange").getType());
assertEquals(QueryType.D1, entity.getQueries().get("query").getType());
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class ReadModelFromXmlTest method testWriteReadQueryOperation.
@Test
public void testWriteReadQueryOperation() throws Exception {
final Project project = new Project("TestProject");
final Module module = project.getApplication();
DataElementUtils.saveQuiet(module);
final Entity table = new Entity("table", module, EntityType.TABLE);
DataElementUtils.saveQuiet(table);
final Operation op = Operation.createOperation("op", Operation.OPERATION_TYPE_JAVA, table);
DataElementUtils.saveQuiet(op);
final Query query = new Query("q", table);
DataElementUtils.saveQuiet(query);
query.getOperationNames().add("op");
final Path tempFolder = Files.createTempDirectory("be4-temp");
Serialization.save(project, tempFolder);
final Project readProject = Serialization.load(tempFolder);
final Entity readEntity = readProject.getApplication().getEntity("table");
assertEquals("op", readEntity.getQueries().get("q").getOperationNames().getValuesArray()[0]);
FileUtils.deleteRecursively(tempFolder);
}
Aggregations