use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.
the class MetadataColumnComparator method updatePackage.
private void updatePackage(IMetadataConnection metadataConnectionTemp) {
if (metadataConnectionTemp == null) {
return;
}
Driver derbyDriver = null;
java.sql.Connection sqlConn = null;
ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
// get dbType before get connection so that the dbtype won't be null.TDI-18366
String dbType = metadataConnectionTemp.getDbType();
DatabaseConnection dbConn = (DatabaseConnection) metadataConnectionTemp.getCurrentConnection();
List list = MetadataConnectionUtils.getConnection(metadataConnectionTemp);
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof Driver) {
String driverClass = metadataConnectionTemp.getDriverClass();
if (MetadataConnectionUtils.isDerbyRelatedDb(driverClass, dbType)) {
derbyDriver = (Driver) list.get(i);
}
}
if (list.get(i) instanceof java.sql.Connection) {
sqlConn = (java.sql.Connection) list.get(i);
}
}
try {
if (sqlConn != null) {
DatabaseMetaData dm = null;
// Added by Marvin Wang on Mar. 13, 2013 for loading hive jars dynamically, refer to TDI-25072.
if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(dbType)) {
dm = HiveConnectionManager.getInstance().extractDatabaseMetaData(metadataConnectionTemp);
} else {
dm = extractMeta.getDatabaseMetaData(sqlConn, dbType, false, metadataConnectionTemp.getDatabase());
}
MetadataFillFactory.getDBInstance().fillCatalogs(dbConn, dm, MetadataConnectionUtils.getPackageFilter(dbConn, dm, true));
MetadataFillFactory.getDBInstance().fillSchemas(dbConn, dm, MetadataConnectionUtils.getPackageFilter(dbConn, dm, false));
}
} catch (Exception e) {
ExceptionHandler.process(e);
} finally {
if (sqlConn != null) {
ConnectionUtils.closeConnection(sqlConn);
}
if (derbyDriver != null) {
try {
//$NON-NLS-1$
derbyDriver.connect("jdbc:derby:;shutdown=true", null);
} catch (SQLException e) {
// exception of shutdown success. no need to catch.
}
}
}
}
use of org.talend.core.model.metadata.IMetadataConnection 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.IMetadataConnection in project tdi-studio-se by Talend.
the class MetadataColumnComparator method saveEMFMetadataColumn.
@SuppressWarnings("unchecked")
private static void saveEMFMetadataColumn(String id, List<MetadataColumn> columnNodes) {
DatabaseConnectionItem item = getEMFItem(id);
final DatabaseConnection connection = (DatabaseConnection) item.getConnection();
IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection);
Set<MetadataTable> tableset = ConnectionHelper.getTables(connection);
List<MetadataTable> tables = new ArrayList<MetadataTable>();
tables.addAll(tableset);
List<MetadataColumn> emfCols = new ArrayList<MetadataColumn>();
List<MetadataColumn> dbCols = new ArrayList<MetadataColumn>();
for (MetadataColumn col : columnNodes) {
for (MetadataTable table : tables) {
if (table.getLabel().equals(col.getTable().getLabel())) {
List<TdColumn> returnCols = ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, table.getSourceName());
for (MetadataColumn emfcolumn : table.getColumns()) {
for (MetadataColumn column : returnCols) {
if (emfcolumn.getLabel().equals(col.getLabel()) && column.getLabel().equals(col.getOriginalField())) {
emfCols.add(emfcolumn);
dbCols.add(column);
}
}
}
}
}
}
saveOneMetadataColumn(emfCols, columnNodes, dbCols);
saveMetaData(item);
}
use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.
the class MetadataColumnComparator method getRepositoryNodeFromDB.
/**
* method "getRepositoryNodeFromDB".
*
* @param oldNode
* @return
*/
@SuppressWarnings("unchecked")
public RepositoryNode getRepositoryNodeFromDB(RepositoryNode oldNode, String selectedContext) {
DatabaseConnectionItem item = getItem(getRoot(oldNode));
DatabaseConnection connection = (DatabaseConnection) item.getConnection();
IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection, false, selectedContext);
try {
modifyOldRepositoryNode(connection, iMetadataConnection, oldNode);
} catch (Exception e) {
ExceptionHandler.process(e);
}
return oldNode;
}
use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.
the class AbstractElementPropertySectionController method isConnectionExist.
protected boolean isConnectionExist() {
ISQLBuilderService service = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ISQLBuilderService.class)) {
service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
}
if (service == null) {
return false;
}
if (contextManager != null && contextManager.getDefaultContext().getContextParameterList().size() != 0) {
initConnectionParametersWithContext(elem, contextManager.getDefaultContext());
}
DatabaseConnection connection = service.createConnection(connParameters);
if (connection != null) {
IMetadataConnection metadataConnection = null;
metadataConnection = ConvertionHelper.convert(connection);
return checkExistConnections(metadataConnection);
}
return false;
}
Aggregations