Search in sources :

Example 1 with NoSQLReflectionException

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

the class CassandraOldVersionMetadataHandler method getKeySpaces.

private List<Object> getKeySpaces(NoSQLConnection connection) throws NoSQLServerException {
    List<Object> keySpaces = new ArrayList<Object>();
    try {
        List<Object> ksDefs = (List<Object>) NoSQLReflection.invokeMethod(getOrCreateCluster(connection), // $NON-NLS-1$
        "describeKeyspaces");
        keySpaces.addAll(ksDefs);
    } catch (NoSQLReflectionException e) {
        throw new NoSQLServerException(e);
    }
    return keySpaces;
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Example 2 with NoSQLReflectionException

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

the class MongoDBConnectionUtil method getDatabaseNames.

public static synchronized List<String> getDatabaseNames(NoSQLConnection connection, Object mongoClient) throws NoSQLServerException {
    List<String> databaseNames = null;
    try {
        databaseNames = Collections.synchronizedList(new ArrayList<String>());
        if (isUpgradeVersion(connection)) {
            String requireAuthAttr = connection.getAttributes().get(IMongoDBAttributes.REQUIRED_AUTHENTICATION);
            boolean requireAuth = requireAuthAttr == null ? false : Boolean.valueOf(requireAuthAttr);
            // 
            String requireEncryptionAttr = connection.getAttributes().get(IMongoDBAttributes.REQUIRED_ENCRYPTION);
            boolean requireEncryption = requireEncryptionAttr == null ? false : Boolean.valueOf(requireEncryptionAttr);
            if (mongoClient == null) {
                mongoClient = getMongo(connection, requireAuth, requireEncryption);
            }
            Iterable mongoIterable = (Iterable) NoSQLReflection.invokeMethod(mongoClient, "listDatabaseNames");
            for (Object dbname : mongoIterable) {
                databaseNames.add((String) dbname);
            }
        } else {
            if (mongoClient == null) {
                mongoClient = getMongo(connection);
            }
            Iterable mongoIterable = (Iterable) NoSQLReflection.invokeMethod(mongoClient, "listDatabaseNames");
            for (Object dbname : mongoIterable) {
                databaseNames.add((String) dbname);
            }
        }
    } catch (NoSQLReflectionException e) {
        throw new NoSQLServerException(e);
    }
    return databaseNames;
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) ArrayList(java.util.ArrayList) JSONObject(org.talend.utils.json.JSONObject) ASN1Object(org.bouncycastle.asn1.ASN1Object) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Example 3 with NoSQLReflectionException

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

the class Neo4jConnectionUtil method getResultIterator.

public static synchronized Iterator<Map<String, Object>> getResultIterator(NoSQLConnection connection, String cypher, Object db1) throws NoSQLServerException {
    Iterator<Map<String, Object>> resultIterator = null;
    Object db = db1;
    try {
        db = getDB(connection, true);
        ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
        String isRemoteAttr = connection.getAttributes().get(INeo4jAttributes.REMOTE_SERVER);
        boolean isRemote = isRemoteAttr == null ? false : Boolean.valueOf(isRemoteAttr);
        if (isRemote) {
            Object queryResult = NoSQLReflection.invokeMethod(getQueryEngine(db, classLoader), "query", new Object[] { cypher, null }, String.class, // $NON-NLS-1$
            Map.class);
            resultIterator = (Iterator<Map<String, Object>>) // $NON-NLS-1$
            NoSQLReflection.invokeMethod(// $NON-NLS-1$
            queryResult, // $NON-NLS-1$
            "iterator", new Object[0]);
        } else {
            Object executionResult = NoSQLReflection.invokeMethod(getExecutionEngine(db, classLoader, connection), "execute", // $NON-NLS-1$
            new Object[] { cypher });
            resultIterator = (Iterator<Map<String, Object>>) // $NON-NLS-1$
            NoSQLReflection.invokeMethod(// $NON-NLS-1$
            executionResult, // $NON-NLS-1$
            "iterator", new Object[0]);
        }
    } catch (NoSQLReflectionException e) {
        throw new NoSQLServerException(e);
    }
    return resultIterator;
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with NoSQLReflectionException

use of org.talend.repository.nosql.exceptions.NoSQLReflectionException 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 NoSQLReflectionException

use of org.talend.repository.nosql.exceptions.NoSQLReflectionException 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

NoSQLReflectionException (org.talend.repository.nosql.exceptions.NoSQLReflectionException)12 NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)11 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)4 ArrayList (java.util.ArrayList)3 ASN1Object (org.bouncycastle.asn1.ASN1Object)3 JSONObject (org.talend.utils.json.JSONObject)3 HashSet (java.util.HashSet)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1