Search in sources :

Example 6 with DataTable

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;
}
Also used : CodeTable(org.openforis.collect.relational.model.CodeTable) DataTable(org.openforis.collect.relational.model.DataTable) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) DataColumn(org.openforis.collect.relational.model.DataColumn) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 7 with DataTable

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;
}
Also used : DataTable(org.openforis.collect.relational.model.DataTable) PhysicalSchema(mondrian.olap.MondrianDef.PhysicalSchema) MondrianDef(mondrian.olap.MondrianDef) RelationalSchema(org.openforis.collect.relational.model.RelationalSchema) PhysicalSchema(mondrian.olap.MondrianDef.PhysicalSchema)

Example 8 with DataTable

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);
        }
    }
}
Also used : Path(org.openforis.idm.path.Path) DataTable(org.openforis.collect.relational.model.DataTable) Node(org.openforis.idm.model.Node) Row(org.openforis.collect.relational.data.Row)

Example 9 with DataTable

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);
        }
    }
}
Also used : DataTable(org.openforis.collect.relational.model.DataTable) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) BigInteger(java.math.BigInteger) CollectRecord(org.openforis.collect.model.CollectRecord) Record(org.jooq.Record) DataPrimaryKeyColumn(org.openforis.collect.relational.model.DataPrimaryKeyColumn) DataAccessException(org.jooq.exception.DataAccessException)

Example 10 with DataTable

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);
    }
}
Also used : DataTable(org.openforis.collect.relational.model.DataTable) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) DataAncestorFKColumn(org.openforis.collect.relational.model.DataAncestorFKColumn)

Aggregations

DataTable (org.openforis.collect.relational.model.DataTable)16 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)6 ArrayList (java.util.ArrayList)5 CodeTable (org.openforis.collect.relational.model.CodeTable)5 BigInteger (java.math.BigInteger)4 Record (org.jooq.Record)4 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)4 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 CodeValueFKColumn (org.openforis.collect.relational.model.CodeValueFKColumn)3 DataAncestorFKColumn (org.openforis.collect.relational.model.DataAncestorFKColumn)3 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)3 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)3 TaxonAttributeDefinition (org.openforis.idm.metamodel.TaxonAttributeDefinition)3 Field (org.jooq.Field)2 CollectRecord (org.openforis.collect.model.CollectRecord)2 DataPrimaryKeyColumn (org.openforis.collect.relational.model.DataPrimaryKeyColumn)2 RelationalSchema (org.openforis.collect.relational.model.RelationalSchema)2 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)2 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)2