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

The following examples show how to use org.pentaho.di.core.database.DatabaseMeta#getObjectId() . 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: KettleDatabaseRepository.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * This method saves the object ID of the database object (if not null) in the step attributes
 *
 * @param id_job
 * @param nr
 * @param id_jobentry
 * @param nameCode
 * @param nameCode
 * @param idCode
 * @param database
 */
public void saveDatabaseMetaJobEntryAttribute( ObjectId id_job, ObjectId id_jobentry, int nr, String nameCode,
  String idCode, DatabaseMeta database ) throws KettleException {
  ObjectId id = null;
  if ( database != null ) {
    id = database.getObjectId();
    Long id_database = id == null ? Long.valueOf( -1L ) : new LongObjectId( id ).longValue();

    // Save both the ID and the name of the database connection...
    //
    saveJobEntryAttribute( id_job, id_jobentry, nr, idCode, id_database );
    saveJobEntryAttribute( id_job, id_jobentry, nr, nameCode, id_database );

    insertJobEntryDatabase( id_job, id_jobentry, id );
  }
}
 
Example 2
Source File: MemoryRepository.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void saveDatabaseMetaJobEntryAttribute( ObjectId id_job, ObjectId id_jobentry, int nr, String nameCode,
    String idCode, DatabaseMeta database ) throws KettleException {
  ObjectId id = null;
  if ( database != null ) {
    id = database.getObjectId();
    Long id_database = id == null ? Long.valueOf( -1L ) : new LongObjectId( id ).longValue();

    // Save both the ID and the name of the database connection...
    //
    saveJobEntryAttribute( id_job, id_jobentry, nr, idCode, id_database );
    saveJobEntryAttribute( id_job, id_jobentry, nr, nameCode, id_database );

    insertJobEntryDatabase( id_job, id_jobentry, id );
  }
}
 
Example 3
Source File: KettleDatabaseRepositoryDatabaseDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Saves the database information into a given repository.
 *
 * @param databaseMeta
 *          The database metadata object to store
 *
 * @throws KettleException
 *           if an error occurs.
 */
public void saveDatabaseMeta( DatabaseMeta databaseMeta ) throws KettleException {
  try {
    // If we don't have an ID, we don't know which entry in the database we need to update.
    // See if a database with the same name is already available...
    if ( databaseMeta.getObjectId() == null ) {
      databaseMeta.setObjectId( getDatabaseID( databaseMeta.getName() ) );
    }

    // Still not found? --> Insert
    if ( databaseMeta.getObjectId() == null ) {
      // Insert new Note in repository
      //
      databaseMeta.setObjectId( insertDatabase(
        databaseMeta.getName(), databaseMeta.getPluginId(), DatabaseMeta.getAccessTypeDesc( databaseMeta
          .getAccessType() ), databaseMeta.getHostname(), databaseMeta.getDatabaseName(), databaseMeta
          .getDatabasePortNumberString(), databaseMeta.getUsername(), databaseMeta.getPassword(),
        databaseMeta.getServername(), databaseMeta.getDataTablespace(), databaseMeta.getIndexTablespace() ) );
    } else {
      // --> found entry with the same name...

      // Update the note...
      updateDatabase(
        databaseMeta.getObjectId(), databaseMeta.getName(), databaseMeta.getPluginId(), DatabaseMeta
          .getAccessTypeDesc( databaseMeta.getAccessType() ), databaseMeta.getHostname(), databaseMeta
          .getDatabaseName(), databaseMeta.getDatabasePortNumberString(), databaseMeta.getUsername(),
        databaseMeta.getPassword(), databaseMeta.getServername(), databaseMeta.getDataTablespace(),
        databaseMeta.getIndexTablespace() );
    }

    // For the extra attributes, just delete them and re-add them.
    delDatabaseAttributes( databaseMeta.getObjectId() );

    // OK, now get a list of all the attributes set on the database connection...
    insertDatabaseAttributes( databaseMeta.getObjectId(), databaseMeta.getAttributes() );
  } catch ( KettleDatabaseException dbe ) {
    throw new KettleException(
      "Error saving database connection or one of its attributes to the repository.", dbe );
  }
}
 
Example 4
Source File: KettleDatabaseRepository.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public ObjectId getDatabaseID( String name ) throws KettleException {
  ObjectId exactMatch = databaseDelegate.getDatabaseID( name );
  if ( exactMatch == null ) {
    // look for a database
    DatabaseMeta database = DatabaseMeta.findDatabase( getDatabases(), name );
    return ( database == null ) ? null : database.getObjectId();
  } else {
    return exactMatch;
  }
}
 
