Search in sources :

Example 6 with NoSQLReflectionException

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

the class CassandraMetadataHandler method getSuperColumnFamilyNames.

@Override
public Set<String> getSuperColumnFamilyNames(NoSQLConnection connection, String ksName) throws NoSQLServerException {
    Set<String> scfNames = new HashSet<String>();
    Object session = null;
    ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
    try {
        if (ksName == null) {
            List<String> ksNames = getKeySpaceNames(connection);
            for (String name : ksNames) {
                scfNames.addAll(getColumnFamilyNames(connection, name));
            }
        } else {
            initCluster(connection);
            // $NON-NLS-1$ //$NON-NLS-2$
            session = NoSQLReflection.invokeMethod(cluster, "connect", new Object[] { "system" });
            Object toPrepare = // $NON-NLS-1$
            NoSQLReflection.newInstance(// $NON-NLS-1$
            "com.datastax.driver.core.SimpleStatement", new Object[] { "select * from schema_columnfamilies where keyspace_name =?" }, // $NON-NLS-1$
            classLoader);
            Object prepared = // $NON-NLS-1$
            NoSQLReflection.invokeMethod(// $NON-NLS-1$
            session, // $NON-NLS-1$
            "prepare", // $NON-NLS-1$
            new Object[] { toPrepare }, // $NON-NLS-1$
            Class.forName("com.datastax.driver.core.RegularStatement", false, classLoader));
            Object statement = // $NON-NLS-1$
            NoSQLReflection.invokeMethod(// $NON-NLS-1$
            prepared, // $NON-NLS-1$
            "bind", // $NON-NLS-1$
            new Object[] { new Object[] { ksName } }, Object[].class);
            // Statement
            Object resultSet = // $NON-NLS-1$
            NoSQLReflection.invokeMethod(// $NON-NLS-1$
            session, // $NON-NLS-1$
            "execute", // $NON-NLS-1$
            new Object[] { statement }, // $NON-NLS-1$
            Class.forName("com.datastax.driver.core.Statement", false, classLoader));
            // $NON-NLS-1$
            Iterator iterator = (Iterator) NoSQLReflection.invokeMethod(resultSet, "iterator");
            while (iterator.hasNext()) {
                Object row = iterator.next();
                // String type = row.getString("type");s
                // $NON-NLS-1$ //$NON-NLS-2$
                String type = (String) NoSQLReflection.invokeMethod(row, "getString", new Object[] { "type" });
                String scfName = (String) NoSQLReflection.invokeMethod(row, "getString", // $NON-NLS-1$ //$NON-NLS-2$
                new Object[] { "columnfamily_name" });
                if (type.equalsIgnoreCase("super")) {
                    // $NON-NLS-1$
                    scfNames.add(scfName);
                }
            }
        }
    } catch (Exception e) {
        throw new NoSQLServerException(e);
    } finally {
        try {
            if (session != null) {
                // $NON-NLS-1$
                NoSQLReflection.invokeMethod(session, "close");
                closeConnections();
            }
        } catch (NoSQLReflectionException e) {
            // only for debug
            e.printStackTrace();
        }
    }
    return scfNames;
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) Iterator(java.util.Iterator) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException) HashSet(java.util.HashSet)

Example 7 with NoSQLReflectionException

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

the class CassandraMetadataHandler method getKeySpaces.

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

Example 8 with NoSQLReflectionException

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

the class MongoDBConnectionUtil method getDB.

public static synchronized Object getDB(NoSQLConnection connection, String dbName, Object mongoClient) throws NoSQLServerException {
    Object db = null;
    if (StringUtils.isEmpty(dbName)) {
        return db;
    }
    try {
        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);
        updateConfigProperties(requireEncryption);
        if (isUpgradeLatestVersion(connection)) {
            if (mongoClient == null) {
                mongoClient = getMongo(connection, requireAuth, requireEncryption);
            }
            db = // $NON-NLS-1$
            NoSQLReflection.invokeMethod(// $NON-NLS-1$
            mongoClient, // $NON-NLS-1$
            "getDatabase", new Object[] { dbName });
        } else if (isUpgradeVersion(connection)) {
            if (mongoClient == null) {
                mongoClient = getMongo(connection, requireAuth, requireEncryption);
            }
            db = // $NON-NLS-1$
            NoSQLReflection.invokeMethod(// $NON-NLS-1$
            mongoClient, // $NON-NLS-1$
            "getDB", new Object[] { dbName });
        } else {
            if (mongoClient == null) {
                mongoClient = getMongo(connection);
            }
            // $NON-NLS-1$
            db = NoSQLReflection.invokeMethod(mongoClient, "getDB", new Object[] { dbName });
            // Do authenticate
            if (requireAuth) {
                String userName = connection.getAttributes().get(IMongoDBAttributes.USERNAME);
                String password = connection.getValue(connection.getAttributes().get(IMongoDBAttributes.PASSWORD), false);
                if (connection.isContextMode()) {
                    ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
                    userName = ContextParameterUtils.getOriginalValue(contextType, userName);
                    password = ContextParameterUtils.getOriginalValue(contextType, password);
                }
                if (userName != null && password != null) {
                    boolean authorized = (Boolean) NoSQLReflection.invokeMethod(db, "authenticate", // $NON-NLS-1$
                    new Object[] { userName, password.toCharArray() });
                    if (!authorized) {
                        // $NON-NLS-1$
                        throw new NoSQLServerException(Messages.getString("MongoDBConnectionUtil.ConnotLogon", dbName));
                    }
                }
            }
        }
    } catch (NoSQLReflectionException e) {
        throw new NoSQLServerException(e);
    }
    return db;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) JSONObject(org.talend.utils.json.JSONObject) ASN1Object(org.bouncycastle.asn1.ASN1Object) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Example 9 with NoSQLReflectionException

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

