Java Code Examples for org.pentaho.di.core.database.Database#getTableFields()
The following examples show how to use
org.pentaho.di.core.database.Database#getTableFields() .
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: DatabaseLookupMeta.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Override public RowMetaInterface getTableFields() { RowMetaInterface fields = null; if ( databaseMeta != null ) { Database db = new Database( loggingObject, databaseMeta ); databases = new Database[] { db }; // Keep track of this one for cancelQuery try { db.connect(); String tableName = databaseMeta.environmentSubstitute( tablename ); String schemaTable = databaseMeta.getQuotedSchemaTableCombination( schemaName, tableName ); fields = db.getTableFields( schemaTable ); } catch ( KettleDatabaseException dbe ) { logError( BaseMessages.getString( PKG, "DatabaseLookupMeta.ERROR0004.ErrorGettingTableFields" ) + dbe.getMessage() ); } finally { db.disconnect(); } } return fields; }
Example 2
Source File: XulDatabaseExplorerController.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public void getDDL() { if ( model.getTable() == null ) { return; } Database db = new Database( null, this.model.getDatabaseMeta() ); try { db.connect(); String tableName = getSchemaAndTable( this.model ); RowMetaInterface r = db.getTableFields( tableName ); String sql = db.getCreateTableStatement( tableName, r, null, false, null, true ); SQLEditor se = new SQLEditor( this.getDatabaseMeta(), this.dbExplorerDialog.getShell(), SWT.NONE, this.model .getDatabaseMeta(), this.dbcache, sql ); se.open(); } catch ( KettleDatabaseException dbe ) { new ErrorDialog( this.dbExplorerDialog.getShell(), BaseMessages.getString( PKG, "Dialog.Error.Header" ), BaseMessages .getString( PKG, "DatabaseExplorerDialog.Error.RetrieveLayout" ), dbe ); } finally { db.disconnect(); } }
Example 3
Source File: TransProfileFactory.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private RowMetaInterface getTableFields( LoggingObjectInterface parentLoggingObject ) throws KettleDatabaseException { Database database = new Database( parentLoggingObject, databaseMeta ); try { database.connect(); return database.getTableFields( schemaTable ); } finally { database.disconnect(); } }
Example 4
Source File: PGBulkLoaderMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public RowMetaInterface getRequiredFields( VariableSpace space ) throws KettleException { String realTableName = space.environmentSubstitute( tableName ); String realSchemaName = space.environmentSubstitute( schemaName ); if ( databaseMeta != null ) { Database db = new Database( loggingObject, databaseMeta ); try { db.connect(); if ( !Utils.isEmpty( realTableName ) ) { String schemaTable = databaseMeta.getQuotedSchemaTableCombination( realSchemaName, realTableName ); // Check if this table exists... if ( db.checkTableExists( schemaTable ) ) { return db.getTableFields( schemaTable ); } else { throw new KettleException( BaseMessages.getString( PKG, "GPBulkLoaderMeta.Exception.TableNotFound" ) ); } } else { throw new KettleException( BaseMessages.getString( PKG, "GPBulkLoaderMeta.Exception.TableNotSpecified" ) ); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "GPBulkLoaderMeta.Exception.ErrorGettingFields" ), e ); } finally { db.disconnect(); } } else { throw new KettleException( BaseMessages.getString( PKG, "GPBulkLoaderMeta.Exception.ConnectionNotDefined" ) ); } }
Example 5
Source File: MonetDBBulkLoaderMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public RowMetaInterface getRequiredFields( VariableSpace space ) throws KettleException { String realTableName = space.environmentSubstitute( tableName ); String realSchemaName = space.environmentSubstitute( schemaName ); if ( databaseMeta != null ) { Database db = new Database( loggingObject, databaseMeta ); try { db.connect(); if ( !Utils.isEmpty( realTableName ) ) { String schemaTable = databaseMeta.getQuotedSchemaTableCombination( realSchemaName, realTableName ); // Check if this table exists... if ( db.checkTableExists( schemaTable ) ) { return db.getTableFields( schemaTable ); } else { throw new KettleException( BaseMessages.getString( PKG, "MonetDBBulkLoaderMeta.Exception.TableNotFound" ) ); } } else { throw new KettleException( BaseMessages.getString( PKG, "MonetDBBulkLoaderMeta.Exception.TableNotSpecified" ) ); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "MonetDBBulkLoaderMeta.Exception.ErrorGettingFields" ), e ); } finally { db.disconnect(); } } else { throw new KettleException( BaseMessages.getString( PKG, "MonetDBBulkLoaderMeta.Exception.ConnectionNotDefined" ) ); } }
Example 6
Source File: OraBulkLoaderMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public RowMetaInterface getRequiredFields( VariableSpace space ) throws KettleException { String realTableName = space.environmentSubstitute( tableName ); String realSchemaName = space.environmentSubstitute( schemaName ); if ( databaseMeta != null ) { Database db = new Database( loggingObject, databaseMeta ); try { db.connect(); if ( !Utils.isEmpty( realTableName ) ) { String schemaTable = databaseMeta.getQuotedSchemaTableCombination( realSchemaName, realTableName ); // Check if this table exists... if ( db.checkTableExists( schemaTable ) ) { return db.getTableFields( schemaTable ); } else { throw new KettleException( BaseMessages.getString( PKG, "OraBulkLoaderMeta.Exception.TableNotFound" ) ); } } else { throw new KettleException( BaseMessages.getString( PKG, "OraBulkLoaderMeta.Exception.TableNotSpecified" ) ); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "OraBulkLoaderMeta.Exception.ErrorGettingFields" ), e ); } finally { db.disconnect(); } } else { throw new KettleException( BaseMessages.getString( PKG, "OraBulkLoaderMeta.Exception.ConnectionNotDefined" ) ); } }
Example 7
Source File: MySQLBulkLoaderMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public RowMetaInterface getRequiredFields( VariableSpace space ) throws KettleException { String realTableName = space.environmentSubstitute( tableName ); String realSchemaName = space.environmentSubstitute( schemaName ); if ( databaseMeta != null ) { Database db = new Database( loggingObject, databaseMeta ); try { db.connect(); if ( !Utils.isEmpty( realTableName ) ) { String schemaTable = databaseMeta.getQuotedSchemaTableCombination( realSchemaName, realTableName ); // Check if this table exists... if ( db.checkTableExists( schemaTable ) ) { return db.getTableFields( schemaTable ); } else { throw new KettleException( BaseMessages.getString( PKG, "MySQLBulkLoaderMeta.Exception.TableNotFound" ) ); } } else { throw new KettleException( BaseMessages.getString( PKG, "MySQLBulkLoaderMeta.Exception.TableNotSpecified" ) ); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "MySQLBulkLoaderMeta.Exception.ErrorGettingFields" ), e ); } finally { db.disconnect(); } } else { throw new KettleException( BaseMessages.getString( PKG, "MySQLBulkLoaderMeta.Exception.ConnectionNotDefined" ) ); } }
Example 8
Source File: LucidDBStreamingLoaderMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public RowMetaInterface getRequiredFields( VariableSpace space ) throws KettleException { String realTableName = space.environmentSubstitute( tableName ); String realSchemaName = space.environmentSubstitute( schemaName ); if ( databaseMeta != null ) { Database db = new Database( loggingObject, databaseMeta ); try { db.connect(); if ( !Utils.isEmpty( realTableName ) ) { String schemaTable = databaseMeta.getQuotedSchemaTableCombination( realSchemaName, realTableName ); // Check if this table exists... if ( db.checkTableExists( schemaTable ) ) { return db.getTableFields( schemaTable ); } else { throw new KettleException( BaseMessages.getString( PKG, "LucidDBStreamingLoaderMeta.Exception.TableNotFound" ) ); } } else { throw new KettleException( BaseMessages.getString( PKG, "LucidDBStreamingLoaderMeta.Exception.TableNotSpecified" ) ); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "LucidDBStreamingLoaderMeta.Exception.ErrorGettingFields" ), e ); } finally { db.disconnect(); } } else { throw new KettleException( BaseMessages.getString( PKG, "LucidDBStreamingLoaderMeta.Exception.ConnectionNotDefined" ) ); } }
Example 9
Source File: GPLoadMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public RowMetaInterface getRequiredFields( VariableSpace space ) throws KettleException { String realTableName = space.environmentSubstitute( tableName ); String realSchemaName = space.environmentSubstitute( schemaName ); if ( databaseMeta != null ) { Database db = new Database( loggingObject, databaseMeta ); try { db.connect(); if ( !Utils.isEmpty( realTableName ) ) { String schemaTable = databaseMeta.getQuotedSchemaTableCombination( realSchemaName, realTableName ); // Check if this table exists... if ( db.checkTableExists( schemaTable ) ) { return db.getTableFields( schemaTable ); } else { throw new KettleException( BaseMessages.getString( PKG, "GPLoadMeta.Exception.TableNotFound" ) ); } } else { throw new KettleException( BaseMessages.getString( PKG, "GPLoadMeta.Exception.TableNotSpecified" ) ); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "GPLoadMeta.Exception.ErrorGettingFields" ), e ); } finally { db.disconnect(); } } else { throw new KettleException( BaseMessages.getString( PKG, "GPLoadMeta.Exception.ConnectionNotDefined" ) ); } }
Example 10
Source File: LucidDBBulkLoaderMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public RowMetaInterface getRequiredFields( VariableSpace space ) throws KettleException { String realTableName = space.environmentSubstitute( tableName ); String realSchemaName = space.environmentSubstitute( schemaName ); if ( databaseMeta != null ) { Database db = new Database( loggingObject, databaseMeta ); try { db.connect(); if ( !Utils.isEmpty( realTableName ) ) { String schemaTable = databaseMeta.getQuotedSchemaTableCombination( realSchemaName, realTableName ); // Check if this table exists... if ( db.checkTableExists( schemaTable ) ) { return db.getTableFields( schemaTable ); } else { throw new KettleException( BaseMessages.getString( PKG, "LucidDBBulkLoaderMeta.Exception.TableNotFound" ) ); } } else { throw new KettleException( BaseMessages.getString( PKG, "LucidDBBulkLoaderMeta.Exception.TableNotSpecified" ) ); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "LucidDBBulkLoaderMeta.Exception.ErrorGettingFields" ), e ); } finally { db.disconnect(); } } else { throw new KettleException( BaseMessages.getString( PKG, "LucidDBBulkLoaderMeta.Exception.ConnectionNotDefined" ) ); } }
Example 11
Source File: GPBulkLoaderMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public RowMetaInterface getRequiredFields( VariableSpace space ) throws KettleException { String realTableName = space.environmentSubstitute( tableName ); String realSchemaName = space.environmentSubstitute( schemaName ); if ( databaseMeta != null ) { Database db = new Database( loggingObject, databaseMeta ); try { db.connect(); if ( !Utils.isEmpty( realTableName ) ) { String schemaTable = databaseMeta.getQuotedSchemaTableCombination( realSchemaName, realTableName ); // Check if this table exists... if ( db.checkTableExists( schemaTable ) ) { return db.getTableFields( schemaTable ); } else { throw new KettleException( BaseMessages.getString( PKG, "GPBulkLoaderMeta.Exception.TableNotFound" ) ); } } else { throw new KettleException( BaseMessages.getString( PKG, "GPBulkLoaderMeta.Exception.TableNotSpecified" ) ); } } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "GPBulkLoaderMeta.Exception.ErrorGettingFields" ), e ); } finally { db.disconnect(); } } else { throw new KettleException( BaseMessages.getString( PKG, "GPBulkLoaderMeta.Exception.ConnectionNotDefined" ) ); } }
Example 12
Source File: CombinationLookupMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
protected RowMetaInterface getDatabaseTableFields( Database db, String schemaName, String tableName ) throws KettleDatabaseException { // First try without connecting to the database... (can be S L O W) String schemaTable = databaseMeta.getQuotedSchemaTableCombination( schemaName, tableName ); RowMetaInterface extraFields = db.getTableFields( schemaTable ); if ( extraFields == null ) { // now we need to connect db.connect(); extraFields = db.getTableFields( schemaTable ); } return extraFields; }
Example 13
Source File: PhysicalTableImporter.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 4 votes |
public static PhysicalTable importTableDefinition( Database database, String schemaName, String tableName, String locale ) throws KettleException { UniqueList<PhysicalColumn> fields = new UniqueArrayList<PhysicalColumn>(); String id = tableName; String tablename = tableName; // Remove id = Const.toID( tableName ); // Set the id to a certain standard... id = Settings.getPhysicalTableIDPrefix() + id; if ( Settings.isAnIdUppercase() ) { id = id.toUpperCase(); } PhysicalTable physicalTable = new PhysicalTable( id, schemaName, tableName, database.getDatabaseMeta(), fields ); // Also set a localized description... String niceName = beautifyName( tablename ); physicalTable.getConcept().setName( locale, niceName ); DatabaseMeta dbMeta = database.getDatabaseMeta(); String schemaTableCombination = dbMeta.getSchemaTableCombination( dbMeta.quoteField( schemaName ), dbMeta.quoteField( tableName ) ); RowMetaInterface row = database.getTableFields( schemaTableCombination ); if ( row != null && row.size() > 0 ) { for ( int i = 0; i < row.size(); i++ ) { ValueMetaInterface v = row.getValueMeta( i ); PhysicalColumn physicalColumn = importPhysicalColumnDefinition( v, physicalTable, locale ); try { fields.add( physicalColumn ); } catch ( ObjectAlreadyExistsException e ) { // Don't add this column // TODO: show error dialog. } } } String upper = tablename.toUpperCase(); if ( upper.startsWith( "D_" ) || upper.startsWith( "DIM" ) || upper.endsWith( "DIM" ) ) { physicalTable.setTableType( TableTypeSettings.DIMENSION ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } if ( upper.startsWith( "F_" ) || upper.startsWith( "FACT" ) || upper.endsWith( "FACT" ) ) { physicalTable.setTableType( TableTypeSettings.FACT ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } return physicalTable; }
Example 14
Source File: PhysicalTableImporter.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 4 votes |
public static SqlPhysicalTable importTableDefinition( Database database, String schemaName, String tableName, String locale, ImportStrategy importStrategy ) throws KettleException { String id = ( Util.getPhysicalTableIdPrefix() + Util.toId( tableName ) ).toUpperCase(); SqlPhysicalTable physicalTable = new SqlPhysicalTable(); physicalTable.setId( id ); physicalTable.setTargetSchema( schemaName ); List<IPhysicalColumn> fields = physicalTable.getPhysicalColumns(); physicalTable.setTargetTable( tableName ); // id, schemaName, tableName, // database.getDatabaseMeta(), fields); // Also set a localized description... String niceName = beautifyName( tableName ); physicalTable.setName( new LocalizedString( locale, niceName ) ); DatabaseMeta dbMeta = database.getDatabaseMeta(); String schemaTableCombination = dbMeta.getSchemaTableCombination( dbMeta.quoteField( schemaName ), dbMeta.quoteField( tableName ) ); RowMetaInterface row = database.getTableFields( schemaTableCombination ); if ( row != null && row.size() > 0 ) { for ( int i = 0; i < row.size(); i++ ) { ValueMetaInterface v = row.getValueMeta( i ); if ( importStrategy.shouldInclude( v ) ) { IPhysicalColumn physicalColumn = importPhysicalColumnDefinition( v, physicalTable, locale, importStrategy ); fields.add( physicalColumn ); } } } String upper = tableName.toUpperCase(); if ( upper.startsWith( "D_" ) || upper.startsWith( "DIM" ) || upper.endsWith( "DIM" ) ) { physicalTable.setTableType( TableType.DIMENSION ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } if ( upper.startsWith( "F_" ) || upper.startsWith( "FACT" ) || upper.endsWith( "FACT" ) ) { physicalTable.setTableType( TableType.FACT ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } return physicalTable; }
Example 15
Source File: JobEntryMysqlBulkLoadDialog.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Get a list of columns, comma separated, allow the user to select from it. */ private void getListColumns() { if ( !Utils.isEmpty( wTablename.getText() ) ) { DatabaseMeta databaseMeta = jobMeta.findDatabase( wConnection.getText() ); if ( databaseMeta != null ) { Database database = new Database( loggingObject, databaseMeta ); database.shareVariablesWith( jobMeta ); try { database.connect(); String schemaTable = databaseMeta.getQuotedSchemaTableCombination( wSchemaname.getText(), wTablename.getText() ); RowMetaInterface row = database.getTableFields( schemaTable ); String[] available = row.getFieldNames(); String[] source = wListattribut.getText().split( "," ); for ( int i = 0; i < source.length; i++ ) { source[i] = Const.trim( source[i] ); } int[] idxSource = Const.indexsOfStrings( source, available ); EnterSelectionDialog dialog = new EnterSelectionDialog( shell, available, BaseMessages.getString( PKG, "JobMysqlBulkLoad.SelectColumns.Title" ), BaseMessages.getString( PKG, "JobMysqlBulkLoad.SelectColumns.Message" ) ); dialog.setMulti( true ); dialog.setAvoidQuickSearch(); dialog.setSelectedNrs( idxSource ); if ( dialog.open() != null ) { String columns = ""; int[] idx = dialog.getSelectionIndeces(); for ( int i = 0; i < idx.length; i++ ) { if ( i > 0 ) { columns += ", "; } columns += available[idx[i]]; } wListattribut.setText( columns ); } } catch ( KettleDatabaseException e ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.Error.Title" ), BaseMessages .getString( PKG, "JobMysqlBulkLoad.ConnectionError2.DialogMessage" ), e ); } finally { database.disconnect(); } } } }
Example 16
Source File: XulDatabaseExplorerController.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void getDDLForOther() { if ( databases != null ) { try { // Now select the other connection... // Only take non-SAP ERP connections.... List<DatabaseMeta> dbs = new ArrayList<DatabaseMeta>(); for ( int i = 0; i < databases.size(); i++ ) { if ( ( ( databases.get( i ) ).getDatabaseInterface().isExplorable() ) ) { dbs.add( databases.get( i ) ); } } String[] conn = new String[dbs.size()]; for ( int i = 0; i < conn.length; i++ ) { conn[i] = ( dbs.get( i ) ).getName(); } EnterSelectionDialog esd = new EnterSelectionDialog( this.dbExplorerDialog.getShell(), conn, BaseMessages.getString( PKG, "DatabaseExplorerDialog.TargetDatabase.Title" ), BaseMessages.getString( PKG, "DatabaseExplorerDialog.TargetDatabase.Message" ) ); String target = esd.open(); if ( target != null ) { DatabaseMeta targetdbi = DatabaseMeta.findDatabase( dbs, target ); Database targetdb = new Database( null, targetdbi ); try { targetdb.connect(); String tableName = getSchemaAndTable( model ); RowMetaInterface r = targetdb.getTableFields( tableName ); String sql = targetdb.getCreateTableStatement( tableName, r, null, false, null, true ); SQLEditor se = new SQLEditor( this.getDatabaseMeta(), this.dbExplorerDialog.getShell(), SWT.NONE, this.model .getDatabaseMeta(), this.dbcache, sql ); se.open(); } finally { targetdb.disconnect(); } } } catch ( KettleDatabaseException dbe ) { new ErrorDialog( this.dbExplorerDialog.getShell(), BaseMessages.getString( PKG, "Dialog.Error.Header" ), BaseMessages .getString( PKG, "DatabaseExplorerDialog.Error.GenDDL" ), dbe ); } } else { MessageBox mb = new MessageBox( this.dbExplorerDialog.getShell(), SWT.NONE | SWT.ICON_INFORMATION ); mb.setMessage( BaseMessages.getString( PKG, "DatabaseExplorerDialog.NoConnectionsKnown.Message" ) ); mb.setText( BaseMessages.getString( PKG, "DatabaseExplorerDialog.NoConnectionsKnown.Title" ) ); mb.open(); } }