Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. public Connection getConnection() throws SQLException {
  2. return DriverManager.getConnection("jdbc:neo4j:bolt://localhost:port");
  3. }
  4.  
  5. public Connection getConnection(String username, String password) throws SQLException {
  6. return DriverManager.getConnection("jdbc:neo4j:bolt://localhost:port");
  7. }
  8.  
  9. @Override
  10. public PrintWriter getLogWriter() throws SQLException {
  11. return pw;
  12. }
  13.  
  14. @Override
  15. public void setLogWriter(PrintWriter out) throws SQLException {
  16. pw = out;
  17. }
  18.  
  19. @Override
  20. public void setLoginTimeout(int seconds) throws SQLException {
  21. }
  22.  
  23. @Override
  24. public int getLoginTimeout() throws SQLException {
  25. return 0;
  26. }
  27. @Override
  28. public <T> T unwrap(Class<T> iface) throws SQLException {
  29. return ConnectionPoolDataSource.class.equals(iface) ? (T) this : super.unwrap(iface);
  30. }
  31.  
  32. @Override
  33. public boolean isWrapperFor(Class<?> iface) throws SQLException {
  34. return ConnectionPoolDataSource.class.equals(iface) || super.isWrapperFor(iface);
  35. }
  36.  
  37. @Override
  38. public PooledConnection getPooledConnection() throws SQLException {
  39. System.out.println("Inside getPooledConnection with args + Neo4jConnectionPoolDataSource");
  40. return new Neo4jPooledConnection(null,null);
  41. }
  42. @Override
  43. public PooledConnection getPooledConnection(String paramString1,
  44. String paramString2) throws SQLException {
  45.  
  46. return new Neo4jPooledConnection("username","password");
  47. }
  48. public class Neo4jPooledConnection implements PooledConnection {
  49.  
  50. private Connection con;
  51. private String user;
  52. private String password;
  53.  
  54. public Neo4jPooledConnection(String user, String password)
  55. {
  56. this.con = con;
  57. this.user = user;
  58. this.password = password;
  59.  
  60.  
  61. }
  62.  
  63.  
  64. public void addConnectionEventListener(ConnectionEventListener connectionEventListener)
  65. { }
  66.  
  67. public void removeConnectionEventListener(ConnectionEventListener connectionEventListener)
  68. { }
  69.  
  70.  
  71. public void close()
  72. throws SQLException
  73. {
  74. if (con != null) {
  75. con.close();
  76. con = null;
  77. }
  78. }
  79.  
  80.  
  81. public Connection getConnection() throws SQLException {
  82.  
  83. if (con == null || con.isClosed()) {
  84. con = ((user == null)
  85. ? Neo4jConnectionPoolDataSource.this.getConnection()
  86. : Neo4jConnectionPoolDataSource.this.getConnection(user, password));
  87. return con;
  88. } else
  89. { throw new IllegalStateException();}
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement