Search in sources :

Example 6 with DatabaseConnection

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;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 7 with DatabaseConnection

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.
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection) Driver(java.sql.Driver) ExtractMetaDataUtils(org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils) DatabaseMetaData(java.sql.DatabaseMetaData) SQLException(java.sql.SQLException) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 8 with DatabaseConnection

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);
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ICDCProviderService(org.talend.core.ui.ICDCProviderService) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IRepositoryService(org.talend.repository.model.IRepositoryService) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 9 with DatabaseConnection

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 "";
    }
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 10 with DatabaseConnection

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 "";
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode)

Aggregations

DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)211 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)66 Connection (org.talend.core.model.metadata.builder.connection.Connection)53 ConnectionItem (org.talend.core.model.properties.ConnectionItem)42 ArrayList (java.util.ArrayList)41 PersistenceException (org.talend.commons.exception.PersistenceException)41 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)39 Test (org.junit.Test)33 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)30 Property (org.talend.core.model.properties.Property)30 Item (org.talend.core.model.properties.Item)26 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)20 IElementParameter (org.talend.core.model.process.IElementParameter)19 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)18 RepositoryNode (org.talend.repository.model.RepositoryNode)18 SQLException (java.sql.SQLException)17 TdTable (org.talend.cwm.relational.TdTable)17 Catalog (orgomg.cwm.resource.relational.Catalog)17 List (java.util.List)15 ReturnCode (org.talend.utils.sugars.ReturnCode)14