Search in sources :

Example 96 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tbd-studio-se by Talend.

the class MongoDBConnectionUtil method getDB.

public static synchronized Object getDB(NoSQLConnection connection) throws NoSQLServerException {
    String dbName = connection.getAttributes().get(IMongoDBAttributes.DATABASE);
    if (connection.isContextMode()) {
        ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
        dbName = ContextParameterUtils.getOriginalValue(contextType, dbName);
    }
    return getDB(connection, dbName);
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType)

Example 97 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tbd-studio-se by Talend.

the class MongoDBConnectionUtil method getMongo.

public static synchronized Object getMongo(NoSQLConnection connection) throws NoSQLServerException {
    Object mongo = null;
    ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
    String useReplicaAttr = connection.getAttributes().get(IMongoDBAttributes.USE_REPLICA_SET);
    boolean useReplica = useReplicaAttr == null ? false : Boolean.valueOf(useReplicaAttr);
    ContextType contextType = null;
    if (connection.isContextMode()) {
        contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
    }
    try {
        if (useReplica) {
            List<Object> addrs = new ArrayList<Object>();
            String replicaSet = connection.getAttributes().get(IMongoDBAttributes.REPLICA_SET);
            List<HashMap<String, Object>> replicaSetList = getReplicaSetList(replicaSet, false);
            for (HashMap<String, Object> rowMap : replicaSetList) {
                String host = (String) rowMap.get(IMongoConstants.REPLICA_HOST_KEY);
                String port = (String) rowMap.get(IMongoConstants.REPLICA_PORT_KEY);
                if (contextType != null) {
                    host = ContextParameterUtils.getOriginalValue(contextType, host);
                    port = ContextParameterUtils.getOriginalValue(contextType, port);
                }
                if (host != null && port != null) {
                    Object serverAddress = // $NON-NLS-1$
                    NoSQLReflection.newInstance(// $NON-NLS-1$
                    "com.mongodb.ServerAddress", new Object[] { host, Integer.parseInt(port) }, classLoader, String.class, int.class);
                    addrs.add(serverAddress);
                }
            }
            mongo = // $NON-NLS-1$
            NoSQLReflection.newInstance(// $NON-NLS-1$
            "com.mongodb.Mongo", // $NON-NLS-1$
            new Object[] { addrs }, classLoader, List.class);
        } else {
            String host = connection.getAttributes().get(IMongoDBAttributes.HOST);
            String port = connection.getAttributes().get(IMongoDBAttributes.PORT);
            if (contextType != null) {
                host = ContextParameterUtils.getOriginalValue(contextType, host);
                port = ContextParameterUtils.getOriginalValue(contextType, port);
            }
            mongo = // $NON-NLS-1$
            NoSQLReflection.newInstance(// $NON-NLS-1$
            "com.mongodb.Mongo", // $NON-NLS-1$
            new Object[] { host, Integer.parseInt(port) }, classLoader, String.class, int.class);
        }
        mongos.add(mongo);
    } catch (Exception e) {
        throw new NoSQLServerException(e);
    }
    return mongo;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) HashMap(java.util.HashMap) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) ArrayList(java.util.ArrayList) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) JSONException(org.talend.utils.json.JSONException) JSONObject(org.talend.utils.json.JSONObject) ASN1Object(org.bouncycastle.asn1.ASN1Object) List(java.util.List) ArrayList(java.util.ArrayList)

Example 98 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType 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 99 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType 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)

Example 100 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tbd-studio-se by Talend.

the class CassandraOldVersionMetadataHandler method getKeySpace.

private Object getKeySpace(NoSQLConnection connection, String ksName) throws NoSQLServerException {
    ContextType contextType = null;
    if (StringUtils.isEmpty(ksName)) {
        return null;
    }
    if (connection.isContextMode()) {
        contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
    }
    if (contextType != null) {
        ksName = ContextParameterUtils.getOriginalValue(contextType, ksName);
    }
    Object ksDef = null;
    try {
        // $NON-NLS-1$
        ksDef = NoSQLReflection.invokeMethod(getOrCreateCluster(connection), "describeKeyspace", new Object[] { ksName });
    } catch (Exception e) {
        throw new NoSQLServerException(e);
    }
    return ksDef;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Aggregations

ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)108 ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)27 ArrayList (java.util.ArrayList)26 ContextItem (org.talend.core.model.properties.ContextItem)21 PersistenceException (org.talend.commons.exception.PersistenceException)17 File (java.io.File)16 NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)15 HadoopClusterConnection (org.talend.repository.model.hadoopcluster.HadoopClusterConnection)13 NoSQLReflectionException (org.talend.repository.nosql.exceptions.NoSQLReflectionException)13 Test (org.junit.Test)12 HashMap (java.util.HashMap)10 List (java.util.List)10 ProcessItem (org.talend.core.model.properties.ProcessItem)9 IOException (java.io.IOException)8 Map (java.util.Map)8 EList (org.eclipse.emf.common.util.EList)7 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 Property (org.talend.core.model.properties.Property)6 HashSet (java.util.HashSet)5