activerecord-jdbc-adapter-ficoh 1.3.21-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +35 -0
  3. data/.travis.yml +462 -0
  4. data/.yardopts +4 -0
  5. data/Appraisals +36 -0
  6. data/CONTRIBUTING.md +49 -0
  7. data/Gemfile +68 -0
  8. data/History.md +1191 -0
  9. data/LICENSE.txt +25 -0
  10. data/README.md +277 -0
  11. data/RUNNING_TESTS.md +88 -0
  12. data/Rakefile +298 -0
  13. data/Rakefile.jdbc +20 -0
  14. data/activerecord-jdbc-adapter.gemspec +63 -0
  15. data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
  16. data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
  17. data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
  18. data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
  19. data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
  20. data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
  21. data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
  22. data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
  23. data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
  24. data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
  25. data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
  26. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
  27. data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
  28. data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
  29. data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
  30. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
  31. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
  32. data/lib/activerecord-jdbc-adapter.rb +1 -0
  33. data/lib/arel/visitors/compat.rb +64 -0
  34. data/lib/arel/visitors/db2.rb +137 -0
  35. data/lib/arel/visitors/derby.rb +112 -0
  36. data/lib/arel/visitors/firebird.rb +79 -0
  37. data/lib/arel/visitors/h2.rb +25 -0
  38. data/lib/arel/visitors/hsqldb.rb +32 -0
  39. data/lib/arel/visitors/postgresql_jdbc.rb +6 -0
  40. data/lib/arel/visitors/sql_server.rb +225 -0
  41. data/lib/arel/visitors/sql_server/ng42.rb +293 -0
  42. data/lib/arjdbc.rb +22 -0
  43. data/lib/arjdbc/db2.rb +4 -0
  44. data/lib/arjdbc/db2/adapter.rb +802 -0
  45. data/lib/arjdbc/db2/as400.rb +137 -0
  46. data/lib/arjdbc/db2/column.rb +177 -0
  47. data/lib/arjdbc/db2/connection_methods.rb +45 -0
  48. data/lib/arjdbc/derby.rb +3 -0
  49. data/lib/arjdbc/derby/active_record_patch.rb +13 -0
  50. data/lib/arjdbc/derby/adapter.rb +567 -0
  51. data/lib/arjdbc/derby/connection_methods.rb +16 -0
  52. data/lib/arjdbc/derby/schema_creation.rb +15 -0
  53. data/lib/arjdbc/discover.rb +104 -0
  54. data/lib/arjdbc/firebird.rb +4 -0
  55. data/lib/arjdbc/firebird/adapter.rb +468 -0
  56. data/lib/arjdbc/firebird/connection_methods.rb +20 -0
  57. data/lib/arjdbc/h2.rb +3 -0
  58. data/lib/arjdbc/h2/adapter.rb +335 -0
  59. data/lib/arjdbc/h2/connection_methods.rb +22 -0
  60. data/lib/arjdbc/hsqldb.rb +3 -0
  61. data/lib/arjdbc/hsqldb/adapter.rb +304 -0
  62. data/lib/arjdbc/hsqldb/connection_methods.rb +23 -0
  63. data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
  64. data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
  65. data/lib/arjdbc/informix.rb +5 -0
  66. data/lib/arjdbc/informix/adapter.rb +160 -0
  67. data/lib/arjdbc/informix/connection_methods.rb +9 -0
  68. data/lib/arjdbc/jdbc.rb +62 -0
  69. data/lib/arjdbc/jdbc/adapter.rb +997 -0
  70. data/lib/arjdbc/jdbc/adapter_require.rb +46 -0
  71. data/lib/arjdbc/jdbc/arel_support.rb +149 -0
  72. data/lib/arjdbc/jdbc/base_ext.rb +34 -0
  73. data/lib/arjdbc/jdbc/callbacks.rb +52 -0
  74. data/lib/arjdbc/jdbc/column.rb +83 -0
  75. data/lib/arjdbc/jdbc/connection.rb +26 -0
  76. data/lib/arjdbc/jdbc/connection_methods.rb +59 -0
  77. data/lib/arjdbc/jdbc/driver.rb +44 -0
  78. data/lib/arjdbc/jdbc/error.rb +75 -0
  79. data/lib/arjdbc/jdbc/extension.rb +69 -0
  80. data/lib/arjdbc/jdbc/java.rb +13 -0
  81. data/lib/arjdbc/jdbc/type_cast.rb +154 -0
  82. data/lib/arjdbc/jdbc/type_converter.rb +142 -0
  83. data/lib/arjdbc/mssql.rb +7 -0
  84. data/lib/arjdbc/mssql/adapter.rb +822 -0
  85. data/lib/arjdbc/mssql/column.rb +207 -0
  86. data/lib/arjdbc/mssql/connection_methods.rb +72 -0
  87. data/lib/arjdbc/mssql/explain_support.rb +99 -0
  88. data/lib/arjdbc/mssql/limit_helpers.rb +231 -0
  89. data/lib/arjdbc/mssql/lock_methods.rb +77 -0
  90. data/lib/arjdbc/mssql/types.rb +343 -0
  91. data/lib/arjdbc/mssql/utils.rb +82 -0
  92. data/lib/arjdbc/mysql.rb +3 -0
  93. data/lib/arjdbc/mysql/adapter.rb +998 -0
  94. data/lib/arjdbc/mysql/bulk_change_table.rb +150 -0
  95. data/lib/arjdbc/mysql/column.rb +167 -0
  96. data/lib/arjdbc/mysql/connection_methods.rb +137 -0
  97. data/lib/arjdbc/mysql/explain_support.rb +82 -0
  98. data/lib/arjdbc/mysql/schema_creation.rb +58 -0
  99. data/lib/arjdbc/oracle.rb +4 -0
  100. data/lib/arjdbc/oracle/adapter.rb +968 -0
  101. data/lib/arjdbc/oracle/column.rb +136 -0
  102. data/lib/arjdbc/oracle/connection_methods.rb +21 -0
  103. data/lib/arjdbc/postgresql.rb +3 -0
  104. data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +21 -0
  105. data/lib/arjdbc/postgresql/adapter.rb +1498 -0
  106. data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
  107. data/lib/arjdbc/postgresql/base/oid.rb +412 -0
  108. data/lib/arjdbc/postgresql/base/pgconn.rb +8 -0
  109. data/lib/arjdbc/postgresql/base/schema_definitions.rb +132 -0
  110. data/lib/arjdbc/postgresql/column.rb +640 -0
  111. data/lib/arjdbc/postgresql/connection_methods.rb +44 -0
  112. data/lib/arjdbc/postgresql/explain_support.rb +53 -0
  113. data/lib/arjdbc/postgresql/oid/bytea.rb +3 -0
  114. data/lib/arjdbc/postgresql/oid_types.rb +265 -0
  115. data/lib/arjdbc/postgresql/schema_creation.rb +60 -0
  116. data/lib/arjdbc/railtie.rb +11 -0
  117. data/lib/arjdbc/sqlite3.rb +3 -0
  118. data/lib/arjdbc/sqlite3/adapter.rb +654 -0
  119. data/lib/arjdbc/sqlite3/connection_methods.rb +36 -0
  120. data/lib/arjdbc/sqlite3/explain_support.rb +29 -0
  121. data/lib/arjdbc/sybase.rb +2 -0
  122. data/lib/arjdbc/sybase/adapter.rb +47 -0
  123. data/lib/arjdbc/tasks.rb +13 -0
  124. data/lib/arjdbc/tasks/database_tasks.rb +66 -0
  125. data/lib/arjdbc/tasks/databases.rake +91 -0
  126. data/lib/arjdbc/tasks/databases3.rake +239 -0
  127. data/lib/arjdbc/tasks/databases4.rake +39 -0
  128. data/lib/arjdbc/tasks/db2_database_tasks.rb +104 -0
  129. data/lib/arjdbc/tasks/derby_database_tasks.rb +95 -0
  130. data/lib/arjdbc/tasks/h2_database_tasks.rb +31 -0
  131. data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
  132. data/lib/arjdbc/tasks/jdbc_database_tasks.rb +169 -0
  133. data/lib/arjdbc/tasks/mssql_database_tasks.rb +46 -0
  134. data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +297 -0
  135. data/lib/arjdbc/tasks/oracle_database_tasks.rb +65 -0
  136. data/lib/arjdbc/util/quoted_cache.rb +60 -0
  137. data/lib/arjdbc/util/serialized_attributes.rb +98 -0
  138. data/lib/arjdbc/util/table_copier.rb +108 -0
  139. data/lib/arjdbc/version.rb +8 -0
  140. data/lib/generators/jdbc/USAGE +9 -0
  141. data/lib/generators/jdbc/jdbc_generator.rb +17 -0
  142. data/pom.xml +285 -0
  143. data/rails_generators/jdbc_generator.rb +15 -0
  144. data/rails_generators/templates/config/initializers/jdbc.rb +10 -0
  145. data/rails_generators/templates/lib/tasks/jdbc.rake +11 -0
  146. data/rakelib/01-tomcat.rake +51 -0
  147. data/rakelib/02-test.rake +151 -0
  148. data/rakelib/bundler_ext.rb +11 -0
  149. data/rakelib/db.rake +58 -0
  150. data/rakelib/rails.rake +77 -0
  151. data/src/java/arjdbc/ArJdbcModule.java +288 -0
  152. data/src/java/arjdbc/db2/DB2Module.java +77 -0
  153. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +128 -0
  154. data/src/java/arjdbc/derby/DerbyModule.java +180 -0
  155. data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +153 -0
  156. data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +190 -0
  157. data/src/java/arjdbc/h2/H2Module.java +50 -0
  158. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +86 -0
  159. data/src/java/arjdbc/hsqldb/HSQLDBModule.java +74 -0
  160. data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +76 -0
  161. data/src/java/arjdbc/jdbc/AdapterJavaService.java +43 -0
  162. data/src/java/arjdbc/jdbc/Callable.java +44 -0
  163. data/src/java/arjdbc/jdbc/ConnectionFactory.java +77 -0
  164. data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +156 -0
  165. data/src/java/arjdbc/jdbc/DriverConnectionFactory.java +63 -0
  166. data/src/java/arjdbc/jdbc/DriverWrapper.java +128 -0
  167. data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +32 -0
  168. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +4541 -0
  169. data/src/java/arjdbc/jdbc/SQLBlock.java +54 -0
  170. data/src/java/arjdbc/jdbc/WithResultSet.java +37 -0
  171. data/src/java/arjdbc/mssql/MSSQLModule.java +91 -0
  172. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +193 -0
  173. data/src/java/arjdbc/mysql/MySQLModule.java +140 -0
  174. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +456 -0
  175. data/src/java/arjdbc/oracle/OracleModule.java +81 -0
  176. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +477 -0
  177. data/src/java/arjdbc/postgresql/ByteaUtils.java +171 -0
  178. data/src/java/arjdbc/postgresql/DriverImplementation.java +78 -0
  179. data/src/java/arjdbc/postgresql/PGDriverImplementation.java +535 -0
  180. data/src/java/arjdbc/postgresql/PostgreSQLModule.java +189 -0
  181. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +489 -0
  182. data/src/java/arjdbc/sqlite3/SQLite3Module.java +93 -0
  183. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +405 -0
  184. data/src/java/arjdbc/util/CallResultSet.java +826 -0
  185. data/src/java/arjdbc/util/DateTimeUtils.java +517 -0
  186. data/src/java/arjdbc/util/NumberUtils.java +50 -0
  187. data/src/java/arjdbc/util/ObjectSupport.java +65 -0
  188. data/src/java/arjdbc/util/QuotingUtils.java +139 -0
  189. data/src/java/arjdbc/util/StringCache.java +60 -0
  190. data/src/java/arjdbc/util/StringHelper.java +155 -0
  191. metadata +288 -0
