OracleProvider.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // Mainsoft.Data.Jdbc.Providers.OracleProvider
  3. //
  4. // Authors:
  5. // Konstantin Triger <[email protected]>
  6. // Boris Kirzner <[email protected]>
  7. //
  8. // (C) 2006 Mainsoft Corporation (http://www.mainsoft.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.Collections;
  32. using Mainsoft.Data.Configuration;
  33. using System.Reflection;
  34. namespace Mainsoft.Data.Jdbc.Providers
  35. {
  36. public class OracleProvider : GenericProvider
  37. {
  38. #region Consts
  39. private const string Port = "Port";
  40. #endregion //Consts
  41. #region Fields
  42. #endregion // Fields
  43. #region Constructors
  44. public OracleProvider (IDictionary providerInfo) : base (providerInfo)
  45. {
  46. }
  47. #endregion // Constructors
  48. #region Properties
  49. #endregion // Properties
  50. #region Methods
  51. public override IConnectionStringDictionary GetConnectionStringBuilder (string connectionString)
  52. {
  53. IConnectionStringDictionary conectionStringBuilder = base.GetConnectionStringBuilder (connectionString);
  54. string port = (string) conectionStringBuilder [Port];
  55. if (port == null || port.Length == 0) {
  56. port = (string) ProviderInfo [Port];
  57. conectionStringBuilder.Add (Port, port);
  58. }
  59. return conectionStringBuilder;
  60. }
  61. public override java.sql.Connection GetConnection(IConnectionStringDictionary conectionStringBuilder) {
  62. return new OracleConnection(base.GetConnection (conectionStringBuilder));
  63. }
  64. #endregion //Methods
  65. #region OracleConnection
  66. sealed class OracleConnection : Connection {
  67. public OracleConnection(java.sql.Connection connection)
  68. : base(connection) {}
  69. public override java.sql.CallableStatement prepareCall(string arg_0) {
  70. return base.prepareCall (arg_0);
  71. }
  72. public override java.sql.CallableStatement prepareCall(string arg_0, int arg_1, int arg_2) {
  73. return new OracleCallableStatement(base.prepareCall (arg_0, arg_1, arg_2));
  74. }
  75. public override java.sql.CallableStatement prepareCall(string arg_0, int arg_1, int arg_2, int arg_3) {
  76. return new OracleCallableStatement(base.prepareCall (arg_0, arg_1, arg_2, arg_3));
  77. }
  78. public override java.sql.PreparedStatement prepareStatement(string arg_0) {
  79. return new OraclePreparedStatement(base.prepareStatement (arg_0));
  80. }
  81. public override java.sql.PreparedStatement prepareStatement(string arg_0, int arg_1) {
  82. return new OraclePreparedStatement(base.prepareStatement (arg_0, arg_1));
  83. }
  84. public override java.sql.PreparedStatement prepareStatement(string arg_0, int arg_1, int arg_2) {
  85. return new OraclePreparedStatement(base.prepareStatement (arg_0, arg_1, arg_2));
  86. }
  87. public override java.sql.PreparedStatement prepareStatement(string arg_0, int arg_1, int arg_2, int arg_3) {
  88. return new OraclePreparedStatement(base.prepareStatement (arg_0, arg_1, arg_2, arg_3));
  89. }
  90. public override java.sql.PreparedStatement prepareStatement(string arg_0, int[] arg_1) {
  91. return new OraclePreparedStatement(base.prepareStatement (arg_0, arg_1));
  92. }
  93. public override java.sql.PreparedStatement prepareStatement(string arg_0, string[] arg_1) {
  94. return new OraclePreparedStatement(base.prepareStatement (arg_0, arg_1));
  95. }
  96. }
  97. #endregion
  98. sealed class OraclePreparedStatement : PreparedStatement, IPreparedStatement {
  99. readonly MethodInfo _info;
  100. public OraclePreparedStatement(java.sql.PreparedStatement statement)
  101. : base(statement) {
  102. _info = Wrapped.GetType().GetMethod("setFixedCHAR");
  103. }
  104. #region IPreparedStatement Members
  105. public void setBit(int parameterIndex, int value) {
  106. base.setInt(parameterIndex, value);
  107. }
  108. public void setChar(int parameterIndex, string value) {
  109. if (_info == null) {
  110. base.setString(parameterIndex, value);
  111. return;
  112. }
  113. _info.Invoke(Wrapped, new object[] {
  114. new java.lang.Integer(parameterIndex),
  115. value});
  116. }
  117. public void setNumeric(int parameterIndex, java.math.BigDecimal value) {
  118. base.setBigDecimal(parameterIndex, value);
  119. }
  120. public void setReal(int parameterIndex, double value) {
  121. base.setDouble(parameterIndex, value);
  122. }
  123. #endregion
  124. }
  125. sealed class OracleCallableStatement : CallableStatement, IPreparedStatement {
  126. readonly MethodInfo _info;
  127. public OracleCallableStatement(java.sql.CallableStatement statement)
  128. : base(statement) {
  129. _info = Wrapped.GetType().GetMethod("setFixedCHAR");
  130. }
  131. #region IPreparedStatement Members
  132. public void setBit(int parameterIndex, int value) {
  133. base.setInt(parameterIndex, value);
  134. }
  135. public void setChar(int parameterIndex, string value) {
  136. if (_info == null) {
  137. base.setString(parameterIndex, value);
  138. return;
  139. }
  140. _info.Invoke(Wrapped, new object[] {
  141. new java.lang.Integer(parameterIndex),
  142. value});
  143. }
  144. public void setNumeric(int parameterIndex, java.math.BigDecimal value) {
  145. base.setBigDecimal(parameterIndex, value);
  146. }
  147. public void setReal(int parameterIndex, double value) {
  148. base.setDouble(parameterIndex, value);
  149. }
  150. #endregion
  151. }
  152. }
  153. }