use of org.molgenis.emx2.Column in project molgenis-emx2 by molgenis.
the class JsonLdExample method create.
public static void create(Schema schema) {
Table personTable = schema.create(table("Person").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#Person").add(column("name").setPkey().setSemantics("https://schema.org/docs/jsonldcontext.jsonld#name"), column("jobTitle").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#jobTitle").setRequired(true), column("telephone").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#telephone"), column("url").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#url")));
personTable.insert(row("name", "Jane Doe", "jobTitle", "Professor", "telephone", "(425) 123-4567", "url", "http://www.janedoe.com"), row("id", "2", "name", "Mary Stone", "jobTitle", "Cook"));
Table recipeTable = schema.create(table("Recipe").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#Recipe").add(column("name").setPkey().setSemantics("https://schema.org/docs/jsonldcontext.jsonld#name"), column("author").setType(REF).setRefTable("Person").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#author").setRequired(true), column("datePublished").setType(DATE).setSemantics("https://schema.org/docs/jsonldcontext.jsonld#datePublished").setRequired(true), column("prepTime").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#prepTime").setRequired(true)));
recipeTable.insert(row("name", "Mary's Cookies", "author", "Mary Stone", "datePublished", "2018-03-10", "prepTime", "PT20M"));
}
use of org.molgenis.emx2.Column in project molgenis-emx2 by molgenis.
the class SettingsDataModel method create.
public static void create(Schema schema) {
TableMetadata tm = table("Settings");
tm.add(column("schema").setKey(1));
tm.add(column("key").setKey(1));
tm.add(column("value"));
schema.create(tm);
}
use of org.molgenis.emx2.Column in project molgenis-emx2 by molgenis.
the class TableSort method sortTableByDependency.
public static void sortTableByDependency(List<TableMetadata> tableList) {
ArrayList<TableMetadata> result = new ArrayList<>();
ArrayList<TableMetadata> todo = new ArrayList<>(tableList);
// ensure deterministic order
todo.sort(new Comparator<TableMetadata>() {
@Override
public int compare(TableMetadata o1, TableMetadata o2) {
return o1.getTableName().compareTo(o2.getTableName());
}
});
while (!todo.isEmpty()) {
int size = todo.size();
for (int i = 0; i < todo.size(); i++) {
TableMetadata current = todo.get(i);
boolean depends = false;
for (int j = 0; j < todo.size(); j++) {
if (current.getInherit() != null && current.getImportSchema() == null && todo.get(j).equals(current.getInheritedTable())) {
depends = true;
break;
}
}
if (!depends)
for (Column c : current.getColumns()) {
if (c.getRefTableName() != null && !c.isRefback()) {
for (int j = 0; j < todo.size(); j++) {
if (i != j && (todo.get(j).getTableName().equals(c.getRefTableName()))) {
depends = true;
break;
}
}
}
}
if (!depends) {
result.add(todo.get(i));
todo.remove(i);
}
}
// check for circular relationship
if (size == todo.size()) {
throw new MolgenisException("circular dependency error: following tables have circular dependency: " + todo.stream().map(TableMetadata::getTableName).collect(Collectors.joining(",")));
}
}
tableList.clear();
tableList.addAll(result);
}
use of org.molgenis.emx2.Column in project molgenis-emx2 by molgenis.
the class TestGetSetAllTypesOnRows method addContents.
private void addContents(SchemaMetadata m, List<ColumnType> columnTypes) {
TableMetadata t = m.create(table("TypeTest"));
for (ColumnType columnType : columnTypes) {
t.add(column("test" + columnType).setType(columnType).setRequired(true));
t.add(column("test" + columnType + "_nullable").setType(columnType));
t.add(column("test" + columnType + "_readonly").setType(columnType).setReadonly(true));
}
}
use of org.molgenis.emx2.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();
}
Aggregations