protected GraphDatabaseService getEngine() { return getServer().getDb(); }
protected GraphDatabaseShellServer getGraphDatabaseShellServer( File path, boolean readOnly, String configFile ) throws RemoteException { return new GraphDatabaseShellServer( factory, path, readOnly, configFile ); }
@Override public Response interpretLine( Serializable clientId, String line, Output out ) throws ShellException { boolean alreadyBound = bindTransaction( clientId ); try { return super.interpretLine( clientId, line, out ); } finally { if ( !alreadyBound ) { unbindAndRegisterTransaction( clientId ); } } }
public void unbindAndRegisterTransaction( Serializable clientId ) throws ShellException { try { ThreadToStatementContextBridge threadToStatementContextBridge = getThreadToStatementContextBridge(); KernelTransaction tx = threadToStatementContextBridge.getTopLevelTransactionBoundToThisThread( false ); threadToStatementContextBridge.unbindTransactionFromCurrentThread(); if ( tx == null ) { clients.remove( clientId ); } else { clients.put( clientId, tx ); } } catch ( Exception e ) { throw wrapException( e ); } }
@Override protected String getPrompt( Session session ) throws ShellException { try ( org.neo4j.graphdb.Transaction transaction = this.getDb().beginTx() ) { Object rawCustomPrompt = session.get( PROMPT_KEY ); String customPrompt = rawCustomPrompt != null ? rawCustomPrompt.toString() : getDefaultPrompt(); String output = bashInterpreter.interpret( customPrompt, this, session ); transaction.success(); return output; } }
@Override public Continuation execute( AppCommandParser parser, Session session, Output out ) throws Exception { try ( Transaction tx = getServer().getDb().beginTransaction( implicit, AUTH_DISABLED ) ) { getServer().registerTopLevelTransactionInProgress( session.getId() ); Continuation result = this.exec( parser, session, out ); if ( result == Continuation.EXCEPTION_CAUGHT ) { tx.failure(); } else { tx.success(); } return result; } }
IndexingService indexingService = getServer().getDb().getDependencyResolver().resolveDependency( IndexingService.class ); if ( indexingService == null ) int propertyKey; TokenRead tokenRead = getServer().getTokenRead(); labelKey = tokenRead.nodeLabel( labels[0].name() ); propertyKey = tokenRead.propertyKey( property );
public GraphDatabaseShellServer( GraphDatabaseFactory factory, File path, boolean readOnly, String configFileOrNull ) throws RemoteException { this( instantiateGraphDb( factory, path, readOnly, configFileOrNull ), readOnly ); this.graphDbCreatedHere = true; }
public void registerTopLevelTransactionInProgress( Serializable clientId ) { if ( !clients.containsKey( clientId ) ) { ThreadToStatementContextBridge threadToStatementContextBridge = getThreadToStatementContextBridge(); KernelTransaction tx = threadToStatementContextBridge.getTopLevelTransactionBoundToThisThread( false ); clients.put( clientId, tx ); } }
public GraphDatabaseShellServer enable( GraphDatabaseShellServer server ) throws RemoteException { server.makeRemotelyAvailable( host, port, name ); return server; } }
protected static void printAndInterpretTemplateLines( Collection<String> templateLines, boolean newLineBetweenHits, NodeOrRelationship entity, GraphDatabaseShellServer server, Session session, Output out ) throws ShellException, RemoteException { if ( templateLines.isEmpty() ) { out.println( getDisplayName( server, session, entity, true ) ); } if ( !templateLines.isEmpty() ) { Map<String, Object> data = new HashMap<>(); data.put( "i", entity.getId() ); for ( String command : templateLines ) { String line = TextUtil.templateString( command, data ); server.interpretLine( session.getId(), line, out ); } } if ( newLineBetweenHits ) { out.println(); } }
@Override public Continuation execute( AppCommandParser parser, Session session, Output out ) throws Exception { if ( parser.arguments().isEmpty() ) // Dump the whole graph { try ( Transaction tx = getServer().getDb().beginTransaction( implicit, AUTH_DISABLED ) ) { getServer().registerTopLevelTransactionInProgress( session.getId() ); final SubGraph graph = DatabaseSubGraph.from( getServer().getDb() ); export( graph, out ); tx.success(); return Continuation.INPUT_COMPLETE; } } else { AppCommandParser newParser = newParser( parser ); return super.execute( newParser, session, out ); } }
public boolean bindTransaction( Serializable clientId ) throws ShellException { KernelTransaction tx = clients.get( clientId ); if ( tx != null ) { try { ThreadToStatementContextBridge bridge = getThreadToStatementContextBridge(); if ( bridge.getKernelTransactionBoundToThisThread( false ) == tx ) { // This thread is already bound to this transaction. This can happen if a shell command // in turn calls out to other shell commands. In those cases the sub-commands should just // participate in the existing transaction. Neo4j already has support for nested // transactions, but in the shell server, we are managing the transaction context bridge // in this laborious and manual way, so it is easier for us to just avoid re-binding the // existing transaction. We return 'true' here to indicate that our transaction context // is nested, and that we therefor have to avoid unbinding this transaction later. return true; } bridge.bindTransactionToCurrentThread( tx ); } catch ( Exception e ) { throw wrapException( e ); } } return false; }
/** * @param path the path to the directory where the database should be created * @param readOnly make the instance read-only * @param configFileOrNull path to a configuration file or <code>null</code> * @throws RemoteException if an RMI error occurs. */ public GraphDatabaseShellServer( File path, boolean readOnly, String configFileOrNull ) throws RemoteException { this( instantiateGraphDb( new GraphDatabaseFactory(), path, readOnly, configFileOrNull ), readOnly ); this.graphDbCreatedHere = true; }
public TokenRead getTokenRead() { return getThreadToStatementContextBridge().getKernelTransactionBoundToThisThread( true ).tokenRead(); }
protected Store getStore() { if (store == null) { AppShellServer server = getServer(); if (!(server instanceof GraphDatabaseShellServer)) { throw new IllegalStateException("Unexpected server type " + server); } GraphDatabaseService db = ((GraphDatabaseShellServer) server).getDb(); store = new GraphDbStore(db); } return store; }
@SuppressWarnings( "boxing" ) GraphDatabaseShellServer load( GraphDatabaseAPI graphDb ) throws RemoteException { if ( !enable ) { return null; } return enable( new GraphDatabaseShellServer( graphDb, read_only ) ); }
protected Node getNodeById( long id ) { return this.getServer().getDb().getNodeById( id ); }
private static void startLocalShell() throws Exception { graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH ); createExampleGraph(); ShellServer shellServer = new GraphDatabaseShellServer( (GraphDatabaseAPI) graphDb ); ShellLobby.newClient( shellServer ).grabPrompt(); shellServer.shutdown(); }
private DependencyResolver getDependencyResolver() { return getServer().getDb().getDependencyResolver(); }