Advertisement
Guest User

Untitled

a guest
Nov 9th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. public static synchronized Connection getOrientDbConnection(String appName)
  2. {
  3. try {
  4. // address of Db Server
  5. OServerAdmin serverAdmin = new OServerAdmin
  6. ("remote:" + ip + ":" + port + "/"
  7. + appName).connect("root", "1234");
  8.  
  9. if (serverAdmin.existsDatabase())
  10. {
  11. serverAdmin.close();
  12. Properties info = new Properties();
  13. info.put("user", "root");
  14. info.put("password", "1234");
  15. Connection conn = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:remote:" + ip + ":" + port + "/"
  16. + appName, info);
  17.  
  18. //System.out.println(" Database Connection instance returned for : " + appName + " for thread ID : " + Thread.currentThread().getId());
  19.  
  20. return conn;
  21. }
  22. else
  23. {
  24. // "Type_Of_Db", "Type_Of_Storage"
  25. serverAdmin.createDatabase("GRAPH", "plocal");
  26. serverAdmin.close();
  27.  
  28. OrientGraphFactory graphFactory = new OrientGraphFactory(
  29. "remote:" + ip + ":" + port + "/" + appName);
  30. /**
  31. * ####################### Do This only Ones-Per-Database #####################
  32. * 1. Create index with unique field
  33. * @name = unique index will be created only one time for a particular database
  34. *
  35. *
  36. */
  37. OrientGraphNoTx graph = graphFactory.getNoTx();
  38. graph.createKeyIndex("name", Vertex.class, new Parameter<String, String>("type", "UNIQUE"));
  39.  
  40. // shutdown the graph which created Index immediately
  41. graph.commit();
  42. graph.shutdown();
  43.  
  44. // close all db pools
  45. graphFactory.close();
  46.  
  47. try
  48. {
  49. Properties info = new Properties();
  50. info.put("user", "root");
  51. info.put("password", "pcp");
  52. Connection conn = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:remote:" + UserflowConstant.ip + ":" + UserflowConstant.port + "/" + appName, info);
  53.  
  54. //System.out.println(" Database created and Connection instance return for : " + appName + " for thread ID : " + Thread.currentThread().getId());
  55.  
  56. return conn;
  57.  
  58. } catch (Exception e) {
  59. //System.out.println("Problem creating database or getting connection from database " + " for thread ID : " + Thread.currentThread().getId() + e.getMessage());
  60. e.getMessage();
  61. return null;
  62. }
  63.  
  64. }
  65. }
  66. catch(Exception e)
  67. {
  68. e.getMessage();
  69. }
  70. return null;
  71. }
  72.  
  73. Connection conn = DB.getOrientDbConnection(String appName)
  74.  
  75. // create vertex
  76. // create edges
  77.  
  78. conn.commit()
  79. conn.close();
  80.  
  81. Name: OrientDB <- Asynch Client (/192.168.1.11:4424)
  82. State: RUNNABLE
  83. Total blocked: 0 Total waited: 136
  84.  
  85. Stack trace:
  86. java.net.SocketInputStream.socketRead0(Native Method)
  87. java.net.SocketInputStream.socketRead(Unknown Source)
  88. java.net.SocketInputStream.read(Unknown Source)
  89. java.net.SocketInputStream.read(Unknown Source)
  90. java.io.BufferedInputStream.fill(Unknown Source)
  91. java.io.BufferedInputStream.read(Unknown Source)
  92. - locked java.io.BufferedInputStream@1780dcd
  93. java.io.DataInputStream.readByte(Unknown Source)
  94. com.orientechnologies.orient.enterprise.channel.binary.OChannelBinary.readByte(OChannelBinary.java:68)
  95. com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient.beginResponse(OChannelBinaryAsynchClient.java:189)
  96. com.orientechnologies.orient.client.binary.OAsynchChannelServiceThread.execute(OAsynchChannelServiceThread.java:51)
  97. com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:77)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement