Java Code Examples for org.pentaho.di.core.database.DatabaseMeta#setName()
The following examples show how to use
org.pentaho.di.core.database.DatabaseMeta#setName() .
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: PurRepository.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Override public List<DatabaseMeta> readDatabases() throws KettleException { readWriteLock.readLock().lock(); try { List<RepositoryFile> children = getAllFilesOfType( null, RepositoryObjectType.DATABASE, false ); List<DatabaseMeta> dbMetas = new ArrayList<DatabaseMeta>(); for ( RepositoryFile file : children ) { DataNode node; node = pur.getDataForRead( file.getId(), NodeRepositoryFileData.class ).getNode(); DatabaseMeta databaseMeta = (DatabaseMeta) databaseMetaTransformer.dataNodeToElement( node ); databaseMeta.setName( file.getTitle() ); dbMetas.add( databaseMeta ); } return dbMetas; } catch ( Exception e ) { throw new KettleException( "Unable to read all databases", e ); } finally { readWriteLock.readLock().unlock(); } }
Example 2
Source File: SharedObjectSyncUtilTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void synchronizeConnectionsRename() throws Exception { final String databaseName = BEFORE_SYNC_VALUE; DatabaseMeta sharedDB0 = createDatabaseMeta( databaseName, true ); saveSharedObjects( SHARED_OBJECTS_FILE, sharedDB0 ); JobMeta job1 = createJobMeta(); spoonDelegates.jobs.addJob( job1 ); JobMeta job2 = createJobMeta(); spoonDelegates.jobs.addJob( job2 ); DatabaseMeta sharedDB2 = job2.getDatabase( 0 ); assertEquals( databaseName, sharedDB2.getName() ); DatabaseMeta sharedDB1 = job1.getDatabase( 0 ); assertEquals( databaseName, sharedDB1.getName() ); assertTrue( sharedDB1 != sharedDB2 ); assertThat( sharedDB1.getName(), equalTo( BEFORE_SYNC_VALUE ) ); sharedDB2.setName( AFTER_SYNC_VALUE ); sharedUtil.synchronizeConnections( sharedDB2, BEFORE_SYNC_VALUE ); assertThat( sharedDB1.getName(), equalTo( AFTER_SYNC_VALUE ) ); }
Example 3
Source File: KettleFileRepository_DatabaseNames_Test.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void getDatabaseId_ReturnsExactMatch_PriorToCaseInsensitiveMatch() throws Exception { final String exact = "databaseExactMatch"; final String similar = exact.toLowerCase(); assertNotSame( similar, exact ); DatabaseMeta db = saveDatabase( exact ); // simulate legacy repository - store a DB with a name different only in case DatabaseMeta another = new DatabaseMeta(); another.setName( similar ); FileObject fileObject = repository.getFileObject( another ); assertFalse( fileObject.exists() ); // just create it - enough for this case fileObject.createFile(); assertTrue( fileObject.exists() ); ObjectId id = this.repository.getDatabaseID( exact ); assertEquals( db.getObjectId(), id ); }
Example 4
Source File: TransMetaTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testDatabaseNotOverridden() throws Exception { final String name = "db meta"; DatabaseMeta dbMetaShared = new DatabaseMeta(); dbMetaShared.setName( name ); dbMetaShared.setHostname( "host" ); DatabaseMeta dbMetaStore = new DatabaseMeta(); dbMetaStore.setName( name ); dbMetaStore.setHostname( "anotherhost" ); IMetaStore mstore = new MemoryMetaStore(); DatabaseMetaStoreUtil.createDatabaseElement( mstore, dbMetaStore ); TransMeta trans = new TransMeta(); trans.addOrReplaceDatabase( dbMetaShared ); trans.setMetaStore( mstore ); trans.importFromMetaStore(); DatabaseMeta dbMeta = trans.findDatabase( name ); assertEquals( dbMetaShared.getHostname(), dbMeta.getHostname() ); }
Example 5
Source File: JobEntryDialog_ConnectionLine_Test.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void showDbDialog_LoopsUntilUniqueValueIsInput() throws Exception { DatabaseMeta db1 = createDefaultDatabase(); DatabaseMeta db2 = createDefaultDatabase(); db2.setName( INPUT_NAME ); JobMeta jobMeta = new JobMeta(); jobMeta.addDatabase( db1 ); jobMeta.addDatabase( db2 ); final String expectedResult = INPUT_NAME + "2"; DatabaseDialog databaseDialog = mock( DatabaseDialog.class ); when( databaseDialog.open() ) // duplicate .thenReturn( INPUT_NAME ) // duplicate with spaces .thenReturn( INPUT_NAME + " " ) // duplicate in other case .thenReturn( INPUT_NAME.toUpperCase() ) // unique value .thenReturn( expectedResult ); JobEntryDialog dialog = mock( JobEntryDialog.class ); dialog.databaseDialog = databaseDialog; dialog.jobMeta = jobMeta; when( dialog.showDbDialogUnlessCancelledOrValid( anyDbMeta(), anyDbMeta() ) ).thenCallRealMethod(); // try to rename db1 ("qwerty") String result = dialog.showDbDialogUnlessCancelledOrValid( (DatabaseMeta) db1.clone(), db1 ); assertEquals( expectedResult, result ); // database dialog should be shown four times verify( databaseDialog, times( 4 ) ).open(); // and the error message should be shown three times verify( dialog, times( 3 ) ).showDbExistsDialog( anyDbMeta() ); }
Example 6
Source File: BaseStepDialog_ConnectionLine_Test.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public String answer( InvocationOnMock invocation ) throws Throwable { DatabaseMeta meta = (DatabaseMeta) invocation.getArguments()[ 0 ]; meta.setName( name ); meta.setHostname( host ); return name; }
Example 7
Source File: JobEntryDialog_ConnectionLine_Test.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public String answer( InvocationOnMock invocation ) throws Throwable { DatabaseMeta meta = (DatabaseMeta) invocation.getArguments()[ 0 ]; meta.setName( name ); meta.setHostname( host ); return name; }
Example 8
Source File: EditConnectionListenerTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public String answer( InvocationOnMock invocation ) throws Throwable { DatabaseMeta meta = (DatabaseMeta) invocation.getArguments()[0]; meta.setName( name ); meta.setHostname( host ); return name; }
Example 9
Source File: SpoonDBDelegate.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public void editConnection( DatabaseMeta databaseMeta ) { HasDatabasesInterface hasDatabasesInterface = spoon.getActiveHasDatabasesInterface(); if ( hasDatabasesInterface == null ) { return; // program error, exit just to make sure. } String originalName = databaseMeta.getName(); getDatabaseDialog().setDatabaseMeta( databaseMeta ); getDatabaseDialog().setDatabases( hasDatabasesInterface.getDatabases() ); String newname = getDatabaseDialog().open(); if ( !Utils.isEmpty( newname ) ) { // null: CANCEL databaseMeta.setName( originalName ); databaseMeta = getDatabaseDialog().getDatabaseMeta(); if ( !newname.equals( originalName ) && databaseMeta.findDatabase( hasDatabasesInterface.getDatabases(), newname ) != null ) { databaseMeta.setName( newname.trim() ); DatabaseDialog.showDatabaseExistsDialog( spoon.getShell(), databaseMeta ); databaseMeta.setName( originalName ); databaseMeta.setDisplayName( originalName ); return; } databaseMeta.setName( newname.trim() ); databaseMeta.setDisplayName( newname.trim() ); saveConnection( databaseMeta, Const.VERSION_COMMENT_EDIT_VERSION ); if ( databaseMeta.isShared() ) { sharedObjectSyncUtil.synchronizeConnections( databaseMeta, originalName ); } saveConnection( databaseMeta, Const.VERSION_COMMENT_EDIT_VERSION ); if ( databaseMeta.isShared() ) { sharedObjectSyncUtil.synchronizeConnections( databaseMeta, originalName ); } refreshTree(); } spoon.setShellText(); }
Example 10
Source File: RepositoryExplorerDialog.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public boolean renameDatabase( String name, String newname ) { boolean retval = false; try { if ( Utils.isEmpty( newname ) ) { throw new KettleException( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Exception.NameCanNotBeEmpty" ) ); } if ( !name.equals( newname ) ) { ObjectId id = rep.getDatabaseID( name ); if ( id != null ) { DatabaseMeta databaseMeta = rep.loadDatabaseMeta( id, null ); // reads last version databaseMeta.setName( newname ); rep.insertLogEntry( "Renaming database connection '" + getDatabaseDialog().getDatabaseMeta().getName() + "'" ); rep.save( databaseMeta, Const.VERSION_COMMENT_EDIT_VERSION, null ); retval = true; } else { MessageBox mb = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK ); mb .setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Rename.ErrorFinding.Message1" ) + name + "]" + Const.CR + BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Rename.ErrorFinding.Message2" ) ); mb.setText( BaseMessages .getString( PKG, "RepositoryExplorerDialog.Connection.Rename.ErrorFinding.Title" ) ); mb.open(); } } } catch ( KettleException e ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Rename.UnexpectedError.Title" ), BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Rename.UnexpectedError.Message" ), e ); } return retval; }
Example 11
Source File: AsyncDatabaseActionTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Before public void before() { dbMeta = new DatabaseMeta(); H2DatabaseMeta h2 = new H2DatabaseMeta(); dbMeta.setDatabaseInterface( h2 ); dbMeta.setName( "mem:TEST" ); dbMeta.setDBName( "mem:TEST" ); dbMeta.setDatabaseType( "H2" ); KettleLogStore.getAppender().addLoggingEventListener( errorLogListener ); }
Example 12
Source File: ExecSQLMetaInjectionTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { check( "SQL", () -> meta.getSql() ); check( "EXECUTE_FOR_EACH_ROW", () -> meta.isExecutedEachInputRow() ); check( "UPDATE_STATS_FIELD", () -> meta.getUpdateField() ); check( "INSERT_STATS_FIELD", () -> meta.getInsertField() ); check( "DELETE_STATS_FIELD", () -> meta.getDeleteField() ); check( "READ_STATS_FIELD", () -> meta.getReadField() ); check( "EXECUTE_AS_SINGLE_STATEMENT", () -> meta.isSingleStatement() ); check( "REPLACE_VARIABLES", () -> meta.isReplaceVariables() ); check( "QUOTE_STRINGS", () -> meta.isQuoteString() ); check( "BIND_PARAMETERS", () -> meta.isParams() ); check( "PARAMETER_NAME", () -> meta.getArguments()[ 0 ] ); // skip connection name testing, so we can provide our own custom handling skipPropertyTest( "CONNECTIONNAME" ); // mock the database connections final DatabaseMeta db1 = new DatabaseMeta(); db1.setName( "my connection 1" ); final DatabaseMeta db2 = new DatabaseMeta(); db2.setName( "my connection 2" ); final DatabaseMeta db3 = new DatabaseMeta(); db3.setName( "my connection 3" ); final List<SharedObjectInterface> mockDbs = Arrays.asList( new SharedObjectInterface[] { db1, db2, db3 } ); final StepMeta parentStepMeta = Mockito.mock( StepMeta.class ); final TransMeta parentTransMeta = Mockito.mock( TransMeta.class ); Mockito.doReturn( mockDbs ).when( parentTransMeta ).getDatabases(); Mockito.doReturn( parentTransMeta ).when( parentStepMeta ).getParentTransMeta(); meta.setParentStepMeta( parentStepMeta ); injector.setProperty( meta, "CONNECTIONNAME", setValue( new ValueMetaString( "my connection 2" ), "my connection 2" ), "my connection 2" ); // verify we get back the correct connection assertEquals( db2, meta.getDatabaseMeta() ); }
Example 13
Source File: DatabaseMetaLoadSaveValidator.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public DatabaseMeta getTestObject() { DatabaseMeta db = new DatabaseMeta(); db.setObjectId( new LongObjectId( rand.nextInt( Integer.MAX_VALUE ) ) ); db.setName( UUID.randomUUID().toString() ); db.setHostname( UUID.randomUUID().toString() ); db.setUsername( UUID.randomUUID().toString() ); db.setPassword( UUID.randomUUID().toString() ); return db; }
Example 14
Source File: KettleFileRepository_DatabaseNames_Test.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private DatabaseMeta saveDatabase( String name ) throws Exception { DatabaseMeta db = new DatabaseMeta(); db.setName( name ); repository.save( db, null, null ); assertNotNull( db.getObjectId() ); return db; }
Example 15
Source File: RepositoryTestBase.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Ignore @Test public void testRenameAndUndelete() throws Exception { RepositoryDirectoryInterface rootDir = initRepo(); JobMeta jobMeta = createJobMeta( EXP_JOB_NAME ); RepositoryDirectoryInterface jobsDir = rootDir.findDirectory( DIR_JOBS ); repository.save( jobMeta, VERSION_COMMENT_V1, null ); deleteStack.push( jobMeta ); repository.deleteJob( jobMeta.getObjectId() ); assertFalse( repository.exists( EXP_JOB_NAME, jobsDir, RepositoryObjectType.JOB ) ); RepositoryObject robj = new RepositoryObject( jobMeta.getObjectId(), jobMeta.getName(), jobMeta.getRepositoryDirectory(), null, null, jobMeta.getRepositoryElementType(), null, false ); repository.undeleteObject( robj ); assertTrue( repository.exists( EXP_JOB_NAME, jobsDir, RepositoryObjectType.JOB ) ); repository.renameJob( jobMeta.getObjectId(), jobsDir, EXP_JOB_NAME_NEW ); assertFalse( repository.exists( EXP_JOB_NAME, jobsDir, RepositoryObjectType.JOB ) ); assertTrue( repository.exists( EXP_JOB_NAME_NEW, jobsDir, RepositoryObjectType.JOB ) ); TransMeta transMeta = createTransMeta( EXP_DBMETA_NAME ); RepositoryDirectoryInterface transDir = rootDir.findDirectory( DIR_TRANSFORMATIONS ); repository.save( transMeta, VERSION_COMMENT_V1, null ); deleteStack.push( transMeta ); repository.renameTransformation( transMeta.getObjectId(), transDir, EXP_TRANS_NAME_NEW ); assertFalse( repository.exists( EXP_TRANS_NAME.concat( EXP_DBMETA_NAME ), transDir, RepositoryObjectType.TRANSFORMATION ) ); assertTrue( repository.exists( EXP_TRANS_NAME_NEW, transDir, RepositoryObjectType.TRANSFORMATION ) ); DatabaseMeta dbMeta = createDatabaseMeta( EXP_DBMETA2_NAME ); repository.save( dbMeta, VERSION_COMMENT_V1, null ); deleteStack.push( dbMeta ); dbMeta.setName( EXP_DBMETA_NAME_NEW ); repository.save( dbMeta, VERSION_COMMENT_V2, null ); assertFalse( repository.exists( EXP_DBMETA2_NAME, null, RepositoryObjectType.DATABASE ) ); assertTrue( repository.exists( EXP_DBMETA_NAME_NEW, null, RepositoryObjectType.DATABASE ) ); }
Example 16
Source File: ConnectionsControllerTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void editConnection_NameExists_SameWithSpaces() throws Exception { final String dbName = " name"; DatabaseMeta dbmeta = spy( new DatabaseMeta() ); dbmeta.setName( dbName ); List<UIDatabaseConnection> selectedConnection = singletonList( new UIDatabaseConnection( dbmeta, repository ) ); when( connectionsTable.<UIDatabaseConnection>getSelectedItems() ).thenReturn( selectedConnection ); when( repository.getDatabaseID( dbName ) ).thenReturn( new StringObjectId( "existing" ) ); when( databaseDialog.open() ).thenReturn( dbName ); controller.editConnection(); verify( dbmeta ).setName( dbName.trim() ); }
Example 17
Source File: ConnectionModelTest.java From pentaho-aggdesigner with GNU General Public License v2.0 | 5 votes |
@Test public void testGetDatabaseMeta() { // this should generate the basic database meta object DatabaseMeta meta = new DatabaseMeta(); meta.setName("test"); connectionModel.setDatabaseMeta(meta); // this should reset the database meta object connectionModel.setDatabaseMeta(null); // this should load the database meta object from disk DatabaseMeta newmeta = connectionModel.getDatabaseMeta(); assertEquals(meta, newmeta); assertEquals(meta.getName(), newmeta.getName()); }
Example 18
Source File: ConnectionsController.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void createConnection() { try { DatabaseMeta databaseMeta = new DatabaseMeta(); databaseMeta.initializeVariablesFrom( null ); getDatabaseDialog().setDatabaseMeta( databaseMeta ); String dbName = getDatabaseDialog().open(); if ( dbName != null ) { dbName = dbName.trim(); databaseMeta.setName( dbName ); databaseMeta.setDisplayName( dbName ); getDatabaseDialog().setDatabaseMeta( databaseMeta ); if ( !dbName.isEmpty() ) { // See if this user connection exists... ObjectId idDatabase = repository.getDatabaseID( dbName ); if ( idDatabase == null ) { repository.insertLogEntry( BaseMessages.getString( PKG, "ConnectionsController.Message.CreatingDatabase", getDatabaseDialog() .getDatabaseMeta().getName() ) ); repository.save( getDatabaseDialog().getDatabaseMeta(), Const.VERSION_COMMENT_INITIAL_VERSION, null ); reloadLoadedJobsAndTransformations(); } else { showAlreadyExistsMessage(); } } } // We should be able to tell the difference between a cancel and an empty database name // // else { // MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); // mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Edit.MissingName.Message")); // mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Edit.MissingName.Title")); // mb.open(); // } } catch ( KettleException e ) { if ( mainController == null || !mainController.handleLostRepository( e ) ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title" ), BaseMessages.getString( PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Message" ), e ); } } finally { refreshConnectionList(); } }
Example 19
Source File: StreamToNodeConvertersPrivateDatabasesTest.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private DatabaseMeta createDb( String name ) { DatabaseMeta meta = new DatabaseMeta(); meta.setName( name ); meta.getDatabaseInterface().setDatabaseName( name ); return meta; }
Example 20
Source File: JobEntryDialog_ConnectionLine_Test.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private DatabaseMeta createDefaultDatabase() { DatabaseMeta existing = new DatabaseMeta(); existing.setName( INITIAL_NAME ); existing.setHostname( INITIAL_HOST ); return existing; }