use of org.talend.core.model.metadata.builder.database.DriverShim in project tdi-studio-se by Talend.
the class SQLBuilderDialog method shutDownDb.
private void shutDownDb(DatabaseConnection databaseConnection) {
IMetadataConnection iMetadataConnection = null;
if (selectedContext == null) {
selectedContext = databaseConnection.getContextName();
}
iMetadataConnection = ConvertionHelper.convert(databaseConnection, false, selectedContext);
String dbType = iMetadataConnection.getDbType();
String driverClassName = iMetadataConnection.getDriverClass();
if (driverClassName.equals(EDatabase4DriverClassName.JAVADB_EMBEDED.getDriverClass()) || dbType.equals(EDatabaseTypeName.JAVADB_EMBEDED.getDisplayName()) || dbType.equals(EDatabaseTypeName.JAVADB_DERBYCLIENT.getDisplayName()) || dbType.equals(EDatabaseTypeName.JAVADB_JCCJDBC.getDisplayName()) || dbType.equals(EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName())) {
String username = iMetadataConnection.getUsername();
String pwd = iMetadataConnection.getPassword();
String dbVersion = iMetadataConnection.getDbVersionString();
String url = iMetadataConnection.getUrl();
Connection connection = null;
DriverShim wapperDriver = null;
try {
List list = ExtractMetaDataUtils.getInstance().connect(dbType, url, username, pwd, driverClassName, iMetadataConnection.getDriverJarPath(), dbVersion, iMetadataConnection.getAdditionalParams());
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof Connection) {
connection = (Connection) list.get(i);
}
if (list.get(i) instanceof DriverShim) {
wapperDriver = (DriverShim) list.get(i);
}
}
}
} catch (Exception e) {
ExceptionHandler.process(e);
} finally {
try {
// for derby
if (wapperDriver != null) {
//$NON-NLS-1$
wapperDriver.connect("jdbc:derby:;shutdown=true", null);
}
if (connection != null) {
// for hsqldb in-process
ConnectionUtils.closeConnection(connection);
}
} catch (SQLException e) {
// exception of shutdown success. no need to catch.
}
}
}
}
use of org.talend.core.model.metadata.builder.database.DriverShim in project tdi-studio-se by Talend.
the class SQLExecution method doExecution.
protected void doExecution() throws Exception {
final long startTime = System.currentTimeMillis();
try {
stmt = connection.createStatement();
//$NON-NLS-1$
setProgressMessage(Messages.getString("SQLResultsView.Executing"));
stmt.setMaxRows(maxRows);
if (isCancelled) {
return;
}
boolean b = stmt.execute(sqlStatement);
if (isCancelled) {
closeStatement();
return;
}
if (b) {
final ResultSet rs = stmt.getResultSet();
if (rs != null) {
if (isCancelled) {
closeStatement();
return;
}
// create new dataset from results
DataSet dataSet = new DataSet(null, rs, null);
final long endTime = System.currentTimeMillis();
// update sql result
sqlResult.setDataSet(dataSet);
sqlResult.setExecutionTimeMillis(endTime - startTime);
closeStatement();
if (isCancelled) {
return;
}
// show results..
displayResults();
// update text on editor
composite.getDisplay().asyncExec(new Runnable() {
public void run() {
}
});
}
} else {
// update text on editor
composite.getDisplay().asyncExec(new Runnable() {
public void run() {
// close tab
parentTab.dispose();
}
});
closeStatement();
if (isCancelled) {
return;
}
}
stmt = null;
} catch (Exception e) {
closeStatement();
throw e;
} finally {
// bug 17980
DriverShim wapperDriver = session.getWapperDriver();
if (wapperDriver != null) {
try {
//$NON-NLS-1$
wapperDriver.connect("jdbc:derby:;shutdown=true", null);
} catch (SQLException e) {
// exception of shutdown success. no need to catch.
}
}
}
}
use of org.talend.core.model.metadata.builder.database.DriverShim in project tdq-studio-se by Talend.
the class ManagedDriver method instanceMSSqlJdbcDriver.
/**
* use jtds SSO mode to connect sqlserver database, only allow to instance driver once.
*
* @param dbType
* @param dbVersion
* @throws ClassNotFoundException
* @throws InstantiationException
* @throws IllegalAccessException
*/
private void instanceMSSqlJdbcDriver(String dbType, String dbVersion) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Map<String, DriverShim> driverCache = ExtractMetaDataUtils.getInstance().getDriverCache();
if (driverCache.containsKey(EDatabase4DriverClassName.MSSQL.getDriverClass())) {
DriverShim driverShim = driverCache.get(EDatabase4DriverClassName.MSSQL.getDriverClass());
jdbcDriver = driverShim;
} else {
instanceJdbcDriver(dbType, dbVersion);
if (jdbcDriver != null) {
DriverShim driverShim = new DriverShim(jdbcDriver);
ExtractMetaDataUtils.getInstance().setDriverCache(driverShim);
}
}
}
use of org.talend.core.model.metadata.builder.database.DriverShim in project tdi-studio-se by Talend.
the class SessionTreeNodeUtils method getSessionTreeNode.
public static SessionTreeNode getSessionTreeNode(DatabaseConnection dbconnection, RepositoryNode repositoryNode, String selectedContext) throws Exception {
// hyWang add for bug 0007014
IMetadataConnection iMetadataConnection = null;
iMetadataConnection = ConvertionHelper.convert(dbconnection, false, selectedContext);
String url = dbconnection.getURL();
if (url == null || url.equals("")) {
url = iMetadataConnection.getUrl();
}
// bug 17980
SQLConnection connection = null;
DriverShim wapperDriver = null;
List list = createSQLConnection(dbconnection, selectedContext, iMetadataConnection);
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof SQLConnection) {
connection = (SQLConnection) list.get(i);
}
if (list.get(i) instanceof DriverShim) {
wapperDriver = (DriverShim) list.get(i);
}
}
}
ISQLAlias alias = createSQLAlias("Repository Name", url, dbconnection.getUsername(), //$NON-NLS-1$
dbconnection.getRawPassword(), // fix bug for 7014,added by hyWang
dbconnection.getSID() == null || dbconnection.getSID().length() == 0 ? (dbconnection.getDatasourceName() == null || //$NON-NLS-1$
dbconnection.getDatasourceName().length() == 0 ? //$NON-NLS-1$
"Database" : dbconnection.getDatasourceName()) : dbconnection.getSID());
SessionTreeModel stm = new SessionTreeModel();
SessionTreeNode session;
if (wapperDriver != null && (iMetadataConnection.getDriverClass().equals(EDatabase4DriverClassName.JAVADB_EMBEDED.getDriverClass()) || iMetadataConnection.getDbType().equals(EDatabaseTypeName.JAVADB_EMBEDED.getDisplayName()) || iMetadataConnection.getDbType().equals(EDatabaseTypeName.JAVADB_DERBYCLIENT.getDisplayName()) || iMetadataConnection.getDbType().equals(EDatabaseTypeName.JAVADB_JCCJDBC.getDisplayName()) || iMetadataConnection.getDbType().equals(EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName()))) {
session = stm.createSessionTreeNode(new SQLConnection[] { connection, connection }, alias, null, dbconnection.getRawPassword(), repositoryNode, wapperDriver);
} else {
session = stm.createSessionTreeNode(new SQLConnection[] { connection, connection }, alias, null, dbconnection.getRawPassword(), repositoryNode);
}
return session;
}
use of org.talend.core.model.metadata.builder.database.DriverShim in project tdi-studio-se by Talend.
the class DbInfo method getConnFromNode.
private void getConnFromNode() {
DriverShim wapperDriver = null;
ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
try {
List list = null;
if (dbType.equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName())) {
list = extractMeta.connect(trueDBTypeForJDBC, url, username, pwd, driverClassName, driverJarPath, dbVersion, additionalParams);
} else {
// driverJarPath set to null,to reget driverJarPath
driverJarPath = "";
list = extractMeta.connect(dbType, url, username, pwd, driverClassName, driverJarPath, dbVersion, additionalParams);
}
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof Connection) {
conn = (Connection) list.get(i);
}
if (list.get(i) instanceof DriverShim) {
wapperDriver = (DriverShim) list.get(i);
}
}
}
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
} finally {
// bug 9162
try {
// if HSQLDB_IN_PROGRESS connection is not closed,HSQLDB_IN_PROGRESS can't open
if (conn != null) {
ConnectionUtils.closeConnection(conn);
}
if (wapperDriver != null && isJavaDB()) {
//$NON-NLS-1$
wapperDriver.connect("jdbc:derby:;shutdown=true", null);
}
} catch (SQLException e) {
// exception of shutdown success. no need to catch.
}
}
}
Aggregations