本文整理汇总了Java中org.pentaho.di.core.database.Database.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Java Database.disconnect方法的具体用法?Java Database.disconnect怎么用?Java Database.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.pentaho.di.core.database.Database
的用法示例。
在下文中一共展示了Database.disconnect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDDL
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
public void getDDL(String tableName)
{
Database db = new Database(dbMeta);
try
{
db.connect();
RowMetaInterface r = db.getTableFields(tableName);
String sql = db.getCreateTableStatement(tableName, r, null, false, null, true);
SQLEditor se = new SQLEditor(dbMeta, shell, SWT.NONE, dbMeta, dbcache, sql);
se.open();
}
catch(KettleDatabaseException dbe)
{
new ErrorDialog(shell, BaseMessages.getString(PKG,"Dialog.Error.Header"),
BaseMessages.getString(PKG,"DatabaseExplorerDialog.Error.RetrieveLayout"), dbe);
}
finally
{
db.disconnect();
}
}
示例2: getDDL
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
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();
}
}
示例3: getSchemaNames
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
/**
* Presents a dialog box to select a schema from the database. Then sets the selected schema in the dialog
*/
private void getSchemaNames() {
DatabaseMeta databaseMeta = transMeta.findDatabase( wConnection.getText() );
if ( databaseMeta != null ) {
Database database = new Database( loggingObject, databaseMeta );
try {
database.connect();
String[] schemas = database.getSchemas();
if ( null != schemas && schemas.length > 0 ) {
schemas = Const.sortStrings( schemas );
EnterSelectionDialog dialog =
new EnterSelectionDialog( shell, schemas, BaseMessages.getString(
PKG, "SnowflakeBulkLoader.Dialog.AvailableSchemas.Title", wConnection.getText() ), BaseMessages
.getString( PKG, "SnowflakeBulkLoader.Dialog.AvailableSchemas.Message", wConnection.getText() ) );
String d = dialog.open();
if ( d != null ) {
wSchema.setText( Const.NVL( d, "" ) );
setTableFieldCombo();
}
} else {
MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
mb.setMessage( BaseMessages.getString( PKG, "SnowflakeBulkLoader.Dialog.NoSchema.Error" ) );
mb.setText( BaseMessages.getString( PKG, "SnowflakeBulkLoader.Dialog.GetSchemas.Error" ) );
mb.open();
}
} catch ( Exception e ) {
new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.Error.Title" ), BaseMessages
.getString( PKG, "SnowflakeBulkLoader.Dialog.ErrorGettingSchemas" ), e );
} finally {
database.disconnect();
}
}
}
示例4: getRequiredFields
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
/**
* Gets a list of fields in the database table
* @param space The variable space
* @return The metadata about the fields in the table.
* @throws KettleException
*/
public RowMetaInterface getRequiredFields( VariableSpace space ) throws KettleException {
String realTableName = space.environmentSubstitute( targetTable );
String realSchemaName = space.environmentSubstitute( targetSchema );
if ( databaseMeta != null ) {
Database db = new Database( loggingObject, databaseMeta );
try {
db.connect();
if ( !Const.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, "SnowflakeBulkLoaderMeta.Exception.TableNotFound" ) );
}
} else {
throw new KettleException( BaseMessages.getString( PKG, "SnowflakeBulkLoaderMeta.Exception.TableNotSpecified" ) );
}
} catch ( Exception e ) {
throw new KettleException(
BaseMessages.getString( PKG, "SnowflakeBulkLoaderMeta.Exception.ErrorGettingFields" ), e );
} finally {
db.disconnect();
}
} else {
throw new KettleException( BaseMessages.getString( PKG, "SnowflakeBulkLoaderMeta.Exception.ConnectionNotDefined" ) );
}
}
示例5: getSQLStatements
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev)
{
SQLStatement retval = new SQLStatement(stepMeta.getName(), database, null); // default: nothing to do!
if (useDatabase) // Otherwise, don't bother!
{
if (database!=null)
{
Database db = new Database(loggingObject, database);
db.shareVariablesWith(transMeta);
try
{
db.connect();
if (!db.checkSequenceExists(schemaName, sequenceName))
{
String cr_table = db.getCreateSequenceStatement(sequenceName, startAt, incrementBy, maxValue, true);
retval.setSQL(cr_table);
}
else
{
retval.setSQL(null); // Empty string means: nothing to do: set it to null...
}
}
catch(KettleException e)
{
retval.setError(BaseMessages.getString(PKG, "AddSequenceMeta.ErrorMessage.UnableToConnectDB")+Const.CR+e.getMessage()); //$NON-NLS-1$
}
finally
{
db.disconnect();
}
}
else
{
retval.setError(BaseMessages.getString(PKG, "AddSequenceMeta.ErrorMessage.NoConnectionDefined")); //$NON-NLS-1$
}
}
return retval;
}
示例6: getRequiredFields
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
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 (!Const.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"));
}
}
示例7: getTableFields
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
private RowMetaInterface getTableFields(LoggingObjectInterface parentLoggingObject) throws KettleDatabaseException {
Database database = new Database(parentLoggingObject, databaseMeta);
try {
database.connect();
return database.getTableFields(schemaTable);
}
finally {
database.disconnect();
}
}
示例8: injectDataSetIntoStep
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
private void injectDataSetIntoStep( final Trans trans, final TransMeta transMeta,
final String dataSetName, final MetaStoreFactory<DataSet> dataSetFactory,
final Repository repository, final IMetaStore metaStore, final StepMeta stepMeta,
TransUnitTestSetLocation inputLocation ) throws MetaStoreException, KettleException {
final DataSet dataSet = dataSetFactory.loadElement( dataSetName );
final DataSetGroup group = dataSet.getGroup();
final Database database = new Database( trans, group.getDatabaseMeta() );
final LogChannelInterface log = trans.getLogChannel();
final RowMetaInterface injectRowMeta = DataSetConst.getStepOutputFields(log, transMeta, stepMeta, dataSet, inputLocation);
final RowProducer rowProducer = trans.addRowProducer( stepMeta.getName(), 0 );
// Look for the step into which we'll inject rows...
//
StepMetaDataCombi combi = null;
for ( StepMetaDataCombi step : trans.getSteps() ) {
if ( step.stepname.equals( stepMeta.getName() ) ) {
combi = step;
break;
}
}
if ( combi != null ) {
log.logBasic( "Injecting data set '" + dataSetName + "' into step '" + stepMeta.getName() + "', fields: "+injectRowMeta.toStringMeta() );
final List<Object[]> rows = dataSet.getAllRows(log, inputLocation, injectRowMeta);
// Pass rows
try {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
for( Object[] row : rows ) {
// pass the row with the external names
//
rowProducer.putRow( injectRowMeta, row );
}
rowProducer.finished();
} catch ( Exception e ) {
throw new RuntimeException( "Problem injecting data set '" + dataSetName + "' row into step '" + stepMeta.getName() + "'", e );
}
}
};
Thread thread = new Thread( runnable );
thread.start();
} finally {
database.disconnect();
}
}
}
示例9: getListColumns
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
/**
* Get a list of columns, comma separated, allow the user to select from it.
*
*/
private void getListColumns()
{
if (!Const.isEmpty(wTablename.getText()))
{
DatabaseMeta databaseMeta = jobMeta.findDatabase(wConnection.getText());
if (databaseMeta!=null)
{
Database database = new Database(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[] = wListColumn.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, Messages.getString("JobMysqlBulkFile.SelectColumns.Title"), Messages.getString("JobMysqlBulkFile.SelectColumns.Message"));
dialog.setMulti(true);
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]];
}
wListColumn.setText(columns);
}
}
catch(KettleDatabaseException e)
{
new ErrorDialog(shell, Messages.getString("System.Dialog.Error.Title"), Messages.getString("JobMysqlBulkFile.ConnectionError2.DialogMessage"), e);
}
finally
{
database.disconnect();
}
}
}
}
示例10: getLastExecutionResult
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
public static String getLastExecutionResult(LogChannelInterface log, LoggingObjectInterface parentObject, ReportSubjectLocation filename) throws KettleException {
LogTableInterface logTable=null;
if (filename.isTransformation()) {
TransMeta transMeta = TransformationInformation.getInstance().getTransMeta(filename);
logTable = transMeta.getTransLogTable();
} else {
JobMeta jobMeta = JobInformation.getInstance().getJobMeta(filename);
logTable = jobMeta.getJobLogTable();
}
if (logTable!=null && logTable.isDefined()) {
DatabaseMeta dbMeta = logTable.getDatabaseMeta();
Database database = new Database(parentObject, dbMeta);
try {
database.connect();
String sql="SELECT ";
sql+=dbMeta.quoteField(logTable.getStatusField().getFieldName())+", ";
sql+=dbMeta.quoteField(logTable.getLogDateField().getFieldName())+", ";
sql+=dbMeta.quoteField(logTable.getErrorsField().getFieldName())+"";
sql+=" FROM ";
sql+=dbMeta.getQuotedSchemaTableCombination(logTable.getSchemaName(), logTable.getTableName());
sql+=" ORDER BY "+dbMeta.quoteField(logTable.getLogDateField().getFieldName())+" DESC";
RowMetaAndData oneRow = database.getOneRow(sql);
String status = oneRow.getString(0, "?");
Date date = oneRow.getDate(1, null);
Long nrErrors = oneRow.getInteger(2);
String evaluation;
if (status.equalsIgnoreCase(LogStatus.END.getStatus())) {
evaluation = "Ended";
} else if (status.equalsIgnoreCase(LogStatus.START.getStatus())) {
evaluation = "Started";
} else if (status.equalsIgnoreCase(LogStatus.STOP.getStatus())) {
evaluation = "Stopped";
} else if (status.equalsIgnoreCase(LogStatus.RUNNING.getStatus())) {
evaluation = "Running";
} else if (status.equalsIgnoreCase(LogStatus.PAUSED.getStatus())) {
evaluation = "Paused";
} else if (status.equalsIgnoreCase(LogStatus.ERROR.getStatus())) {
evaluation = "Failed";
} else {
evaluation = "Unknown";
}
if (nrErrors>0) {
evaluation+=" with errors";
} else {
evaluation+=" with success";
}
return evaluation+" at "+XMLHandler.date2string(date);
} catch(Exception e) {
log.logBasic("Unable to get logging information from log table"+logTable);
} finally {
database.disconnect();
}
}
return null;
}
示例11: getSchemaNames
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
private void getSchemaNames()
{
if(wSchema.isDisposed()) return;
DatabaseMeta databaseMeta = transMeta.findDatabase(wConnection.getText());
if (databaseMeta!=null)
{
Database database = new Database(loggingObject, databaseMeta);
try
{
database.connect();
String schemas[] = database.getSchemas();
if (null != schemas && schemas.length>0) {
schemas=Const.sortStrings(schemas);
EnterSelectionDialog dialog = new EnterSelectionDialog(shell, schemas,
BaseMessages.getString(PKG, "AddSequenceDialog.SelectSequence.Title",wConnection.getText()),
BaseMessages.getString(PKG, "AddSequenceDialog.SelectSequence.Message"));
String d=dialog.open();
if (d!=null)
{
wSchema.setText(Const.NVL(d.toString(), ""));
}
}else
{
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR );
mb.setMessage(BaseMessages.getString(PKG,"AddSequenceDialog.NoSchema.Message"));
mb.setText(BaseMessages.getString(PKG,"AddSequenceDialog.NoSchema.Title"));
mb.open();
}
}
catch(Exception e)
{
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"),
BaseMessages.getString(PKG, "AddSequenceDialog.ErrorGettingSchemas"), e);
}
finally
{
if(database!=null)
{
database.disconnect();
database=null;
}
}
}
}
示例12: getSchemaNames
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
private void getSchemaNames()
{
if(wSchemaname.isDisposed()) return;
DatabaseMeta databaseMeta = transMeta.findDatabase(wConnection.getText());
if (databaseMeta!=null)
{
Database database = new Database(loggingObject, databaseMeta);
database.shareVariablesWith(transMeta);
try
{
database.connect();
String schemas[] = database.getSchemas();
if (null != schemas && schemas.length>0) {
schemas=Const.sortStrings(schemas);
EnterSelectionDialog dialog = new EnterSelectionDialog(shell, schemas,
BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.Title", wConnection.getText()),
BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.Message"));
String d=dialog.open();
if (d!=null)
{
wSchemaname.setText(Const.NVL(d.toString(), ""));
}
}else
{
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR );
mb.setMessage(BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.Empty.Message"));
mb.setText(BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.Empty.Title"));
mb.open();
}
}
catch(Exception e)
{
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"),
BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.ConnectionError"), e);
}
finally
{
if(database!=null)
{
database.disconnect();
database=null;
}
}
}
}
示例13: getRequiredFields
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
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 (!Const.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"));
}
}
示例14: getSQLStatements
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev)
{
SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null); // default: nothing to do!
if (databaseMeta!=null)
{
if (prev!=null && prev.size()>0)
{
if (!Const.isEmpty(tablename))
{
Database db = new Database(databaseMeta);
db.shareVariablesWith(transMeta);
try
{
db.connect();
String schemaTable = databaseMeta.getQuotedSchemaTableCombination(schemaName, tablename);
String cr_table = db.getDDL(schemaTable, prev);
// Empty string means: nothing to do: set it to null...
if (cr_table==null || cr_table.length()==0) cr_table=null;
retval.setSQL(cr_table);
}
catch(KettleDatabaseException dbe)
{
retval.setError(Messages.getString("SQLFileOutputMeta.Error.ErrorConnecting", dbe.getMessage()));
}
finally
{
db.disconnect();
}
}
else
{
retval.setError(Messages.getString("SQLFileOutputMeta.Exception.TableNotSpecified"));
}
}
else
{
retval.setError(Messages.getString("SQLFileOutputMeta.Error.NoInput"));
}
}
else
{
retval.setError(Messages.getString("SQLFileOutputMeta.Error.NoConnection"));
}
return retval;
}
示例15: getSchemaNames
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
private void getSchemaNames()
{
DatabaseMeta databaseMeta = transMeta.findDatabase(wConnection.getText());
if (databaseMeta!=null)
{
Database database = new Database(loggingObject, databaseMeta);
try
{
database.connect();
String schemas[] = database.getSchemas();
if (null != schemas && schemas.length>0) {
schemas=Const.sortStrings(schemas);
EnterSelectionDialog dialog = new EnterSelectionDialog(shell, schemas,
BaseMessages.getString(PKG,"InsertUpDateDialog.AvailableSchemas.Title",wConnection.getText()),
BaseMessages.getString(PKG,"InsertUpDateDialog.AvailableSchemas.Message",wConnection.getText()));
String d=dialog.open();
if (d!=null)
{
wSchema.setText(Const.NVL(d.toString(), ""));
setTableFieldCombo();
}
}else
{
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR );
mb.setMessage(BaseMessages.getString(PKG,"InsertUpDateDialog.NoSchema.Error"));
mb.setText(BaseMessages.getString(PKG,"InsertUpDateDialog.GetSchemas.Error"));
mb.open();
}
}
catch(Exception e)
{
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"),
BaseMessages.getString(PKG,"InsertUpDateDialog.ErrorGettingSchemas"), e);
}
finally
{
if(database!=null)
{
database.disconnect();
database=null;
}
}
}
}