use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class SessionTreeNodeManager method getSessionTreeNode.
/**
* Converts the DatabaseConnection to SessionTreeNode, and stores the SessionTreeNode.
*
* @param repositoryNode RepositoryNode
* @param selectedContext
* @return SessionTreeNode
*/
public SessionTreeNode getSessionTreeNode(RepositoryNode repositoryNode, String selectedContext) throws Exception {
// Gets the root RepositoryNode
RepositoryNode root = getRoot(repositoryNode);
// Gets the DatabaseConnection
DatabaseConnection connection = (DatabaseConnection) ((ConnectionItem) root.getObject().getProperty().getItem()).getConnection();
if (EDatabaseTypeName.ACCESS.getDisplayName().equals(connection.getDatabaseType())) {
if (connection.getURL().lastIndexOf("=") != connection.getURL().length() - 1) {
//$NON-NLS-1$
connection.setDatasourceName(connection.getURL().substring(connection.getURL().lastIndexOf(File.separator) + 1, connection.getURL().length()));
connection.setSID(connection.getURL().substring(connection.getURL().lastIndexOf(File.separator) + 1, connection.getURL().length()));
}
}
SessionTreeNode sessionTreeNode = map.get(connection);
// hyWang modified for bug 0007062
if (sessionTreeNode != null && !sessionTreeNode.isConnectionClosed()) {
return sessionTreeNode;
}
// If the node is not existent,creates one and cache it.
sessionTreeNode = SessionTreeNodeUtils.getSessionTreeNode(connection, root, selectedContext);
map.put(connection, sessionTreeNode);
return sessionTreeNode;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class CatalogNode method getSchemaName.
/**
* @return SchemaName.
*/
public String getSchemaName() {
DatabaseConnection databaseConnection = getSession().getDatabaseConnection();
if (databaseConnection == null) {
return null;
}
String schema = databaseConnection.getUiSchema();
if (schema != null && schema.length() == 0) {
return null;
}
return ExtractMetaDataUtils.getInstance().getSchema();
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection 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.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class SQLBuilderDialog method close.
@Override
public boolean close() {
try {
SqlBuilderPlugin.getDefault().getRepositoryService().removeRepositoryChangedListener(this);
if (this.nodeInEditor != null) {
RepositoryNode root = SQLBuilderRepositoryNodeManager.getRoot(this.nodeInEditor);
if (root != null) {
DatabaseConnection connection = (DatabaseConnection) ((ConnectionItem) root.getObject().getProperty().getItem()).getConnection();
shutDownDb(connection);
}
}
clean();
SQLBuilderRepositoryNodeManager.removeAllRepositoryNodes();
} catch (Exception e) {
ExceptionHandler.process(e);
} finally {
super.close();
}
return true;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection 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);
}
Aggregations