NEO4J JDBC Add relationship error - neo4j

I am trying to add a relationship to nodes using Neo4J JDBC driver and have formed the following query :
MATCH (node1:USER {fameId : 'test1'}),(node2:BEAM {eventUId : 'E000000016'})
CREATE (node1)-[r:PERFORMED{type:'test'}]->(node2)`
When I try to run this query using:
mConnection.createStatement().execute("MATCH (node1:USER {fameId : 'test1'}),(node2:BEAM {eventUId : 'E000000016'}) CREATE (node1)-[r:PERFORMED{type:'test'}]->(node2)")
It gives me the following error :
Error executing query MATCH (node1:USER {fameId : 'test1'}),(node2:BEAM {eventUId : 'E000000016'}) CREATE (node1)-[r:PERFORMED{type:'test'}]->(node2)
MATCH (node1:USER {fameId : 'test2'}),(node2:BEAM {eventUId : 'E000000016'}) CREATE (node1)-[r:PERFORMED{type:'test'}]->(node2)
with params {}
Please help. I am not able to proceed further :(

Related

Artifactory getStats always returns null object

I am trying to get the download statistics of a docker image we host on our own artifactory server in a groovy plugin on the server.
So far it looks like the manifest.json file has the statistics I am looking for.
repositories.getStats(RepoPath) should return a StatsInfo object which has getDownloadCount().
However, no matter what I pass to repositories.getStats() it always returns a null object.
I've tried:
docker-local
docker-local/ai
docker-local/ai/latest
docker-local/ai/latest/manifest.json
But still repositories.getStats() return a null object.
I would expect the following to work:
def stats = repositories.getStats(RepoPathFactory.create('docker-local','ai/latest/manifest.json'))
def dlCount = stats.getDownloadCount()
But it keeps returning the error:
"Cannot invoke method getDownloadCount() on null object"
Calling ?stats on the manifest.json through the REST API works and it returns a json formatted string with the download statistics. Ex:
my-artifactory-server.io/api/storage/docker-local/ai/latest/manifest.json?stats
"uri" : "my-artifactory-server.io/api/storage/docker-local/ai/latest/manifest.json",
"downloadCount" : 10,
"lastDownloaded" : 1593160404880,
"lastDownloadedBy" : "Peter Griffin",
"remoteDownloadCount" : 0,
"remoteLastDownloaded" : 0
What am I doing wrong?
What you tried looks ok, may be you need to enforce the stats object has to be StatsInfo
Below is my tested and working code which prints the download count of manifest.json
import org.artifactory.repo.RepoPathFactory
import org.artifactory.fs.StatsInfo
executions {
getDockerStats() {
def statsInfo = (StatsInfo) repositories.getStats(RepoPathFactory.create("docker-local","hello-world/latest/manifest.json"))
log.info("stats download count : ${statsInfo.getDownloadCount()}")
}
}
and in the logs
[getDockerStats:12 ] [http-nio-8081-exec-5] - stats download count : 2

neo4j-graphql-schema: Cypher query to Graphql Schema and query

I tested the following query in a Neo4j browser and it worked. Now I am trying to define a schema and query for a React app using the neo4j-graphql-js plugin/driver (import { neo4jgraphql } from "neo4j-graphql-js";). My issue is I do not know how to define a schema that will take 2 parameters, example: action(startTime: {epoch}, endTime: {epoch}). The action node in the DB has the following properties: action, timelist and timestamp.
MATCH (sec:Second)<-[:AT_TIME]-(act:action)-[:TARGET]->(obj:object)
WHERE act.timestamp >= 1499350389000 AND act.timestamp <= 1499350389000
RETURN sec, act, obj

py2neo execute cypher to find path

i use py2neo to find get path ,my function like this :
-----------------------my funciton -----------------
def findrelationall1(graph_db,startmobile,endmobile):
querystring='''MATCH(catelyn:Person {usernbr:%s}), (drogo:Person {usernbr:%s})
MATCH p=(catelyn)-[*..100]-(drogo)
RETURN p'''
result=graph_db.run(querystring1)
for x in result :
dic1=dict(x)
print dic1.values()
return is :
[(c0d4730)-[:a1_a2_201705 {count:4}]->(bf795f0)<-[:b1_b2_201705
{count:4}]-(ae68e9e)]
what "(c0d4730) " is ? a node ?
how can i use this value to return a node and property ?
I think it is the internal id.
Try
from py2neo import remote remote(node)._id
See How to get automatic node ID from py2neo?

Neo4j : When Query using an index hint , I got Unknown error

I use the exactly query just as http://docs.neo4j.org/chunked/milestone/query-using.html says.
My Neo4j Kernel version is
Neo4j - Graph Database Kernel 2.0.0-M03
I don't know why?
It's ok for me to run
CREATE (_1 { `name`:"Emil" })
CREATE (_2:`German` { `name`:"Stefan", `surname`:"Plantikow" })
CREATE (_3 { `age`:34, `name`:"Peter" })
CREATE (_4:`Swedish` { `age`:36, `awesome`:true, `name`:"Andres", `surname`:"Taylor" })
CREATE _1-[:`KNOWS`]->_3
CREATE _2-[:`KNOWS`]->_4
CREATE _4-[:`KNOWS`]->_3
But I got Unknown error while using
match n:Swedish using index n:Swedish(surname)
where n.surname = 'Taylor'
return n
If your query explicitly mandates to use an index, you need to make sure that it exists.
So run before querying:
CREATE INDEX ON :Swedish(surname)

Getting NotInTransactionException while querying neo4j index

I am currently using neo4j 1.8.1 . I am getting NotInTransactionException , when I am querying the neo4j index to get some nodes.
Following is a simple query , which i am executing on neo4j
if (graphDb.index().existsForNodes("NODEINDEX")) {
IndexHits<Node> hits = graphDb.index().forNodes(NODEINDEX).query(query);
}
The following is stacktrace for the exception.
"message" : "Error fetching transaction for current thread",
"exception" : "NotInTransactionException",
"stacktrace" : [ "org.neo4j.kernel.impl.index.IndexConnectionBroker.getCurrentTransaction(IndexConnectionBroker.java:134)", "org.neo4j.kernel.impl.index.IndexConnectionBroker.acquireReadOnlyResourceConnection(IndexConnectionBroker.java:84)", "org.neo4j.index.impl.lucene.LuceneIndex.getReadOnlyConnection(LuceneIndex.java:105)", "org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:245)", "org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:227)", "org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:238)", "com.uprr.netcontrol.starmap.neo4j.plugins.aggregate_node_status.NodeStatusHelper.getGraphNodes(NodeStatusHelper.java:39)",
I found the following in Neo4j api.
private Transaction getCurrentTransaction() throws NotInTransactionException
{
try
{
return transactionManager.getTransaction();
}
catch ( SystemException se )
{
throw new NotInTransactionException(
"Error fetching transaction for current thread", se );
}
}
Do we need to explicitly start a transaction for querying neo4j index?
Any thoughts?
Thanks
Here's a theory: I don't know if this is only an issue with the code pasted here but the check:
if (graphDb.index().existsForNodes("NODEINDEX"))
checks for the index named "NODEINDEX", however the actual query
graphDb.index().forNodes(NODEINDEX).query(query);
checks for the index named whatever is in the constant NODEINDEX. Those two are probably not the same and so it tries to create that index for you and fails due to not being in a transaction.
if there isn't an existing appropriate index, I think it'll create one before returning it; this operation needs to be wrapped in a transaction.

Resources