Search in sources :

Example 1 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.

the class Neo4jConnectionUtilTest method testLocalConnection.

// TODO: FIXME
@Ignore("failed because workbench has not been created")
public void testLocalConnection() throws Exception {
    EMap<String, String> attributes = localConnection.getAttributes();
    // $NON-NLS-1$
    attributes.put(INeo4jAttributes.REMOTE_SERVER, "false");
    attributes.put(INeo4jAttributes.DATABASE_PATH, tmpFolder.getCanonicalPath());
    attributes.put(INeo4jAttributes.DB_VERSION, INeo4jConstants.NEO4J_3_2_X);
    localConnection.setDbType("NEO4J");
    // TUP-15696:"Check Service" for Neo4j does not work after first check.
    // so check twice here
    ExecutorService threadExecutor = null;
    try {
        threadExecutor = Executors.newSingleThreadExecutor();
        Future future = threadExecutor.submit(new Runnable() {

            public void run() {
                try {
                    Neo4jConnectionUtil.checkConnection(localConnection);
                    assertTrue(Neo4jConnectionUtil.checkConnection(localConnection));
                } catch (NoSQLServerException e) {
                    fail(e.getMessage());
                }
            }
        });
        while (true) {
            if (future.get() == null) {
                break;
            }
            Thread.sleep(1000);
        }
    } catch (Exception exception) {
        fail(exception.getMessage());
    } finally {
        if (threadExecutor != null) {
            threadExecutor.shutdown();
        }
    }
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) Ignore(org.junit.Ignore)

Example 2 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.

the class CassandraMetadataHandler method getKeySpaceNames.

@Override
public List<String> getKeySpaceNames(NoSQLConnection connection) throws NoSQLServerException {
    List<String> ksNames = new ArrayList<String>();
    initCluster(connection);
    try {
        List<Object> keySpaces = getKeySpaces(connection);
        for (Object keySpace : keySpaces) {
            // $NON-NLS-1$
            String ksName = (String) NoSQLReflection.invokeMethod(keySpace, "getName");
            ksNames.add(ksName);
        }
    } catch (Exception e) {
        throw new NoSQLServerException(e);
    }
    return ksNames;
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) ArrayList(java.util.ArrayList) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Example 3 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.

the class CassandraMetadataHandler method getColumns.

@Override
public List<Object> getColumns(NoSQLConnection connection, String ksName, String cfName) throws NoSQLServerException {
    List<Object> columns = new ArrayList<Object>();
    try {
        Object keySpace = getKeySpace(connection, ksName);
        if (keySpace == null) {
            return columns;
        }
        // $NON-NLS-1$
        Collection<Object> tables = (Collection) NoSQLReflection.invokeMethod(keySpace, "getTables");
        for (Object table : tables) {
            // $NON-NLS-1$
            String name = (String) NoSQLReflection.invokeMethod(table, "getName");
            if (name != null && cfName.equals(name)) {
                // $NON-NLS-1$
                columns.addAll((List) NoSQLReflection.invokeMethod(table, "getColumns"));
                break;
            }
        }
    } catch (Exception e) {
        throw new NoSQLServerException(e);
    }
    return columns;
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) ArrayList(java.util.ArrayList) Collection(java.util.Collection) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Example 4 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.

the class CassandraMetadataHandler method checkConnection.

@Override
public boolean checkConnection(NoSQLConnection connection) throws NoSQLServerException {
    Object session = null;
    try {
        cluster = null;
        initCluster(connection);
        ContextType contextType = null;
        String ksName = connection.getAttributes().get(ICassandraAttributies.DATABASE);
        if (connection.isContextMode()) {
            contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
        }
        if (contextType != null) {
            ksName = ContextParameterUtils.getOriginalValue(contextType, ksName);
        }
        // if cancel to interrupt check connection, throw exception
        if (Thread.currentThread().interrupted()) {
            // $NON-NLS-1$
            throw new InterruptedException();
        }
        if (StringUtils.isEmpty(ksName)) {
            // $NON-NLS-1$
            session = NoSQLReflection.invokeMethod(cluster, "connect");
        } else {
            // $NON-NLS-1$
            session = NoSQLReflection.invokeMethod(cluster, "connect", new Object[] { ksName });
        }
        return true;
    } catch (Exception e) {
        if (e instanceof InterruptedException) {
            // $NON-NLS-1$
            throw new NoSQLServerException(Messages.getString("noSQLConnectionTest.cancelCheckConnection"), e);
        } else {
            throw new NoSQLServerException(e);
        }
    } finally {
        try {
            if (session != null) {
                // $NON-NLS-1$
                NoSQLReflection.invokeMethod(session, "close");
            }
        } catch (NoSQLReflectionException e) {
            // only for debug
            e.printStackTrace();
        }
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Example 5 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.

the class CassandraMetadataHandler method closeConnections.

@Override
public void closeConnections() throws NoSQLServerException {
    try {
        if (cluster != null) {
            // $NON-NLS-1$
            NoSQLReflection.invokeMethod(cluster, "close");
            cluster = null;
        }
    } catch (NoSQLReflectionException e) {
        throw new NoSQLServerException(e);
    }
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Aggregations

NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)36 NoSQLReflectionException (org.talend.repository.nosql.exceptions.NoSQLReflectionException)33 ArrayList (java.util.ArrayList)13 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)13 ASN1Object (org.bouncycastle.asn1.ASN1Object)9 JSONObject (org.talend.utils.json.JSONObject)9 List (java.util.List)7 JSONException (org.talend.utils.json.JSONException)6 HashSet (java.util.HashSet)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SSLContext (javax.net.ssl.SSLContext)3 File (java.io.File)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 MappingTypeRetriever (org.talend.core.model.metadata.MappingTypeRetriever)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1