Search in sources :

Example 1 with SchemaUpdateResult

use of eu.etaxonomy.cdm.database.update.SchemaUpdateResult in project cdmlib by cybertaxonomy.

the class TestModelUpdate method updateH2.

private void updateH2(String pathToProject) {
    String pathInProject = "src\\test\\resources\\h2";
    String path = pathToProject + pathInProject;
    ICdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", "sa", "", path);
    try {
        CdmUpdater updater = new CdmUpdater();
        SchemaUpdateResult result = updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
        System.out.println(result.createReport());
    } catch (Exception e) {
        e.printStackTrace();
    }
    // CdmPersistentDataSource.save(dataSource.getName(), dataSource);
    CdmApplicationController appCtr;
    appCtr = CdmApplicationController.NewInstance(dataSource, DbSchemaValidation.VALIDATE);
    appCtr.close();
    System.out.println("\nEnd Datasource");
}
Also used : ICdmDataSource(eu.etaxonomy.cdm.database.ICdmDataSource) CdmApplicationController(eu.etaxonomy.cdm.api.application.CdmApplicationController) SchemaUpdateResult(eu.etaxonomy.cdm.database.update.SchemaUpdateResult) CdmUpdater(eu.etaxonomy.cdm.database.update.CdmUpdater)

Example 2 with SchemaUpdateResult

use of eu.etaxonomy.cdm.database.update.SchemaUpdateResult in project cdmlib by cybertaxonomy.

the class TestModelUpdate method updateEdaphobasePostgres.

// enable only if needed
@SuppressWarnings("unused")
private void updateEdaphobasePostgres() {
    String serverSql = "130.133.70.26";
    String database = "cdm_edaphobase";
    int port = 5433;
    String username = "edaphobase";
    String password = AccountStore.readOrStorePassword(database, serverSql, username, null);
    ICdmDataSource dataSource = CdmDataSource.NewPostgreSQLInstance(serverSql, database, port, username, password);
    try {
        CdmUpdater updater = new CdmUpdater();
        SchemaUpdateResult result = updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
        System.out.println(result.createReport());
    } catch (Exception e) {
        e.printStackTrace();
    }
    // CdmPersistentDataSource.save(dataSource.getName(), dataSource);
    CdmApplicationController appCtr;
    appCtr = CdmApplicationController.NewInstance(dataSource, DbSchemaValidation.VALIDATE);
    appCtr.close();
    System.out.println("\nEnd Datasource");
}
Also used : ICdmDataSource(eu.etaxonomy.cdm.database.ICdmDataSource) CdmApplicationController(eu.etaxonomy.cdm.api.application.CdmApplicationController) SchemaUpdateResult(eu.etaxonomy.cdm.database.update.SchemaUpdateResult) CdmUpdater(eu.etaxonomy.cdm.database.update.CdmUpdater)

Example 3 with SchemaUpdateResult

use of eu.etaxonomy.cdm.database.update.SchemaUpdateResult in project cdmlib by cybertaxonomy.

the class TestModelUpdate method testSelectedDb.

private void testSelectedDb() {
    DbSchemaValidation schema = DbSchemaValidation.VALIDATE;
    DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
    String database = (schema == DbSchemaValidation.VALIDATE ? "cdm527" : "cdm529");
    // database = "cdm_test1";
    CdmDataSource dataSource = getDatasource(dbType, database);
    try {
        // int n = dataSource.executeUpdate("UPDATE CdmMetaData SET value = '3.1.0.0.201607300000' WHERE propertyname = 0 ");
        CdmUpdater updater = new CdmUpdater();
        if (schema == DbSchemaValidation.VALIDATE) {
            SchemaUpdateResult result = updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
            String report = result.createReport().toString();
            System.out.println(report);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        CdmApplicationController appCtr = CdmApplicationController.NewInstance(dataSource, schema);
        if (schema == DbSchemaValidation.CREATE) {
            System.out.println("fillData");
            appCtr.getCommonService().createFullSampleData();
            appCtr.getNameService().list(null, null, null, null, null);
            TransactionStatus tx = appCtr.startTransaction(false);
            TemporalData td = (TemporalData) appCtr.getDescriptionElementService().find(UUID.fromString("9a1c91c0-fc58-4310-94cb-8c26115985d3"));
            td.getFeature().setSupportsCategoricalData(true);
            appCtr.getTermService().saveOrUpdate(td.getFeature());
            System.out.println(td.getPeriod());
            appCtr.commitTransaction(tx);
        }
        appCtr.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("Ready");
}
Also used : DbSchemaValidation(eu.etaxonomy.cdm.database.DbSchemaValidation) CdmApplicationController(eu.etaxonomy.cdm.api.application.CdmApplicationController) DatabaseTypeEnum(eu.etaxonomy.cdm.database.DatabaseTypeEnum) TemporalData(eu.etaxonomy.cdm.model.description.TemporalData) ICdmDataSource(eu.etaxonomy.cdm.database.ICdmDataSource) CdmDataSource(eu.etaxonomy.cdm.database.CdmDataSource) TransactionStatus(org.springframework.transaction.TransactionStatus) SchemaUpdateResult(eu.etaxonomy.cdm.database.update.SchemaUpdateResult) CdmUpdater(eu.etaxonomy.cdm.database.update.CdmUpdater)

Aggregations

CdmApplicationController (eu.etaxonomy.cdm.api.application.CdmApplicationController)3 ICdmDataSource (eu.etaxonomy.cdm.database.ICdmDataSource)3 CdmUpdater (eu.etaxonomy.cdm.database.update.CdmUpdater)3 SchemaUpdateResult (eu.etaxonomy.cdm.database.update.SchemaUpdateResult)3 CdmDataSource (eu.etaxonomy.cdm.database.CdmDataSource)1 DatabaseTypeEnum (eu.etaxonomy.cdm.database.DatabaseTypeEnum)1 DbSchemaValidation (eu.etaxonomy.cdm.database.DbSchemaValidation)1 TemporalData (eu.etaxonomy.cdm.model.description.TemporalData)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1