the class MongoDBConnectionUtil method getCollectionNames.

public static synchronized Set<String> getCollectionNames(NoSQLConnection connection, String dbName, Object mongoClient) throws NoSQLServerException {
    Set<String> collectionNames = new HashSet<String>();
    Object db = null;
    if (mongoClient == null) {
        mongoClient = getMongoVersioned(connection);
    }
    if (dbName != null) {
        db = getDB(connection, dbName, mongoClient);
    } else {
        dbName = connection.getAttributes().get(IMongoDBAttributes.DATABASE);
        if (connection.isContextMode()) {
            ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
            dbName = ContextParameterUtils.getOriginalValue(contextType, dbName);
        }
        db = getDB(connection, dbName, mongoClient);
    }
    if (db == null) {
        List<String> databaseNames = getDatabaseNames(connection, mongoClient);
        for (String databaseName : databaseNames) {
            collectionNames.addAll(getCollectionNames(connection, databaseName, mongoClient));
        }
    } else {
        try {
            if (isUpgradeLatestVersion(connection)) {
                // $NON-NLS-1$
                Iterable<String> iter = (Iterable<String>) NoSQLReflection.invokeMethod(db, "listCollectionNames");
                Iterator<String> iterator = iter.iterator();
                while (iterator.hasNext()) {
                    collectionNames.add(iterator.next());
                }
            } else {
                // $NON-NLS-1$
                collectionNames = (Set<String>) NoSQLReflection.invokeMethod(db, "getCollectionNames");
            }
        } catch (NoSQLReflectionException e) {
            throw new NoSQLServerException(e);
        }
    }
    return collectionNames;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) JSONObject(org.talend.utils.json.JSONObject) ASN1Object(org.bouncycastle.asn1.ASN1Object) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException) HashSet(java.util.HashSet)

Example 10 with NoSQLReflectionException

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

the class Neo4jConnectionUtil method getDB.

public static synchronized Object getDB(NoSQLConnection connection, boolean useCache) throws NoSQLServerException {
    if (useCache && graphDb != null) {
        return graphDb;
    }
    Object db = null;
    ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
    try {
        boolean isRemote = Boolean.valueOf(connection.getAttributes().get(INeo4jAttributes.REMOTE_SERVER));
        if (isRemote) {
            String serverUrl = StringUtils.trimToEmpty(connection.getAttributes().get(INeo4jAttributes.SERVER_URL));
            if (connection.isContextMode()) {
                ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
                serverUrl = ContextParameterUtils.getOriginalValue(contextType, serverUrl);
            }
            if (isNeedAuthorization(connection)) {
                String usename = StringUtils.trimToEmpty(connection.getAttributes().get(INeo4jAttributes.USERNAME));
                String password = StringUtils.trimToEmpty(connection.getAttributes().get(INeo4jAttributes.PASSWORD));
                if (connection.isContextMode()) {
                    ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
                    usename = ContextParameterUtils.getOriginalValue(contextType, usename);
                    password = ContextParameterUtils.getOriginalValue(contextType, password);
                } else {
                    password = connection.getValue(password, false);
                }
                db = NoSQLReflection.newInstance(// $NON-NLS-1$
                "org.neo4j.rest.graphdb.RestGraphDatabase", // $NON-NLS-1$
                new Object[] { serverUrl, usename, password }, classLoader);
            } else {
                db = // $NON-NLS-1$
                NoSQLReflection.newInstance(// $NON-NLS-1$
                "org.neo4j.rest.graphdb.RestGraphDatabase", // $NON-NLS-1$
                new Object[] { serverUrl }, classLoader);
            }
        } else {
            String dbPath = StringUtils.trimToEmpty(connection.getAttributes().get(INeo4jAttributes.DATABASE_PATH));
            if (connection.isContextMode()) {
                ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
                dbPath = ContextParameterUtils.getOriginalValue(contextType, dbPath);
            }
            Object dbFactory = // $NON-NLS-1$
            NoSQLReflection.newInstance(// $NON-NLS-1$
            "org.neo4j.graphdb.factory.GraphDatabaseFactory", // $NON-NLS-1$
            new Object[0], classLoader);
            if (isVersionSince32(connection)) {
                File dbFile = new File(dbPath);
                db = // $NON-NLS-1$
                NoSQLReflection.invokeMethod(// $NON-NLS-1$
                dbFactory, // $NON-NLS-1$
                "newEmbeddedDatabase", new Object[] { dbFile });
            } else {
                db = // $NON-NLS-1$
                NoSQLReflection.invokeMethod(// $NON-NLS-1$
                dbFactory, // $NON-NLS-1$
                "newEmbeddedDatabase", new Object[] { dbPath });
            }
        }
        registerShutdownHook(db);
    } catch (NoSQLReflectionException e) {
        throw new NoSQLServerException(e);
    }
    return graphDb = db;
}
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) File(java.io.File)

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