Java Code Examples for org.pentaho.di.repository.Repository#save()

The following examples show how to use org.pentaho.di.repository.Repository#save() . 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: SpoonDBDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void saveConnection( DatabaseMeta db, String versionComment ) {
  // Also add to repository?
  Repository rep = spoon.getRepository();

  if ( rep != null ) {
    if ( !rep.getSecurityProvider().isReadOnly() ) {
      try {

        if ( Utils.isEmpty( versionComment ) ) {
          rep.insertLogEntry( "Saving database '" + db.getName() + "'" );
        } else {
          rep.insertLogEntry( "Save database : " + versionComment );
        }
        rep.save( db, versionComment, null );
        spoon.getLog().logDetailed(
          BaseMessages.getString( PKG, "Spoon.Log.SavedDatabaseConnection", db.getDatabaseName() ) );

        db.setChanged( false );
      } catch ( KettleException ke ) {
        new ErrorDialog( spoon.getShell(),
          BaseMessages.getString( PKG, "Spoon.Dialog.ErrorSavingConnection.Title" ),
          BaseMessages.getString( PKG, "Spoon.Dialog.ErrorSavingConnection.Message", db.getDatabaseName() ), ke );
      }
    } else {
      // This repository user is read-only!
      //
      new ErrorDialog(
        spoon.getShell(), BaseMessages.getString( PKG, "Spoon.Dialog.UnableSave.Title" ), BaseMessages
          .getString( PKG, "Spoon.Dialog.ErrorSavingConnection.Message", db.getDatabaseName() ),
        new KettleException( BaseMessages.getString( PKG, "Spoon.Dialog.Exception.ReadOnlyRepositoryUser" ) ) );
    }
  }

}
 
Example 2
Source File: SpoonSharedObjectDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
protected <T extends SharedObjectInterface & RepositoryElementInterface & ChangedFlagInterface>
    void saveSharedObjectToRepository( T sharedObject, String versionComment ) throws KettleException {
  Repository rep = spoon.getRepository();
  if ( rep != null  ) {
    if ( !rep.getSecurityProvider().isReadOnly() ) {
      rep.save( sharedObject, versionComment, null );
      sharedObject.clearChanged();
    } else {
      throw new KettleException( BaseMessages.getString(
          PKG, "Spoon.Dialog.Exception.ReadOnlyRepositoryUser" ) );
    }
  }
}
 
Example 3
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 4
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 );
      }
    }
  }
}