@@ -0,0 +1,50 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright 2015 Karol Bucek.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+ package arjdbc.util;
25
+
26
+ import org.jruby.util.ByteList;
27
+
28
+ /**
29
+ *
30
+ * @author kares
31
+ */
32
+ public abstract class NumberUtils {
33
+
34
+ public static ByteList appendLong(final long value, final ByteList bytes) {
35
+ final String str = Long.toString(value);
36
+ for ( int i = 0; i < str.length(); i++ ) {
37
+ bytes.append( str.charAt(i) );
38
+ }
39
+ return bytes;
40
+ }
41
+
42
+ public static ByteList appendInteger(final int value, final ByteList bytes) {
43
+ final String str = Integer.toString(value);
44
+ for ( int i = 0; i < str.length(); i++ ) {
45
+ bytes.append( str.charAt(i) );
46
+ }
47
+ return bytes;
48
+ }
49
+
50
+ }
@@ -0,0 +1,65 @@
1
+
2
+ package arjdbc.util;
3
+
4
+ import java.util.List;
5
+ import org.jruby.Ruby;
6
+ import org.jruby.RubyBasicObject;
7
+ import org.jruby.RubyString;
8
+ import org.jruby.runtime.ThreadContext;
9
+ import org.jruby.runtime.builtin.IRubyObject;
10
+ import org.jruby.runtime.builtin.Variable;
11
+
12
+ public abstract class ObjectSupport {
13
+
14
+ @SuppressWarnings("unchecked")
15
+ public static RubyString inspect(final RubyBasicObject self) {
16
+ return inspect(self, (List) self.getInstanceVariableList());
17
+ }
18
+
19
+ public static RubyString inspect(final RubyBasicObject self, final List<Variable> variableList) {
20
+ final Ruby runtime = self.getRuntime();
21
+ return RubyString.newString(runtime, inspect(runtime, self, variableList));
22
+ }
23
+
24
+ private static StringBuilder inspect(final Ruby runtime, final RubyBasicObject self,
25
+ final List<Variable> variableList) {
26
+ final StringBuilder part = new StringBuilder();
27
+ String cname = self.getMetaClass().getRealClass().getName();
28
+ part.append("#<").append(cname).append(":0x");
29
+ part.append(Integer.toHexString(System.identityHashCode(self)));
30
+
31
+ if (runtime.isInspecting(self)) {
32
+ /* 6:tags 16:addr 1:eos */
33
+ part.append(" ...>");
34
+ return part;
35
+ }
36
+ try {
37
+ runtime.registerInspecting(self);
38
+ final ThreadContext context = runtime.getCurrentContext();
39
+ return inspectObj(context, variableList, part);
40
+ } finally {
41
+ runtime.unregisterInspecting(self);
42
+ }
43
+ }
44
+
45
+ private static StringBuilder inspectObj(final ThreadContext context,
46
+ final List<Variable> variableList,
47
+ final StringBuilder part) {
48
+ String sep = "";
49
+
50
+ for ( final Variable ivar : variableList ) {
51
+ part.append(sep).append(' ').append( ivar.getName() ).append('=');
52
+ final Object ival = ivar.getValue();
53
+ if ( ival instanceof IRubyObject ) {
54
+ part.append( ((IRubyObject) ival).callMethod(context, "inspect") );
55
+ }
56
+ else { // allow the variable to come formatted (as is) already :
57
+ part.append( ival ); // ival == null ? "nil" : ival.toString()
58
+ }
59
+ sep = ",";
60
+ }
61
+ part.append('>');
62
+ return part;
63
+ }
64
+
65
+ }
@@ -0,0 +1,139 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright 2013 Karol Bucek.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+ package arjdbc.util;
25
+
26
+ import org.jruby.RubyString;
27
+ import org.jruby.runtime.ThreadContext;
28
+ import org.jruby.runtime.builtin.IRubyObject;
29
+ import org.jruby.util.ByteList;
30
+
31
+ /**
32
+ * Shared (common) quoting helpers.
33
+ *
34
+ * <br>
35
+ * NOTE: This is internal API !
36
+ * <br>
37
+ *
38
+ * @author kares
39
+ */
40
+ public abstract class QuotingUtils {
41
+
42
+ public static final ByteList BYTES_0 = new ByteList(new byte[] { '0' }, false);
43
+
44
+ public static final ByteList BYTES_1 = new ByteList(new byte[] { '1' }, false);
45
+
46
+ // e.g. string.gsub("'", "''") -> quoteCharWith(string, '\'', '\'');
47
+ public static RubyString quoteCharWith(
48
+ final ThreadContext context,
49
+ final RubyString string,
50
+ final char value, final char quote) {
51
+ return quoteCharWith(context, string, value, quote, 0, 8);
52
+ }
53
+
54
+ @SuppressWarnings("deprecation")
55
+ public static RubyString quoteCharWith(
56
+ final ThreadContext context,
57
+ final RubyString string,
58
+ final char value, final char quote,
59
+ final int newOffset, final int newSizeDiff) {
60
+
61
+ final ByteList stringBytes = string.getByteList();
62
+ final byte[] bytes = stringBytes.unsafeBytes();
63
+ final int begin = stringBytes.getBegin();
64
+ final int realSize = stringBytes.getRealSize();
65
+
66
+ ByteList quotedBytes = null; int appendFrom = begin;
67
+ for ( int i = begin; i < begin + realSize; i++ ) {
68
+ if ( bytes[i] == value ) {
69
+ if ( quotedBytes == null ) {
70
+ quotedBytes = new ByteList(
71
+ new byte[realSize + newOffset + newSizeDiff],
72
+ stringBytes.getEncoding(), false
73
+ );
74
+ quotedBytes.begin = newOffset;
75
+ quotedBytes.realSize = 0;
76
+ }
77
+ quotedBytes.append(bytes, appendFrom, i - appendFrom);
78
+ quotedBytes.append(quote).append(value); // e.g. "'" => "''"
79
+ appendFrom = i + 1;
80
+ }
81
+ }
82
+ if ( quotedBytes != null ) { // append what's left in the end :
83
+ quotedBytes.append(bytes, appendFrom, begin + realSize - appendFrom);
84
+ }
85
+ else return string; // nothing changed, can return original
86
+
87
+ return context.runtime.newString(quotedBytes);
88
+ }
89
+
90
+ @SuppressWarnings("deprecation")
91
+ public static RubyString quoteCharAndDecorateWith(
92
+ final ThreadContext context, final RubyString string,
93
+ final char value, final char quote,
94
+ final byte prefix, final byte suffix) {
95
+
96
+ final ByteList str = string.getByteList();
97
+ final RubyString quotedString = // part.gsub('v', 'vv')
98
+ quoteCharWith(context, string, value, quote, 1, 4 + 1);
99
+ if ( quotedString == string ) {
100
+ final int realSize = str.getRealSize();
101
+ final ByteList quoted = new ByteList(
102
+ new byte[realSize + 2], string.getEncoding(), false
103
+ );
104
+ quoted.begin = 0; quoted.realSize = 0;
105
+ quoted.append(prefix);
106
+ quoted.append(str.unsafeBytes(), str.getBegin(), realSize);
107
+ quoted.append(suffix);
108
+ return context.runtime.newString(quoted);
109
+ }
110
+ // we got a new string with a reserve of 1 byte front and back :
111
+ final ByteList quoted = quotedString.getByteList();
112
+ quoted.begin = 0; // setBegin invalidates
113
+ quoted.bytes[0] = prefix; quoted.realSize++;
114
+ quoted.append(suffix);
115
+ return quotedString;
116
+ }
117
+
118
+ public static final ByteList BYTES_SINGLE_Q = new ByteList(new byte[] { '\'' }, false);
119
+ public static final ByteList BYTES_SINGLE_Q_x2 = new ByteList(new byte[] { '\'', '\'' }, false);
120
+
121
+ // string.gsub("'", "''") :
122
+ public static IRubyObject quoteSingleQuotesWithFallback(
123
+ final ThreadContext context, final IRubyObject string) {
124
+ // string.gsub("'", "''") :
125
+ if ( string instanceof RubyString ) {
126
+ final char single = '\'';
127
+ return quoteCharWith(context, (RubyString) string, single, single);
128
+ }
129
+ else { // ActiveSupport::Multibyte::Chars
130
+ return string.callMethod(context, "gsub",
131
+ new IRubyObject[] {
132
+ context.runtime.newString(BYTES_SINGLE_Q),
133
+ context.runtime.newString(BYTES_SINGLE_Q_x2)
134
+ }
135
+ );
136
+ }
137
+ }
138
+
139
+ }
@@ -0,0 +1,60 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright 2014 Karol Bucek.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+ package arjdbc.util;
25
+
26
+ import java.util.WeakHashMap;
27
+
28
+ import org.jruby.Ruby;
29
+ import org.jruby.RubyString;
30
+ import org.jruby.runtime.ThreadContext;
31
+ import org.jruby.util.ByteList;
32
+
33
+ /**
34
+ * Cache of _unicode_ strings.
35
+ *
36
+ * @author kares
37
+ */
38
+ public final class StringCache {
39
+
40
+ final WeakHashMap<String, ByteList> cache = new WeakHashMap<String, ByteList>(64);
41
+
42
+ public RubyString get(final ThreadContext context, final String key) {
43
+ final ByteList bytes = cache.get(key);
44
+ if ( bytes == null ) return store(context, key);
45
+ final Ruby runtime = context.runtime;
46
+ return (RubyString) RubyString.newString(runtime, bytes).freeze(context);
47
+ }
48
+
49
+ private RubyString store(final ThreadContext context, final String key) {
50
+ final Ruby runtime = context.runtime;
51
+ final RubyString str = RubyString.newUnicodeString(runtime, key);
52
+ synchronized (cache) { cache.put(key, str.getByteList()); }
53
+ return (RubyString) str.freeze(context);
54
+ }
55
+
56
+ public void clear() {
57
+ cache.clear();
58
+ }
59
+
60
+ }
@@ -0,0 +1,155 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright 2014 Karol Bucek.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+ package arjdbc.util;
25
+
26
+ import java.io.IOException;
27
+ import java.io.InputStream;
28
+
29
+ import org.jcodings.Encoding;
30
+ import org.jcodings.specific.UTF16BEEncoding;
31
+ import org.jcodings.specific.UTF8Encoding;
32
+ import org.jruby.Ruby;
33
+ import org.jruby.RubyString;
34
+ import org.jruby.util.ByteList;
35
+
36
+ /**
37
+ * Some (Ruby) byte string helpers.
38
+ *
39
+ * @author kares
40
+ */
41
+ public abstract class StringHelper {
42
+
43
+ public static byte decByte(final int digit) {
44
+ switch (digit) {
45
+ case 0 : return '0';
46
+ case 1 : return '1';
47
+ case 2 : return '2';
48
+ case 3 : return '3';
49
+ case 4 : return '4';
50
+ case 5 : return '5';
51
+ case 6 : return '6';
52
+ case 7 : return '7';
53
+ case 8 : return '8';
54
+ case 9 : return '9';
55
+ }
56
+ throw new IllegalStateException("unexpected digit: " + digit);
57
+ }
58
+
59
+ public static RubyString newString(final Ruby runtime, final CharSequence str) {
60
+ return new RubyString(runtime, runtime.getString(), str, UTF8Encoding.INSTANCE);
61
+ }
62
+
63
+ public static RubyString newString(final Ruby runtime, final byte[] bytes) {
64
+ final ByteList byteList = new ByteList(bytes, false);
65
+ return new RubyString(runtime, runtime.getString(), byteList);
66
+ }
67
+
68
+ public static RubyString newUTF8String(final Ruby runtime, final byte[] bytes) {
69
+ final ByteList byteList = new ByteList(bytes, false);
70
+ return new RubyString(runtime, runtime.getString(), byteList, UTF8Encoding.INSTANCE);
71
+ }
72
+
73
+ public static RubyString newUTF8String(final Ruby runtime, final CharSequence str) {
74
+ return new RubyString(runtime, runtime.getString(), str, UTF8Encoding.INSTANCE);
75
+ }
76
+
77
+ public static RubyString newEmptyUTF8String(final Ruby runtime) {
78
+ return newUTF8String(runtime, ByteList.NULL_ARRAY);
79
+ }
80
+
81
+ public static RubyString newUnicodeString(final Ruby runtime, final CharSequence str) {
82
+ Encoding defaultInternal = runtime.getDefaultInternalEncoding();
83
+ if (defaultInternal == UTF16BEEncoding.INSTANCE) {
84
+ return RubyString.newUTF16String(runtime, str);
85
+ }
86
+ return newUTF8String(runtime, str);
87
+ }
88
+
89
+ public static int readBytes(final ByteList output, final InputStream input)
90
+ throws IOException {
91
+ @SuppressWarnings("deprecation") // capacity :
92
+ final int buffSize = output.bytes.length - output.begin;
93
+ return readBytes(output, input, buffSize);
94
+ }
95
+
96
+ public static int readBytes(final ByteList output, final InputStream input, int buffSize)
97
+ throws IOException {
98
+ int read = 0;
99
+ while ( true ) {
100
+ output.ensure( output.getRealSize() + buffSize );
101
+ final int begin = output.getBegin();
102
+ final int size = output.getRealSize();
103
+ int n = input.read(output.unsafeBytes(), begin + size, buffSize);
104
+ if ( n == -1 ) break;
105
+ output.setRealSize( size + n ); read += n;
106
+ }
107
+ return read;
108
+ }
109
+
110
+ public static boolean startsWithIgnoreCase(final ByteList bytes, final byte[] start) {
111
+ int p = nonWhitespaceIndex(bytes, bytes.getBegin());
112
+ final byte[] stringBytes = bytes.unsafeBytes();
113
+ if ( stringBytes[p] == '(' ) {
114
+ p = nonWhitespaceIndex(bytes, p + 1);
115
+ }
116
+
117
+ for ( int i = 0; i < bytes.getRealSize() && i < start.length; i++ ) {
118
+ if ( Character.toLowerCase(stringBytes[p + i]) != start[i] ) return false;
119
+ }
120
+ return true;
121
+ }
122
+
123
+ public static int nonWhitespaceIndex(final ByteList string, final int off) {
124
+ final int end = string.getBegin() + string.getRealSize();
125
+ final byte[] stringBytes = string.unsafeBytes();
126
+ for ( int i = off; i < end; i++ ) {
127
+ if ( ! Character.isWhitespace( stringBytes[i] ) ) return i;
128
+ }
129
+ return end;
130
+ }
131
+
132
+ @SuppressWarnings("deprecation")
133
+ private static int nonSpaceIndex(final byte[] str, int beg, int len) {
134
+ for ( int i = beg; i < len; i++ ) {
135
+ if ( ! Character.isSpace( (char) str[i] ) ) return i;
136
+ }
137
+ return len;
138
+ }
139
+
140
+ private static int nonDigitIndex(final byte[] str, int beg, int len) {
141
+ for ( int i = beg; i < len; i++ ) {
142
+ if ( ! Character.isDigit( (char) str[i] ) ) return i;
143
+ }
144
+ return len;
145
+ }
146
+
147
+ private static int extractIntValue(final byte[] str, int beg, int end) {
148
+ int n = 0;
149
+ for ( int i = beg; i < end; i++ ) {
150
+ n = 10 * n + ( str[i] - '0' );
151
+ }
152
+ return n;
153
+ }
154
+
155
+ }