Search in sources :

Example 6 with ExtractMetaDataUtils

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;
}
Also used : ExtractMetaDataUtils(org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 7 with ExtractMetaDataUtils

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);
    }
}
Also used : ErrorDialogWithDetailAreaAndContinueButton(org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton) Statement(java.sql.Statement) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) ExtractMetaDataUtils(org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) ProcessorException(org.talend.designer.runprocess.ProcessorException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ResultSetMetaData(java.sql.ResultSetMetaData) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ResultSet(java.sql.ResultSet) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 8 with ExtractMetaDataUtils

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.
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ExtractMetaDataUtils(org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils) List(java.util.List) DriverShim(org.talend.core.model.metadata.builder.database.DriverShim) SQLException(java.sql.SQLException)

Aggregations

ExtractMetaDataUtils (org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils)8 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)5 List (java.util.List)4 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)3 DatabaseMetaData (java.sql.DatabaseMetaData)2 Connection (org.talend.core.model.metadata.builder.connection.Connection)2 IElementParameter (org.talend.core.model.process.IElementParameter)2 ConnectionItem (org.talend.core.model.properties.ConnectionItem)2 Item (org.talend.core.model.properties.Item)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Connection (java.sql.Connection)1 Driver (java.sql.Driver)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 Statement (java.sql.Statement)1 Entry (java.util.Map.Entry)1