use of org.folio.dbschema.Table in project raml-module-builder by folio-org.
the class CQL2PgJSON method indexNode.
private String indexNode(String index, Table targetTable, CQLTermNode node, IndexTextAndJsonValues vals, CqlModifiers modifiers) throws QueryValidationException {
// primary key
if ("id".equals(index)) {
return pgId(node, index);
}
DbIndex dbIndex;
if (targetTable == null || dbTable.equals(targetTable)) {
dbIndex = dbIndexMap.computeIfAbsent(index, i -> DbSchemaUtils.getDbIndex(dbTable, index));
} else {
// foreign table
dbIndex = dbIndexMap.computeIfAbsent(vals.getIndexJson(), i -> DbSchemaUtils.getDbIndex(targetTable, index));
}
if (dbIndex.isForeignKey()) {
return pgId(node, index);
}
String comparator = node.getRelation().getBase().toLowerCase();
switch(comparator) {
case "=":
if (CqlTermFormat.NUMBER == modifiers.getCqlTermFormat()) {
return queryBySql(dbIndex, vals, node, comparator, modifiers);
} else {
return queryByFt(index, dbIndex, vals, node, comparator, modifiers, targetTable);
}
case "adj":
case "all":
case "any":
return queryByFt(index, dbIndex, vals, node, comparator, modifiers, targetTable);
case "==":
case "<>":
if (CqlTermFormat.STRING == modifiers.getCqlTermFormat()) {
return queryByLike(index, dbIndex, vals, node, comparator, modifiers, targetTable);
} else {
return queryBySql(dbIndex, vals, node, comparator, modifiers);
}
case "<":
case ">":
case "<=":
case ">=":
return queryBySql(dbIndex, vals, node, comparator, modifiers);
default:
throw new CQLFeatureUnsupportedException("Relation " + comparator + " not implemented yet: " + node.toString());
}
}
use of org.folio.dbschema.Table in project raml-module-builder by folio-org.
the class CQL2PgJSON method initDbTable.
InitDbTableResult initDbTable() {
if (jsonField == null) {
logger.log(Level.SEVERE, "loadDbSchema(): No primary table name, can not load");
return InitDbTableResult.NO_PRIMARY_TABLE_NAME;
}
// Remove the json blob field name, usually ".jsonb", but in tests also
// ".user_data" etc.
String tname = this.jsonField.replaceAll("\\.[^.]+$", "");
for (Table table : dbSchema.getTables()) {
if ("DELETE".equalsIgnoreCase(table.getMode())) {
continue;
}
if (tname.equalsIgnoreCase(table.getTableName())) {
dbTable = table;
return InitDbTableResult.TABLE_FOUND;
}
if (table.isWithAuditing() && tname.equalsIgnoreCase(table.getAuditingTableName())) {
return InitDbTableResult.AUDIT_TABLE_FOUND;
}
}
logger.log(Level.SEVERE, "loadDbSchema loadDbSchema(): Table {0} NOT FOUND", tname);
return InitDbTableResult.NOT_FOUND;
}
use of org.folio.dbschema.Table in project raml-module-builder by folio-org.
the class CQL2PgJSONTest method queryByFtComparatorException.
@Test(expected = QueryValidationException.class)
public void queryByFtComparatorException() throws QueryValidationException {
Table setup = new Table();
setup.setTableName("test");
cql2pgJson.queryByFt("indexText", "name=abc", "unknownComparator", null, setup);
}
use of org.folio.dbschema.Table in project raml-module-builder by folio-org.
the class SchemaMaker method generateOptimisticLocking.
public static String generateOptimisticLocking(String tenant, String module, String tablename) {
try {
Table table = new Table();
table.setTableName(tablename);
table.setWithOptimisticLocking(OptimisticLockingMode.FAIL);
Map<String, Object> parameters = new HashMap<>(3);
parameters.put("myuniversity", tenant);
parameters.put("mymodule", module);
parameters.put("table", table);
Template tableTemplate = cfg.getTemplate("optimistic_locking.ftl");
Writer writer = new StringWriter();
tableTemplate.process(parameters, writer);
return writer.toString();
} catch (IOException | TemplateException e) {
throw new RuntimeException(e);
}
}
Aggregations