transactd 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (306) hide show
  1. checksums.yaml +4 -4
  2. data/BUILD_UNIX-JA +46 -67
  3. data/BUILD_WIN-JA +106 -63
  4. data/CMakeLists.txt +40 -15
  5. data/README +219 -75
  6. data/README-JA +207 -76
  7. data/README_ORMSRCGEN +118 -0
  8. data/README_ORMSRCGEN-JA +115 -0
  9. data/bin/common/tdclc_32_2_0.dll +0 -0
  10. data/bin/common/tdclc_64_2_0.dll +0 -0
  11. data/build/common/check_for_link_iconv.cmake +18 -14
  12. data/build/common/create_symlink.cmake.in +25 -0
  13. data/build/common/get_boost_libs.cmake +23 -23
  14. data/build/common/options.cmake +0 -66
  15. data/build/common/smart_install.cmake +3 -3
  16. data/build/common/transactd.rc.in +15 -5
  17. data/build/common/transactd_cl_common.cmake +37 -18
  18. data/build/common/transactd_cl_output.cmake +55 -13
  19. data/build/common/transactd_common.cmake +108 -31
  20. data/build/swig/php/generate.cmake.in +15 -17
  21. data/build/swig/php/generate.cmd.in +15 -9
  22. data/build/swig/php/php.swg +124 -82
  23. data/build/swig/php/transactd.no_yield.php +4494 -0
  24. data/build/swig/php/transactd.no_yield.php.git.patch +685 -0
  25. data/build/swig/php/transactd.no_yield.php.patch +685 -0
  26. data/build/swig/php/transactd.yield.php +4461 -0
  27. data/build/swig/php/transactd.yield.php.git.patch +652 -0
  28. data/build/swig/php/transactd.yield.php.patch +652 -0
  29. data/build/swig/referencecounter.h +79 -0
  30. data/build/swig/ruby/ruby.swg +226 -76
  31. data/build/swig/ruby/threadBlockRegionWrapper.h +71 -0
  32. data/build/swig/ruby/without_gvl.swg +87 -0
  33. data/build/swig/tdcl.i +659 -170
  34. data/build/swig/validatablepointer.h +91 -0
  35. data/build/tdclc/CMakeLists.txt +49 -34
  36. data/build/tdclc/{tdclc_64.cbproj → tdclc.cbproj} +65 -20
  37. data/build/tdclc/tdclc.rc +0 -0
  38. data/build/tdclcpp/CMakeLists.txt +84 -20
  39. data/build/tdclcpp/tdclcpp.rc +0 -0
  40. data/build/tdclcpp/{tdclcpp_bcb_64.cbproj → tdclcpp_bc.cbproj} +168 -44
  41. data/build/tdclrb/CMakeLists.txt +84 -66
  42. data/build/tdclrb/bldgem/extconf.rb +28 -3
  43. data/build/tdclrb/gem/helper.rb +11 -1
  44. data/build/tdclrb/gem_output.cmake +20 -16
  45. data/index_ja.html +15 -0
  46. data/source/bzs/db/IBlobBuffer.h +15 -17
  47. data/source/bzs/db/blobBuffer.h +186 -140
  48. data/source/bzs/db/blobStructs.h +37 -37
  49. data/source/bzs/db/engine/mysql/IReadRecords.h +34 -34
  50. data/source/bzs/db/engine/mysql/bookmark.h +150 -147
  51. data/source/bzs/db/engine/mysql/database.cpp +1721 -1526
  52. data/source/bzs/db/engine/mysql/database.h +608 -370
  53. data/source/bzs/db/engine/mysql/dbManager.cpp +213 -201
  54. data/source/bzs/db/engine/mysql/dbManager.h +115 -104
  55. data/source/bzs/db/engine/mysql/errorMessage.cpp +49 -50
  56. data/source/bzs/db/engine/mysql/errorMessage.h +25 -26
  57. data/source/bzs/db/engine/mysql/fieldAccess.h +55 -61
  58. data/source/bzs/db/engine/mysql/mydebuglog.cpp +326 -292
  59. data/source/bzs/db/engine/mysql/mydebuglog.h +63 -55
  60. data/source/bzs/db/engine/mysql/mysqlInternal.h +182 -125
  61. data/source/bzs/db/engine/mysql/mysqlThd.cpp +121 -121
  62. data/source/bzs/db/engine/mysql/mysqlThd.h +20 -20
  63. data/source/bzs/db/engine/mysql/percentageKey.h +241 -228
  64. data/source/bzs/db/protocol/ICommandExecuter.h +18 -17
  65. data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +543 -514
  66. data/source/bzs/db/protocol/hs/hsCommandExecuter.h +155 -158
  67. data/source/bzs/db/protocol/tdap/btrDate.cpp +213 -180
  68. data/source/bzs/db/protocol/tdap/btrDate.h +39 -37
  69. data/source/bzs/db/protocol/tdap/client/activeTable.cpp +173 -0
  70. data/source/bzs/db/protocol/tdap/client/activeTable.h +165 -0
  71. data/source/bzs/db/protocol/tdap/client/activeTableImple.h +370 -0
  72. data/source/bzs/db/protocol/tdap/client/bulkInsert.h +13 -23
  73. data/source/bzs/db/protocol/tdap/client/client.cpp +81 -68
  74. data/source/bzs/db/protocol/tdap/client/client.h +361 -320
  75. data/source/bzs/db/protocol/tdap/client/connMgr.cpp +17 -22
  76. data/source/bzs/db/protocol/tdap/client/connMgr.h +17 -19
  77. data/source/bzs/db/protocol/tdap/client/connectionPool.cpp +243 -0
  78. data/source/bzs/db/protocol/tdap/client/connectionPool.h +109 -0
  79. data/source/bzs/db/protocol/tdap/client/database.cpp +327 -219
  80. data/source/bzs/db/protocol/tdap/client/database.h +141 -118
  81. data/source/bzs/db/protocol/tdap/client/databaseFactory.cpp +60 -62
  82. data/source/bzs/db/protocol/tdap/client/databaseManager.h +255 -0
  83. data/source/bzs/db/protocol/tdap/client/dbDef.cpp +315 -202
  84. data/source/bzs/db/protocol/tdap/client/dbDef.h +40 -32
  85. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +390 -371
  86. data/source/bzs/db/protocol/tdap/client/errorMessage.cpp +148 -56
  87. data/source/bzs/db/protocol/tdap/client/errorMessage_ja.cpp +149 -57
  88. data/source/bzs/db/protocol/tdap/client/export.h +35 -0
  89. data/source/bzs/db/protocol/tdap/client/field.cpp +1985 -0
  90. data/source/bzs/db/protocol/tdap/client/field.h +393 -0
  91. data/source/bzs/db/protocol/tdap/client/fieldDDF.cpp +14 -14
  92. data/source/bzs/db/protocol/tdap/client/fieldDDF.h +11 -14
  93. data/source/bzs/db/protocol/tdap/client/fieldNameAlias.cpp +123 -0
  94. data/source/bzs/db/protocol/tdap/client/fieldNameAlias.h +58 -0
  95. data/source/bzs/db/protocol/tdap/client/fields.h +178 -0
  96. data/source/bzs/db/protocol/tdap/client/fileDDF.cpp +13 -16
  97. data/source/bzs/db/protocol/tdap/client/fileDDF.h +11 -17
  98. data/source/bzs/db/protocol/tdap/client/filter.h +423 -259
  99. data/source/bzs/db/protocol/tdap/client/groupComp.h +117 -0
  100. data/source/bzs/db/protocol/tdap/client/groupQuery.cpp +818 -0
  101. data/source/bzs/db/protocol/tdap/client/groupQuery.h +281 -0
  102. data/source/bzs/db/protocol/tdap/client/indexDDF.cpp +14 -17
  103. data/source/bzs/db/protocol/tdap/client/indexDDF.h +11 -14
  104. data/source/bzs/db/protocol/tdap/client/memRecord.cpp +231 -0
  105. data/source/bzs/db/protocol/tdap/client/memRecord.h +145 -0
  106. data/source/bzs/db/protocol/tdap/client/memRecordset.cpp +448 -0
  107. data/source/bzs/db/protocol/tdap/client/memRecordset.h +159 -0
  108. data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +300 -173
  109. data/source/bzs/db/protocol/tdap/client/nsDatabase.h +53 -36
  110. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +171 -128
  111. data/source/bzs/db/protocol/tdap/client/nsTable.h +121 -87
  112. data/source/bzs/db/protocol/tdap/client/pooledDatabaseManager.h +173 -0
  113. data/source/bzs/db/protocol/tdap/client/recordset.cpp +209 -0
  114. data/source/bzs/db/protocol/tdap/client/recordset.h +86 -0
  115. data/source/bzs/db/protocol/tdap/client/recordsetImple.h +596 -0
  116. data/source/bzs/db/protocol/tdap/client/request.h +227 -170
  117. data/source/bzs/db/protocol/tdap/client/serializer.cpp +1288 -0
  118. data/source/bzs/db/protocol/tdap/client/serializer.h +295 -0
  119. data/source/bzs/db/protocol/tdap/client/sharedData.cpp +9 -12
  120. data/source/bzs/db/protocol/tdap/client/sharedData.h +18 -16
  121. data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +494 -473
  122. data/source/bzs/db/protocol/tdap/client/sqlBuilder.h +51 -53
  123. data/source/bzs/db/protocol/tdap/client/stringConverter.h +214 -148
  124. data/source/bzs/db/protocol/tdap/client/table.cpp +929 -1665
  125. data/source/bzs/db/protocol/tdap/client/table.h +413 -87
  126. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +642 -534
  127. data/source/bzs/db/protocol/tdap/client/trdboostapiInternal.h +25 -40
  128. data/source/bzs/db/protocol/tdap/client/trdclcppautolink.h +11 -15
  129. data/source/bzs/db/protocol/tdap/client/trdormapi.h +378 -437
  130. data/source/bzs/db/protocol/tdap/client/trnsctcl.def +1 -1
  131. data/source/bzs/db/protocol/tdap/fieldComp.h +127 -0
  132. data/source/bzs/db/protocol/tdap/myDateTime.cpp +352 -345
  133. data/source/bzs/db/protocol/tdap/mysql/characterset.cpp +75 -78
  134. data/source/bzs/db/protocol/tdap/mysql/characterset.h +18 -19
  135. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +216 -199
  136. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.h +23 -14
  137. data/source/bzs/db/protocol/tdap/mysql/debuglog.cpp +354 -314
  138. data/source/bzs/db/protocol/tdap/mysql/debuglog.h +57 -47
  139. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +905 -739
  140. data/source/bzs/db/protocol/tdap/mysql/request.h +152 -159
  141. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +1044 -879
  142. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +87 -81
  143. data/source/bzs/db/protocol/tdap/tdapRequest.h +162 -130
  144. data/source/bzs/db/protocol/tdap/tdapSchema.cpp +368 -166
  145. data/source/bzs/db/protocol/tdap/tdapSchema.h +702 -566
  146. data/source/bzs/db/protocol/tdap/tdapcapi.h +387 -353
  147. data/source/bzs/db/transactd/appBuilderImple.h +21 -20
  148. data/source/bzs/db/transactd/appModule.cpp +350 -98
  149. data/source/bzs/db/transactd/appModule.h +31 -37
  150. data/source/bzs/db/transactd/connManager.cpp +138 -135
  151. data/source/bzs/db/transactd/connManager.h +28 -21
  152. data/source/bzs/db/transactd/connectionRecord.h +39 -39
  153. data/source/bzs/db/transactd/transactd.cpp +217 -203
  154. data/source/bzs/env/boost_bcb_link.h +131 -0
  155. data/source/bzs/env/compiler.h +136 -79
  156. data/source/bzs/env/crosscompile.cpp +57 -57
  157. data/source/bzs/env/crosscompile.h +130 -115
  158. data/source/bzs/env/fileopen.h +7 -8
  159. data/source/bzs/env/mbcswchrLinux.cpp +4 -9
  160. data/source/bzs/env/mbcswchrLinux.h +37 -34
  161. data/source/bzs/env/tcharMinGW.h +59 -0
  162. data/source/bzs/env/tstring.h +90 -95
  163. data/source/bzs/example/changeSchema.cpp +22 -23
  164. data/source/bzs/example/changeSchema_c.cpp +22 -24
  165. data/source/bzs/example/connection_pool_c.cpp +49 -104
  166. data/source/bzs/example/createDatabase.cpp +40 -47
  167. data/source/bzs/example/createDatabase_c.cpp +38 -43
  168. data/source/bzs/example/deleteRecords.cpp +10 -15
  169. data/source/bzs/example/deleteRecords_c.cpp +10 -14
  170. data/source/bzs/example/dropDatabase.cpp +3 -9
  171. data/source/bzs/example/dropDatabase_c.cpp +5 -6
  172. data/source/bzs/example/insertRecords.cpp +37 -29
  173. data/source/bzs/example/insertRecords_c.cpp +19 -25
  174. data/source/bzs/example/ormap_c.cpp +621 -0
  175. data/source/bzs/example/queryData.cpp +371 -0
  176. data/source/bzs/example/queryData.h +16 -0
  177. data/source/bzs/example/query_c.cpp +109 -0
  178. data/source/bzs/example/readRecords.cpp +27 -27
  179. data/source/bzs/example/readRecords_c.cpp +25 -23
  180. data/source/bzs/example/updateRecords.cpp +16 -21
  181. data/source/bzs/example/updateRecords_c.cpp +8 -12
  182. data/source/bzs/example/update_with_transaction.cpp +21 -24
  183. data/source/bzs/example/update_with_transaction_c.cpp +12 -15
  184. data/source/bzs/example/useORMRecord.cpp +177 -0
  185. data/source/bzs/netsvc/client/tcpClient.cpp +167 -156
  186. data/source/bzs/netsvc/client/tcpClient.h +541 -489
  187. data/source/bzs/netsvc/server/IAppModule.h +119 -32
  188. data/source/bzs/netsvc/server/iserver.h +21 -23
  189. data/source/bzs/netsvc/server/serverCpt.cpp +421 -391
  190. data/source/bzs/netsvc/server/serverCpt.h +41 -43
  191. data/source/bzs/netsvc/server/serverPipe.cpp +580 -565
  192. data/source/bzs/netsvc/server/serverPipe.h +44 -45
  193. data/source/bzs/netsvc/server/serverTpool.cpp +333 -303
  194. data/source/bzs/netsvc/server/serverTpool.h +38 -43
  195. data/source/bzs/rtl/benchmark.cpp +91 -31
  196. data/source/bzs/rtl/benchmark.h +76 -22
  197. data/source/bzs/rtl/datetime.cpp +231 -233
  198. data/source/bzs/rtl/datetime.h +16 -16
  199. data/source/bzs/rtl/debuglog.cpp +48 -51
  200. data/source/bzs/rtl/debuglog.h +55 -44
  201. data/source/bzs/rtl/exception.h +55 -48
  202. data/source/bzs/rtl/stl_uty.cpp +27 -28
  203. data/source/bzs/rtl/stl_uty.h +28 -29
  204. data/source/bzs/rtl/stringBuffers.cpp +8 -6
  205. data/source/bzs/rtl/stringBuffers.h +16 -9
  206. data/source/bzs/rtl/strtrim.cpp +90 -91
  207. data/source/bzs/rtl/strtrim.h +14 -16
  208. data/source/bzs/test/tdclatl/bench_query_atl.js +647 -0
  209. data/source/bzs/test/tdclatl/bench_tdclatl.js +303 -303
  210. data/source/bzs/test/tdclatl/test_query_atl.js +669 -0
  211. data/source/bzs/test/tdclphp/bench.php +357 -0
  212. data/source/bzs/test/tdclphp/transactd_Test.php +907 -303
  213. data/source/bzs/test/tdclphp/transactd_blob_Test.php +21 -49
  214. data/source/bzs/test/tdclphp/transactd_datetime_Test.php +41 -75
  215. data/source/bzs/test/tdclphp/transactd_kanjischema_Test.php +23 -37
  216. data/source/bzs/test/tdclphp/transactd_pool_Test.php +120 -0
  217. data/source/bzs/test/tdclrb/bench_tdclcpp.rb +4 -6
  218. data/source/bzs/test/tdclrb/prepare.rb +15 -12
  219. data/source/bzs/test/tdclrb/transactd_blob_spec.rb +29 -32
  220. data/source/bzs/test/tdclrb/transactd_datetime_spec.rb +0 -29
  221. data/source/bzs/test/tdclrb/transactd_kanjischema_spec.rb +18 -19
  222. data/source/bzs/test/tdclrb/transactd_pool_spec.rb +107 -0
  223. data/source/bzs/test/tdclrb/transactd_spec.rb +734 -142
  224. data/source/bzs/test/transactdBench/query_bench.cpp +156 -0
  225. data/source/bzs/test/transactdBench/scaling_bench.cpp +265 -0
  226. data/source/bzs/test/transactdBench/transactdBench.cpp +107 -83
  227. data/source/bzs/test/transactdBench/transactdBench2.cpp +122 -83
  228. data/source/bzs/test/transactdBench/workerBase.cpp +5 -0
  229. data/source/bzs/test/transactdBench/workerBase.h +88 -0
  230. data/source/bzs/test/transactdBench/workerMySQLImple.h +333 -0
  231. data/source/bzs/test/transactdBench/workerTransactdImple.h +201 -0
  232. data/source/bzs/test/trdclengn/test_blob.cpp +121 -73
  233. data/source/bzs/test/trdclengn/test_trdclengn.cpp +1244 -426
  234. data/source/global/ormsrcgen/confParam.h +80 -0
  235. data/source/global/ormsrcgen/fieldName.cpp +77 -0
  236. data/source/global/ormsrcgen/fieldName.h +43 -0
  237. data/source/global/ormsrcgen/main.cpp +196 -0
  238. data/source/global/ormsrcgen/srcgen.cpp +763 -0
  239. data/source/global/ormsrcgen/srcgen.h +72 -0
  240. data/source/global/ormsrcgen/template/fieldNameList_sample.txt +2 -0
  241. data/source/global/ormsrcgen/template/ormDataClass_template.cpp +48 -0
  242. data/source/global/ormsrcgen/template/ormDataClass_template.h +34 -0
  243. data/source/global/ormsrcgen/template/ormMapClass_template.cpp +51 -0
  244. data/source/global/ormsrcgen/template/ormMapClass_template.h +62 -0
  245. data/source/global/ormsrcgen/template/template.cnf +38 -0
  246. data/source/global/querystmts/querystmts.cpp +237 -0
  247. data/source/global/tdclatl/ConnectParams.cpp +77 -0
  248. data/source/global/tdclatl/ConnectParams.h +70 -0
  249. data/source/global/tdclatl/Database.cpp +132 -128
  250. data/source/global/tdclatl/Database.h +60 -49
  251. data/source/global/tdclatl/DbDef.cpp +68 -64
  252. data/source/global/tdclatl/DbDef.h +36 -36
  253. data/source/global/tdclatl/Field.cpp +12 -17
  254. data/source/global/tdclatl/Field.h +15 -12
  255. data/source/global/tdclatl/FieldDef.cpp +75 -36
  256. data/source/global/tdclatl/FieldDef.h +38 -19
  257. data/source/global/tdclatl/FieldDefs.cpp +74 -0
  258. data/source/global/tdclatl/FieldDefs.h +56 -0
  259. data/source/global/tdclatl/FieldNames.cpp +99 -0
  260. data/source/global/tdclatl/FieldNames.h +66 -0
  261. data/source/global/tdclatl/Flags.cpp +75 -37
  262. data/source/global/tdclatl/Flags.h +13 -12
  263. data/source/global/tdclatl/GroupQuery.cpp +119 -0
  264. data/source/global/tdclatl/GroupQuery.h +65 -0
  265. data/source/global/tdclatl/KeyDef.cpp +15 -14
  266. data/source/global/tdclatl/KeyDef.h +20 -17
  267. data/source/global/tdclatl/KeySegment.cpp +13 -12
  268. data/source/global/tdclatl/PooledDbManager.cpp +223 -0
  269. data/source/global/tdclatl/PooledDbManager.h +76 -0
  270. data/source/global/tdclatl/QueryBase.cpp +206 -127
  271. data/source/global/tdclatl/QueryBase.h +55 -59
  272. data/source/global/tdclatl/Record.cpp +214 -0
  273. data/source/global/tdclatl/Record.h +96 -0
  274. data/source/global/tdclatl/Recordset.cpp +278 -0
  275. data/source/global/tdclatl/Recordset.h +83 -0
  276. data/source/global/tdclatl/RecordsetQuery.cpp +118 -0
  277. data/source/global/tdclatl/RecordsetQuery.h +126 -0
  278. data/source/global/tdclatl/Table.cpp +57 -60
  279. data/source/global/tdclatl/Table.h +32 -29
  280. data/source/global/tdclatl/TableDef.cpp +63 -62
  281. data/source/global/tdclatl/TableDef.h +20 -22
  282. data/source/global/tdclatl/TdVersion.cpp +3 -3
  283. data/source/global/tdclatl/TdVersion.h +15 -11
  284. data/source/global/tdclatl/_IDatabaseEvents_CP.h +99 -92
  285. data/source/global/tdclatl/activeTable.cpp +355 -0
  286. data/source/global/tdclatl/activeTable.h +79 -0
  287. data/source/global/tdclatl/dllmain.cpp +4 -3
  288. data/source/global/tdclatl/dllmain.h +7 -6
  289. data/source/global/tdclatl/keySegment.h +22 -18
  290. data/source/global/tdclatl/resource.h +0 -0
  291. data/source/global/tdclatl/stdafx.h +6 -4
  292. data/source/global/tdclatl/targetver.h +0 -1
  293. data/source/global/tdclatl/tdclatl.cpp +10 -5
  294. data/source/global/tdclatl/tdclatl.idl +530 -14
  295. data/source/linux/charsetConvert.h +78 -79
  296. data/source/linux/linuxTypes.h +9 -12
  297. data/source/linux/tchar.h +168 -166
  298. data/transactd.gemspec +24 -16
  299. metadata +98 -12
  300. data/bin/common/tdclc_32_1_2.dll +0 -0
  301. data/bin/common/tdclc_64_1_2.dll +0 -0
  302. data/build/tdclc/tdclc_32.cbproj +0 -173
  303. data/build/tdclcpp/tdclcpp_bcb_32.cbproj +0 -232
  304. data/build/tdclrb/GEM_VERSION +0 -3
  305. data/source/bzs/db/protocol/tdap/client/filter.cpp +0 -43
  306. data/source/bzs/example/useORM.cpp +0 -585
