Search in sources :

Example 1 with ICdmDataSource

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

the class DatabaseMappingTest method testGetDatabase.

// ******************* TESTS *****************************/
@Test
@Ignore
public void testGetDatabase() {
    ICdmDataSource datasource = mapping.getDatabase();
    Assert.assertNotNull("Datasource should not be null", datasource);
    String sql = "INSERT INTO " + DatabaseMapping.TABLE_IMPORT_MAPPING + "( task_id, source_namespace, source_id, destination_namespace, destination_id)  ";
    sql += "VALUES ( 'mappingID', 'ns1', 'source1', 'destNs', 'dest1')";
    try {
        datasource.executeUpdate(sql);
    } catch (SQLException e) {
        // maybe it just only exists
        logger.warn("Error occurred");
    }
}
Also used : ICdmDataSource(eu.etaxonomy.cdm.database.ICdmDataSource) SQLException(java.sql.SQLException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with ICdmDataSource

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

the class DatabaseServiceHibernateImpl method connectToDatabase.

@Override
public boolean connectToDatabase(DatabaseTypeEnum databaseTypeEnum, String server, String database, String username, String password, int port, String filePath, H2Mode mode) throws TermNotFoundException {
    ICdmDataSource dataSource = CdmDataSource.NewInstance(databaseTypeEnum, server, database, port, username, password);
    CdmPersistentDataSource tmpDataSource = saveDataSource(TMP_DATASOURCE, dataSource);
    boolean result = connectToDatasource(tmpDataSource);
    CdmPersistentSourceUtils.delete(tmpDataSource);
    return result;
}
Also used : ICdmDataSource(eu.etaxonomy.cdm.database.ICdmDataSource) CdmPersistentDataSource(eu.etaxonomy.cdm.database.CdmPersistentDataSource)

Example 3 with ICdmDataSource

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

the class TestScriptRemote method testNewConfigControler.

private void testNewConfigControler() {
    DbSchemaValidation schema = DbSchemaValidation.VALIDATE;
    String server;
    String database;
    String username;
    ICdmDataSource dataSource;
    // List<CdmPersistentDataSource> lsDataSources = CdmPersistentDataSource.getAllDataSources();
    // System.out.println(lsDataSources);
    // dataSource = lsDataSources.get(1);
    // DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
    // server = "localhost";
    // database = "cdm_bupleurum";
    // //		database = "cdm_production_edaphobase";
    // username = "edit";
    // dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
    // server = "160.45.63.171";
    // database = "cdm_production_flora_malesiana_prospective";
    // username = "edit";
    // dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
    server = "test.e-taxonomy.eu";
    database = "cdm_rem_conf_am";
    username = "edit";
    dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
    // String server = "localhost";
    // String database = "testCDM";
    // String username = "postgres";
    // dataSource = CdmDataSource.NewInstance(DatabaseTypeEnum.PostgreSQL, server, database, DatabaseTypeEnum.PostgreSQL.getDefaultPort(), username, AccountStore.readOrStorePassword(server, database, username, null));
    // //SQLServer
    // server = "BGBM-PESISQL";
    // database = "cdm36";
    // int port = 1433;
    // username = "cdmupdater";
    // dataSource = CdmDataSource.NewSqlServer2012Instance(server, database, port, username, AccountStore.readOrStorePassword(server, database, username, null));
    // 
    // //H2
    // String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2";
    // //		String path = "C:\\Users\\pesiimport\\.cdmLibrary\\writableResources\\h2\\LocalH2";
    // //      String path = "C:\\Users\\a.mueller\\eclipse\\svn\\cdmlib-trunk\\cdmlib-remote-webapp\\src\\test\\resources\\h2";
    // username = "sa";
    // dataSource = CdmDataSource.NewH2EmbeddedInstance("cdm", username, "", path);
    // dataSource = CdmDataSource.NewH2EmbeddedInstance(database, username, "sa");
    // server = "160.45.63.201";
    // database = "cdm_integration_cichorieae";
    // username = "edit";
    // dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
    CdmApplicationController appCtr = CdmRemoteApplicationController.NewRemoteInstance(dataSource, schema);
    try {
        doTemporary(appCtr);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // List<UuidAndTitleCache<TaxonBase>> list = appCtr.getTaxonService().getUuidAndTitleCache(null, 10, "Abies alba%");
    // System.out.println(list);
    // appCtr.getOccurrenceService().findRootUnitDTOs(UUID.fromString("2debf5ee-cb57-40bc-af89-173d1d17cefe"));
    // aggregateDDS(appCtr);
    // aggregateDistribution(appCtr);
    appCtr.close();
    System.exit(0);
}
Also used : ICdmDataSource(eu.etaxonomy.cdm.database.ICdmDataSource) DbSchemaValidation(eu.etaxonomy.cdm.database.DbSchemaValidation) CdmApplicationController(eu.etaxonomy.cdm.api.application.CdmApplicationController) IOException(java.io.IOException)

Example 4 with ICdmDataSource

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

the class Cdm2CdmVocabularyImportTest method setUpClass.

@BeforeClass
@Ignore
public static void setUpClass() throws Exception {
    // this.startH2Server();
    boolean omitTermLoading = true;
    // TODO remove user directory
    ICdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("testVoc", "sa", "", "C:\\Users\\a.mueller\\tmp\\testVoc");
    // int a = dataSource.executeUpdate("CREATE TABLE HIBERNATE_SEQUENCES ("
    // + " sequence_name VARCHAR(255), next_val BIGINT )");
    // try {
    // ResultSet rs = dataSource.executeQuery("SELECT * FROM INFORMATION_SCHEMA.TABLES");
    // while(rs.next()){
    // for (int i = 1; i<=12; i++){
    // System.out.print(";"+rs.getObject(i));
    // }
    // System.out.println();
    // }
    // dataSource.executeQuery("select tbl.next_val from hibernate_sequences tbl where tbl.sequence_name='a'");
    otherRepository = CdmApplicationController.NewInstance(dataSource, DbSchemaValidation.CREATE, omitTermLoading);
    // } catch (Exception e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    System.out.println("started");
    TermVocabulary<DefinedTerm> voc = createTestVocabulary(otherRepository);
    createTestGraph(otherRepository, voc);
}
Also used : ICdmDataSource(eu.etaxonomy.cdm.database.ICdmDataSource) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm) BeforeClass(org.junit.BeforeClass) Ignore(org.junit.Ignore)

Example 5 with ICdmDataSource

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

the class SDDImportExportTest method customDataSource.

/**
 * @param loadedDataSource
 * @return
 */
private ICdmDataSource customDataSource() {
    CdmPersistentDataSource loadedDataSource = null;
    // ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_test_niels2", 3306, "edit", password, code);
    String dataSourceName = "cdm_test2";
    String password = CdmUtils.readInputLine("Password: ");
    ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("127.0.0.1", "cdm_test2", 3306, "ljm", password);
    // ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("160.45.63.201", "cdm_test", 3306, "edit", password);
    boolean connectionAvailable;
    try {
        connectionAvailable = dataSource.testConnection();
        logger.debug("Is connection avaiable " + connectionAvailable);
        Assert.assertTrue("Testdatabase is not available", connectionAvailable);
    } catch (ClassNotFoundException e1) {
        e1.printStackTrace();
    } catch (SQLException e1) {
        e1.printStackTrace();
    }
    CdmPersistentDataSource.save(dataSourceName, dataSource);
    try {
        loadedDataSource = CdmPersistentDataSource.NewInstance(dataSourceName);
    // CdmApplicationController.NewInstance(loadedDataSource, DbSchemaValidation.CREATE);
    // NomenclaturalCode loadedCode = loadedDataSource.getNomenclaturalCode();
    // 
    // Assert.assertEquals(NomenclaturalCode.ICNAFP, loadedCode);
    } catch (DataSourceNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // return loadedDataSource;
    return dataSource;
}
Also used : ICdmDataSource(eu.etaxonomy.cdm.database.ICdmDataSource) SQLException(java.sql.SQLException) CdmPersistentDataSource(eu.etaxonomy.cdm.database.CdmPersistentDataSource) DataSourceNotFoundException(eu.etaxonomy.cdm.database.DataSourceNotFoundException)

Aggregations

ICdmDataSource (eu.etaxonomy.cdm.database.ICdmDataSource)30 CdmApplicationController (eu.etaxonomy.cdm.api.application.CdmApplicationController)11 DbSchemaValidation (eu.etaxonomy.cdm.database.DbSchemaValidation)7 SQLException (java.sql.SQLException)7 Ignore (org.junit.Ignore)6 List (java.util.List)4 Test (org.junit.Test)4 TransactionStatus (org.springframework.transaction.TransactionStatus)4 ICdmRepository (eu.etaxonomy.cdm.api.application.ICdmRepository)3 CdmPersistentDataSource (eu.etaxonomy.cdm.database.CdmPersistentDataSource)3 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)3 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)3 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 URI (eu.etaxonomy.cdm.common.URI)2 IProgressMonitor (eu.etaxonomy.cdm.common.monitor.IProgressMonitor)2 DatabaseTypeEnum (eu.etaxonomy.cdm.database.DatabaseTypeEnum)2 CdmUpdater (eu.etaxonomy.cdm.database.update.CdmUpdater)2 SchemaUpdateResult (eu.etaxonomy.cdm.database.update.SchemaUpdateResult)2