private static Object getExecutionEngine(Object db, ClassLoader classLoader) throws NoSQLReflectionException { Object ee = executionEngine; if (ee != null) { return ee; } try { ee = NoSQLReflection.newInstance( "org.neo4j.cypher.javacompat.ExecutionEngine", new Object[] {db}, // $NON-NLS-1$ classLoader, Class.forName( "org.neo4j.graphdb.GraphDatabaseService", true, classLoader)); // $NON-NLS-1$ } catch (ClassNotFoundException e) { throw new NoSQLReflectionException(e); } return executionEngine = ee; }
private static Object getQueryEngine(Object db, ClassLoader classLoader) throws NoSQLReflectionException { Object qe = queryEngine; if (qe != null) { return qe; } Object restAPI = NoSQLReflection.invokeMethod(db, "getRestAPI", new Object[0]); // $NON-NLS-1$ try { qe = NoSQLReflection.newInstance( "org.neo4j.rest.graphdb.query.RestCypherQueryEngine", //$NON-NLS-1$ new Object[] {restAPI}, classLoader, Class.forName("org.neo4j.rest.graphdb.RestAPI", true, classLoader)); // $NON-NLS-1$ } catch (ClassNotFoundException e) { throw new NoSQLReflectionException(e); } return queryEngine = qe; }
public static synchronized Object getDB(NoSQLConnection connection) throws NoSQLServerException { 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.getAttributes().get(INeo4jAttributes.DB_VERSION))) { 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( "org.neo4j.rest.graphdb.RestGraphDatabase", new Object[] {serverUrl, usename, password}, // $NON-NLS-1$ classLoader); } else { db = NoSQLReflection.newInstance( "org.neo4j.rest.graphdb.RestGraphDatabase", new Object[] {serverUrl}, // $NON-NLS-1$ 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 = NoSQLReflection.newInstance( "org.neo4j.graphdb.factory.GraphDatabaseFactory", new Object[0], // $NON-NLS-1$ classLoader); db = NoSQLReflection.invokeMethod( dbFactory, "newEmbeddedDatabase", //$NON-NLS-1$ new Object[] {dbPath}); } registerShutdownHook(db); } catch (NoSQLReflectionException e) { throw new NoSQLServerException(e); } return graphDb = db; }
@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); session = NoSQLReflection.invokeMethod( cluster, "connect", new Object[] {"system"}); // $NON-NLS-1$ //$NON-NLS-2$ Object toPrepare = NoSQLReflection.newInstance( "com.datastax.driver.core.SimpleStatement", //$NON-NLS-1$ new Object[] {"select * from schema_columnfamilies where keyspace_name =?"}, classLoader); //$NON-NLS-1$ Object prepared = NoSQLReflection.invokeMethod( session, "prepare", new Object[] {toPrepare}, // $NON-NLS-1$ Class.forName( "com.datastax.driver.core.RegularStatement", false, classLoader)); //$NON-NLS-1$ Object statement = NoSQLReflection.invokeMethod( prepared, "bind", new Object[] {new Object[] {ksName}}, // $NON-NLS-1$ Object[].class); // Statement Object resultSet = NoSQLReflection.invokeMethod( session, "execute", 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"); // $NON-NLS-1$ while (iterator.hasNext()) { Object row = iterator.next(); // String type = row.getString("type");s String type = (String) NoSQLReflection.invokeMethod( row, "getString", new Object[] {"type"}); // $NON-NLS-1$ //$NON-NLS-2$ String scfName = (String) NoSQLReflection.invokeMethod( row, "getString", new Object[] {"columnfamily_name"}); // $NON-NLS-1$ //$NON-NLS-2$ if (type.equalsIgnoreCase("super")) { // $NON-NLS-1$ scfNames.add(scfName); } } } } catch (Exception e) { throw new NoSQLServerException(e); } finally { try { if (session != null) { NoSQLReflection.invokeMethod(session, "close"); // $NON-NLS-1$ closeConnections(); } } catch (NoSQLReflectionException e) { // only for debug e.printStackTrace(); } } return scfNames; }