use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project molgenis-emx2 by molgenis.
the class EvaluateExpressionsTest method testCheckValidationSuccess.
@Test
public void testCheckValidationSuccess() {
Map<String, Object> values = new HashMap<>();
Collection<Column> columns = new ArrayList<>();
String validation = "true && true";
Column column = new Column("name");
column.setValidation(validation);
columns.add(column);
checkValidation(values, columns);
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project molgenis-emx2 by molgenis.
the class EvaluateExpressionsTest method testCheckValidationInvalidExpression.
@Test
public void testCheckValidationInvalidExpression() {
Map<String, Object> values = new HashMap<>();
Collection<Column> columns = new ArrayList<>();
String validation = "this is very invalid";
Column column = new Column("name");
column.setValidation(validation);
columns.add(column);
try {
checkValidation(values, columns);
} catch (MolgenisException exception) {
assertEquals("Cannot execute expression: this is very invalid", exception.getMessage());
}
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project molgenis-emx2 by molgenis.
the class SqlColumnRefArrayExecutor method createReferenceExistsCheck.
/**
* trigger on this column to check if foreign key exists. Might be composite key, i.e., list of
* columns
*/
private static void createReferenceExistsCheck(DSLContext jooq, Column column) {
String schemaName = column.getSchema().getName();
Name thisTable = name(schemaName, column.getTable().getTableName());
Name toTable = name(column.getRefSchema(), column.getRefTableName());
String functionName = getReferenceExistsCheckName(column);
List<Reference> references = column.getReferences();
String fromColumns = references.stream().map(r -> name(r.getName()).toString()).collect(Collectors.joining(","));
String toColumns = references.stream().map(r -> name(r.getRefTo()).toString()).collect(Collectors.joining(","));
String errorColumns = references.stream().map(r -> "COALESCE(error_row." + name(r.getRefTo()).toString() + ",'NULL')").collect(Collectors.joining("||','||"));
String exceptFilter = references.stream().map(r -> {
if (r.isOverlappingRef()) {
return name(r.getRefTo()) + " = NEW." + name(r.getName());
} else {
return name(r.getRefTo()) + " = ANY (NEW." + name(r.getName()) + ")";
}
}).collect(Collectors.joining(" AND "));
String unnestRefs = references.stream().map(r -> {
// can be overlapping with non_array reference
if (r.isOverlappingRef()) {
return "NEW." + name(r.getName()) + " AS " + name(r.getRefTo());
} else {
return "UNNEST(NEW." + name(r.getName()) + ") AS " + name(r.getRefTo());
}
}).collect(Collectors.joining(","));
String nonRefLinkFieldsAreNotNull = references.stream().filter(r -> !r.isOverlapping()).map(r2 -> "error_row." + name(r2.getRefTo()) + " IS NOT NULL ").collect(Collectors.joining(" OR "));
jooq.execute("CREATE OR REPLACE FUNCTION {0}() RETURNS trigger AS $BODY$ " + "\nDECLARE error_row RECORD;" + "\nBEGIN" + "\n\tFOR error_row IN SELECT {1} EXCEPT SELECT {2} FROM {3} WHERE {10} LOOP" + // exclude if only refLink fields are set
"\n\t\tIF {11} THEN" + "\n\t\t\tRAISE EXCEPTION USING ERRCODE='23503', MESSAGE = 'insert or update on table \"'||{9}||'\" violates foreign key (ref_array) constraint'" + " , DETAIL = 'Key ('||{6}||')=('|| {5} ||') is not present in table \"'||{7}||'\", column(s)('||{8}||')';" + "\n\t\tEND IF;" + "\n\tEND LOOP;" + "\n\tRETURN NEW;" + "\nEND; $BODY$ LANGUAGE plpgsql;", // 0
name(schemaName, functionName), // 1
keyword(unnestRefs), // 2
keyword(toColumns), // 3
toTable, // 4
thisTable, // 5
keyword(errorColumns), // 6
inline(fromColumns), // 7
inline(column.getRefTableName()), // 8
inline(toColumns), // 9
inline(column.getTableName()), // 10
keyword(exceptFilter), // 11
keyword(nonRefLinkFieldsAreNotNull));
// add the trigger
jooq.execute("CREATE CONSTRAINT TRIGGER {0} " + "\n\tAFTER INSERT OR UPDATE OF {1} ON {2} FROM {3}" + "\n\tDEFERRABLE INITIALLY IMMEDIATE " + "\n\tFOR EACH ROW EXECUTE PROCEDURE {4}()", name(functionName), keyword(fromColumns), thisTable, toTable, name(column.getTable().getSchema().getName(), functionName));
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project molgenis-emx2 by molgenis.
the class SqlColumnRefExecutor method createRefConstraints.
public static void createRefConstraints(DSLContext jooq, Column refColumn) {
validateColumn(refColumn);
Name fkeyConstraintName = name(getRefConstraintName(refColumn));
Name thisTable = getJooqTable(refColumn.getTable()).getQualifiedName();
List<Name> thisColumns = refColumn.getReferences().stream().map(c -> name(c.getName())).collect(Collectors.toList());
List<Name> otherColumns = refColumn.getReferences().stream().map(c -> name(c.getRefTo())).collect(Collectors.toList());
Name fkeyTable = name(refColumn.getRefTable().getSchemaName(), refColumn.getRefTableName());
ConstraintForeignKeyOnStep constraint = constraint(fkeyConstraintName).foreignKey(thisColumns.toArray(new Name[thisColumns.size()])).references(fkeyTable, otherColumns.toArray(new Name[otherColumns.size()])).onUpdateCascade();
if (refColumn.isCascadeDelete()) {
constraint = constraint.onDeleteCascade();
}
jooq.alterTable(getJooqTable(refColumn.getTable())).add(constraint).execute();
jooq.execute("ALTER TABLE {0} ALTER CONSTRAINT {1} DEFERRABLE INITIALLY IMMEDIATE", thisTable, fkeyConstraintName);
jooq.createIndex(getIndexName(refColumn)).on(thisTable, thisColumns.toArray(new Name[thisColumns.size()])).execute();
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project beam by apache.
the class BigtableTableTestUtils method bigTableSegmentedRows.
static com.google.bigtable.v2.Row[] bigTableSegmentedRows() {
com.google.bigtable.v2.Row[] rows = new com.google.bigtable.v2.Row[5];
List<Column> columns = ImmutableList.of(column("boolColumn", booleanToByteArray(true)), column("doubleColumn", doubleToByteArray(5.5)), column("longColumn", Longs.toByteArray(10L)), column("stringColumn", "stringValue".getBytes(UTF_8)));
Family family = Family.newBuilder().setName("familyTest").addAllColumns(columns).build();
for (int i = 0; i < 5; i++) {
rows[i] = com.google.bigtable.v2.Row.newBuilder().setKey(byteStringUtf8("key" + i)).addFamilies(family).build();
}
return rows;
}
Aggregations