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

The following examples show how to use org.pentaho.di.core.database.DatabaseMeta#getAttributes() . 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: ThinModelConverter.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static SqlDataSource convertFromLegacy( DatabaseMeta database ) {
  SqlDataSource dataSource = new SqlDataSource();

  dataSource.setDialectType( database.getDatabaseTypeDesc() );
  dataSource.setDatabaseName( database.environmentSubstitute( database.getDatabaseName() ) );
  dataSource.setHostname( database.environmentSubstitute( database.getHostname() ) );
  dataSource.setPort( database.environmentSubstitute( database.getDatabasePortNumberString() ) );
  dataSource.setUsername( database.environmentSubstitute( database.getUsername() ) );
  dataSource.setPassword( database.environmentSubstitute( database.getPassword() ) );
  dataSource.setServername( database.environmentSubstitute( database.getServername() ) );

  if ( database.getAccessType() == DatabaseMeta.TYPE_ACCESS_JNDI ) {
    dataSource.setType( DataSourceType.values()[database.getAccessType()] );
  } else if ( database.getAccessType() == DatabaseMeta.TYPE_ACCESS_NATIVE ) {
    dataSource.setType( DataSourceType.NATIVE );
  }

  // And now load the attributes...
  if ( database.getAttributes() != null ) {
    for ( Object key : database.getAttributes().keySet() ) {
      dataSource.getAttributes().put( (String) key,
          database.environmentSubstitute( (String) database.getAttributes().get( key ) ) );
    }
  }

  return dataSource;
}
 
Example 2
Source File: RepositoryImporter.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Adapted from KettleDatabaseRepositoryDatabaseDelegate.saveDatabaseMeta
 */
protected boolean equals( DatabaseMeta databaseMeta, DatabaseMeta databaseMeta2 ) {
  if ( !equals( databaseMeta.getName(), databaseMeta2.getName() ) ) {
    return false;
  } else if ( !equals( databaseMeta.getPluginId(), databaseMeta2.getPluginId() ) ) {
    return false;
  } else if ( !equals( databaseMeta.getAccessType(), databaseMeta2.getAccessType() ) ) {
    return false;
  } else if ( !equals( databaseMeta.getHostname(), databaseMeta2.getHostname() ) ) {
    return false;
  } else if ( !equals( databaseMeta.getDatabaseName(), databaseMeta2.getDatabaseName() ) ) {
    return false;
  } else if ( !equals( databaseMeta.getDatabasePortNumberString(), databaseMeta2.getDatabasePortNumberString() ) ) {
    return false;
  } else if ( !equals( databaseMeta.getUsername(), databaseMeta2.getUsername() ) ) {
    return false;
  } else if ( !equals( databaseMeta.getPassword(), databaseMeta2.getPassword() ) ) {
    return false;
  } else if ( !equals( databaseMeta.getServername(), databaseMeta2.getServername() ) ) {
    return false;
  } else if ( !equals( databaseMeta.getDataTablespace(), databaseMeta2.getDataTablespace() ) ) {
    return false;
  } else if ( !equals( databaseMeta.getIndexTablespace(), databaseMeta2.getIndexTablespace() ) ) {
    return false;
  }
  Map<Object, Object> databaseMeta2Attributes = new HashMap<Object, Object>( databaseMeta2.getAttributes() );
  for ( Entry<Object, Object> databaseMetaEntry : new HashMap<Object, Object>( databaseMeta.getAttributes() )
      .entrySet() ) {
    Object value = databaseMeta2Attributes.remove( databaseMetaEntry.getKey() );
    if ( !equals( value, databaseMetaEntry.getValue() ) ) {
      return false;
    }
  }
  if ( databaseMeta2Attributes.size() > 0 ) {
    return false;
  }
  return true;
}
 
