本文整理汇总了Java中org.neo4j.helpers.collection.IteratorUtil.singleOrNull方法的典型用法代码示例。如果您正苦于以下问题:Java IteratorUtil.singleOrNull方法的具体用法?Java IteratorUtil.singleOrNull怎么用?Java IteratorUtil.singleOrNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.neo4j.helpers.collection.IteratorUtil
的用法示例。
在下文中一共展示了IteratorUtil.singleOrNull方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIdentity
import org.neo4j.helpers.collection.IteratorUtil; //导入方法依赖的package包/类
@POST
@Path("/identity")
public Response createIdentity(@DefaultValue("") @QueryParam("email") String email,
@DefaultValue("") @QueryParam("md5hash") String hash,
@Context GraphDatabaseService db) throws IOException {
hash = Identity.getHash(email, hash);
try ( Transaction tx = db.beginTx() ) {
Node identity = IteratorUtil.singleOrNull(
db.findNodesByLabelAndProperty(Labels.Identity, "hash", hash));
if (identity == null) {
identity = db.createNode(Labels.Identity);
identity.setProperty("hash", hash);
}
tx.success();
} catch (Throwable t) {
// If it is not a duplicate, then something bad happened
if (!(t instanceof ConstraintViolationException)){
throw Exception.identityNotCreated;
}
}
return Response.ok().build();
}
示例2: createPage
import org.neo4j.helpers.collection.IteratorUtil; //导入方法依赖的package包/类
@POST
@Path("/page")
public Response createPage(@DefaultValue("") @QueryParam("url") String url,
@Context GraphDatabaseService db) throws IOException {
url = Page.getPageURL(url);
try ( Transaction tx = db.beginTx() ) {
Node page = IteratorUtil.singleOrNull(
db.findNodesByLabelAndProperty(Labels.Page, "url", url));
if (page == null) {
page = db.createNode(Labels.Page);
page.setProperty("url", url);
}
tx.success();
} catch (Throwable t) {
// If it is not a duplicate, then something bad happened
if (!(t instanceof ConstraintViolationException)){
throw Exception.pageNotCreated;
}
}
return Response.ok().build();
}
示例3: getUserFOFs
import org.neo4j.helpers.collection.IteratorUtil; //导入方法依赖的package包/类
@GET
@Path("/user/{username}/fofs")
public Response getUserFOFs(@PathParam("username") String username, @Context GraphDatabaseService db) throws IOException {
List<Map<String, Object>> results = new ArrayList<>();
HashMap<Node, int[]> fofs = new HashMap<>();
try ( Transaction tx = db.beginTx() )
{
final Node user = IteratorUtil.singleOrNull(db.findNodesByLabelAndProperty(Labels.User, "username", username));
findFofs(fofs, user);
List<Map.Entry<Node, int[]>> fofList = orderFofs(fofs);
returnFofs(results, fofList.subList(0, Math.min(fofList.size(), 10)));
}
return Response.ok().entity(objectMapper.writeValueAsString(results)).build();
}
示例4: getSingle
import org.neo4j.helpers.collection.IteratorUtil; //导入方法依赖的package包/类
@Override
public T getSingle()
{
try
{
return IteratorUtil.singleOrNull( (Iterator<T>) this );
}
finally
{
close();
}
}
示例5: getPageNode
import org.neo4j.helpers.collection.IteratorUtil; //导入方法依赖的package包/类
public static Node getPageNode(String url, GraphDatabaseService db) {
Node page = IteratorUtil.singleOrNull(
db.findNodesByLabelAndProperty(Labels.Page, "url", url));
if(page != null) {
return page;
} else {
throw Exception.pageNotFound;
}
}
示例6: getIdentityNode
import org.neo4j.helpers.collection.IteratorUtil; //导入方法依赖的package包/类
public static Node getIdentityNode(String hash, GraphDatabaseService db) {
Node identity = IteratorUtil.singleOrNull(
db.findNodesByLabelAndProperty(Labels.Identity, "hash", hash));
if(identity != null) {
return identity;
} else {
throw Exception.identityNotFound;
}
}
示例7: getSingle
import org.neo4j.helpers.collection.IteratorUtil; //导入方法依赖的package包/类
public T getSingle()
{
try
{
return IteratorUtil.singleOrNull( (Iterator<T>) this );
}
finally
{
close();
}
}