use of org.talend.repository.nosql.exceptions.NoSQLServerException 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;
}
use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class Neo4jConnectionUtil method checkConnection.
public static synchronized boolean checkConnection(NoSQLConnection connection) throws NoSQLServerException {
boolean canConnect = true;
final ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
ClassLoader currCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
Object dbConnection = null;
try {
boolean isRemote = Boolean.valueOf(connection.getAttributes().get(INeo4jAttributes.REMOTE_SERVER));
if (isRemote && isVersionSince32(connection)) {
String usename = StringUtils.trimToEmpty(connection.getAttributes().get(INeo4jAttributes.USERNAME));
String password = StringUtils.trimToEmpty(connection.getAttributes().get(INeo4jAttributes.PASSWORD));
String serverUrl = StringUtils.trimToEmpty(connection.getAttributes().get(INeo4jAttributes.SERVER_URL));
if (connection.isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
if (contextType != null) {
usename = ContextParameterUtils.getOriginalValue(contextType, usename);
password = ContextParameterUtils.getOriginalValue(contextType, password);
serverUrl = ContextParameterUtils.getOriginalValue(contextType, serverUrl);
}
} else {
password = connection.getValue(password, false);
}
// if cancel to interrupt check connection, throw exception
if (Thread.currentThread().interrupted()) {
throw new InterruptedException();
}
Object basic = NoSQLReflection.invokeStaticMethod("org.neo4j.driver.v1.AuthTokens", "basic", new Object[] { usename, password }, classLoader, String.class, String.class);
NoSQLReflection.invokeStaticMethod("org.neo4j.driver.v1.GraphDatabase", "driver", new Object[] { serverUrl, basic }, classLoader, String.class, Class.forName("org.neo4j.driver.v1.AuthToken", true, classLoader));
return canConnect;
}
// if cancel to interrupt check connection, throw exception
if (Thread.currentThread().interrupted()) {
// $NON-NLS-1$
throw new InterruptedException();
}
final Object db = getDB(connection);
dbConnection = db;
if (isRemote) {
// $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
db, // $NON-NLS-1$
"getAllNodes", new Object[0]);
} else {
if (isVersion1(connection)) {
doCheck(db, classLoader, connection);
} else {
new ExecutionUnitWithTransaction() {
@Override
protected Object run() throws Exception {
doCheck(db, classLoader, connection);
return null;
}
}.execute(db);
}
}
} catch (Exception e) {
canConnect = false;
resetAll();
if (e instanceof InterruptedException) {
// $NON-NLS-1$
throw new NoSQLServerException(Messages.getString("noSQLConnectionTest.cancelCheckConnection"), e);
} else {
// $NON-NLS-1$
throw new NoSQLServerException(Messages.getString("Neo4jConnectionUtil.cannotConnectDatabase"), e);
}
} finally {
if (dbConnection != null) {
shutdownNeo4JDb(dbConnection);
}
Thread.currentThread().setContextClassLoader(currCL);
}
return canConnect;
}
use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class CassandraOldVersionMetadataHandler method getOrCreateCluster.
private Object getOrCreateCluster(NoSQLConnection connection) throws NoSQLServerException {
if (cluster != null) {
return cluster;
}
try {
ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
ContextType contextType = null;
String host = connection.getAttributes().get(ICassandraAttributies.HOST);
String port = connection.getAttributes().get(ICassandraAttributies.PORT);
if (connection.isContextMode()) {
contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
}
if (contextType != null) {
host = ContextParameterUtils.getOriginalValue(contextType, host);
port = ContextParameterUtils.getOriginalValue(contextType, port);
}
// $NON-NLS-1$
String hostIps = host + ":" + port;
Object hostsConfiguration = NoSQLReflection.newInstance("me.prettyprint.cassandra.service.CassandraHostConfigurator", new String[] { hostIps }, // $NON-NLS-1$
classLoader);
java.util.Map<String, String> credentialsPros = new java.util.HashMap<String, String>();
String requireAuthAttr = connection.getAttributes().get(ICassandraAttributies.REQUIRED_AUTHENTICATION);
boolean requireAuth = requireAuthAttr == null ? false : Boolean.valueOf(requireAuthAttr);
if (requireAuth) {
String username = connection.getAttributes().get(ICassandraAttributies.USERNAME);
String password = connection.getValue(connection.getAttributes().get(ICassandraAttributies.PASSWORD), false);
if (contextType != null) {
username = ContextParameterUtils.getOriginalValue(contextType, username);
password = ContextParameterUtils.getOriginalValue(contextType, password);
}
// $NON-NLS-1$
credentialsPros.put("username", username);
// $NON-NLS-1$
credentialsPros.put("password", password);
}
cluster = NoSQLReflection.invokeStaticMethod(// $NON-NLS-1$ //$NON-NLS-2$
"me.prettyprint.hector.api.factory.HFactory", // $NON-NLS-1$ //$NON-NLS-2$
"getOrCreateCluster", new Object[] { "Cassandra_Cluster_" + System.currentTimeMillis(), hostsConfiguration, credentialsPros }, classLoader, String.class, Class.forName("me.prettyprint.cassandra.service.CassandraHostConfigurator", true, classLoader), // $NON-NLS-1$ //$NON-NLS-2$
Map.class);
} catch (Exception e) {
throw new NoSQLServerException(e);
}
return cluster;
}
use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class CassandraOldVersionMetadataHandler method getColumnName.
@Override
public String getColumnName(NoSQLConnection connection, Object column) throws NoSQLServerException {
// $NON-NLS-1$
String columnName = "";
ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
try {
// $NON-NLS-1$
Object columnNameBA = NoSQLReflection.invokeMethod(column, "getName");
columnName = (String) // $NON-NLS-1$ //$NON-NLS-2$
NoSQLReflection.invokeStaticMethod(// $NON-NLS-1$ //$NON-NLS-2$
"org.apache.cassandra.utils.ByteBufferUtil", // $NON-NLS-1$ //$NON-NLS-2$
"string", new Object[] { columnNameBA }, classLoader, // $NON-NLS-1$
Class.forName("java.nio.ByteBuffer", true, classLoader));
} catch (Exception e) {
throw new NoSQLServerException(e);
}
return columnName;
}
use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.
the class CassandraOldVersionMetadataHandler method getColumnFamilyNames.
private Set<String> getColumnFamilyNames(NoSQLConnection connection, String ksName, boolean isSuper) throws NoSQLServerException {
Set<String> cfNames = new HashSet<String>();
try {
Object keySpace = null;
if (ksName == null) {
keySpace = getKeySpace(connection);
} else {
keySpace = getKeySpace(connection, ksName);
if (keySpace == null) {
return cfNames;
}
}
if (keySpace == null) {
List<String> ksNames = getKeySpaceNames(connection);
for (String name : ksNames) {
cfNames.addAll(getColumnFamilyNames(connection, name));
}
} else {
// $NON-NLS-1$
List<Object> cfDefs = (List<Object>) NoSQLReflection.invokeMethod(keySpace, "getCfDefs");
for (Object cfDef : cfDefs) {
// $NON-NLS-1$
String cfName = (String) NoSQLReflection.invokeMethod(cfDef, "getName");
Object cfTypeObj = NoSQLReflection.invokeMethod(cfDef, "getColumnType");
// $NON-NLS-1$
String cfType = (String) NoSQLReflection.invokeMethod(cfTypeObj, "getValue");
if (isSuper) {
if ("Super".equalsIgnoreCase(cfType)) {
// $NON-NLS-1$
cfNames.add(cfName);
}
} else {
if ("Standard".equalsIgnoreCase(cfType)) {
// $NON-NLS-1$
cfNames.add(cfName);
}
}
}
}
} catch (Exception e) {
throw new NoSQLServerException(e);
}
return cfNames;
}
Aggregations