/** Load the Database Info */ public DatabaseMeta loadDatabaseMeta(ObjectId id_database) throws KettleException { DatabaseMeta databaseMeta = new DatabaseMeta(); try { RowMetaAndData r = getDatabase(id_database); if (r != null) { ObjectId id_database_type = new LongObjectId( r.getInteger( KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE_TYPE, 0)); // con_type String dbTypeDesc = getDatabaseTypeCode(id_database_type); if (dbTypeDesc != null) { databaseMeta.setDatabaseInterface(DatabaseMeta.getDatabaseInterface(dbTypeDesc)); databaseMeta.setAttributes(new Properties()); // new attributes } databaseMeta.setObjectId(id_database); databaseMeta.setName(r.getString(KettleDatabaseRepository.FIELD_DATABASE_NAME, "")); ObjectId id_database_contype = new LongObjectId( r.getInteger( KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE_CONTYPE, 0)); // con_access databaseMeta.setAccessType( DatabaseMeta.getAccessType(getDatabaseConTypeCode(id_database_contype))); databaseMeta.setHostname( r.getString(KettleDatabaseRepository.FIELD_DATABASE_HOST_NAME, "")); databaseMeta.setDBName( r.getString(KettleDatabaseRepository.FIELD_DATABASE_DATABASE_NAME, "")); databaseMeta.setDBPort(r.getString(KettleDatabaseRepository.FIELD_DATABASE_PORT, "")); databaseMeta.setUsername(r.getString(KettleDatabaseRepository.FIELD_DATABASE_USERNAME, "")); databaseMeta.setPassword( Encr.decryptPasswordOptionallyEncrypted( r.getString(KettleDatabaseRepository.FIELD_DATABASE_PASSWORD, ""))); databaseMeta.setServername( r.getString(KettleDatabaseRepository.FIELD_DATABASE_SERVERNAME, "")); databaseMeta.setDataTablespace( r.getString(KettleDatabaseRepository.FIELD_DATABASE_DATA_TBS, "")); databaseMeta.setIndexTablespace( r.getString(KettleDatabaseRepository.FIELD_DATABASE_INDEX_TBS, "")); // Also, load all the properties we can find... final Collection<RowMetaAndData> attrs = repository.connectionDelegate.getDatabaseAttributes(id_database); for (RowMetaAndData row : attrs) { String code = row.getString(KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_CODE, ""); String attribute = row.getString(KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_VALUE_STR, ""); databaseMeta.getAttributes().put(code, Const.NVL(attribute, "")); } } return databaseMeta; } catch (KettleDatabaseException dbe) { throw new KettleException( "Error loading database connection from repository (id_database=" + id_database + ")", dbe); } }
private Domain generateModel() { Domain domain = null; try { DatabaseMeta database = new DatabaseMeta(); database.setDatabaseType("Hypersonic"); // $NON-NLS-1$ database.setAccessType(DatabaseMeta.TYPE_ACCESS_JNDI); database.setDBName("SampleData"); // $NON-NLS-1$ database.setName("SampleData"); // $NON-NLS-1$ System.out.println(database.testConnection()); TableModelerSource source = new TableModelerSource(database, "ORDERS", null); // $NON-NLS-1$ domain = source.generateDomain(); List<OlapDimension> olapDimensions = new ArrayList<OlapDimension>(); OlapDimension dimension = new OlapDimension(); dimension.setName("test"); // $NON-NLS-1$ dimension.setTimeDimension(false); olapDimensions.add(dimension); domain .getLogicalModels() .get(1) .setProperty("olap_dimensions", olapDimensions); // $NON-NLS-1$ } catch (Exception e) { e.printStackTrace(); } return domain; }