use of org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils in project tdi-studio-se by Talend.
the class MetadataColumnComparator method getDatabaseMetaData.
/**
* method "getDatabaseMetaData" get databaseMetaData.
*
* @param iMetadataConnection contains connection
* @return dbMetaData DatabaseMetaData .
* @throws SQLException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
*/
public DatabaseMetaData getDatabaseMetaData(IMetadataConnection iMetadataConnection) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
extractMeta.getConnection(iMetadataConnection.getDbType(), iMetadataConnection.getUrl(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDatabase(), iMetadataConnection.getSchema(), iMetadataConnection.getDriverClass(), iMetadataConnection.getDriverJarPath(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getAdditionalParams());
String dbType = iMetadataConnection.getDbType();
DatabaseMetaData dbMetaData = null;
// Added by Marvin Wang on Mar. 13, 2013 for loading hive jars dynamically, refer to TDI-25072.
if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(dbType)) {
dbMetaData = HiveConnectionManager.getInstance().extractDatabaseMetaData(iMetadataConnection);
} else {
dbMetaData = extractMeta.getDatabaseMetaData(extractMeta.getConn(), dbType, iMetadataConnection.isSqlMode(), iMetadataConnection.getDatabase());
}
return dbMetaData;
}
use of org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils in project tdi-studio-se by Talend.
the class GuessSchemaController method runShadowProcessForPerl.
private void runShadowProcessForPerl() {
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(this.composite.getShell());
try {
pmd.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (columns != null) {
columns.clear();
}
//$NON-NLS-1$
monitor.beginTask(Messages.getString("GuessSchemaController.waitOpenDatabase"), IProgressMonitor.UNKNOWN);
if (connParameters == null) {
initConnectionParameters();
}
ISQLBuilderService service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
DatabaseConnection connt = service.createConnection(connParameters);
IMetadataConnection iMetadataConnection = null;
boolean isStatus = false;
ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
if (connt != null) {
iMetadataConnection = ConvertionHelper.convert(connt);
isStatus = checkConnection(iMetadataConnection);
}
if (!monitor.isCanceled()) {
try {
if (isStatus) {
extractMeta.getConnection(iMetadataConnection.getDbType(), iMetadataConnection.getUrl(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDatabase(), iMetadataConnection.getSchema(), iMetadataConnection.getDriverClass(), iMetadataConnection.getDriverJarPath(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getAdditionalParams());
if (extractMeta.getConn() != null) {
Statement smst = extractMeta.getConn().createStatement();
extractMeta.setQueryStatementTimeout(smst);
ResultSet rs = smst.executeQuery(memoSQL);
ResultSetMetaData rsmd = rs.getMetaData();
int numbOfColumn = rsmd.getColumnCount();
int count = 0;
List<String[]> cvsArrays = new ArrayList<String[]>();
while (rs.next() && count < 50) {
String[] dataOneRow = new String[numbOfColumn];
for (int i = 1; i <= numbOfColumn; i++) {
String tempStr = rs.getString(i);
dataOneRow[i - 1] = tempStr;
}
cvsArrays.add(dataOneRow);
count++;
}
refreshMetaDataTable(rsmd, cvsArrays);
extractMeta.closeConnection();
}
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//$NON-NLS-1$
String pid = "org.talend.sqlbuilder";
//$NON-NLS-1$
String mainMsg = "Database connection is failed. ";
ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
if (dialog.getCodeOfButton() == Window.OK) {
openParamemerDialog(composite.getShell(), part.getProcess().getContextManager());
}
}
});
}
} catch (Exception e) {
extractMeta.closeConnection();
ExceptionHandler.process(e);
final String strExcepton = "Connect to DB error ,or some errors in SQL query string, or 'Guess Schema' not compatible with current SQL query string." + System.getProperty("line.separator");
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(composite.getShell(), Messages.getString("GuessSchemaController.connError"), //$NON-NLS-1$
strExcepton);
}
});
}
}
}
});
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
use of org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils 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