Example 5
Source File: KettleDatabaseRepository.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * This method saves the object ID of the database object (if not null) in the step attributes
 *
 * @param id_transformation
 * @param id_step
 * @param string
 * @param database
 */
public void saveDatabaseMetaStepAttribute( ObjectId id_transformation, ObjectId id_step, String code,
  DatabaseMeta database ) throws KettleException {
  ObjectId id = null;
  if ( database != null ) {
    id = database.getObjectId();
    Long id_database = id == null ? Long.valueOf( -1L ) : new LongObjectId( id ).longValue();
    saveStepAttribute( id_transformation, id_step, code, id_database );
  }
}
 
Example 6
Source File: MemoryRepository.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void saveDatabaseMetaStepAttribute( ObjectId id_transformation, ObjectId id_step, String code,
    DatabaseMeta database ) throws KettleException {
  ObjectId id = null;
  if ( database != null ) {
    id = database.getObjectId();
    Long id_database = id == null ? Long.valueOf( -1L ) : new LongObjectId( id ).longValue();
    saveStepAttribute( id_transformation, id_step, code, id_database );
  }
}
 
Example 7
Source File: RepositoryProxy.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void saveDatabaseMetaJobEntryAttribute( ObjectId idJob, ObjectId idJobentry, int nr, String nameCode,
    String code, DatabaseMeta database ) throws KettleException {
  if ( database != null && database.getObjectId() != null ) {
    DataNodeRef ref = new DataNodeRef( database.getObjectId().getId() );
    node.setProperty( code + PROP_CODE_NR_SEPARATOR + nr, ref );
  }
}
 
Example 8
Source File: RepositoryProxy.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void saveDatabaseMetaStepAttribute( ObjectId idTransformation, ObjectId idStep, String code,
    DatabaseMeta database ) throws KettleException {
  if ( database != null && database.getObjectId() != null ) {
    DataNodeRef ref = new DataNodeRef( database.getObjectId().getId() );
    node.setProperty( code, ref );
  }
}
 
Example 9
Source File: JobDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void saveSharedObjects( final RepositoryElementInterface element, final String versionComment )
  throws KettleException {
  JobMeta jobMeta = (JobMeta) element;
  // Now store the databases in the job.
  // Only store if the database has actually changed or doesn't have an object ID (imported)
  //
  for ( DatabaseMeta databaseMeta : jobMeta.getDatabases() ) {
    if ( databaseMeta.hasChanged() || databaseMeta.getObjectId() == null ) {
      if ( databaseMeta.getObjectId() == null
          || unifiedRepositoryConnectionAclService.hasAccess( databaseMeta.getObjectId(),
              RepositoryFilePermission.WRITE ) ) {
        repo.save( databaseMeta, versionComment, null );
      } else {
        log.logError( BaseMessages.getString( PKG, "PurRepository.ERROR_0004_DATABASE_UPDATE_ACCESS_DENIED",
            databaseMeta.getName() ) );
      }
    }
  }

  // Store the slave server
  //
  for ( SlaveServer slaveServer : jobMeta.getSlaveServers() ) {
    if ( slaveServer.hasChanged() || slaveServer.getObjectId() == null ) {
      repo.save( slaveServer, versionComment, null );
    }
  }
}
 
Example 10
Source File: StreamToJobNodeConverter.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void saveSharedObjects( final Repository repo, final RepositoryElementInterface element )
  throws KettleException {
  JobMeta jobMeta = (JobMeta) element;
  // First store the databases and other depending objects in the transformation.
  List<String> databaseNames = Arrays.asList( repo.getDatabaseNames( true ) );

  int dbIndex = 0;
  int indexToReplace = 0;
  boolean updateMeta = Boolean.FALSE;

  for ( DatabaseMeta databaseMeta : jobMeta.getDatabases() ) {
    if ( !databaseNames.contains( databaseMeta.getName() ) ) {
      if ( databaseMeta.getObjectId() == null || !StringUtils.isEmpty( databaseMeta.getHostname() ) ) {
        repo.save( databaseMeta, null, null );
      }
    } else if ( databaseMeta.getObjectId() == null ) {
      indexToReplace = dbIndex;
      updateMeta = Boolean.TRUE;
    }

    dbIndex++;
  }

  // if db already exists in repo, get that object id and put it
  // in the transMeta db collection
  if ( updateMeta ) {
    DatabaseMeta dbMetaToReplace = jobMeta.getDatabase( indexToReplace );
    dbMetaToReplace.setObjectId( repo.getDatabaseID( dbMetaToReplace.getName() ) );
    jobMeta.removeDatabase( indexToReplace );
    jobMeta.addDatabase( dbMetaToReplace );
  }
  // Store the slave servers...
  //
  for ( SlaveServer slaveServer : jobMeta.getSlaveServers() ) {
    if ( slaveServer.getObjectId() == null ) {
      repo.save( slaveServer, null, null );
    }
  }

}
 
