Java Code Examples for org.pentaho.di.core.database.DatabaseMeta#setServername()

The following examples show how to use org.pentaho.di.core.database.DatabaseMeta#setServername() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RepositoryTestBase.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected DatabaseMeta createDatabaseMeta( final String dbName ) throws Exception {
  DatabaseMeta dbMeta = new DatabaseMeta();
  dbMeta.setName( dbName );
  dbMeta.setHostname( EXP_DBMETA_HOSTNAME );
  dbMeta.setDatabaseType( EXP_DBMETA_TYPE );
  dbMeta.setAccessType( EXP_DBMETA_ACCESS );
  dbMeta.setDBName( EXP_DBMETA_DBNAME );
  dbMeta.setDBPort( EXP_DBMETA_PORT );
  dbMeta.setUsername( EXP_DBMETA_USERNAME );
  dbMeta.setPassword( EXP_DBMETA_PASSWORD );
  dbMeta.setServername( EXP_DBMETA_SERVERNAME );
  dbMeta.setDataTablespace( EXP_DBMETA_DATA_TABLESPACE );
  dbMeta.setIndexTablespace( EXP_DBMETA_INDEX_TABLESPACE );
  // Properties attrs = new Properties();
  // exposed mutable state; yikes
  dbMeta.getAttributes().put( EXP_DBMETA_ATTR1_KEY, EXP_DBMETA_ATTR1_VALUE );
  dbMeta.getAttributes().put( EXP_DBMETA_ATTR2_KEY, EXP_DBMETA_ATTR2_VALUE );
  // TODO mlowery more testing on DatabaseMeta options
  return dbMeta;
}
 
Example 2
Source File: CwmSchemaFactory.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read a DatabaseMeta from a CWM model by providing the catalog reference.
 *
 * @param cwm
 * @param catalog
 * @return a new DatabaseMeta instance, read from the specified CWM model.
 */
public DatabaseMeta getDatabaseMeta( CWM cwm, CwmCatalog catalog ) {
  DatabaseMeta databaseMeta = new DatabaseMeta();

  databaseMeta.setName( catalog.getName() );

  databaseMeta.setHostname( cwm.getFirstTaggedValue( catalog, CWM.TAG_DATABASE_SERVER ) );
  databaseMeta.setDatabaseType( cwm.getFirstTaggedValue( catalog, CWM.TAG_DATABASE_TYPE ) );
  databaseMeta.setAccessType( DatabaseMeta
    .getAccessType( cwm.getFirstTaggedValue( catalog, CWM.TAG_DATABASE_ACCESS ) ) );
  databaseMeta.setDBName( cwm.getFirstTaggedValue( catalog, CWM.TAG_DATABASE_DATABASE ) );
  databaseMeta.setDBPort( cwm.getFirstTaggedValue( catalog, CWM.TAG_DATABASE_PORT ) );
  databaseMeta.setUsername( cwm.getFirstTaggedValue( catalog, CWM.TAG_DATABASE_USERNAME ) );
  databaseMeta.setPassword( cwm.getFirstTaggedValue( catalog, CWM.TAG_DATABASE_PASSWORD ) );
  databaseMeta.setServername( cwm.getFirstTaggedValue( catalog, CWM.TAG_DATABASE_SERVERNAME ) );
  databaseMeta.setDataTablespace( cwm.getFirstTaggedValue( catalog, CWM.TAG_DATABASE_DATA_TABLESPACE ) );
  databaseMeta.setIndexTablespace( cwm.getFirstTaggedValue( catalog, CWM.TAG_DATABASE_INDEX_TABLESPACE ) );

  // And now load the attributes...
  CwmTaggedValue[] taggedValue = cwm.getTaggedValues( catalog );
  for ( int i = 0; i < taggedValue.length; i++ ) {
    if ( taggedValue[ i ].getTag().startsWith( CWM.TAG_DATABASE_ATTRIBUTE_PREFIX ) ) {
      String key = taggedValue[ i ].getTag().substring( CWM.TAG_DATABASE_ATTRIBUTE_PREFIX.length() );
      String attribute = taggedValue[ i ].getValue();

      // Add the attribute
      databaseMeta.getAttributes().put( key, attribute );
    }
  }

  return databaseMeta;
}
 
Example 3
Source File: ThinModelConverter.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static DatabaseMeta convertToLegacy( String name, SqlDataSource datasource ) {
  // make sure that the Kettle environment is initialized before DatabaseMeta creation
  try {
    KettleEnvironment.init( false );
  } catch ( KettleException e ) {
    logger.error( "Error initializing the Kettle Environment", e );
    throw new RuntimeException( "Error initializing the Kettle Environment", e );
  }

  DatabaseMeta databaseMeta = new DatabaseMeta();

  databaseMeta.setName( name );

  databaseMeta.setHostname( datasource.getHostname() );
  if ( datasource.getDialectType() == null ) {
    // default to mysql if dialect is null
    databaseMeta.setDatabaseType( "GENERIC" ); //$NON-NLS-1$
  } else {
    databaseMeta.setDatabaseType( datasource.getDialectType() );
  }
  databaseMeta.setAccessType( DatabaseMeta.getAccessType( datasource.getType().toString() ) );
  databaseMeta.setDBName( datasource.getDatabaseName() );
  databaseMeta.setDBPort( datasource.getPort() );
  databaseMeta.setUsername( datasource.getUsername() );
  databaseMeta.setPassword( datasource.getPassword() );
  databaseMeta.setServername( datasource.getServername() );

  // And now load the attributes...
  for ( String key : datasource.getAttributes().keySet() ) {
    databaseMeta.getAttributes().put( key, datasource.getAttributes().get( key ) );
  }
  return databaseMeta;
}
 
Example 4
Source File: KettleDatabaseRepositoryDatabaseDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 *
 * 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 );
  }
}