public void addCardInfoToNeo4j() { DBCursor cursor = cardCollection.find(); DBObject sortObject = new BasicDBObject(); sortObject.put("name", 1); // cursor = cursor.sort(sortObject); cursor.addOption(Bytes.QUERYOPTION_NOTIMEOUT); int count = 0; while (cursor.hasNext()) { DBObject cardObject = cursor.next(); String cardName = cardObject.get("name").toString().toUpperCase(); if (cardNodes.get(cardName) == null) { Node newCardNode = graphDb.createNode(); newCardNode.setProperty("name", cardName); for (String property : cardObject.keySet()) { if (!property.equalsIgnoreCase("name")) { newCardNode.setProperty(property, cardObject.get(property).toString()); } } cardNodes.put(cardName, newCardNode); } else { Node node = cardNodes.get(cardName); for (String property : cardObject.keySet()) { if (!property.equalsIgnoreCase("name")) { node.setProperty(property, cardObject.get(property).toString()); } } } count++; System.out.println("Processed " + count + " card"); } }
private void init() { try { Mongo m = new Mongo(mongoHost, mongoPort); DB db = m.getDB("mtg"); db.authenticate("mtg", "mtg".toCharArray()); cardCollection = db.getCollection(collectionName); graphDb = new RestGraphDatabase(HEROKU_NEO4J, herokuUser, herokuPassword); Iterable<Node> allNodes = graphDb.getAllNodes(); Iterator<Node> it = allNodes.iterator(); while (it.hasNext()) { Node node = it.next(); if (node.hasProperty("name")) { cardNodes.put(node.getProperty("name").toString(), node); } } System.out.println("There are " + cardNodes.size() + " card nodes"); registerShutdownHook(graphDb); } catch (Exception e) { throw new RuntimeException(e); } }
public RestConfig(RestGraphDatabase restGraphDatabase) { super( restGraphDatabase, restGraphDatabase.getStoreDir(), null, Collections.<String, String>emptyMap(), null, new TxModule(true, null) { @Override public TransactionManager getTxManager() { return new NullTransactionManager(); } }, null, null, null, null, null, null, null, null); }