Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions DesktopNeo4j/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
AutoUpdate-Show-In-Client: false
OpenIDE-Module: org.gephi.desktop.neo4j
OpenIDE-Module-Layer: org/gephi/desktop/neo4j/layer.xml
OpenIDE-Module-Localizing-Bundle: org/gephi/desktop/neo4j/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0.2
Manifest-Version: 1.0
AutoUpdate-Show-In-Client: false
OpenIDE-Module: org.gephi.desktop.neo4j
OpenIDE-Module-Layer: org/gephi/desktop/neo4j/layer.xml
OpenIDE-Module-Localizing-Bundle: org/gephi/desktop/neo4j/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0.2

10 changes: 5 additions & 5 deletions DesktopNeo4j/nbproject/project.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
javac.source=1.6
javac.compilerargs=-Xlint -Xlint:-serial
license.file=../agpl-3.0.txt
nbm.module.author=Gephi.org
nbm.needs.restart=true
javac.source=1.7
javac.compilerargs=-Xlint -Xlint:-serial
license.file=../agpl-3.0.txt
nbm.module.author=Gephi.org
nbm.needs.restart=true
30 changes: 22 additions & 8 deletions DesktopNeo4j/src/org/gephi/desktop/neo4j/Neo4jMenuAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ License, or (at your option) any later version.
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JMenu;
Expand All @@ -56,6 +58,7 @@ License, or (at your option) any later version.
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.visualization.VizController;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.kernel.StoreLockException;
import org.netbeans.validation.api.ui.ValidationPanel;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
Expand Down Expand Up @@ -180,14 +183,21 @@ private static void initProject() {
}
}

