當前位置: 首頁>>代碼示例>>Java>>正文


Java Transaction.finish方法代碼示例

本文整理匯總了Java中org.neo4j.graphdb.Transaction.finish方法的典型用法代碼示例。如果您正苦於以下問題:Java Transaction.finish方法的具體用法?Java Transaction.finish怎麽用?Java Transaction.finish使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.neo4j.graphdb.Transaction的用法示例。


在下文中一共展示了Transaction.finish方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: analyseDb

import org.neo4j.graphdb.Transaction; //導入方法依賴的package包/類
private void analyseDb() {
	Transaction tx = graphDb.beginTx();
	try {
		PathFinder<Path> finder = GraphAlgoFactory.allPaths(//
				PathExpanders.forTypeAndDirection(RelTypes.KNOWS, Direction.BOTH), -1);
		Iterable<Path> paths = finder.findAllPaths(firstNode, secondNode);
		for (Path path : paths) {
			for (Node node : path.nodes()) {
				for (String prop : node.getPropertyKeys())
					System.out.print(prop);
				System.out.print(node.toString());
			}

			for (Relationship relationship : path.relationships())
				System.out.print(relationship.toString());
		}
		tx.success();
	} finally {
		tx.finish();
	}
}
 
開發者ID:stefano-bragaglia,項目名稱:NeoDD,代碼行數:22,代碼來源:Application.java

示例2: setSignificanceBit

import org.neo4j.graphdb.Transaction; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
/***
 * Sets significanceBit field of node to significanceBit.
 * @param node
 * @param significanceBit
 */
public void setSignificanceBit(Node node, int significanceBit)
{
	String tempString = serializer.serialize(significanceBit);
	Transaction tx = graphDB.beginTx();
	try
	{
		node.setProperty("__significanceBit", tempString);
		tx.success();
	}finally
	{
		tx.finish();
	}
}
 
開發者ID:matanso,項目名稱:OASSIS,代碼行數:20,代碼來源:NaiveAlgorithm.java

示例3: storeShortUrl

import org.neo4j.graphdb.Transaction; //導入方法依賴的package包/類
@Override
public void storeShortUrl(ShortUrl shortUrl) {
    Transaction tx = db.beginTx();
    try {
        Node node = template.createNode(new Property(KEY, shortUrl.getKey()));
        node.setProperty(LONG_URL, shortUrl.getLongUrl());
        node.setProperty(USER_ID, shortUrl.getUser().getId());
        index.index(node, KEY, shortUrl.getKey());
        tx.success();
    } catch (Exception ex) {
        logger.error("Problem shortening url in the graph", ex);
        tx.failure();
    } finally {
        tx.finish();
    }

}
 
開發者ID:Glamdring,項目名稱:welshare,代碼行數:18,代碼來源:ViralLinkDaoNeo4j.java

示例4: followingTest

import org.neo4j.graphdb.Transaction; //導入方法依賴的package包/類
@Test
public void followingTest() throws Exception {
    Transaction tx = db.beginTx();
    User user = new User();
    user.setId("foo");
    user.setUsername("ufoo");
    User followed = new User();
    followed.setId("bar");
    followed.setUsername("ubar");
    Following f = new Following();
    f.setFollower(user);
    f.setFollowed(followed);
    try {
        dao.saveFollowing(f);
        tx.success();
    } catch (Exception ex) {
        tx.failure();
        throw ex;
    } finally {
        tx.finish();
    }
}
 
開發者ID:Glamdring,項目名稱:welshare,代碼行數:23,代碼來源:FollowingTest.java

示例5: NaiveAlgorithm

import org.neo4j.graphdb.Transaction; //導入方法依賴的package包/類
/**
 * First off we start a graphDB. then we go over all valid assignments and add them all to undecided keys.
 * We have nodeDic to keep track of all entered nodes, one for each assignment which we also do in the 
 * while loop (enter a node with it's relevant matadata using json and Gson, for each assignment)
 * @param TupleQueryResult validAssignments, int suppToMakeSig, int usersToMakeSig.
 */
@SuppressWarnings("deprecation")
public NaiveAlgorithm(TupleQueryResult validAssignments, int suppToMakeSig, int usersToMakeSig) 
{
	/*first off we start a graphDB. then we go over all valid assignments and add them all to undecided keys.
	 * We have nodeDic to keep track of all entered nodes, one for each assignment which we also do in the 
	 * while loop (enter a node with it's relevant matadata using json and Gson, for each assignment) */
	super(validAssignments);
	this.nodeDic = new HashMap<BindingSet, Node>();
	this.MSP = new ArrayList<BindingSet>();
	this.undecidedKeys = new ArrayList<BindingSet>();
	this.suppToMakeSig =suppToMakeSig;
	this.usersToMakeSig = usersToMakeSig;
	
	BindingSet tempBindingSet = null;
	Node node = null;
	Transaction tx = graphDB.beginTx();
	try
	{
		while(validAssignments.hasNext())
		{ 
			tempBindingSet = validAssignments.next();
			node = graphDB.createNode();
			setBindingSet(node, tempBindingSet);
			setSupportDic(node, new HashMap<String,Integer>());
			setSignificanceBit(node, 0);
			nodeDic.put(tempBindingSet, node);
			this.undecidedKeys.add(tempBindingSet);
		}
		tx.success();
	}catch (QueryEvaluationException e)
	{
		e.printStackTrace();
	}finally
	{
		tx.finish();
	}
}
 
開發者ID:matanso,項目名稱:OASSIS,代碼行數:44,代碼來源:NaiveAlgorithm.java

示例6: update

import org.neo4j.graphdb.Transaction; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
/**
 * input: assignment and userID and his support for said assignment.
 * @param assignment, userID, suuport.
 */
