Hi Michael.

I tried out using jdbc driver using the same scenario mentioned earlier
 inserting data by batch of 500 queries
and query
MERGE (firstNode {id:{1}})
ON CREATE SET firstNode.brand="{2}", firstNode.updated = timestamp(),firstNode
:Soap
ON MATCH SET firstNode.updated=timestamp()
MERGE (secondNode{id:'{3}'}) 
ON CREATE SET secondNode.name="{4}", secondNode.updated = timestamp(), 
secondNode:Company
ON MATCH SET secondNode.updated=timestamp()
WITH firstNode, secondNode 
//CHANGE MANUFACTURER if there is an existing manufacturer
OPTIONAL MATCH firstNode - [existing:`manufacturer`] - () 
DELETE existing 
CREATE UNIQUE p = (firstNode)-[r:`manufacturer`]-(secondNode) RETURN p;
and was wondering why jdbc driver processing time is slower that the java 
rest binding, or I am just using the wrong way... because for a small 
sample data 619 nodes and 4611 relationships it took the jdbc driver one 
minute to insert the data while, it just took 21 seconds for the java rest 
binding to insert the data.  
Here is the code used for inserting data:
public void processList(List<CYPHERExecuteQueryObject> list) {
        for (CYPHERExecuteQueryObject c : list) {
            neo4jjdbcinsert(c.getQuery(), c.getParams());
            ctr++;
            if (ctr == 500) {
                commit();
                ctr = 0;
            }
        }
    }

    // set auto commit to false
    public void neo4jjdbcinsert(String query, Object... params) {
        try {
            if (con.isClosed()) {
                con = (Neo4jConnection) 
DriverManager.getConnection("jdbc:neo4j://localhost:7474/");
                con.setAutoCommit(false);
            }
            HashMap<String, Object> map = new HashMap<>();
            for (int i = 0; i < params.length; i++) {
                map.put(i + 1 +"", params[i]);
            }
            try {
                con.executeQuery(query, map);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void commit() {
        try {
            con.commit();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
}


Thanks

On Friday, May 2, 2014 4:14:30 PM UTC+8, Gene Tan wrote:
>
> Thanks! Michael, will try this out
>
> On Thursday, May 1, 2014 5:15:12 PM UTC+8, Michael Hunger wrote:
>>
>> 1. Use labels + indexes (or constraints)
>>
>> Without an label + existing index your first operation (merge) will have 
>> to go over all nodes in the graph to find if there is already a duplicate 
>> which it would then merge to
>> the second CREATE UNIQUE should be a MERGE too.
>>
>> 2. Use parameters for your literal input values, otherwise cypher has to 
>> recompile the query every time and cannot reuse-the pre-compiled query 
>> plans.
>> 3. you might want to move from Java-Rest-Binding to the JDBC driver, 
>> which is much better for cypher interactions with the server.
>>
>>
>>
>> On Wed, Apr 30, 2014 at 9:25 AM, Gene Tan <[email protected]> wrote:
>>
>>> Hello,
>>>
>>> I am new to neo4j 
>>> currently already have a graph that contains at least 180000 nodes and 
>>> 1400000 
>>> relationships , 
>>> I am inserting data by batch of 500 queries, through the java rest 
>>> binding library, and have observed that some queries had encountered read 
>>> timeout, I was wondering if it is because of my query used for inserting 
>>> data. Or is it related to configurations with neo4j..
>>> Here is a sample query that I am using for inserting data
>>>
>>>> MERGE (firstNode {id:'1234'})
>>>> ON CREATE SET firstNode.brand="Dove", firstNode.updated = 
>>>> timestamp(),firstNode
>>>> :Soap
>>>> ON MATCH SET firstNode.updated=timestamp()
>>>> MERGE (secondNode{id:'2345'}) 
>>>> ON CREATE SET secondNode.name="Dove Manufacturer", secondNode.updated 
>>>> =timestamp
>>>> (), firstNode:Company
>>>> ON MATCH SET secondNode.updated=timestamp()
>>>> WITH firstNode, secondNode 
>>>> //CHANGE MANUFACTURER if there is an existing manufacturer
>>>> OPTIONAL MATCH firstNode - [existing:`manufacturer`] - () 
>>>> DELETE existing 
>>>> CREATE UNIQUE p = (firstNode)-[r:`manufacturer`]-(secondNode) RETURN p;
>>>>
>>>
>>> Is there anyway to make this query run faster?
>>>
>>> Thanks!
>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Neo4j" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to