private static void handleLocalDatabaseError(Exception e) {
private static void handleLocalDatabaseError(Exception e, GraphDatabaseService db) {
String errorMessage = null;

if (e.getClass() == Neo4jStoreAlreadyInUseException.class)
Collection<Class> inUseExceptions = Arrays.<Class>asList(Neo4jStoreAlreadyInUseException.class,StoreLockException.class);
if (inUseExceptions.contains(e.getClass()) || inUseExceptions.contains(e.getCause().getClass()))
errorMessage = NbBundle.getMessage(Neo4jMenuAction.class, "CTL_Neo4j_DatabaseStorageAlreadyInUse");

NotifyDescriptor notifyDescriptor = new NotifyDescriptor.Message(errorMessage, JOptionPane.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(notifyDescriptor);

try {
if (db!=null) db.shutdown();
} catch(Exception ex) {
// ignore
}
}

private static class FullImportMenuAction extends AbstractAction {
Expand All @@ -213,12 +223,16 @@ public void actionPerformed(ActionEvent e) {
NbPreferences.forModule(Neo4jMenuAction.class).put(IMPORT_LAST_PATH, neo4jDirectory.getParentFile().getAbsolutePath());
}

GraphDatabaseService tempGraphDB;
GraphDatabaseService tempGraphDB = null;
try {
tempGraphDB = Neo4jUtils.localDatabase(neo4jDirectory);
}
catch (Neo4jStoreAlreadyInUseException storeInUseException) {
handleLocalDatabaseError(storeInUseException);
handleLocalDatabaseError(storeInUseException,tempGraphDB);
return;
}
catch (RuntimeException exception) {
handleLocalDatabaseError(exception,tempGraphDB);
return;
}

Expand Down Expand Up @@ -306,12 +320,12 @@ public void actionPerformed(ActionEvent e) {
NbPreferences.forModule(Neo4jMenuAction.class).put(IMPORT_LAST_PATH, neo4jDirectory.getParentFile().getAbsolutePath());
}

GraphDatabaseService tempGraphDB;
GraphDatabaseService tempGraphDB = null;
try {
tempGraphDB = Neo4jUtils.localDatabase(neo4jDirectory);
}
catch (Neo4jStoreAlreadyInUseException storeInUseException) {
handleLocalDatabaseError(storeInUseException);
handleLocalDatabaseError(storeInUseException,tempGraphDB);
return;
}

Expand Down Expand Up @@ -407,12 +421,12 @@ public void actionPerformed(ActionEvent e) {

@Override
public void run() {
GraphDatabaseService tempGraphDB;
GraphDatabaseService tempGraphDB = null;
try {
tempGraphDB = Neo4jUtils.localDatabase(neo4jDirectory);
}
catch (Neo4jStoreAlreadyInUseException storeInUseException) {
handleLocalDatabaseError(storeInUseException);
handleLocalDatabaseError(storeInUseException,tempGraphDB);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ License, or (at your option) any later version.
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.TransactionFailureException;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;

/**
*
Expand All @@ -40,7 +40,10 @@ private Neo4jUtils() {
public static GraphDatabaseService localDatabase(File neo4jDirectory) throws Neo4jStoreAlreadyInUseException {

try {
return new EmbeddedGraphDatabase(neo4jDirectory.getAbsolutePath());
return new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder(neo4jDirectory.getAbsolutePath())
.setConfig("allow_store_upgrade","true")
.newGraphDatabase();
}
catch (TransactionFailureException e) {
if (e.getCause() instanceof IllegalStateException)
Expand Down
12 changes: 6 additions & 6 deletions Neo4jPlugin/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
AutoUpdate-Show-In-Client: false
OpenIDE-Module: org.gephi.neo4j.plugin
OpenIDE-Module-Localizing-Bundle: org/gephi/neo4j/plugin/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0.3
Manifest-Version: 1.0
AutoUpdate-Show-In-Client: false
OpenIDE-Module: org.gephi.neo4j.plugin
OpenIDE-Module-Localizing-Bundle: org/gephi/neo4j/plugin/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0.3

10 changes: 5 additions & 5 deletions Neo4jPlugin/nbproject/project.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
javac.source=1.6
javac.compilerargs=-Xlint -Xlint:-serial
license.file=../agpl-3.0.txt
nbm.module.author=Gephi.org
nbm.needs.restart=true
javac.source=1.7
javac.compilerargs=-Xlint -Xlint:-serial
license.file=../agpl-3.0.txt
nbm.module.author=Gephi.org
nbm.needs.restart=true
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ License, or (at your option) any later version.
import org.gephi.project.api.WorkspaceListener;
import org.gephi.project.api.WorkspaceProvider;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.jmx.Primitives;
import org.neo4j.management.Neo4jManager;
import org.neo4j.kernel.GraphDatabaseAPI;
import org.neo4j.kernel.impl.core.NodeManager;
import org.openide.util.Lookup;

/**
Expand Down Expand Up @@ -264,9 +265,8 @@ public static class Neo4jGraphModel {

public Neo4jGraphModel(GraphDatabaseService graphDb) {
this.graphDb = graphDb;

int numberOfNeo4jNodeIds = (int) Neo4jManager.get().getPrimitivesBean().getNumberOfNodeIdsInUse();

NodeManager nodeManager = ((GraphDatabaseAPI)graphDb).getDependencyResolver().resolveDependency(NodeManager.class);
int numberOfNeo4jNodeIds = (int) nodeManager.getNumberOfIdsInUse(Node.class);
this.neo4jToGephiNodeMap = new TLongIntHashMap(numberOfNeo4jNodeIds, 1f);
this.gephiToNeo4jNodeMap = new TIntLongHashMap(numberOfNeo4jNodeIds, 1f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ License, or (at your option) any later version.
import org.gephi.data.properties.PropertiesColumn;
import org.neo4j.graphdb.DynamicRelationshipType;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;


/**
Expand Down Expand Up @@ -57,8 +58,14 @@ public String storageEngineName() {
@Override
public Object getNodeAttributeValue(Long delegateId, AttributeColumn attributeColumn) {
GraphDatabaseService graphDB = GraphModelImportConverter.getGraphDBForCurrentWorkspace();

return graphDB.getNodeById(delegateId).getProperty(attributeColumn.getId());
Transaction tx = graphDB.beginTx();
try {
final Object value = graphDB.getNodeById(delegateId).getProperty(attributeColumn.getId());
tx.success();
return value;
} finally {
tx.close();
}
}

@Override
Expand All @@ -69,25 +76,45 @@ public void setNodeAttributeValue(Long delegateId, AttributeColumn attributeColu

GraphDatabaseService graphDB = GraphModelImportConverter.getGraphDBForCurrentWorkspace();

graphDB.getNodeById(delegateId).setProperty(attributeColumn.getId(), nodeValue);
Transaction tx = graphDB.beginTx();
try {
graphDB.getNodeById(delegateId).setProperty(attributeColumn.getId(), nodeValue);
tx.success();
} finally {
tx.close();
}
}

@Override
public void deleteNodeAttributeValue(Long delegateId, AttributeColumn attributeColumn) {
GraphDatabaseService graphDB = GraphModelImportConverter.getGraphDBForCurrentWorkspace();

graphDB.getNodeById(delegateId).removeProperty(attributeColumn.getId());
Transaction tx = graphDB.beginTx();
try {
graphDB.getNodeById(delegateId).removeProperty(attributeColumn.getId());
tx.success();
} finally {
tx.close();
}
}


@Override
public Object getEdgeAttributeValue(Long delegateId, AttributeColumn attributeColumn) {
GraphDatabaseService graphDB = GraphModelImportConverter.getGraphDBForCurrentWorkspace();

if (attributeColumn.getId().equals(PropertiesColumn.NEO4J_RELATIONSHIP_TYPE.getId()))
return graphDB.getRelationshipById(delegateId).getType().name();
else
return graphDB.getRelationshipById(delegateId).getProperty(attributeColumn.getId());
Transaction tx = graphDB.beginTx();
try {
Object value;
if (attributeColumn.getId().equals(PropertiesColumn.NEO4J_RELATIONSHIP_TYPE.getId()))
value = graphDB.getRelationshipById(delegateId).getType().name();
else
value = graphDB.getRelationshipById(delegateId).getProperty(attributeColumn.getId());
tx.success();
return value;
} finally {
tx.close();
}
}

@Override
Expand All @@ -98,14 +125,26 @@ public void setEdgeAttributeValue(Long delegateId, AttributeColumn attributeColu

GraphDatabaseService graphDB = GraphModelImportConverter.getGraphDBForCurrentWorkspace();

graphDB.getRelationshipById(delegateId).setProperty(attributeColumn.getId(), edgeValue);
Transaction tx = graphDB.beginTx();
try {
graphDB.getRelationshipById(delegateId).setProperty(attributeColumn.getId(), edgeValue);
tx.success();
} finally {
tx.close();
}
}

@Override
public void deleteEdgeAttributeValue(Long delegateId, AttributeColumn attributeColumn) {
GraphDatabaseService graphDB = GraphModelImportConverter.getGraphDBForCurrentWorkspace();

graphDB.getRelationshipById(delegateId).removeProperty(attributeColumn.getId());
Transaction tx = graphDB.beginTx();
try {
graphDB.getRelationshipById(delegateId).removeProperty(attributeColumn.getId());
tx.success();
} finally {
tx.close();
}
}

public GraphItemDelegateFactoryProvider<Long> graphItemDelegateFactoryProvider() {
Expand Down Expand Up @@ -138,32 +177,58 @@ public static Neo4jGraphItemDelegateFactoryProviderImpl getInstance() {
public Long createNode() {
GraphDatabaseService graphDB = GraphModelImportConverter.getGraphDBForCurrentWorkspace();

return graphDB.createNode().getId();
Transaction tx = graphDB.beginTx();
try {
long id = graphDB.createNode().getId();
tx.success();
return id;
} finally {
tx.close();
}
}

@Override
public void deleteNode(Long nodeId) {
GraphDatabaseService graphDB = GraphModelImportConverter.getGraphDBForCurrentWorkspace();

graphDB.getNodeById(nodeId).delete();
Transaction tx = graphDB.beginTx();
try {
graphDB.getNodeById(nodeId).delete();
tx.success();
} finally {
tx.close();
}
}

@Override
public Long createEdge(Long startNodeId, Long endNodeId) {
GraphDatabaseService graphDB = GraphModelImportConverter.getGraphDBForCurrentWorkspace();

org.neo4j.graphdb.Node startNode = graphDB.getNodeById(startNodeId);
org.neo4j.graphdb.Node endNode = graphDB.getNodeById(endNodeId);

return startNode.createRelationshipTo(endNode,
DynamicRelationshipType.withName(DEFAULT_RELATIONSHIP_TYPE_NAME)).getId();
Transaction tx = graphDB.beginTx();
try {
org.neo4j.graphdb.Node startNode = graphDB.getNodeById(startNodeId);
org.neo4j.graphdb.Node endNode = graphDB.getNodeById(endNodeId);

long id = startNode.createRelationshipTo(endNode,
DynamicRelationshipType.withName(DEFAULT_RELATIONSHIP_TYPE_NAME)).getId();
tx.success();
return id;
} finally {
tx.close();
}
}

@Override
public void deleteEdge(Long edgeId) {
GraphDatabaseService graphDB = GraphModelImportConverter.getGraphDBForCurrentWorkspace();

graphDB.getRelationshipById(edgeId).delete();
Transaction tx = graphDB.beginTx();
try {
graphDB.getRelationshipById(edgeId).delete();
tx.success();
} finally {
tx.close();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ License, or (at your option) any later version.
import org.neo4j.graphdb.traversal.Evaluators;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.graphdb.traversal.Traverser;
import org.neo4j.kernel.Traversal;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
Expand Down Expand Up @@ -105,7 +104,7 @@ public void importDatabase(GraphDatabaseService graphDB, long startNodeId, Trave
NodeReturnFilter nodeReturnFilter = null;

if (startNodeId != NO_START_NODE) {
TraversalDescription traversalDescription = Traversal.description();
TraversalDescription traversalDescription = graphDB.traversalDescription();

traversalDescription = order.update(traversalDescription);

Expand Down Expand Up @@ -137,7 +136,7 @@ private void doImport(GraphDatabaseService graphDB, Traverser traverser, NodeRet
importGraph(graphDB, traverser, nodeReturnFilter);
transaction.success();
} finally {
transaction.finish();
transaction.close();
}

Progress.finish(progressTicket);
Expand Down
Loading