@@ -0,0 +1,621 @@
1
+ /*=================================================================
2
+ Copyright (C) 2014 BizStation Corp All rights reserved.
3
+
4
+ This program is free software; you can redistribute it and/or
5
+ modify it under the terms of the GNU General Public License
6
+ as published by the Free Software Foundation; either version 2
7
+ of the License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program; if not, write to the Free Software
16
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17
+ 02111-1307, USA.
18
+ =================================================================*/
19
+ #include <bzs/db/protocol/tdap/client/trdormapi.h>
20
+ #include <bzs/db/protocol/tdap/client/databaseManager.h>
21
+ #include <boost/iterator/iterator_facade.hpp>
22
+ #include <iostream>
23
+ #include <vector>
24
+
25
+ /**
26
+ @brief Read records and manual O/R mapping example
27
+
28
+ This program read records of the "user" table where group = 3.
29
+ And O/R mapping to the user class.
30
+ This program use the filter operation on server side.
31
+
32
+ Please execute "create database" , "change schema" and "insert records" example
33
+ before execute this example.
34
+
35
+ */
36
+
37
+ using namespace bzs::db::protocol::tdap::client;
38
+ using namespace bzs::db::protocol::tdap;
39
+
40
+ class user;
41
+ typedef boost::shared_ptr<user> user_ptr;
42
+ typedef std::vector<user_ptr> user_ptr_list;
43
+ typedef std::vector<user*> user_list;
44
+ typedef boost::shared_ptr<user_list> user_list_ptr;
45
+
46
+ class group;
47
+ typedef boost::shared_ptr<group> group_ptr;
48
+ typedef std::vector<group_ptr> group_ptr_list;
49
+ typedef std::vector<group*> group_list;
50
+ typedef boost::shared_ptr<group_list> group_list_ptr;
51
+
52
+ /** class group
53
+ This is a model
54
+ */
55
+ class group
56
+ {
57
+ int m_id;
58
+ std::string m_name;
59
+ mutable user_ptr_list* m_users;
60
+
61
+ protected:
62
+ group(void* owner) : m_id(0), m_users(NULL) {}
63
+
64
+ public:
65
+ ~group() { delete m_users; }
66
+
67
+ int id() const { return m_id; }
68
+ const std::string& name() const { return m_name; }
69
+ void setId(int v) { m_id = v; }
70
+ void setName(const char* v) { m_name = v; }
71
+ user_ptr_list& users() const
72
+ {
73
+ if (!m_users)
74
+ m_users = new user_ptr_list;
75
+ return *m_users;
76
+ }
77
+
78
+ /* create instance */
79
+ static group* create(void* owner) { return new group(owner); };
80
+ };
81
+
82
+ group* create(group_ptr_list& m, int)
83
+ {
84
+ return group::create(&m);
85
+ }
86
+
87
+ /** class group_fdi
88
+ This is a dynamic field index cache resolv from field name.
89
+ An index is cached at instruction execution time,
90
+ it becomes strong to change of a schema.
91
+ */
92
+ class group_fdi
93
+ {
94
+
95
+ public:
96
+ short id;
97
+ short name;
98
+
99
+ /* Implement the init function which a argument of 'table*'. */
100
+ void init(table* tb)
101
+ {
102
+ id = tb->fieldNumByName(_T("id"));
103
+ name = tb->fieldNumByName(_T("name"));
104
+ }
105
+ };
106
+
107
+ /* Global functions of fdi instance and init */
108
+ group_fdi* createFdi(group_fdi*)
109
+ {
110
+ return new group_fdi();
111
+ }
112
+ void destroyFdi(group_fdi* p)
113
+ {
114
+ delete p;
115
+ }
116
+ void initFdi(group_fdi* fdi, table* tb)
117
+ {
118
+ fdi->init(tb);
119
+ }
120
+
121
+ /* model table mapping class */
122
+ class group_orm
123
+ {
124
+ const group_fdi& m_fdi;
125
+
126
+ public:
127
+ /* Define mdl_typename type */
128
+ typedef group mdl_typename;
129
+
130
+ /* Define fdi_typename type
131
+ When fdi is not used , It is define "typedef fdibase fdi_typename;"
132
+ When other fdi is used, you can the fdi type specify at create
133
+ activeObject instance
134
+ like "activeObject<group, other_fdi>" */
135
+ typedef group_fdi fdi_typename;
136
+
137
+ /* Constructor , which a argument of 'fdi_typename fdi&' */
138
+ group_orm(const fdi_typename& fdi) : m_fdi(fdi) {}
139
+
140
+ /* Compare function , only fields of unique keys are compared. */
141
+ bool compKeyValue(group& l, group& r, int keyNum) const
142
+ {
143
+ return l.id() < r.id();
144
+ }
145
+
146
+ void setKeyValues(group& g, const fields& fds, int keyNum)
147
+ {
148
+ fds[m_fdi.id] = g.id();
149
+ }
150
+
151
+ void writeMap(group& g, const fields& fds, int optipn)
152
+ {
153
+ fds[m_fdi.id] = g.id();
154
+ fds[m_fdi.name] = g.name();
155
+ }
156
+
157
+ void readMap(group& g, const fields& fds, int optipn)
158
+ {
159
+ g.setId(fds[m_fdi.id].i());
160
+ g.setName(fds[m_fdi.name].a_str()); // get by ansi string
161
+ }
162
+
163
+ void readAuntoincValue(group& g, const fields& fds, int optipn)
164
+ {
165
+ g.setId(fds[m_fdi.id].i());
166
+ }
167
+
168
+ /* Get a table name from a target model. */
169
+ const _TCHAR* getTableName() { return _T("group1"); }
170
+ };
171
+
172
+ /** User class */
173
+ class user
174
+ {
175
+ mutable group* m_grp;
176
+ int m_id;
177
+ int m_group_id;
178
+ std::string m_name;
179
+ std::string m_tel;
180
+
181
+ protected:
182
+ user(void* owner) : m_grp(NULL), m_id(0) {}
183
+
184
+ public:
185
+ ~user() { delete m_grp; }
186
+ group* grp() const
187
+ {
188
+ if (m_grp == NULL)
189
+ {
190
+ m_grp = group::create(0);
191
+ m_grp->setId(m_group_id);
192
+ }
193
+ return m_grp;
194
+ }
195
+ int id() const { return m_id; }
196
+ int group_id() const { return m_group_id; }
197
+ const std::string& name() const { return m_name; }
198
+ const std::string& tel() const { return m_tel; }
199
+ void setId(int v) { m_id = v; }
200
+ void setGroup_id(int v) { m_group_id = v; }
201
+ void setName(const char* v) { m_name = v; }
202
+ void setTel(const char* v) { m_tel = v; }
203
+
204
+ static user* create(void* owner) { return new user(owner); };
205
+ };
206
+
207
+ class user_fdi
208
+ {
209
+
210
+ public:
211
+ short id;
212
+ short name;
213
+ short tel;
214
+ short group_id;
215
+ void init(table* tb)
216
+ {
217
+ id = tb->fieldNumByName(_T("id"));
218
+ name = tb->fieldNumByName(_T("name"));
219
+ tel = tb->fieldNumByName(_T("tel"));
220
+ group_id = tb->fieldNumByName(_T("group"));
221
+ }
222
+ };
223
+
224
+ user_fdi* createFdi(user_fdi*)
225
+ {
226
+ return new user_fdi();
227
+ }
228
+ void destroyFdi(user_fdi* p)
229
+ {
230
+ delete p;
231
+ }
232
+ void initFdi(user_fdi* fdi, table* tb)
233
+ {
234
+ fdi->init(tb);
235
+ }
236
+
237
+ //------------------------------------------------------------------------------
238
+ // The original collection exsample
239
+ //------------------------------------------------------------------------------
240
+ /* When the original collection used it is not vector,
241
+ iterator for the collection is required.
242
+ */
243
+ class mdls;
244
+
245
+ class mdlsIterator
246
+ : public boost::iterator_facade<mdlsIterator, user*,
247
+ boost::random_access_traversal_tag>
248
+ {
249
+ friend class boost::iterator_core_access;
250
+ size_t m_index;
251
+ mdls* m_mdls;
252
+ user*& dereference() const;
253
+ void increment();
254
+ void decrement();
255
+ void advance(size_t n);
256
+ int distance_to(const mdlsIterator& r) const;
257
+ bool equal(const mdlsIterator& r) const;
258
+
259
+ public:
260
+ mdlsIterator(mdls* m, size_t index = 0);
261
+ };
262
+
263
+ /* This is a exsample of the origianl collection of user model. */
264
+ class mdls
265
+ {
266
+ mutable std::vector<user*> m_users;
267
+
268
+ public:
269
+ void clear() { m_users.clear(); }
270
+
271
+ user*& item(size_t index) const { return m_users[index]; }
272
+
273
+ user* add(user* u)
274
+ {
275
+ m_users.push_back(u);
276
+ return u;
277
+ }
278
+
279
+ size_t size() { return m_users.size(); }
280
+
281
+ user* operator[](unsigned int index) const { return item(index); }
282
+
283
+ /* Define item_type type */
284
+ typedef user* item_type;
285
+
286
+ /* Define iterator type */
287
+ typedef mdlsIterator iterator;
288
+ };
289
+
290
+ /* implement th iterator */
291
+ user*& mdlsIterator::dereference() const
292
+ {
293
+ return m_mdls->item(m_index);
294
+ }
295
+ void mdlsIterator::increment()
296
+ {
297
+ ++m_index;
298
+ }
299
+ void mdlsIterator::decrement()
300
+ {
301
+ --m_index;
302
+ }
303
+ void mdlsIterator::advance(size_t n)
304
+ {
305
+ m_index += n;
306
+ }
307
+ int mdlsIterator::distance_to(const mdlsIterator& r) const
308
+ {
309
+ return (int)(r.m_index - m_index);
310
+ }
311
+ bool mdlsIterator::equal(const mdlsIterator& r) const
312
+ {
313
+ return m_index == r.m_index;
314
+ }
315
+ mdlsIterator::mdlsIterator(mdls* m, size_t index) : m_index(index), m_mdls(m)
316
+ {
317
+ }
318
+
319
+ /* Implemant global functions of push_back begin end and clear in client
320
+ * namespace */
321
+ namespace bzs
322
+ {
323
+ namespace db
324
+ {
325
+ namespace protocol
326
+ {
327
+ namespace tdap
328
+ {
329
+ namespace client
330
+ {
331
+
332
+ template <> inline mdlsIterator begin(mdls& m)
333
+ {
334
+ return mdlsIterator(&m, 0);
335
+ }
336
+
337
+ template <> inline mdlsIterator end(mdls& m)
338
+ {
339
+ return mdlsIterator(&m, m.size());
340
+ }
341
+
342
+ #if (_MSC_VER || (__BCPLUSPLUS__ && !defined(__clang__)))
343
+ inline void push_back(mdls& m, user* u)
344
+ {
345
+ m.add(u);
346
+ }
347
+ #else
348
+ template <> inline void push_back(mdls& m, user* u)
349
+ {
350
+ m.add(u);
351
+ }
352
+ #endif
353
+ }
354
+ }
355
+ }
356
+ }
357
+ }
358
+
359
+ //------------------------------------------------------------------------------
360
+
361
+ user* create(mdls& m, int)
362
+ {
363
+ return user::create(&m);
364
+ }
365
+ user* create(user_ptr_list& m, int)
366
+ {
367
+ return user::create(&m);
368
+ }
369
+
370
+ class user_orm
371
+ {
372
+ const user_fdi& m_fdi;
373
+
374
+ public:
375
+ user_orm(const user_fdi& fdi) : m_fdi(fdi) {}
376
+
377
+ bool compKeyValue(user& l, user& r, int keyNum) const
378
+ {
379
+ if (keyNum == 0)
380
+ return l.id() < r.id();
381
+ return 1;
382
+ }
383
+
384
+ void setKeyValues(user& u, const fields& fds, int keyNum)
385
+ {
386
+ fds[m_fdi.id] = u.id();
387
+ }
388
+
389
+ void writeMap(user& u, const fields& fds, int optipn)
390
+ {
391
+ fds[m_fdi.id] = u.id();
392
+ fds[m_fdi.name] = u.name();
393
+ fds[m_fdi.tel] = u.tel();
394
+ fds[m_fdi.group_id] = u.group_id();
395
+ }
396
+
397
+ void readMap(user& u, const fields& fds, int optipn)
398
+ {
399
+ u.setId(fds[m_fdi.id].i());
400
+ u.setGroup_id(fds[m_fdi.group_id].i());
401
+ u.setName(fds[m_fdi.name].a_str()); // get by ansi string
402
+ u.setTel(fds[m_fdi.tel].a_str()); // get by ansi string
403
+ }
404
+
405
+ void readAuntoincValue(user& u, const fields& fds, int optipn)
406
+ {
407
+ u.setId(fds[m_fdi.id].i());
408
+ }
409
+
410
+ const _TCHAR* getTableName() { return _T("user"); }
411
+
412
+ typedef user mdl_typename;
413
+ typedef user_fdi fdi_typename;
414
+
415
+ /* Definition the collection_orm_typename type when using an original
416
+ * collection.*/
417
+ typedef mdlsHandler<user_orm, mdls> collection_orm_typename;
418
+ };
419
+
420
+ typedef user_orm::collection_orm_typename users_orm;
421
+
422
+ //------------------------------------------------------------------------------
423
+
424
+ /* client filter function */
425
+ int isMatch(const fields& fds)
426
+ {
427
+ return filter_validate_value;
428
+ }
429
+
430
+ /** dump user to screen */
431
+ template <class T> void dumpUser(const T user)
432
+ {
433
+ std::cout << " id " << user->id() << std::endl;
434
+ std::cout << " name " << user->name() << std::endl;
435
+ std::cout << " group " << user->grp()->name() << std::endl;
436
+ std::cout << " tel " << user->tel() << std::endl << std::endl;
437
+ }
438
+
439
+ bool sortFunc2(const user* l, const user* r)
440
+ {
441
+ return l->name() < r->name();
442
+ }
443
+
444
+ void readUsers(databaseManager& db, std::vector<user_ptr>& users)
445
+ {
446
+ static int find_group_id = 2;
447
+ static const char_td keynum_group = 1;
448
+ static const char_td primary_key = 0;
449
+
450
+ /* Create the activeObject instance of user_orm. */
451
+ activeObject<user_orm> ut(&db);
452
+
453
+ //-------------------------------------------------------------------------
454
+ // Single model operations
455
+ //-------------------------------------------------------------------------
456
+ /* Create user of id=12. */
457
+ int id = 12;
458
+ user_ptr u(user::create(0));
459
+ u->setId(id);
460
+ u->setName("moriwaki");
461
+ u->setTel("81-999-9999");
462
+ u->setGroup_id(1);
463
+
464
+ /* Save a user */
465
+ ut.index(primary_key);
466
+ ut.save(*u); // insert or update
467
+
468
+ /* Read a user of id=12 */
469
+ ut.read(*u);
470
+
471
+ /* Update telephone number of the user. */
472
+ u->setTel("81-999-8888");
473
+ ut.update(*u);
474
+
475
+ /* Changing unique key value .*/
476
+ ut.index(primary_key).keyValue(u->id());
477
+ u->setId(13);
478
+ bool noKeyValueFromObj = false;
479
+ ut.update(*u, noKeyValueFromObj); /* Dont read key value from model */
480
+
481
+ /* Delete a user 1. */
482
+ ut.del(*u);
483
+
484
+ /* Delete a user 2. */
485
+ // ut.index(primary_key).keyValue(id).del();
486
+
487
+ /* Read a group model.
488
+ Using shared pointer.
489
+ */
490
+ group_ptr grp(group::create(0));
491
+ activeObject<group_orm> gt(&db);
492
+ gt.index(primary_key).keyValue(2).read(*grp, noKeyValueFromObj);
493
+
494
+ /* Using pure pointer. */
495
+ group* g = group::create(0);
496
+ g->setId(2);
497
+ gt.read(*g);
498
+ delete g;
499
+
500
+ //-------------------------------------------------------------------------
501
+ // Multi model operations (find operation)
502
+ //-------------------------------------------------------------------------
503
+
504
+ /* Set key number and key value of start record position */
505
+ ut.index(keynum_group).keyValue(find_group_id);
506
+
507
+ /* Create query of find */
508
+ query q;
509
+ q.select(_T("*")).where(_T("group"), _T("="), find_group_id);
510
+
511
+ /* Execute read by the query.
512
+ Users is vector collection .
513
+ */
514
+ ut.read(users, q);
515
+
516
+ /* Using original collection. */
517
+ mdls m;
518
+ ut.index(keynum_group).keyValue(find_group_id).read(m, q);
519
+
520
+ /* When Using other map handler, use readMap method.
521
+ */
522
+ users_orm users_hdr(m);
523
+ ut.readMap(users_hdr, q);
524
+
525
+ /* Using clrient filter exsample.
526
+ Set a client filter function or function object to read method.
527
+ */
528
+ ut.index(keynum_group).keyValue(find_group_id).read(users, q, isMatch);
529
+
530
+ /* Using id list reading, that like 'in' of SQL.
531
+ Read groups of id= 1, 2, and 3
532
+ */
533
+ gt.index(primary_key);
534
+ q.reset();
535
+ std::vector<group_ptr> gmdls;
536
+ q.select(_T("id"), _T("name")).in(1, 2, 3);
537
+ gt.read(gmdls, q);
538
+
539
+ //-------------------------------------------------------------------------
540
+ // Like the ActiveRecord operation has_many
541
+ //-------------------------------------------------------------------------
542
+ q.reset().where(_T("group"), _T("="), grp->id());
543
+ ut.index(keynum_group).keyValue(grp->id()).read(grp->users(), q);
544
+
545
+ //-------------------------------------------------------------------------
546
+ // Like the ActiveRecord operations belongs_to and has_one
547
+ //-------------------------------------------------------------------------
548
+ /* Read user models belongs to object of 'group', that use readEach method
549
+ Specify the get function pointer group model from user model.
550
+ Group id list is listed automatically.
551
+ */
552
+ query qe;
553
+ /* Read group name only */
554
+ qe.select(_T("id"), _T("name"));
555
+
556
+ gt.index(primary_key);
557
+ gt.readEach(users, &user::grp, qe);
558
+
559
+ /* Using the Origianl collection is same as. */
560
+ gt.readEach(m, &user::grp, qe);
561
+
562
+ /* Group id list is listed by yourself. */
563
+ group_list_ptr grps(listup(users, &user::grp));
564
+ gt.index(primary_key).readEach(*grps, qe);
565
+
566
+ /* Using the Origianl collection is same as. */
567
+ group_list_ptr grps2(listup(m, &user::grp));
568
+ gt.index(primary_key).readEach(*grps2, qe);
569
+
570
+ /* Order by */
571
+ users.clear();
572
+ ut.index(0).keyValue(0).read(users, q.all());
573
+ sort(users, &user::name, &user::id);
574
+
575
+ /* Order by for original collection */
576
+ m.clear();
577
+ ut.index(0).keyValue(0).read(m, q);
578
+ sort(m, &user::name, &user::id);
579
+
580
+ /* Using original sort function */
581
+ std::sort(begin(m), end(m), &sortFunc2);
582
+
583
+ /* Using for_each function */
584
+ std::cout << "--- vector for each ---" << std::endl;
585
+ std::for_each(users.begin(), users.end(), dumpUser<user_ptr&>);
586
+
587
+ /* Using for_each function of original collection */
588
+ std::cout << "--- original collection for each ---" << std::endl;
589
+ std::for_each(begin(m), end(m), dumpUser<user*>);
590
+
591
+ /* Using only table operation */
592
+ table_ptr tb = ut.table();
593
+ tb->clearOwnerName();
594
+ }
595
+
596
+ #pragma argsused
597
+ int _tmain(int argc, _TCHAR* argv[])
598
+ {
599
+ database_ptr db = createDatabaseObject();
600
+ try
601
+ {
602
+ connectParams param(_T("tdap"), _T("localhost"), _T("test"),
603
+ _T("test"));
604
+ openDatabase(db, param);
605
+
606
+ databaseManager mgr(db);
607
+ std::vector<user_ptr> users;
608
+
609
+ readUsers(mgr, users);
610
+ std::cout << "Read records success.\nRecord count = " << users.size()
611
+ << std::endl;
612
+
613
+ return 0;
614
+ }
615
+
616
+ catch (bzs::rtl::exception& e)
617
+ {
618
+ std::tcout << _T("[ERROR] ") << *bzs::rtl::getMsg(e) << std::endl;
619
+ }
620
+ return 1;
621
+ }