use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class ErDiagramComposite method getSchema.
private String getSchema() {
DatabaseConnection connection = (DatabaseConnection) ((ConnectionItem) rootNode.getObject().getProperty().getItem()).getConnection();
String schema = "";
if (ConnectionUtils.isTeradata(connection.getURL())) {
schema = connection.getSID();
} else {
schema = connection.getUiSchema();
}
if (connection.isContextMode()) {
schema = DatabaseConnectionParameterUtil.getContextTrueValue(connection, schema);
}
return schema;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection 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.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class EditQueriesAction method init.
@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
boolean canWork = !selection.isEmpty() && selection.size() == 1;
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (factory.isUserReadOnlyOnCurrentProject()) {
canWork = false;
}
if (canWork) {
Object o = selection.getFirstElement();
repositoryNode = (RepositoryNode) o;
switch(repositoryNode.getType()) {
case REPOSITORY_ELEMENT:
if (repositoryNode.getObject().getRepositoryStatus() == ERepositoryStatus.DELETED || repositoryNode.getObject().getRepositoryStatus() == ERepositoryStatus.LOCK_BY_OTHER) {
canWork = false;
}
// Studio does not support this action for impala, TBD-3827.
if (!isUnderDBConnection(repositoryNode)) {
canWork = false;
}
if (repositoryNode.getObjectType() != ERepositoryObjectType.METADATA_CONNECTIONS && repositoryNode.getObjectType() != ERepositoryObjectType.METADATA_CON_QUERY && repositoryNode.getObjectType() != ERepositoryObjectType.METADATA_CON_TABLE) {
canWork = false;
} else {
// for cdc
if (PluginChecker.isCDCPluginLoaded()) {
ICDCProviderService cdcService = (ICDCProviderService) GlobalServiceRegister.getDefault().getService(ICDCProviderService.class);
if (cdcService != null && cdcService.isSubscriberTableNode(repositoryNode)) {
canWork = false;
break;
}
}
IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
if (!repFactory.isPotentiallyEditable(repositoryNode.getObject())) {
canWork = false;
break;
}
}
if (canWork) {
Item item = repositoryNode.getObject().getProperty().getItem();
if (item instanceof DatabaseConnectionItem) {
DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
DatabaseConnection dbConn = (DatabaseConnection) dbItem.getConnection();
String dbType = dbConn.getDatabaseType();
if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(dbType) || EDatabaseTypeName.HBASE.getXmlName().equalsIgnoreCase(dbType) || EDatabaseTypeName.MAPRDB.getXmlName().equalsIgnoreCase(dbType) || EDatabaseTypeName.IMPALA.getXmlName().equalsIgnoreCase(dbType)) {
canWork = false;
break;
}
}
}
break;
default:
canWork = false;
}
if (canWork && (!ProjectManager.getInstance().isInCurrentMainProject(repositoryNode) || !isLastVersion(repositoryNode))) {
canWork = false;
}
}
setEnabled(canWork);
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class GenerateSelectSQLAction method getTablePrefix.
private String getTablePrefix(IRepositoryNode node) {
RepositoryNode root = SQLBuilderRepositoryNodeManager.getRoot((RepositoryNode) node);
DatabaseConnection connection = (DatabaseConnection) ((ConnectionItem) root.getObject().getProperty().getItem()).getConnection();
if (connection.getUiSchema() != null && !connection.getUiSchema().trim().equals("")) {
//$NON-NLS-1$
return connection.getUiSchema();
} else {
//$NON-NLS-1$
return "";
}
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class GenerateSelectSQLAction method getPrePostfix.
/**
* Get Prepostfix.
*
* @param node the selected node
* @return PrePostfix
*/
private String getPrePostfix(IRepositoryNode node) {
RepositoryNode root = SQLBuilderRepositoryNodeManager.getRoot((RepositoryNode) node);
DatabaseConnection connection = (DatabaseConnection) ((ConnectionItem) root.getObject().getProperty().getItem()).getConnection();
if (TextUtil.isDoubleQuotesNeededDbType(connection.getDatabaseType())) {
//$NON-NLS-1$
return "\"";
}
//$NON-NLS-1$
return "";
}
Aggregations