JDCConnection.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. namespace System.Data.Common
  2. {
  3. using java.sql;
  4. using java.util;
  5. using System;
  6. public class JDCConnection : Connection
  7. {
  8. private JDCConnectionPool pool;
  9. private Connection conn;
  10. private bool inuse;
  11. private long timestamp;
  12. public JDCConnection(Connection conn, JDCConnectionPool pool)
  13. {
  14. this.conn=conn;
  15. this.pool=pool;
  16. this.inuse=false;
  17. this.timestamp=0;
  18. }
  19. public bool lease()
  20. {
  21. lock(this)
  22. {
  23. if(inuse)
  24. {
  25. return false;
  26. }
  27. else
  28. {
  29. inuse=true;
  30. timestamp = java.lang.System.currentTimeMillis();
  31. return true;
  32. }
  33. }
  34. }
  35. public bool validate()
  36. {
  37. try
  38. {
  39. conn.getMetaData();
  40. }
  41. catch (Exception)
  42. {
  43. return false;
  44. }
  45. return true;
  46. }
  47. public bool inUse()
  48. {
  49. return inuse;
  50. }
  51. public long getLastUse()
  52. {
  53. return timestamp;
  54. }
  55. public void close() //throws SQLException
  56. {
  57. pool.returnConnection(this);
  58. }
  59. public void expireLease()
  60. {
  61. inuse=false;
  62. }
  63. protected Connection getConnection()
  64. {
  65. return conn;
  66. }
  67. public void setTypeMap(Map map) //throws SQLException
  68. {
  69. conn.setTypeMap(map);
  70. }
  71. public Map getTypeMap() //throws SQLException
  72. {
  73. return conn.getTypeMap();
  74. }
  75. public PreparedStatement prepareStatement(String sql) //throws SQLException
  76. {
  77. return conn.prepareStatement(sql);
  78. }
  79. public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) //throws SQLException
  80. {
  81. return conn.prepareStatement(sql, resultSetType, resultSetConcurrency);
  82. }
  83. public CallableStatement prepareCall(String sql) //throws SQLException
  84. {
  85. return conn.prepareCall(sql);
  86. }
  87. public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) //throws SQLException
  88. {
  89. return conn.prepareCall(sql, resultSetType, resultSetConcurrency);
  90. }
  91. public Statement createStatement(int resultSetType, int resultSetConcurrency) //throws SQLException
  92. {
  93. return conn.createStatement(resultSetType, resultSetConcurrency);
  94. }
  95. public Statement createStatement() //throws SQLException
  96. {
  97. return conn.createStatement();
  98. }
  99. public String nativeSQL(String sql) //throws SQLException
  100. {
  101. return conn.nativeSQL(sql);
  102. }
  103. public void setAutoCommit(bool autoCommit) //throws SQLException
  104. {
  105. conn.setAutoCommit(autoCommit);
  106. }
  107. public bool getAutoCommit() //throws SQLException
  108. {
  109. return conn.getAutoCommit();
  110. }
  111. public void commit() //throws SQLException
  112. {
  113. conn.commit();
  114. }
  115. public void rollback() //throws SQLException
  116. {
  117. conn.rollback();
  118. }
  119. public bool isClosed() //throws SQLException
  120. {
  121. if(conn.isClosed())
  122. return true;
  123. return !inUse();
  124. }
  125. public DatabaseMetaData getMetaData() //throws SQLException
  126. {
  127. return conn.getMetaData();
  128. }
  129. public void setReadOnly(bool readOnly) //throws SQLException
  130. {
  131. conn.setReadOnly(readOnly);
  132. }
  133. public bool isReadOnly()// throws SQLException
  134. {
  135. return conn.isReadOnly();
  136. }
  137. public void setCatalog(String catalog) //throws SQLException
  138. {
  139. conn.setCatalog(catalog);
  140. }
  141. public String getCatalog() //throws SQLException
  142. {
  143. return conn.getCatalog();
  144. }
  145. public void setTransactionIsolation(int level) //throws SQLException
  146. {
  147. conn.setTransactionIsolation(level);
  148. }
  149. public int getTransactionIsolation() //throws SQLException
  150. {
  151. return conn.getTransactionIsolation();
  152. }
  153. public SQLWarning getWarnings() //throws SQLException
  154. {
  155. return conn.getWarnings();
  156. }
  157. public void clearWarnings() //throws SQLException
  158. {
  159. conn.clearWarnings();
  160. }
  161. // --------- JDBC 3.0 -------------
  162. /*
  163. public void setHoldability(int holdability)
  164. {
  165. conn.setHoldability(holdability);
  166. }
  167. public int getHoldability()
  168. {
  169. return conn.getHoldability();
  170. }
  171. public Savepoint setSavepoint()
  172. {
  173. return conn.setSavepoint();
  174. }
  175. public Savepoint setSavepoint(string name)
  176. {
  177. return conn.setSavepoint(name);
  178. }
  179. public void rollback(Savepoint savepoint)
  180. {
  181. conn.rollback(savepoint);
  182. }
  183. public void releaseSavepoint(Savepoint savepoint)
  184. {
  185. conn.releaseSavepoint(savepoint);
  186. }
  187. public Statement createStatement(int resultSetType, int resultSetConcurrency,
  188. int resultSetHoldability)
  189. {
  190. return conn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
  191. }
  192. public PreparedStatement prepareStatement(String sql, int resultSetType,
  193. int resultSetConcurrency, int resultSetHoldability)
  194. {
  195. throw new NotImplementedException();
  196. }
  197. public CallableStatement prepareCall(String sql, int resultSetType,
  198. int resultSetConcurrency,
  199. int resultSetHoldability)
  200. {
  201. return conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
  202. }
  203. public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
  204. {
  205. return conn.prepareStatement(sql, autoGeneratedKeys);
  206. }
  207. public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
  208. {
  209. return conn.prepareStatement(sql, columnIndexes);
  210. }
  211. public PreparedStatement prepareStatement(String sql, String[] columnNames)
  212. {
  213. return conn.prepareStatement(sql, columnNames);
  214. }
  215. */
  216. }
  217. }