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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations