@EggGump
2018-01-31T10:53:21.000000Z
字数 2701
阅读 539
字符串 upper,lower,substring,replace,aggregation聚类 max,min,sum,avg,count,关系函数startnode,endnode,id,type,数据库的备份与恢复,索引:可提高应用程序性能,unique 属性值唯一性限制,在java中创建数据(eclipse) 原生java API(这一部分还没学完)
未分类
在此输入正文
null排除或选择
MATCH (e:Employee)
WHERE e.id IS NULL
RETURN e.id,e.name,e.sal,e.deptnoin语法
MATCH (e:Employee)
WHERE e.id IN [123,124]
RETURN e.id,e.name,e.sal,e.deptno- 为已有节点创建关系(王阳指导)
match(a:Employee),(b:Employee) where a.Name='ZhaoPeng' and b.Name='Bob'
create(a)-[r:Like]->(b) return r
- 字符串 upper,lower,substring,replace
match(e:Employee)
return e.Id,substring(e.Name,0,2),e.Sal,e.DeptNo- aggregation聚类 max,min,sum,avg,count
match(e:Employee) return count(*) 返回查询行数
match(e:Employee) return max(e.Sal),min(e.Sal)返回工资最大最小值
match(e:Employee) return avg(e.Sal),sum(e.Sal)返回工资的均值与总值- 关系函数startnode,endnode,id,type
match(a)-[r:Like]-(b)
return startnode(r) 查找关系的开始节点
match(a)-[r:Like]-(b)
return id(r),type(r) 返回关系的ID和类型,这里的类型就是它的标签- 数据库的备份与恢复
备份:手动把data\*.db中的所有文件打包起来存到别的地方
恢复:手动把刚才的打包文件再解压到*.db文件中。。有点扯蛋,我还以为会有什么很厉害的方- 索引:可提高应用程序性能
create index on :Employee(Name)
Drop index on:Employee(Name)- unique 属性值唯一性限制
create constraint on (e:Employee)
assert e.Id is unique
此时,再插入一个相同的Id就会出错
drop constraint on (e:Employee)
assert e.Id is unique
丢弃先前的限制,此时又可以插入相同的数据了
1.创建一个java project
2.将neo4j里面的lib文件夹中所有的jar包导入到项目中。
3.编写代码,运行即可创建一个数据库,经验证可用
//public Neo4JJavaAPIDBOperation.java 主文件
package com.neusoft.www.neo4j.java.example;
import java.io.File;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
public class Neo4JJavaAPIDBOperation {
public static void main(String[] args) {
File directoryDB = new File("C:/Neo4jDB") ;
GraphDatabaseFactory dbFactory = new GraphDatabaseFactory() ;
GraphDatabaseService db = dbFactory.newEmbeddedDatabase(directoryDB) ;
try(Transaction tx = db.beginTx()) {
//Perform DB operations
//new node
Node javaNode = db.createNode(MyLabels.JAVA) ;
Node scalaNode = db.createNode(MyLabels.SCALA) ;
//set node properties
String property = "Property" ;
for(int i = 0; i < 4; i ++) {
javaNode.setProperty(property+i, i);
scalaNode.setProperty(property+i, i);
}
//add node relationship
Relationship relationship = javaNode.createRelationshipTo(scalaNode, MyRelationship.JVM_LANGIAGES) ;
for(int i = 0; i < 3; i ++) {
relationship.setProperty(property + 1, i);
}
tx.success();
}catch(Exception e) {}
System.out.println("Done successfully") ;
}
}
//public MyLabels.java 这是一个枚举
package com.neusoft.www.neo4j.java.example;
import org.neo4j.graphdb.Label;
public enum MyLabels implements Label{
JAVA,SQL,SCALA ;
}
//这也是一个枚举
package com.neusoft.www.neo4j.java.example;
import org.neo4j.graphdb.RelationshipType;
public enum MyRelationship implements RelationshipType {
JVM_LANGIAGES,NON_JVM_LAVGIAGES ;
}
准备工作与前面相同,下面是编代码
java