TIBCO®图形数据库-构建应用程序

由:
最后更新:
2018年8月05日晚上6:11

TIBCO®图形数据库-构建应用程序

Javadocs

样例应用程序

版权所有:TIBCO Software Ivwin黑nc. /** *保留所有权利。* *根据Apache许可2.0版本(以下简称“许可”)获得许可;您不能使用此文件,除非*符合许可证。*与此文件一起包含在分发包中的许可证副本。*你也可以获得一份许可证在http://www.apache.org/licenses/license - 2.0 * *除非适用法律要求或书面同意,*在许可证下发布的软件分布在一个“目前的”基础上,没有任何形式的保证或条件,明示或默示。*请参阅许可证,了解许可证下控制许可的特定语言和*限制。* */导入com.tibco.tgdb.connection.TGConnection;进口com.tibco.tgdb.connection.TGConnectionFactory;进口com.tibco.tgdb.log.TGLogManager; import com.tibco.tgdb.log.TGLogger; import com.tibco.tgdb.model.TGEdge; import com.tibco.tgdb.model.TGEntity; import com.tibco.tgdb.model.TGGraphMetadata; import com.tibco.tgdb.model.TGGraphObjectFactory; import com.tibco.tgdb.model.TGKey; import com.tibco.tgdb.model.TGNode; import com.tibco.tgdb.model.TGNodeType; public class CreateAndUpdate { public String url = "tcp://scott@localhost:8222"; public String passwd = "scott"; public TGLogger.TGLevel logLevel = TGLogger.TGLevel.Info; void run() throws Exception { System.out.printf("Using url : %s, password : %s, log level : %s\n", url, passwd, logLevel.toString()); TGLogger logger = TGLogManager.getInstance().getLogger(); logger.setLevel(logLevel); TGConnection conn = TGConnectionFactory.getInstance().createConnection(url, null, passwd, null); conn.connect(); TGGraphObjectFactory gof = conn.getGraphObjectFactory(); TGGraphMetadata gmd = conn.getGraphMetadata(true); TGNodeType testNodeType = gmd.getNodeType("testnode"); System.out.println("Start transaction 1"); System.out.println("Create node1"); TGNode node1 = gof.createNode(testNodeType); node1.setAttribute("name", "john doe"); node1.setAttribute("rate", 3.3); node1.setAttribute("nickname", "fast"); node1.setAttribute("thing1", true); conn.insertEntity(node1); System.out.println("Create node2"); TGNode node2 = gof.createNode(testNodeType); node2.setAttribute("name", "julie"); node2.setAttribute("factor", 3.3); node2.setAttribute("thing2", false); conn.insertEntity(node2); System.out.println("Create node3"); TGNode node3 = gof.createNode(testNodeType); node3.setAttribute("name", "margo"); node3.setAttribute("factor", 2.3); node3.setAttribute("nickname", "quick"); conn.insertEntity(node3); System.out.println("Create edge1"); TGEdge edge1 = gof.createEdge(node1, node2, TGEdge.DirectionType.BiDirectional); edge1.setAttribute("name", "spouse"); conn.insertEntity(edge1); System.out.println("Create edge2"); TGEdge edge2 = gof.createEdge(node1, node3, TGEdge.DirectionType.Directed); edge2.setAttribute("name", "daughter"); conn.insertEntity(edge2); System.out.println("Commit transaction 1"); conn.commit(); //----- write data to database ----------. Everything is create System.out.println("Commit transaction 1 completed"); System.out.println("Start transaction 2"); // updates System.out.println("Update node1"); node1.setAttribute("age", 40); conn.updateEntity(node1); System.out.println("Delete edge1"); conn.deleteEntity(edge1); System.out.println("Update edge2"); //add a new attribute edge2.setAttribute("extra", true); //update existing one edge2.setAttribute("name", "kid"); conn.updateEntity(edge2); System.out.println("Create node4"); TGNode node4 = gof.createNode(testNodeType); node4.setAttribute("name", "McEnroe"); node4.setAttribute("level", 3.0); conn.insertEntity(node4); System.out.println("Create edge3"); TGEdge edge3 = gof.createEdge(node1, node4, TGEdge.DirectionType.BiDirectional); edge3.setAttribute("name", "Tennis Partner"); conn.insertEntity(edge3); System.out.println("Commit transaction 2"); conn.commit(); // update John doe's value --------. System.out.println("Commit transaction 2 completed"); // conn.getGraphMetadata(true); System.out.println("Start unique get operation"); gmd = conn.getGraphMetadata(true); TGKey key = gof.createCompositeKey("testnode"); key.setAttribute("name", "margo"); TGEntity ent = conn.getEntity(key, null); if (ent != null) { System.out.printf("name : %s\n", ent.getAttribute("name").getValue()); for (TGEdge edge : ((TGNode) ent).getEdges()) { TGNode[] nodes = edge.getVertices(); for (int i=0; i

编译方法:javac -cp /lib/tgdb-client.jar CreateAndUpdate.java

执行命令:java -cp /lib/tgdb-client.jar。/ CreateAndUpdate

附件

附件 大小
二进制数据javadocs.tar.gz 65.13 KB