Example 3
Source File: DatabaseMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static IMetaStoreElement populateDatabaseElement( IMetaStore metaStore, DatabaseMeta databaseMeta ) throws MetaStoreException {

    if ( !metaStore.namespaceExists( PentahoDefaults.NAMESPACE ) ) {
      throw new MetaStoreException( "Namespace '" + PentahoDefaults.NAMESPACE + "' doesn't exist." );
    }

    // If the data type doesn't exist, error out...
    //
    IMetaStoreElementType elementType =
      metaStore.getElementTypeByName(
        PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME );
    if ( elementType == null ) {
      throw new MetaStoreException( "Unable to find the database connection type" );
    }

    elementType = populateDatabaseElementType( metaStore );

    // generate a new database element and populate it with metadata
    //
    IMetaStoreElement element = metaStore.newElement( elementType, databaseMeta.getName(), null );

    element.addChild( metaStore.newAttribute( MetaStoreConst.DB_ATTR_ID_PLUGIN_ID, databaseMeta.getPluginId() ) );

    element.setName( databaseMeta.getName() );

    element.addChild( metaStore
      .newAttribute( MetaStoreConst.DB_ATTR_ID_DESCRIPTION, databaseMeta.getDescription() ) );
    element.addChild( metaStore.newAttribute( MetaStoreConst.DB_ATTR_ID_ACCESS_TYPE, databaseMeta
      .getAccessTypeDesc() ) );
    element.addChild( metaStore.newAttribute( MetaStoreConst.DB_ATTR_ID_HOSTNAME, databaseMeta.getHostname() ) );
    element.addChild( metaStore.newAttribute( MetaStoreConst.DB_ATTR_ID_PORT, databaseMeta
      .getDatabasePortNumberString() ) );
    element.addChild( metaStore.newAttribute( MetaStoreConst.DB_ATTR_ID_DATABASE_NAME, databaseMeta
      .getDatabaseName() ) );
    element.addChild( metaStore.newAttribute( MetaStoreConst.DB_ATTR_ID_USERNAME, databaseMeta.getUsername() ) );
    element.addChild( metaStore.newAttribute( MetaStoreConst.DB_ATTR_ID_PASSWORD, metaStore
      .getTwoWayPasswordEncoder().encode( databaseMeta.getPassword() ) ) );
    element
      .addChild( metaStore.newAttribute( MetaStoreConst.DB_ATTR_ID_SERVERNAME, databaseMeta.getServername() ) );
    element.addChild( metaStore.newAttribute( MetaStoreConst.DB_ATTR_ID_DATA_TABLESPACE, databaseMeta
      .getDataTablespace() ) );
    element.addChild( metaStore.newAttribute( MetaStoreConst.DB_ATTR_ID_INDEX_TABLESPACE, databaseMeta
      .getIndexTablespace() ) );

    IMetaStoreAttribute attributesChild = metaStore.newAttribute( MetaStoreConst.DB_ATTR_ID_ATTRIBUTES, null );
    element.addChild( attributesChild );

    // Now add a list of all the attributes set on the database connection...
    //
    Properties attributes = databaseMeta.getAttributes();
    Enumeration<Object> keys = databaseMeta.getAttributes().keys();
    while ( keys.hasMoreElements() ) {
      String code = (String) keys.nextElement();
      String attribute = (String) attributes.get( code );
      // Add it to the attributes child
      //
      attributesChild.addChild( metaStore.newAttribute( code, attribute ) );
    }

    // Extra information for 3rd-party tools:
    //
    // The driver class
    //
    element
      .addChild( metaStore.newAttribute( MetaStoreConst.DB_ATTR_DRIVER_CLASS, databaseMeta.getDriverClass() ) );

    // The URL
    //
    try {
      element.addChild( metaStore.newAttribute( MetaStoreConst.DB_ATTR_JDBC_URL, databaseMeta.getURL() ) );
    } catch ( Exception e ) {
      throw new MetaStoreException( "Unable to assemble URL from database '" + databaseMeta.getName() + "'", e );
    }

    return element;
  }
 
Example 4
Source File: DatabaseDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public DataNode elementToDataNode( final RepositoryElementInterface element ) throws KettleException {
  DatabaseMeta databaseMeta = (DatabaseMeta) element;
  DataNode rootNode = new DataNode( NODE_ROOT );

  // Then the basic db information
  //
  rootNode.setProperty( PROP_TYPE, databaseMeta.getPluginId() );
  rootNode.setProperty( PROP_CONTYPE, DatabaseMeta.getAccessTypeDesc( databaseMeta.getAccessType() ) );
  rootNode.setProperty( PROP_HOST_NAME, databaseMeta.getHostname() );
  rootNode.setProperty( PROP_DATABASE_NAME, databaseMeta.getDatabaseName() );
  rootNode.setProperty( PROP_PORT, Const.toInt( databaseMeta.getDatabasePortNumberString(), -1 ) );
  rootNode.setProperty( PROP_USERNAME, databaseMeta.getUsername() );
  rootNode.setProperty( PROP_PASSWORD, Encr.encryptPasswordIfNotUsingVariables( databaseMeta.getPassword() ) );
  rootNode.setProperty( PROP_SERVERNAME, databaseMeta.getServername() );
  rootNode.setProperty( PROP_DATA_TBS, databaseMeta.getDataTablespace() );
  rootNode.setProperty( PROP_INDEX_TBS, databaseMeta.getIndexTablespace() );

  rootNode.setProperty( PROP_CONNECT_SQL, setNull( databaseMeta.getConnectSQL() ) );
  rootNode.setProperty( PROP_INITIAL_POOL_SIZE, databaseMeta.getInitialPoolSize() );
  rootNode.setProperty( PROP_MAX_POOL_SIZE, databaseMeta.getMaximumPoolSize() );
  rootNode.setProperty( PROP_IS_POOLING, databaseMeta.isUsingConnectionPool() );
  rootNode.setProperty( PROP_IS_FORCING_TO_LOWER, databaseMeta.isForcingIdentifiersToLowerCase() );
  rootNode.setProperty( PROP_IS_FORCING_TO_UPPER, databaseMeta.isForcingIdentifiersToUpperCase() );
  rootNode.setProperty( PROP_IS_QUOTE_FIELDS, databaseMeta.isQuoteAllFields() );
  rootNode.setProperty( PROP_IS_DECIMAL_SEPERATOR, databaseMeta.isUsingDoubleDecimalAsSchemaTableSeparator() );
  rootNode.setProperty( PROP_SUPPORT_BOOLEAN_DATA_TYPE, databaseMeta.supportsBooleanDataType() );
  rootNode.setProperty( PROP_SUPPORT_TIMESTAMP_DATA_TYPE, databaseMeta.supportsTimestampDataType() );

  if ( databaseMeta.getAttributes() != null && !databaseMeta.getAttributes().isEmpty() ) {
    addNodeToElement( NODE_ATTRIBUTES, rootNode, databaseMeta.getAttributes().entrySet() );
  }

  if ( databaseMeta.getConnectionPoolingProperties() != null && !databaseMeta.getConnectionPoolingProperties().isEmpty() ) {
    addNodeToElement( NODE_POOLING_PROPS, rootNode, databaseMeta.getConnectionPoolingProperties().entrySet() );
  }

  if ( databaseMeta.getExtraOptions() != null && !databaseMeta.getExtraOptions().isEmpty() ) {
    addNodeToElement( NODE_EXTRA_OPTIONS, rootNode, new HashMap<Object, Object>( databaseMeta.getExtraOptions() ).entrySet() );
  }

  return rootNode;
}