Java Code Examples for org.pentaho.di.core.database.DatabaseMeta#shareVariablesWith()
The following examples show how to use
org.pentaho.di.core.database.DatabaseMeta#shareVariablesWith() .
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: KettleFileRepository.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * Read all the databases from the repository, insert into the has databases object, overwriting optionally * * @param TransMeta * The transformation to load into. * @param overWriteShared * if an object with the same name exists, overwrite * @throws KettleException */ public void readDatabases( HasDatabasesInterface transMeta, boolean overWriteShared ) throws KettleException { try { ObjectId[] dbids = getDatabaseIDs( false ); for ( int i = 0; i < dbids.length; i++ ) { DatabaseMeta databaseMeta = loadDatabaseMeta( dbids[i], null ); // reads last version if ( transMeta instanceof VariableSpace ) { databaseMeta.shareVariablesWith( (VariableSpace) transMeta ); } DatabaseMeta check = transMeta.findDatabase( databaseMeta.getName() ); // Check if there already is one in the // transformation if ( check == null || overWriteShared ) { // We only add, never overwrite database connections. if ( databaseMeta.getName() != null ) { transMeta.addOrReplaceDatabase( databaseMeta ); if ( !overWriteShared ) { databaseMeta.setChanged( false ); } } } } } catch ( KettleException e ) { throw e; } }
Example 2
Source File: AbstractMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
protected boolean loadSharedObject( SharedObjectInterface object ) { if ( object instanceof DatabaseMeta ) { DatabaseMeta databaseMeta = (DatabaseMeta) object; databaseMeta.shareVariablesWith( this ); addOrReplaceDatabase( databaseMeta ); } else if ( object instanceof SlaveServer ) { SlaveServer slaveServer = (SlaveServer) object; slaveServer.shareVariablesWith( this ); addOrReplaceSlaveServer( slaveServer ); } else { return false; } return true; }
Example 3
Source File: KettleDatabaseRepositoryJobDelegate.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * Read the database connections in the repository and add them to this job if they are not yet present. * * @param jobMeta * the job to put the database connections in * @param overWriteShared * set to true if you want to overwrite shared connections while loading. * @throws KettleException */ public void readDatabases( JobMeta jobMeta, boolean overWriteShared ) throws KettleException { try { ObjectId[] dbids = repository.getDatabaseIDs( false ); for ( int i = 0; i < dbids.length; i++ ) { DatabaseMeta databaseMeta = repository.loadDatabaseMeta( dbids[i], null ); // reads last version databaseMeta.shareVariablesWith( jobMeta ); // See if there already is one in the transformation // DatabaseMeta check = jobMeta.findDatabase( databaseMeta.getName() ); // We only add, never overwrite database connections. // if ( check == null || overWriteShared ) { if ( databaseMeta.getName() != null ) { jobMeta.addOrReplaceDatabase( databaseMeta ); if ( !overWriteShared ) { databaseMeta.setChanged( false ); } } } } jobMeta.setChanged( false ); } catch ( KettleDatabaseException dbe ) { throw new KettleException( BaseMessages.getString( PKG, "JobMeta.Log.UnableToReadDatabaseIDSFromRepository" ), dbe ); } catch ( KettleException ke ) { throw new KettleException( BaseMessages.getString( PKG, "JobMeta.Log.UnableToReadDatabasesFromRepository" ), ke ); } }
Example 4
Source File: KettleDatabaseRepositoryTransDelegate.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * Read all the databases from the repository, insert into the TransMeta object, overwriting optionally * * @param transMeta * The transformation to load into. * @param overWriteShared * if an object with the same name exists, overwrite * @throws KettleException */ public void readDatabases( TransMeta transMeta, boolean overWriteShared ) throws KettleException { try { ObjectId[] dbids = repository.getDatabaseIDs( false ); for ( int i = 0; i < dbids.length; i++ ) { DatabaseMeta databaseMeta = repository.loadDatabaseMeta( dbids[i], null ); // reads last version databaseMeta.shareVariablesWith( transMeta ); DatabaseMeta check = transMeta.findDatabase( databaseMeta.getName() ); // Check if there already is one in the // transformation if ( check == null || overWriteShared ) { // We only add, never overwrite database connections. if ( databaseMeta.getName() != null ) { transMeta.addOrReplaceDatabase( databaseMeta ); if ( !overWriteShared ) { databaseMeta.setChanged( false ); } } } } transMeta.clearChangedDatabases(); } catch ( KettleDatabaseException dbe ) { throw new KettleException( BaseMessages.getString( PKG, "TransMeta.Log.UnableToReadDatabaseIDSFromRepository" ), dbe ); } catch ( KettleException ke ) { throw new KettleException( BaseMessages.getString( PKG, "TransMeta.Log.UnableToReadDatabasesFromRepository" ), ke ); } }
Example 5
Source File: JobEntryDialog.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@VisibleForTesting String showDbDialogUnlessCancelledOrValid( DatabaseMeta changing, DatabaseMeta origin ) { changing.shareVariablesWith( jobMeta ); DatabaseDialog cid = getDatabaseDialog(); cid.setDatabaseMeta( changing ); cid.setModalDialog( true ); String name = null; boolean repeat = true; while ( repeat ) { name = cid.open(); if ( name == null ) { // Cancel was pressed repeat = false; } else { name = name.trim(); DatabaseMeta same = jobMeta.findDatabase( name ); if ( same == null || same == origin ) { // OK was pressed and input is valid repeat = false; } else { showDbExistsDialog( changing ); } } } return name; }
Example 6
Source File: BaseStepDialog.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@VisibleForTesting String showDbDialogUnlessCancelledOrValid( DatabaseMeta changing, DatabaseMeta origin ) { changing.shareVariablesWith( transMeta ); DatabaseDialog cid = getDatabaseDialog( shell ); cid.setDatabaseMeta( changing ); cid.setModalDialog( true ); if ( cid.getDatabaseMeta() == null ) { return changing.getName(); } String name = null; boolean repeat = true; while ( repeat ) { name = cid.open(); if ( name == null ) { // Cancel was pressed repeat = false; } else { name = name.trim(); DatabaseMeta same = transMeta.findDatabase( name ); if ( same == null || same == origin ) { // OK was pressed and input is valid repeat = false; } else { showDbExistsDialog( changing ); } } } return name; }
Example 7
Source File: TransDelegate.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * Insert all the databases from the repository into the TransMeta object, overwriting optionally * * @param TransMeta * The transformation to load into. * @param overWriteShared * if an object with the same name exists, overwrite * @throws KettleException */ protected void readDatabases( TransMeta transMeta, boolean overWriteShared, List<DatabaseMeta> databaseMetas ) { for ( DatabaseMeta databaseMeta : databaseMetas ) { if ( overWriteShared || transMeta.findDatabase( databaseMeta.getName() ) == null ) { if ( databaseMeta.getName() != null ) { databaseMeta.shareVariablesWith( transMeta ); transMeta.addOrReplaceDatabase( databaseMeta ); if ( !overWriteShared ) { databaseMeta.setChanged( false ); } } } } transMeta.clearChangedDatabases(); }
Example 8
Source File: JobDelegate.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * Insert all the databases from the repository into the JobMeta object, overwriting optionally * * @param jobMeta * The transformation to load into. * @param overWriteShared * if an object with the same name exists, overwrite */ protected void readDatabases( JobMeta jobMeta, boolean overWriteShared, List<DatabaseMeta> databaseMetas ) { for ( DatabaseMeta databaseMeta : databaseMetas ) { if ( overWriteShared || jobMeta.findDatabase( databaseMeta.getName() ) == null ) { if ( databaseMeta.getName() != null ) { databaseMeta.shareVariablesWith( jobMeta ); jobMeta.addOrReplaceDatabase( databaseMeta ); if ( !overWriteShared ) { databaseMeta.setChanged( false ); } } } } jobMeta.clearChanged(); }
Example 9
Source File: ScriptAddedFunctions.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@SuppressWarnings( "unused" ) public static Object fireToDB( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { Object oRC = new Object(); if ( ArgList.length == 2 ) { try { Object scmO = actualObject.get( "_step_" ); Script scm = (Script) scmO; String strDBName = (String) ArgList[0]; String strSQL = (String) ArgList[1]; DatabaseMeta ci = DatabaseMeta.findDatabase( scm.getTransMeta().getDatabases(), strDBName ); if ( ci == null ) { throw new RuntimeException( "Database connection not found: " + strDBName ); } ci.shareVariablesWith( scm ); Database db = new Database( scm, ci ); db.setQueryLimit( 0 ); try { if ( scm.getTransMeta().isUsingUniqueConnections() ) { synchronized ( scm.getTrans() ) { db.connect( scm.getTrans().getTransactionId(), scm.getPartitionID() ); } } else { db.connect( scm.getPartitionID() ); } ResultSet rs = db.openQuery( strSQL ); ResultSetMetaData resultSetMetaData = rs.getMetaData(); int columnCount = resultSetMetaData.getColumnCount(); if ( rs != null ) { List<Object[]> list = new ArrayList<Object[]>(); while ( rs.next() ) { Object[] objRow = new Object[columnCount]; for ( int i = 0; i < columnCount; i++ ) { objRow[i] = rs.getObject( i + 1 ); } list.add( objRow ); } Object[][] resultArr = new Object[list.size()][]; list.toArray( resultArr ); db.disconnect(); return resultArr; } } catch ( Exception er ) { throw new RuntimeException( er.toString() ); } } catch ( Exception e ) { throw new RuntimeException( e.toString() ); } } else { throw new RuntimeException( "The function call fireToDB requires 2 arguments." ); } return oRC; }
Example 10
Source File: ScriptValuesAddedFunctions.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@SuppressWarnings( "unused" ) public static Object fireToDB( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { Object oRC = new Object(); if ( ArgList.length == 2 ) { try { Object scmO = actualObject.get( "_step_", actualObject ); ScriptValuesMod scm = (ScriptValuesMod) Context.jsToJava( scmO, ScriptValuesMod.class ); String strDBName = Context.toString( ArgList[0] ); String strSQL = Context.toString( ArgList[1] ); DatabaseMeta ci = DatabaseMeta.findDatabase( scm.getTransMeta().getDatabases(), strDBName ); if ( ci == null ) { throw Context.reportRuntimeError( "Database connection not found: " + strDBName ); } ci.shareVariablesWith( scm ); Database db = new Database( scm, ci ); db.setQueryLimit( 0 ); try { if ( scm.getTransMeta().isUsingUniqueConnections() ) { synchronized ( scm.getTrans() ) { db.connect( scm.getTrans().getTransactionId(), scm.getPartitionID() ); } } else { db.connect( scm.getPartitionID() ); } ResultSet rs = db.openQuery( strSQL ); ResultSetMetaData resultSetMetaData = rs.getMetaData(); int columnCount = resultSetMetaData.getColumnCount(); if ( rs != null ) { List<Object[]> list = new ArrayList<Object[]>(); while ( rs.next() ) { Object[] objRow = new Object[columnCount]; for ( int i = 0; i < columnCount; i++ ) { objRow[i] = rs.getObject( i + 1 ); } list.add( objRow ); } Object[][] resultArr = new Object[list.size()][]; list.toArray( resultArr ); db.disconnect(); return resultArr; } } catch ( Exception er ) { throw Context.reportRuntimeError( er.toString() ); } } catch ( Exception e ) { throw Context.reportRuntimeError( e.toString() ); } } else { throw Context.reportRuntimeError( "The function call fireToDB requires 2 arguments." ); } return oRC; }
Example 11
Source File: SpoonDBDelegate.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void newConnection( HasDatabasesInterface hasDatabasesInterface ) { DatabaseMeta databaseMeta = new DatabaseMeta(); if ( hasDatabasesInterface instanceof VariableSpace ) { databaseMeta.shareVariablesWith( (VariableSpace) hasDatabasesInterface ); } else { databaseMeta.initializeVariablesFrom( null ); } getDatabaseDialog().setDatabaseMeta( databaseMeta ); String con_name = getDatabaseDialog().open(); if ( !Utils.isEmpty( con_name ) ) { con_name = con_name.trim(); databaseMeta.setName( con_name ); databaseMeta.setDisplayName( con_name ); databaseMeta = getDatabaseDialog().getDatabaseMeta(); if ( databaseMeta.findDatabase( hasDatabasesInterface.getDatabases(), con_name ) == null ) { hasDatabasesInterface.addDatabase( databaseMeta ); spoon.addUndoNew( (UndoInterface) hasDatabasesInterface, new DatabaseMeta[]{(DatabaseMeta) databaseMeta .clone()}, new int[]{hasDatabasesInterface.indexOfDatabase( databaseMeta )} ); if ( spoon.rep != null ) { try { if ( !spoon.rep.getSecurityProvider().isReadOnly() ) { // spoon.rep.getDatabaseID( ) spoon.rep.save( databaseMeta, Const.VERSION_COMMENT_INITIAL_VERSION, null ); } else { throw new KettleException( BaseMessages.getString( PKG, "Spoon.Dialog.Exception.ReadOnlyRepositoryUser" ) ); } } catch ( KettleException e ) { new ErrorDialog( spoon.getShell(), BaseMessages.getString( PKG, "Spoon.Dialog.ErrorSavingConnection.Title" ), BaseMessages.getString( PKG, "Spoon.Dialog.ErrorSavingConnection.Message", databaseMeta.getName() ), e ); } } refreshTree(); } else { DatabaseDialog.showDatabaseExistsDialog( spoon.getShell(), databaseMeta ); } } }