public void update(BindingSet assignment, int userID, int support)
{
	/* input: assignment and userID and his support for said assignment.
	 */
	String userIDString = new Integer(userID).toString();
	int aggAnswer;
	Map<String, Integer> tempDic = null;
	Transaction tx = graphDB.beginTx();
	try
	{
		Node tempNode = nodeDic.get(assignment);
		tempDic = getSupportDic(tempNode);		
		tempDic.put(userIDString, support);
		setSupportDic(tempNode, tempDic);
		aggAnswer = aggregator(assignment);	

		if (aggAnswer == 2) 
		{
			
			undecidedKeys.remove(assignment);
			MSP.add(assignment);
			setSignificanceBit(tempNode, 2);
		}else if (aggAnswer == 1)
		{
			setSignificanceBit(tempNode, 1);
			undecidedKeys.remove(assignment);
		}
		tx.success();
	}finally
	{
		tx.finish();
	}

}
 
開發者ID:matanso,項目名稱:OASSIS,代碼行數:40,代碼來源:NaiveAlgorithm.java

示例7: setSupportDic

import org.neo4j.graphdb.Transaction; //導入方法依賴的package包/類
/***
 * Sets SupportDic field of node to supportDic.
 * @param node
 * @param supportDic
 */
@SuppressWarnings("deprecation")
public void setSupportDic(Node node, Map<String,Integer> supportDic){
	String tempString = serializer.deepSerialize(supportDic);
	Transaction tx = graphDB.beginTx();
	try
	{
		node.setProperty("__supportDic", tempString);
		tx.success();
	}finally
	{
		tx.finish();
	}
}
 
開發者ID:matanso,項目名稱:OASSIS,代碼行數:19,代碼來源:NaiveAlgorithm.java

示例8: setBindingSet

import org.neo4j.graphdb.Transaction; //導入方法依賴的package包/類
/***
 * Sets BindingSet field of node to bindingSet.
 * @param node
 * @param bindingSet
 */
@SuppressWarnings("deprecation")
public void setBindingSet(Node node, BindingSet bindingSet)
{
	String tempString = serializer.serialize(bindingSet);
	Transaction tx = graphDB.beginTx();
	try
	{
		node.setProperty("__bindingSet", tempString);
		tx.success();
	}finally
	{
		tx.finish();
	}
}
 
開發者ID:matanso,項目名稱:OASSIS,代碼行數:20,代碼來源:NaiveAlgorithm.java

示例9: migrateFollowingGraph

import org.neo4j.graphdb.Transaction; //導入方法依賴的package包/類
@Async
public void migrateFollowingGraph() {
    // the jpa dao only needed here, no need to live in the context
    FollowingDaoJpa dao = new FollowingDaoJpa();
    ctx.getAutowireCapableBeanFactory().autowireBean(dao);

    List<User> users = userDao.list(User.class);

    Transaction tx = graphDb.beginTx();
    try {
        for (User user : users) {
            List<User> followers = dao.getFollowers(user);
            for (User follower : followers) {
                if (follower.equals(user)) {
                    continue;
                }
                Following following = dao.findFollowing(follower, user, false);
                if (following.getDateTime() == null) {
                    following.setDateTime(new DateTime().minusMonths(2));
                }
                if (following != null && followingDao.findFollowing(follower, user, false) == null) {
                    followingDao.saveFollowing(following);
                }
            }
        }
        tx.success();
    } catch (RuntimeException ex) {
        tx.failure();
        logger.error("GraphDB transaction problem", ex);
        throw ex;
    } finally {
        tx.finish();
    }
}
 
開發者ID:Glamdring,項目名稱:welshare,代碼行數:35,代碼來源:InternalService.java

示例10: next

import org.neo4j.graphdb.Transaction; //導入方法依賴的package包/類
/***
 * @param userID
 * @return next assignment to query this user, null if none are left.
 */
@SuppressWarnings("deprecation")
@Override
public BindingSet next(int userID) 
{
	/*TODO: maybe make the node making lazy, that is only make the node when the assignment is first asked.
	 * input: userID
	 * output: next assignment to query this user, null if none are left.*/
	String userIDString = new Integer(userID).toString();
	Random random = new Random();
	BindingSet randomKey = null;
	Node tempNode = null;
	Map<String, Integer> tempDic = null;
	Transaction tx = graphDB.beginTx();
	List<BindingSet> listOfAssignments = new ArrayList<BindingSet>(undecidedKeys.size());
	int index;
	
	
	for (BindingSet bindingSet: undecidedKeys)
	{ /*makes a copy of undecidedkeys so that when we iterate over it we can 
												  delete those this userID has answered even though they aren't significant yet. 
												  Remember these two lists contain the same elements and not copies of the elements!*/
		listOfAssignments.add(bindingSet);
	}
	
	try
	{
		while (!listOfAssignments.isEmpty()) 
		{ // iterates over random assignments until an undiscovered one is found.
			index = random.nextInt(listOfAssignments.size());
			randomKey = listOfAssignments.get(index);
			tempNode = nodeDic.get(randomKey);
			tempDic = getSupportDic(tempNode);
			//System.out.println(tempDic.containsKey(userIDString));
			
			if (!tempDic.containsKey(userIDString))
			{ //if user hasn't been asked this assignment before then return it.
				break;
			}else
			{
				listOfAssignments.remove(index);
			}
		}
		tx.success();
	}finally
	{
		tx.finish();
	}
	if (listOfAssignments.isEmpty())
	{
		return null;
	}else
	{
		return randomKey;
	}
}
 
開發者ID:matanso,項目名稱:OASSIS,代碼行數:60,代碼來源:NaiveAlgorithm.java


注:本文中的org.neo4j.graphdb.Transaction.finish方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。