本文整理汇总了Java中org.pentaho.di.core.database.Database.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java Database.getConnection方法的具体用法?Java Database.getConnection怎么用?Java Database.getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.pentaho.di.core.database.Database
的用法示例。
在下文中一共展示了Database.getConnection方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConnection
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
public Connection getConnection() throws SQLException {
Database database = new Database( databaseMeta );
try {
database.connect();
} catch ( KettleException e ) {
e.printStackTrace();
throw new SQLException( e.getMessage() );
}
return database.getConnection();
}
示例2: initConnection
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
/**
* Initialize the connection
* @param meta
* @param data
* @throws Exception
*/
private void initConnection(JdbcMetaDataMeta meta, JdbcMetaDataData data) throws Exception {
//Try to establish a connection in advance
logDebug("Try to establish a connection in advance.");
String connectionSource = meta.getConnectionSource();
logDebug("Connection source: " + connectionSource);
Connection connection;
if (JdbcMetaDataMeta.connectionSourceOptionConnection.equals(connectionSource)) {
//connection is a named kettle connection
Database database = findDatabase(meta.getConnectionName());
database.connect();
connection = database.getConnection();
if (connection == null) {
throw new Exception("Connection returned by database object is null!");
}
data.database = database;
}
else
if (JdbcMetaDataMeta.connectionSourceOptionJDBC.equals(connectionSource)) {
//connection is a user-entered jdbc connection
String jdbcDriver = environmentSubstitute(meta.getJdbcDriverField());
String jdbcUrl = environmentSubstitute(meta.getJdbcUrlField());
String jdbcUser = environmentSubstitute(meta.getJdbcUserField());
String jdbcPassword = environmentSubstitute(meta.getJdbcPasswordField());
logDebug("Attempt to create JDBC connection.");
logDebug("Driver: " + jdbcDriver);
logDebug("Url: " + jdbcUrl);
logDebug("User: " + jdbcUser);
connection = createJdbcConnection(jdbcDriver, jdbcUrl, jdbcUser, jdbcPassword);
}
else
if (JdbcMetaDataMeta.connectionSourceOptionJDBCFields.equals(connectionSource)) {
//Connection is a jdbc connection specified by field values
//we don't know the field values yet, but we can initialize a few vars to access their value later on
connection = null;
data.jdbcDriverField = -1;
data.jdbcUrlField = -1;
data.jdbcUserField = -1;
data.jdbcPasswordField = -1;
}
else
if (JdbcMetaDataMeta.connectionSourceOptionConnectionField.equals(connectionSource)){
//Connection is a named kettle connection specified by a field value
//we don't know about the field value yet, but we can initialize a var to access its value later on
connection = null;
data.connectionField = -1;
}
else {
//should not arrive here, just initialize the connection to make the compiler shut up.
connection = null;
}
//if the connection is null at this point, then we need to establish it on a row by row basis
data.connection = connection;
}
示例3: getConnection
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
/**
* This is called in the processRow function to obtain the contain to apply the metadat method to.
* @param meta
* @param data
* @param row
* @return
* @throws Exception
*/
private Connection getConnection(JdbcMetaDataMeta meta, JdbcMetaDataData data, Object[] row) throws Exception{
Connection connection;
if (data.connection == null) {
//connection could not be initialized at init, so we have to obtain it now on a row by row basis.
String connectionSource = meta.getConnectionSource();
if (JdbcMetaDataMeta.connectionSourceOptionConnectionField.equals(connectionSource)) {
//connection is a named kettle connection specified by a field value
String connectionName = getConnectionNameFromRow(data, row);
//try to get this named connection from the cache
Database database = data.databases.get(connectionName);
if (database == null) {
//we haven't seen this named connection before, try to find it.
database = findDatabase(connectionName);
database.connect();
connection = database.getConnection();
if (connection == null) {
throw new IllegalArgumentException("Connection returned by database is null!");
}
//cache the database for later use
data.databases.put(connectionName, database);
}
else {
//database found in cache, get its connection
connection = database.getConnection();
}
}
else
if (JdbcMetaDataMeta.connectionSourceOptionJDBCFields.equals(connectionSource)) {
//database connectin is a jdbc connection defined by field values.
//try to find this connection in the cache
String[] key = data.connectionKey;
key[0] = getJdbcDriverFromRow(data, row);
key[1] = getJdbcUrlFromRow(data, row);
key[2] = getJdbcUserFromRow(data, row);
key[3] = getJdbcPasswordFromRow(data, row);
connection = data.connections.get(key);
if (connection == null) {
//connection not yet in the cache. Let's create it and cahce it.
connection = createJdbcConnection(key[0], key[1], key[2], key[3]);
data.connections.put(key, connection);
}
}
else {
throw new Exception("Unexpected error acquiring connection");
}
}
else {
connection = data.connection;
}
return connection;
}
示例4: databaseSetup
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
void databaseSetup(InfobrightLoaderMeta meta, InfobrightLoader step) throws KettleException {
db = new Database(meta.getDatabaseMeta());
db.connect();
// FIXME: This will fail if the first row of the table contains a value that
// cannot be read by Java. For example, a DATE field that contains the value
// '0000-00-00'. In this case, the Kettle error message will misleadingly say
// that the table doesn't exist. There doesn't seem to be any workaround.
// See Pentaho JIRA: PDI-2117.
//
requiredRowMeta = meta.getRequiredFields(step);
requiredFields = requiredRowMeta.getFieldNames();
try {
// once the loader is built, this db connection cannot be used by this thread anymore.
// the loader is using it and any other uses of the connection will block.
if (meta.getInfobrightProductType() == null) {
meta.setDataFormat(DataFormat.TXT_VARIABLE); // default for ICE
}
DataFormat dataFormat = DataFormat.valueForDisplayName(meta.getInfobrightProductType());
Connection conn = db.getConnection();
String tableName = meta.getDatabaseMeta().getQuotedSchemaTableCombination(step.environmentSubstitute(meta.getSchemaName()), step.environmentSubstitute(meta.getTablename()));
EtlLogger logger = new KettleEtlLogger(step);
loader = new InfobrightNamedPipeLoader(tableName, conn, logger, dataFormat);
record = loader.createRecord(false); // TODO set to true to support error path
loader.start();
} catch (Exception e) {
db.disconnect();
db = null;
if (loader != null) {
try {
loader.killQuery();
} catch (SQLException e1) {
throw new KettleDatabaseException(e1);
}
}
throw new KettleDatabaseException(e);
}
}
示例5: databaseSetup
import org.pentaho.di.core.database.Database; //导入方法依赖的package包/类
void databaseSetup(InfobrightLoaderMeta meta, InfobrightLoader step) throws KettleException {
db = new Database(step, meta.getDatabaseMeta());
db.connect();
// FIXME: This will fail if the first row of the table contains a value that
// cannot be read by Java. For example, a DATE field that contains the value
// '0000-00-00'. In this case, the Kettle error message will misleadingly say
// that the table doesn't exist. There doesn't seem to be any workaround.
// See Pentaho JIRA: PDI-2117.
//
requiredRowMeta = meta.getRequiredFields(step);
requiredFields = requiredRowMeta.getFieldNames();
try {
// once the loader is built, this db connection cannot be used by this thread anymore.
// the loader is using it and any other uses of the connection will block.
if (meta.getInfobrightProductType() == null) {
meta.setDataFormat(DataFormat.TXT_VARIABLE); // default for ICE
}
DataFormat dataFormat = DataFormat.valueForDisplayName(meta.getInfobrightProductType());
int agentPort = meta.getAgentPort();
Charset charset = meta.getCharset();
Connection conn = db.getConnection();
String tableName = meta.getDatabaseMeta().getQuotedSchemaTableCombination(step.environmentSubstitute(meta.getSchemaName()), step.environmentSubstitute(meta.getTablename()));
EtlLogger logger = new KettleEtlLogger(step);
loader = new InfobrightNamedPipeLoader(tableName, conn, logger, dataFormat, charset, agentPort);
loader.setTimeout(30);
String debugFile = meta.getDebugFile();
if (debugFile != null) {
OutputStream debugOutputStream = new FileOutputStream(debugFile);
loader.setDebugOutputStream(debugOutputStream);
}
record = loader.createRecord(false); // TODO set to true to support error path
loader.start();
} catch (Exception e) {
db.disconnect();
db = null;
if (loader != null) {
try {
loader.killQuery();
} catch (SQLException e1) {
throw new KettleDatabaseException(e1);
}
}
throw new KettleDatabaseException(e);
}
}