Example 11
Source File: TransDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void saveSharedObjects( final RepositoryElementInterface element, final String versionComment )
  throws KettleException {
  TransMeta transMeta = (TransMeta) element;
  // First store the databases and other depending objects in the transformation.
  //

  // Only store if the database has actually changed or doesn't have an object ID (imported)
  //
  for ( DatabaseMeta databaseMeta : transMeta.getDatabases() ) {
    if ( databaseMeta.hasChanged() || databaseMeta.getObjectId() == null ) {
      if ( databaseMeta.getObjectId() == null
          || unifiedRepositoryConnectionAclService.hasAccess( databaseMeta.getObjectId(),
              RepositoryFilePermission.WRITE ) ) {
        repo.save( databaseMeta, versionComment, null );
      } else {
        log.logError( BaseMessages.getString( PKG, "PurRepository.ERROR_0004_DATABASE_UPDATE_ACCESS_DENIED",
            databaseMeta.getName() ) );
      }
    }
  }

  // Store the slave servers...
  //
  for ( SlaveServer slaveServer : transMeta.getSlaveServers() ) {
    if ( slaveServer.hasChanged() || slaveServer.getObjectId() == null ) {
      repo.save( slaveServer, versionComment, null );
    }
  }

  // Store the cluster schemas
  //
  for ( ClusterSchema clusterSchema : transMeta.getClusterSchemas() ) {
    if ( clusterSchema.hasChanged() || clusterSchema.getObjectId() == null ) {
      repo.save( clusterSchema, versionComment, null );
    }
  }

  // Save the partition schemas
  //
  for ( PartitionSchema partitionSchema : transMeta.getPartitionSchemas() ) {
    if ( partitionSchema.hasChanged() || partitionSchema.getObjectId() == null ) {
      repo.save( partitionSchema, versionComment, null );
    }
  }

}
 
Example 12
Source File: StreamToTransNodeConverter.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void saveSharedObjects( final Repository repo, final RepositoryElementInterface element )
  throws KettleException {
  TransMeta transMeta = (TransMeta) element;
  // First store the databases and other depending objects in the transformation.
  List<String> databaseNames = Arrays.asList( repo.getDatabaseNames( true ) );

  int dbIndex = 0;
  boolean updateMeta = Boolean.FALSE;

  List<Integer> transMetaDatabasesToUpdate = new ArrayList<Integer>();

  synchronized ( repo ) {
    for ( DatabaseMeta databaseMeta : transMeta.getDatabases() ) {
      if ( !databaseNames.contains( databaseMeta.getName() ) ) {
        if ( databaseMeta.getObjectId() == null || !StringUtils.isEmpty( databaseMeta.getHostname() ) ) {
          repo.save( databaseMeta, null, null );
        }
      } else if ( databaseMeta.getObjectId() == null ) {
        // add this to the list to update object Ids later
        transMetaDatabasesToUpdate.add( dbIndex );
        updateMeta = Boolean.TRUE;
      }

      dbIndex++;
    }

    if ( updateMeta ) {
      // make sure to update object ids in the transmeta db collection
      for ( Integer databaseMetaIndex : transMetaDatabasesToUpdate ) {
        transMeta.getDatabase( databaseMetaIndex ).setObjectId(
          repo.getDatabaseID( transMeta.getDatabase( databaseMetaIndex ).getName() ) );
      }
    }

    // Store the slave servers...
    //
    for ( SlaveServer slaveServer : transMeta.getSlaveServers() ) {
      if ( slaveServer.hasChanged() || slaveServer.getObjectId() == null ) {
        repo.save( slaveServer, null, null );
      }
    }

    // Store the cluster schemas
    //
    for ( ClusterSchema clusterSchema : transMeta.getClusterSchemas() ) {
      if ( clusterSchema.hasChanged() || clusterSchema.getObjectId() == null ) {
        repo.save( clusterSchema, null, null );
      }
    }

    // Save the partition schemas
    //
    for ( PartitionSchema partitionSchema : transMeta.getPartitionSchemas() ) {
      if ( partitionSchema.hasChanged() || partitionSchema.getObjectId() == null ) {
        repo.save( partitionSchema, null, null );
      }
    }
  }
}