Search in sources :

Example 1 with RelationalSchema

use of org.openforis.collect.relational.model.RelationalSchema in project collect by openforis.

the class RDBReportingRepositories method process.

@Override
public void process(final RecordTransaction recordTransaction) {
    final RelationalSchema rdbSchema = getRelatedRelationalSchema(recordTransaction);
    final CollectSurvey survey = (CollectSurvey) rdbSchema.getSurvey();
    RecordStep step = recordTransaction.getRecordStep();
    withConnection(survey.getName(), step, new Callback() {

        public void execute(Connection connection) {
            RDBUpdater rdbUpdater = createRDBUpdater(rdbSchema, connection);
            for (RecordEvent recordEvent : recordTransaction.getEvents()) {
                EventHandler handler = new EventHandler(recordEvent, rdbSchema, survey, rdbUpdater);
                handler.handle();
            }
        }
    });
}
Also used : RecordStep(org.openforis.collect.event.RecordStep) Connection(java.sql.Connection) RecordEvent(org.openforis.collect.event.RecordEvent) CollectSurvey(org.openforis.collect.model.CollectSurvey) RelationalSchema(org.openforis.collect.relational.model.RelationalSchema)

Example 2 with RelationalSchema

use of org.openforis.collect.relational.model.RelationalSchema in project collect by openforis.

the class RDBReportingRepositories method createRepository.

@Override
public void createRepository(final String surveyName, final RecordStep recordStep, final String preferredLanguage, final ProgressListener progressListener) {
    localRDBStorageManager.deleteRDBFile(surveyName, recordStep);
    updateMondrianSchemaFile(surveyName, preferredLanguage);
    if (saikuDatasourceStorageManager.isSaikuAvailable()) {
        writeSaikuDatasource(surveyName, recordStep);
    }
    final RelationalSchema relationalSchema = getOrInitializeRelationalSchemaDefinition(surveyName);
    withConnection(surveyName, recordStep, new Callback() {

        public void execute(Connection connection) {
            RelationalSchemaCreator relationalSchemaCreator = new JooqRelationalSchemaCreator();
            relationalSchemaCreator.createRelationalSchema(relationalSchema, connection);
            insertRecords(surveyName, recordStep, relationalSchema, connection, progressListener);
            relationalSchemaCreator.addConstraints(relationalSchema, connection);
            relationalSchemaCreator.addIndexes(relationalSchema, connection);
        }
    });
}
Also used : JooqRelationalSchemaCreator(org.openforis.collect.relational.jooq.JooqRelationalSchemaCreator) Connection(java.sql.Connection) JooqRelationalSchemaCreator(org.openforis.collect.relational.jooq.JooqRelationalSchemaCreator) RelationalSchema(org.openforis.collect.relational.model.RelationalSchema)

Example 3 with RelationalSchema

use of org.openforis.collect.relational.model.RelationalSchema in project collect by openforis.

the class RelationalDataConverterTest method testGenerator.

@Test
public void testGenerator() throws Exception {
    RelationalSchemaGenerator rsg = new RelationalSchemaGenerator();
    RelationalSchema rs = rsg.generateSchema(survey, "archenland1");
    List<Table<?>> tables = rs.getTables();
    CollectRecord record = createTestRecord(survey, "123_456");
    Dataset data = rs.createDataset(record);
    data.print(System.out);
// TODO proper integration test
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Table(org.openforis.collect.relational.model.Table) RelationalSchemaGenerator(org.openforis.collect.relational.model.RelationalSchemaGenerator) Dataset(org.openforis.collect.relational.model.Dataset) RelationalSchema(org.openforis.collect.relational.model.RelationalSchema) Test(org.junit.Test)

Example 4 with RelationalSchema

use of org.openforis.collect.relational.model.RelationalSchema in project collect by openforis.

the class RelationalSchemaGeneratorTest method testGenerator.

@Test
public void testGenerator() throws Exception {
    RelationalSchemaGenerator rsg = new RelationalSchemaGenerator();
    RelationalSchema rs = rsg.generateSchema(survey, "archenland1");
    List<Table<?>> tables = rs.getTables();
    // Debug
    for (Table<?> table : tables) {
        DataTable t = (DataTable) table;
        t.print(System.out);
    }
// TODO proper integration test
}
Also used : DataTable(org.openforis.collect.relational.model.DataTable) Table(org.openforis.collect.relational.model.Table) DataTable(org.openforis.collect.relational.model.DataTable) RelationalSchemaGenerator(org.openforis.collect.relational.model.RelationalSchemaGenerator) RelationalSchema(org.openforis.collect.relational.model.RelationalSchema) Test(org.junit.Test)

Example 5 with RelationalSchema

use of org.openforis.collect.relational.model.RelationalSchema in project collect by openforis.

the class CollectRDBPublisher method export.

public void export(String surveyName, String rootEntityName, Step step, String targetSchemaName, Connection targetConn, RelationalSchemaConfig config, ProgressListener progressListener) throws CollectRdbException {
    try {
        targetConn.setAutoCommit(false);
    } catch (SQLException e) {
    }
    try {
        CollectSurvey survey = surveyManager.get(surveyName);
        // Generate relational model
        RelationalSchemaGenerator schemaGenerator = new RelationalSchemaGenerator(config);
        RelationalSchema relationalSchema = schemaGenerator.generateSchema(survey, targetSchemaName);
        RelationalSchemaCreator relationalSchemaCreator = createRelationalSchemaCreator();
        relationalSchemaCreator.createRelationalSchema(relationalSchema, targetConn);
        relationalSchemaCreator.addConstraints(relationalSchema, targetConn);
        relationalSchemaCreator.addIndexes(relationalSchema, targetConn);
        insertData(survey, rootEntityName, step, targetConn, relationalSchema, progressListener);
        targetConn.commit();
        if (LOG.isInfoEnabled()) {
            LOG.info("RDB generation completed");
        }
    } catch (Exception e) {
        try {
            targetConn.rollback();
        } catch (SQLException e1) {
        }
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) RelationalSchemaGenerator(org.openforis.collect.relational.model.RelationalSchemaGenerator) JooqRelationalSchemaCreator(org.openforis.collect.relational.jooq.JooqRelationalSchemaCreator) CollectSurvey(org.openforis.collect.model.CollectSurvey) RelationalSchema(org.openforis.collect.relational.model.RelationalSchema) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

RelationalSchema (org.openforis.collect.relational.model.RelationalSchema)7 RelationalSchemaGenerator (org.openforis.collect.relational.model.RelationalSchemaGenerator)5 Connection (java.sql.Connection)2 Test (org.junit.Test)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 JooqRelationalSchemaCreator (org.openforis.collect.relational.jooq.JooqRelationalSchemaCreator)2 Table (org.openforis.collect.relational.model.Table)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 RecordEvent (org.openforis.collect.event.RecordEvent)1 RecordStep (org.openforis.collect.event.RecordStep)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 DataTable (org.openforis.collect.relational.model.DataTable)1 Dataset (org.openforis.collect.relational.model.Dataset)1