Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
452 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
shell/src/main/java/org/neo4j/shell/kernel/apps/Begin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Copyright (c) 2002-2012 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.shell.kernel.apps; | ||
|
||
import java.rmi.RemoteException; | ||
|
||
import javax.transaction.SystemException; | ||
import javax.transaction.Transaction; | ||
|
||
import org.neo4j.helpers.Service; | ||
import org.neo4j.kernel.AbstractGraphDatabase; | ||
import org.neo4j.shell.App; | ||
import org.neo4j.shell.AppCommandParser; | ||
import org.neo4j.shell.Output; | ||
import org.neo4j.shell.Session; | ||
import org.neo4j.shell.ShellException; | ||
import org.neo4j.shell.kernel.GraphDatabaseShellServer; | ||
|
||
@Service.Implementation(App.class) | ||
public class Begin extends ReadOnlyGraphDatabaseApp | ||
{ | ||
@Override | ||
public String getDescription() | ||
{ | ||
return "Opens a transaction"; | ||
} | ||
|
||
@Override | ||
protected String exec( AppCommandParser parser, Session session, Output out ) | ||
throws ShellException, RemoteException | ||
{ | ||
Transaction tx = currentTransaction( getServer() ); | ||
|
||
getServer().getDb().beginTx(); | ||
Integer txCount = (Integer) session.get( "tx_count" ); | ||
|
||
int count; | ||
if ( txCount == null ) | ||
{ | ||
if ( tx == null ) | ||
{ | ||
count = 0; | ||
} else | ||
{ | ||
count = 1; | ||
} | ||
} else | ||
{ | ||
count = txCount; | ||
} | ||
|
||
session.set( "tx_count", ++count ); | ||
out.println("Transaction started"); | ||
return null; | ||
} | ||
|
||
public static Transaction currentTransaction( GraphDatabaseShellServer server ) throws ShellException | ||
{ | ||
try | ||
{ | ||
return ((AbstractGraphDatabase) server.getDb()).getTxManager().getTransaction(); | ||
} catch ( SystemException e ) | ||
{ | ||
throw new ShellException( e.getMessage() ); | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
shell/src/main/java/org/neo4j/shell/kernel/apps/Commit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Copyright (c) 2002-2012 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.shell.kernel.apps; | ||
|
||
import java.rmi.RemoteException; | ||
|
||
import javax.transaction.SystemException; | ||
import javax.transaction.Transaction; | ||
|
||
import org.neo4j.helpers.Service; | ||
import org.neo4j.kernel.AbstractGraphDatabase; | ||
import org.neo4j.shell.App; | ||
import org.neo4j.shell.AppCommandParser; | ||
import org.neo4j.shell.Output; | ||
import org.neo4j.shell.Session; | ||
import org.neo4j.shell.ShellException; | ||
|
||
@Service.Implementation(App.class) | ||
public class Commit extends ReadOnlyGraphDatabaseApp | ||
{ | ||
public static final String tx_count = "tx_count"; | ||
|
||
@Override | ||
public String getDescription() | ||
{ | ||
return "Commits a transaction"; | ||
} | ||
|
||
@Override | ||
protected String exec( AppCommandParser parser, Session session, Output out ) | ||
throws ShellException, RemoteException | ||
{ | ||
Integer txCount = (Integer) session.get( tx_count ); | ||
|
||
if ( txCount == null || txCount.equals( 0 ) ) | ||
{ | ||
throw new ShellException( "Not in a transaction" ); | ||
} else if ( txCount.equals( 1 ) ) | ||
{ | ||
Transaction tx; | ||
try | ||
{ | ||
tx = ((AbstractGraphDatabase) getServer().getDb()).getTxManager().getTransaction(); | ||
if ( tx == null ) | ||
{ | ||
throw fail( session, "Not in a transaction" ); | ||
} | ||
} catch ( SystemException e ) | ||
{ | ||
throw fail( session, "Not in a transaction" ); | ||
} | ||
|
||
try | ||
{ | ||
tx.commit(); | ||
session.remove( tx_count ); | ||
out.println("Transaction committed"); | ||
return null; | ||
} catch ( Exception e ) | ||
{ | ||
throw fail( session, e.getMessage() ); | ||
} | ||
} else | ||
{ | ||
session.set( tx_count, --txCount ); | ||
out.println("Transaction committed"); | ||
return null; | ||
} | ||
} | ||
|
||
public static ShellException fail( Session session, String message ) throws ShellException | ||
{ | ||
session.remove( tx_count ); | ||
return new ShellException( message ); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
shell/src/main/java/org/neo4j/shell/kernel/apps/Rollback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) 2002-2012 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.shell.kernel.apps; | ||
|
||
import java.rmi.RemoteException; | ||
|
||
import javax.transaction.SystemException; | ||
import javax.transaction.Transaction; | ||
|
||
import org.neo4j.helpers.Service; | ||
import org.neo4j.shell.App; | ||
import org.neo4j.shell.AppCommandParser; | ||
import org.neo4j.shell.Output; | ||
import org.neo4j.shell.Session; | ||
import org.neo4j.shell.ShellException; | ||
|
||
@Service.Implementation(App.class) | ||
public class Rollback extends ReadOnlyGraphDatabaseApp | ||
{ | ||
@Override | ||
public String getDescription() | ||
{ | ||
return "Rolls back all open transactions"; | ||
} | ||
|
||
@Override | ||
protected String exec( AppCommandParser parser, Session session, Output out ) | ||
throws ShellException, RemoteException | ||
{ | ||
Transaction tx = Begin.currentTransaction( getServer() ); | ||
if ( tx == null ) | ||
{ | ||
throw Commit.fail( session, "Not in a transaction" ); | ||
} else | ||
{ | ||
try | ||
{ | ||
tx.rollback(); | ||
out.println("Transaction rolled back"); | ||
return null; | ||
} catch ( SystemException e ) | ||
{ | ||
throw new ShellException( e.getMessage() ); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.