use of org.openforis.collect.relational.model.DataTable in project collect by openforis.
the class NewMondrianSchemaGenerator method generateLevel.
private Level generateLevel(AttributeDefinition nodeDef) {
DataTable dataTable = rdbSchema.getDataTable(nodeDef.getParentDefinition());
Level level = new Level(determineDimensionName(nodeDef), determineLevelCaption(nodeDef));
level.levelType = "Regular";
if (nodeDef instanceof NumericAttributeDefinition) {
level.type = ((NumericAttributeDefinition) nodeDef).getType() == Type.INTEGER ? INTEGER_DATATYPE : NUMERIC_DATATYPE;
} else if (nodeDef instanceof BooleanAttributeDefinition) {
level.type = BOOLEAN_DATATYPE;
} else if (nodeDef instanceof CodeAttributeDefinition) {
level.type = ((CodeAttributeDefinition) nodeDef).getList().isExternal() ? STRING_DATATYPE : INTEGER_DATATYPE;
} else {
level.type = STRING_DATATYPE;
}
if (nodeDef instanceof CodeAttributeDefinition && !((CodeAttributeDefinition) nodeDef).getList().isExternal()) {
CodeAttributeDefinition codeDef = (CodeAttributeDefinition) nodeDef;
CodeTable codeListTable = rdbSchema.getCodeListTable(codeDef);
level.table = codeListTable.getName();
level.column = codeListTable.getPrimaryKeyConstraint().getPrimaryKeyColumn().getName();
level.nameColumn = CodeListTables.getLabelColumnName(rdbConfig, codeDef.getList(), codeDef.getLevelIndex(), language);
} else if (nodeDef instanceof TaxonAttributeDefinition) {
DataColumn dataColumn = dataTable.getDataColumn(((TaxonAttributeDefinition) nodeDef).getCodeFieldDefinition());
level.column = dataColumn.getName();
} else if (nodeDef.isMultiple()) {
// TODO skip multiple attributes?
level.column = nodeDef.getName();
} else {
DataColumn dataColumn = dataTable.getDataColumn(nodeDef.getMainFieldDefinition());
level.column = dataColumn.getName();
}
return level;
}
use of org.openforis.collect.relational.model.DataTable in project collect by openforis.
the class Mondrian4SchemaGenerator method generateSchema.
public MondrianDef.Schema generateSchema() {
MondrianDef.Schema schema = new MondrianDef.Schema();
schema.metamodelVersion = VERSION_4_0;
schema.name = survey.getName();
PhysicalSchema physicalSchema = generatePhysicalSchema();
schema.children.add(physicalSchema);
for (DataTable dataTable : rdbSchema.getDataTables()) {
schema.children.add(createCube(dataTable));
}
return schema;
}
use of org.openforis.collect.relational.model.DataTable in project collect by openforis.
the class DataTableDataExtractor method extractDataInternal.
private void extractDataInternal(DataTable table, Node<?> source, Dataset data) {
// Extract data from this node
Row row = extractRow(source);
data.addRow(row);
// Extract data from descendants
for (DataTable childTable : table.getChildTables()) {
Path path = childTable.getRelativePath();
List<Node<?>> children = path.evaluate(source);
for (Node<?> child : children) {
extractDataInternal(childTable, child, data);
}
}
}
use of org.openforis.collect.relational.model.DataTable in project collect by openforis.
the class JooqDatabaseExporter method insertNode.
private void insertNode(int recordId, Integer parentId, int nodeId, int nodeDefinitionId) {
DataTable table = schema.getDataTableByDefinitionId(nodeDefinitionId);
NodeDefinition nodeDef = table.getNodeDefinition();
BigInteger pkValue = getTableArtificialPK(recordId, nodeDef, nodeId);
QueryCreator queryCreator = new QueryCreator(dsl, schema.getName());
DataPrimaryKeyColumn pkColumn = table.getPrimaryKeyColumn();
org.jooq.Table<Record> jooqTable = queryCreator.getJooqTable(table);
InsertSetMoreStep<Record> insert = dsl.insertInto(jooqTable).set(field(pkColumn.getName()), pkValue);
if (parentId != null) {
Map<String, BigInteger> ancestorFKByColumnName = findAncestorFKByColumnName(schema, table, recordId, parentId);
for (Entry<String, BigInteger> entry : ancestorFKByColumnName.entrySet()) {
insert.set(field(entry.getKey()), entry.getValue());
}
}
try {
insert.execute();
} catch (DataAccessException e) {
if (JooqDaoSupport.isConstraintViolation(e)) {
LOG.warn(String.format("Duplicate node already inserted: survey = %s, node path = %s, record id = %d, parent id = %d, node id = %d", schema.getSurvey().getName(), nodeDef.getPath(), recordId, parentId, nodeId));
} else {
throw new DataAccessException("Failed to insert node into RDB", e);
}
}
}
use of org.openforis.collect.relational.model.DataTable in project collect by openforis.
the class JooqDatabaseExporter method deleteEntity.
@Override
public void deleteEntity(int recordId, int entityId, int entityDefinitionId) {
DataTable tableToDeleteFor = schema.getDataTableByDefinitionId(entityDefinitionId);
EntityDefinition entityDefToDeleteFor = (EntityDefinition) tableToDeleteFor.getNodeDefinition();
BigInteger pkValue = getTableArtificialPK(recordId, entityDefToDeleteFor, entityId);
// delete data from the actual table
batchExecutor.addDelete(tableToDeleteFor, tableToDeleteFor.getPrimaryKeyColumn(), pkValue);
// delete data from descendant tables
List<DataTable> descendantTables = new ArrayList<DataTable>(schema.getDescendantTablesForDefinition(entityDefinitionId));
Collections.reverse(descendantTables);
for (DataTable dataTable : descendantTables) {
DataAncestorFKColumn ancestorIdColumn = dataTable.getAncestorFKColumn(entityDefinitionId);
batchExecutor.addDelete(dataTable, ancestorIdColumn, pkValue);
}
}
Aggregations