use of org.neo4j.kernel.GraphDatabaseAPI in project neo4j-clean-remote-db-addon by jexp.
the class DeleteDatabaseResource method cleanDb.
@DELETE
@Path("/{key}")
@Produces(MediaType.APPLICATION_JSON)
public Response cleanDb(@PathParam("key") String deleteKey) {
GraphDatabaseAPI graph = database.getGraph();
String configKey = config.getString(CONFIG_DELETE_AUTH_KEY);
if (deleteKey == null || configKey == null || !deleteKey.equals(configKey)) {
return Response.status(Status.UNAUTHORIZED).build();
}
try {
Map<String, Object> result = new Neo4jDatabaseCleaner(graph).cleanDb(MAX_NODES_TO_DELETE);
if ((Long) result.get("nodes") >= MAX_NODES_TO_DELETE) {
result.putAll(cleanDbDirectory(database));
}
log.warning("Deleted Database: " + result);
return Response.status(Status.OK).entity(JsonHelper.createJsonFrom(result)).build();
} catch (Throwable e) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(JsonHelper.createJsonFrom(e.getMessage())).build();
}
}
use of org.neo4j.kernel.GraphDatabaseAPI in project blueprints by tinkerpop.
the class Neo4j2BatchGraph method populateKeyIndices.
private static <T extends PropertyContainer> void populateKeyIndices(final GraphDatabaseService rawGraphDB, final AutoIndexer<T> rawAutoIndexer, final Iterable<T> rawElements, final Class elementClass) {
if (!rawAutoIndexer.isEnabled())
return;
final Set<String> properties = rawAutoIndexer.getAutoIndexedProperties();
Transaction tx = rawGraphDB.beginTx();
final PropertyContainer kernel = ((GraphDatabaseAPI) rawGraphDB).getDependencyResolver().resolveDependency(NodeManager.class).newGraphProperties();
kernel.setProperty(elementClass.getSimpleName() + INDEXED_KEYS_POSTFIX, properties.toArray(new String[properties.size()]));
int count = 0;
for (final PropertyContainer pc : rawElements) {
for (final String property : properties) {
if (!pc.hasProperty(property))
continue;
pc.setProperty(property, pc.getProperty(property));
count++;
if (count >= 10000) {
count = 0;
tx.success();
tx.finish();
tx = rawGraphDB.beginTx();
}
}
}
tx.success();
tx.finish();
}
use of org.neo4j.kernel.GraphDatabaseAPI in project blueprints by tinkerpop.
the class Neo4jGraph method rollback.
public void rollback() {
if (null == tx.get()) {
return;
}
GraphDatabaseAPI graphDatabaseAPI = (GraphDatabaseAPI) getRawGraph();
TransactionManager transactionManager = graphDatabaseAPI.getTxManager();
try {
javax.transaction.Transaction t = transactionManager.getTransaction();
if (t == null || t.getStatus() == Status.STATUS_ROLLEDBACK) {
return;
}
tx.get().failure();
} catch (SystemException e) {
throw new RuntimeException(e);
} finally {
tx.get().finish();
tx.remove();
}
}
use of org.neo4j.kernel.GraphDatabaseAPI in project blueprints by tinkerpop.
the class Neo4jGraph method createInternalIndexKey.
private <T extends Element> void createInternalIndexKey(final String key, final Class<T> elementClass) {
final String propertyName = elementClass.getSimpleName() + INDEXED_KEYS_POSTFIX;
if (rawGraph instanceof GraphDatabaseAPI) {
final PropertyContainer pc = ((GraphDatabaseAPI) this.rawGraph).getNodeManager().getGraphProperties();
try {
final String[] keys = (String[]) pc.getProperty(propertyName);
final Set<String> temp = new HashSet<String>(Arrays.asList(keys));
temp.add(key);
pc.setProperty(propertyName, temp.toArray(new String[temp.size()]));
} catch (Exception e) {
// no indexed_keys kernel data property
pc.setProperty(propertyName, new String[] { key });
}
} else {
throw new UnsupportedOperationException("Unable to create an index on a non-GraphDatabaseAPI graph");
}
}
use of org.neo4j.kernel.GraphDatabaseAPI in project blueprints by tinkerpop.
the class Neo4jGraph method dropInternalIndexKey.
private <T extends Element> void dropInternalIndexKey(final String key, final Class<T> elementClass) {
final String propertyName = elementClass.getSimpleName() + INDEXED_KEYS_POSTFIX;
if (rawGraph instanceof GraphDatabaseAPI) {
final PropertyContainer pc = ((GraphDatabaseAPI) this.rawGraph).getNodeManager().getGraphProperties();
try {
final String[] keys = (String[]) pc.getProperty(propertyName);
final Set<String> temp = new HashSet<String>(Arrays.asList(keys));
temp.remove(key);
pc.setProperty(propertyName, temp.toArray(new String[temp.size()]));
} catch (Exception e) {
// no indexed_keys kernel data property
}
} else {
logNotGraphDatabaseAPI();
}
}
Aggregations