001package gu.sql2java; 002import java.util.List; 003import java.util.Map; 004 005import gu.sql2java.exception.ObjectRetrievalException; 006import gu.sql2java.exception.RuntimeDaoException; 007 008import java.util.Collection; 009/** 010 * Interface to handle database calls (save, load, count, etc...) for table. 011 * @author guyadong 012 */ 013public interface TableManager<B extends BaseBean> extends SqlRunner{ 014 015 public interface Action<B>{ 016 017 /** 018 * do action for {@code bean} 019 * @param bean input bean 020 */ 021 void call(B bean); 022 } 023 024 //_____________________________________________________________________ 025 // 026 // COUNT 027 //_____________________________________________________________________ 028 //24 029 /** 030 * Retrieves the number of rows of the table. 031 * 032 * @return the number of rows returned 033 * @throws RuntimeDaoException 034 */ 035 public int countAll()throws RuntimeDaoException; 036 037 //27 038 /** 039 * count the number of elements of a specific bean 040 * 041 * @param bean the bean to look for ant count 042 * @return the number of rows returned 043 * @throws RuntimeDaoException 044 */ 045 public int countUsingTemplate( B bean)throws RuntimeDaoException; 046 047 //20 048 /** 049 * count the number of elements of a specific bean given the search type 050 * 051 * @param bean the template to look for 052 * @param searchType exact ? like ? starting like ? ending link ? <br> 053 * {@value Constant#SEARCH_EXACT} {@link Constant#SEARCH_EXACT} <br> 054 * {@value Constant#SEARCH_LIKE} {@link Constant#SEARCH_LIKE} <br> 055 * {@value Constant#SEARCH_STARTING_LIKE} {@link Constant#SEARCH_STARTING_LIKE} <br> 056 * {@value Constant#SEARCH_ENDING_LIKE} {@link Constant#SEARCH_ENDING_LIKE} <br> 057 * @return the number of rows returned 058 * @throws RuntimeDaoException 059 */ 060 public int countUsingTemplate(B bean, int searchType)throws RuntimeDaoException; 061 062 //25 063 /** 064 * Retrieves the number of rows of the table with a 'where' clause. 065 * It is up to you to pass the 'WHERE' in your where clauses. 066 * 067 * @param where the restriction clause 068 * @return the number of rows returned 069 * @throws RuntimeDaoException 070 */ 071 public int countWhere(String where)throws RuntimeDaoException; 072 073 //10 074 /** 075 * Deletes all rows from table. 076 * @return the number of deleted rows. 077 * @throws RuntimeDaoException 078 */ 079 public int deleteAll()throws RuntimeDaoException; 080 081 //11 082 /** 083 * Deletes rows from the table using a 'where' clause. 084 * It is up to you to pass the 'WHERE' in your where clauses. 085 * <br>Attention, if 'WHERE' is omitted it will delete all records. 086 * 087 * @param where the sql 'where' clause 088 * @return the number of deleted rows 089 * @throws RuntimeDaoException 090 */ 091 public int deleteByWhere(String where)throws RuntimeDaoException; 092 093 //21 094 /** 095 * Deletes rows using a template. 096 * 097 * @param bean the template object(s) to be deleted 098 * @return the number of deleted objects 099 * @throws RuntimeDaoException 100 */ 101 public int deleteUsingTemplate(B bean)throws RuntimeDaoException; 102 103 //2.1 104 /** 105 * Delete row according to its primary keys. 106 * 107 * @param keys primary keys value<br> 108 * for fd_face table<br> 109 * PK# 1 fd_face.id type Integer<br> 110 * for fd_feature table<br> 111 * PK# 1 fd_feature.md5 type String<br> 112 * for fd_image table<br> 113 * PK# 1 fd_image.md5 type String<br> 114 * for fd_store table<br> 115 * PK# 1 fd_store.md5 type String<br> 116 * @return the number of deleted rows 117 * @throws RuntimeDaoException 118 */ 119 public int deleteByPrimaryKey(Object ...keys)throws RuntimeDaoException; 120 121 //2.2 122 /** 123 * Delete row according to primary keys of bean.<br> 124 * 125 * @param bean will be deleted ,all keys must not be null 126 * @return the number of deleted rows,0 returned if bean is null 127 * @throws RuntimeDaoException 128 */ 129 public int delete(B bean)throws RuntimeDaoException; 130 131 //2.4 132 /** 133 * Delete beans.<br> 134 * 135 * @param beans B array will be deleted 136 * @return the number of deleted rows 137 * @throws RuntimeDaoException 138 */ 139 @SuppressWarnings("unchecked") 140 public int delete(B... beans)throws RuntimeDaoException; 141 142 //2.5 143 /** 144 * Delete beans.<br> 145 * 146 * @param beans B collection will be deleted 147 * @return the number of deleted rows 148 * @throws RuntimeDaoException 149 */ 150 public int delete(Collection<B> beans)throws RuntimeDaoException; 151 ////////////////////////////////////// 152 // LOAD ALL 153 ////////////////////////////////////// 154 155 //5 156 /** 157 * Loads all the rows from table. 158 * 159 * @return an array of B bean 160 * @throws RuntimeDaoException 161 */ 162 public B[] loadAll()throws RuntimeDaoException; 163 164 //5-1 165 /** 166 * Loads each row from table and dealt with action. 167 * @param action Action object for do something(not null) 168 * @return the count dealt by action 169 * @throws RuntimeDaoException 170 */ 171 public int loadAll(Action<B> action)throws RuntimeDaoException; 172 173 //6 174 /** 175 * Loads the given number of rows from table, given the start row. 176 * 177 * @param startRow the start row to be used (first row = 1, last row = -1) 178 * @param numRows the number of rows to be retrieved (all rows = a negative number) 179 * @return an array of B bean 180 * @throws RuntimeDaoException 181 */ 182 public B[] loadAll(int startRow, int numRows)throws RuntimeDaoException; 183 184 //6-1 185 /** 186 * Loads the given number of rows from table, given the start row and dealt with action. 187 * @param startRow the start row to be used (first row = 1, last row = -1) 188 * @param numRows the number of rows to be retrieved (all rows = a negative number) 189 * @param action Action object for do something(not null) 190 * @return the count dealt by action 191 * @throws RuntimeDaoException 192 */ 193 public int loadAll(int startRow, int numRows,Action<B> action)throws RuntimeDaoException; 194 195 //5-2 196 /** 197 * Loads all the rows from table. 198 * 199 * @return a list of B bean 200 * @throws RuntimeDaoException 201 */ 202 public List<B> loadAllAsList()throws RuntimeDaoException; 203 204 //6-2 205 /** 206 * Loads the given number of rows from table, given the start row. 207 * 208 * @param startRow the start row to be used (first row = 1, last row = -1) 209 * @param numRows the number of rows to be retrieved (all rows = a negative number) 210 * @return a list of B bean 211 * @throws RuntimeDaoException 212 */ 213 public List<B> loadAllAsList(int startRow, int numRows)throws RuntimeDaoException; 214 215 //1.2 216 /** 217 * Loads a B bean from the table using primary key fields of {@code bean}. 218 * @param bean the B bean with primary key fields 219 * @return a unique B or {@code null} if not found or bean is null 220 * @throws RuntimeDaoException 221 */ 222 public B loadByPrimaryKey(B bean)throws RuntimeDaoException; 223 224 //1.2.2 225 /** 226 * see also {@link #loadByPrimaryKey(BaseBean)} 227 * @param bean 228 * @return a unique B ,otherwise throw exception 229 * @throws ObjectRetrievalException not found 230 * @throws RuntimeDaoException 231 */ 232 public B loadByPrimaryKeyChecked(B bean)throws RuntimeDaoException,ObjectRetrievalException; 233 //1.3 234 /** 235 * Loads a B bean from the table using primary key fields. 236 * when you don't know which is primary key of table,you can use the method. 237 * @param keys primary keys value:<br> 238 * for fd_face table<br> 239 * PK# 1 fd_face.id type Integer<br> 240 * for fd_feature table<br> 241 * PK# 1 fd_feature.md5 type String<br> 242 * for fd_image table<br> 243 * PK# 1 fd_image.md5 type String<br> 244 * for fd_store table<br> 245 * PK# 1 fd_store.md5 type String<br> 246 * @return a unique B or {@code null} if not found 247 * @throws RuntimeDaoException 248 */ 249 public B loadByPrimaryKey(Object ...keys)throws RuntimeDaoException; 250 251 //1.3.2 252 /** 253 * see also {@link #loadByPrimaryKey(Object...)} 254 * @param keys 255 * @return a unique B,otherwise throw exception 256 * @throws ObjectRetrievalException not found 257 * @throws RuntimeDaoException 258 */ 259 public B loadByPrimaryKeyChecked(Object ...keys)throws RuntimeDaoException,ObjectRetrievalException; 260 261 //1.5 262 /** 263 * Returns true if this table contains row with primary key fields. 264 * @param keys primary keys value 265 * @see #loadByPrimaryKey(Object...) 266 * @return 267 * @throws RuntimeDaoException 268 */ 269 public boolean existsPrimaryKey(Object ...keys)throws RuntimeDaoException; 270 271 //1.6 272 /** 273 * Returns true if this table contains row specified by primary key fields of B.<br> 274 * when you don't know which is primary key of table,you can use the method. 275 * @param bean the B bean with primary key fields 276 * @return 277 * @see #loadByPrimaryKey(BaseBean) 278 * @throws RuntimeDaoException 279 */ 280 public boolean existsByPrimaryKey(B bean)throws RuntimeDaoException; 281 //1.7 282 /** 283 * Check duplicated row by primary keys,if row exists throw exception 284 * @param bean the B bean with primary key fields 285 * @return always bean 286 * @see #existsByPrimaryKey(BaseBean) 287 * @throws ObjectRetrievalException has duplicated record 288 * @throws RuntimeDaoException 289 */ 290 public B checkDuplicate(B bean)throws RuntimeDaoException,ObjectRetrievalException; 291 292 ////////////////////////////////////// 293 // SQL 'WHERE' METHOD 294 ////////////////////////////////////// 295 //7 296 /** 297 * Retrieves an array of B given a sql 'where' clause. 298 * 299 * @param where the sql 'where' clause 300 * @return 301 * @throws RuntimeDaoException 302 */ 303 public B[] loadByWhere(String where)throws RuntimeDaoException; 304 305 //7-1 306 /** 307 * Retrieves each row of B bean given a sql 'where' clause and dealt with action. 308 * @param where the sql 'where' clause 309 * @param action Action object for do something(not null) 310 * @return the count dealt by action 311 * @throws RuntimeDaoException 312 */ 313 public int loadByWhere(String where,Action<B> action)throws RuntimeDaoException; 314 315 //8 316 /** 317 * Retrieves an array of B bean given a sql where clause, and a list of fields. 318 * It is up to you to pass the 'WHERE' in your where clauses. 319 * 320 * @param where the sql 'WHERE' clause 321 * @param fieldList array of field's ID 322 * @return 323 * @throws RuntimeDaoException 324 */ 325 public B[] loadByWhere(String where, int[] fieldList)throws RuntimeDaoException; 326 327 //8-1 328 /** 329 * Retrieves each row of B bean given a sql where clause, and a list of fields, 330 * and dealt with action. 331 * It is up to you to pass the 'WHERE' in your where clauses. 332 * @param where the sql 'WHERE' clause 333 * @param fieldList array of field's ID 334 * @param action Action object for do something(not null) 335 * @return the count dealt by action 336 * @throws RuntimeDaoException 337 */ 338 public int loadByWhere(String where, int[] fieldList,Action<B> action)throws RuntimeDaoException; 339 340 //9 341 /** 342 * Retrieves an array of B bean given a sql where clause and a list of fields, and startRow and numRows. 343 * It is up to you to pass the 'WHERE' in your where clauses. 344 * 345 * @param where the sql 'where' clause 346 * @param fieldList table of the field's associated constants 347 * @param startRow the start row to be used (first row = 1, last row = -1) 348 * @param numRows the number of rows to be retrieved (all rows = a negative number) 349 * @return 350 * @throws RuntimeDaoException 351 */ 352 public B[] loadByWhere(String where, int[] fieldList, int startRow, int numRows)throws RuntimeDaoException; 353 354 //9-1 355 /** 356 * Retrieves each row of B bean given a sql where clause and a list of fields, and startRow and numRows, 357 * and dealt with action. 358 * It is up to you to pass the 'WHERE' in your where clauses. 359 * 360 * @param where the sql 'where' clause 361 * @param fieldList table of the field's associated constants 362 * @param startRow the start row to be used (first row = 1, last row = -1) 363 * @param numRows the number of rows to be retrieved (all rows = a negative number) 364 * @param action Action object for do something(not null) 365 * @return the count dealt by action 366 * @throws RuntimeDaoException 367 */ 368 public int loadByWhere(String where, int[] fieldList, int startRow, int numRows,Action<B> action)throws RuntimeDaoException; 369 //7 370 /** 371 * Retrieves a list of B bean given a sql 'where' clause. 372 * 373 * @param where the sql 'where' clause 374 * @return 375 * @throws RuntimeDaoException 376 */ 377 public List<B> loadByWhereAsList(String where)throws RuntimeDaoException; 378 379 //8 380 /** 381 * Retrieves a list of B bean given a sql where clause, and a list of fields. 382 * It is up to you to pass the 'WHERE' in your where clauses. 383 * 384 * @param where the sql 'WHERE' clause 385 * @param fieldList array of field's ID 386 * @return 387 * @throws RuntimeDaoException 388 */ 389 public List<B> loadByWhereAsList(String where, int[] fieldList)throws RuntimeDaoException; 390 391 //9-2 392 /** 393 * Retrieves a list of B bean given a sql where clause and a list of fields, and startRow and numRows. 394 * It is up to you to pass the 'WHERE' in your where clauses. 395 * 396 * @param where the sql 'where' clause 397 * @param fieldList table of the field's associated constants 398 * @param startRow the start row to be used (first row = 1, last row = -1) 399 * @param numRows the number of rows to be retrieved (all rows = a negative number) 400 * @return 401 * @throws RuntimeDaoException 402 */ 403 public List<B> loadByWhereAsList(String where, int[] fieldList, int startRow, int numRows)throws RuntimeDaoException; 404 405 //9-3 406 /** 407 * Retrieves each row of B bean given a sql where clause and a list of fields, and startRow and numRows, 408 * and dealt wity action 409 * It is up to you to pass the 'WHERE' in your where clauses. 410 * 411 * @param where the sql 'where' clause 412 * @param fieldList table of the field's associated constants 413 * @param startRow the start row to be used (first row = 1, last row = -1) 414 * @param numRows the number of rows to be retrieved (all rows = a negative number) 415 * @param action Action object for do something(not null) 416 * @return the count dealt by action 417 * @throws RuntimeDaoException 418 */ 419 public int loadByWhereForAction(String where, int[] fieldList, int startRow, int numRows,Action<B> action)throws RuntimeDaoException; 420 421 //_____________________________________________________________________ 422 // 423 // USING TEMPLATE 424 //_____________________________________________________________________ 425 //18 426 /** 427 * Loads a unique B bean from a template one giving a c 428 * 429 * @param bean the B bean to look for 430 * @return the bean matching the template,or {@code null} if not found or null input argument 431 * @throws ObjectRetrievalException more than one row 432 * @throws RuntimeDaoException 433 */ 434 public B loadUniqueUsingTemplate(B bean)throws RuntimeDaoException; 435 436 //18-1 437 /** 438 * Loads a unique B bean from a template one giving a c 439 * 440 * @param bean the B bean to look for 441 * @return the bean matching the template 442 * @throws ObjectRetrievalException not found or more than one row 443 * @throws RuntimeDaoException 444 */ 445 public B loadUniqueUsingTemplateChecked(B bean)throws RuntimeDaoException,ObjectRetrievalException; 446 447 //19 448 /** 449 * Loads an array of B from a template one. 450 * 451 * @param bean the B bean template to look for 452 * @return all the B beans matching the template 453 * @throws RuntimeDaoException 454 */ 455 public B[] loadUsingTemplate(B bean)throws RuntimeDaoException; 456 457 //19-1 458 /** 459 * Loads each row from a template one and dealt with action. 460 * 461 * @param bean the B bean template to look for 462 * @param action Action object for do something(not null) 463 * @return the count dealt by action 464 * @throws RuntimeDaoException 465 */ 466 public int loadUsingTemplate(B bean,Action<B> action)throws RuntimeDaoException; 467 468 //20 469 /** 470 * Loads an array of B bean from a template one, given the start row and number of rows. 471 * 472 * @param bean the B bean template to look for 473 * @param startRow the start row to be used (first row = 1, last row=-1) 474 * @param numRows the number of rows to be retrieved (all rows = a negative number) 475 * @return all the B matching the template 476 * @throws RuntimeDaoException 477 */ 478 public B[] loadUsingTemplate(B bean, int startRow, int numRows)throws RuntimeDaoException; 479 480 //20-1 481 /** 482 * Loads each row from a template one, given the start row and number of rows and dealt with action. 483 * 484 * @param bean the B bean template to look for 485 * @param startRow the start row to be used (first row = 1, last row=-1) 486 * @param numRows the number of rows to be retrieved (all rows = a negative number) 487 * @param action Action object for do something(not null) 488 * @return the count dealt by action 489 * @throws RuntimeDaoException 490 */ 491 public int loadUsingTemplate(B bean, int startRow, int numRows,Action<B> action)throws RuntimeDaoException; 492 493 //20-5 494 /** 495 * Loads each row from a template one, given the start row and number of rows and dealt with action. 496 * 497 * @param bean the B template to look for 498 * @param fieldList table of the field's associated constants 499 * @param startRow the start row to be used (first row = 1, last row=-1) 500 * @param numRows the number of rows to be retrieved (all rows = a negative number) 501 * @param searchType exact ? like ? starting like ? ending link ? <br> 502 * {@value Constant#SEARCH_EXACT} {@link Constant#SEARCH_EXACT} <br> 503 * {@value Constant#SEARCH_LIKE} {@link Constant#SEARCH_LIKE} <br> 504 * {@value Constant#SEARCH_STARTING_LIKE} {@link Constant#SEARCH_STARTING_LIKE} <br> 505 * {@value Constant#SEARCH_ENDING_LIKE} {@link Constant#SEARCH_ENDING_LIKE} <br> 506 * @param action Action object for do something(not null) 507 * @return the count dealt by action 508 * @throws RuntimeDaoException 509 */ 510 public int loadUsingTemplate(B bean, int[] fieldList, int startRow, int numRows,int searchType, Action<B> action)throws RuntimeDaoException; 511 //20-4 512 /** 513 * Loads a list of B bean from a template one, given the start row and number of rows. 514 * 515 * @param bean the B bean template to look for 516 * @param startRow the start row to be used (first row = 1, last row=-1) 517 * @param numRows the number of rows to be retrieved (all rows = a negative number) 518 * @param searchType exact ? like ? starting like ? ending link ? <br> 519 * {@value Constant#SEARCH_EXACT} {@link Constant#SEARCH_EXACT} <br> 520 * {@value Constant#SEARCH_LIKE} {@link Constant#SEARCH_LIKE} <br> 521 * {@value Constant#SEARCH_STARTING_LIKE} {@link Constant#SEARCH_STARTING_LIKE} <br> 522 * {@value Constant#SEARCH_ENDING_LIKE} {@link Constant#SEARCH_ENDING_LIKE} <br> 523 * @return all the B bean matching the template 524 * @throws RuntimeDaoException 525 */ 526 public B[] loadUsingTemplate(B bean, int startRow, int numRows, int searchType)throws RuntimeDaoException; 527 528 //19-2 529 /** 530 * Loads a list of B bean from a template one. 531 * 532 * @param bean the B bean template to look for 533 * @return all the B beans matching the template 534 * @throws RuntimeDaoException 535 */ 536 public List<B> loadUsingTemplateAsList(B bean)throws RuntimeDaoException; 537 538 //20-2 539 /** 540 * Loads a list of B bean from a template one, given the start row and number of rows. 541 * 542 * @param bean the B bean template to look for 543 * @param startRow the start row to be used (first row = 1, last row=-1) 544 * @param numRows the number of rows to be retrieved (all rows = a negative number) 545 * @return all the B bean matching the template 546 * @throws RuntimeDaoException 547 */ 548 public List<B> loadUsingTemplateAsList(B bean, int startRow, int numRows)throws RuntimeDaoException; 549 550 //20-3 551 /** 552 * Loads an array of B bean from a template one, given the start row and number of rows. 553 * 554 * @param bean the B bean template to look for 555 * @param startRow the start row to be used (first row = 1, last row=-1) 556 * @param numRows the number of rows to be retrieved (all rows = a negative number) 557 * @param searchType exact ? like ? starting like ? ending link? <br> 558 * {@value Constant#SEARCH_EXACT} {@link Constant#SEARCH_EXACT} <br> 559 * {@value Constant#SEARCH_LIKE} {@link Constant#SEARCH_LIKE} <br> 560 * {@value Constant#SEARCH_STARTING_LIKE} {@link Constant#SEARCH_STARTING_LIKE} <br> 561 * {@value Constant#SEARCH_ENDING_LIKE} {@link Constant#SEARCH_ENDING_LIKE} <br> 562 * @return all the B beans matching the template 563 * @throws RuntimeDaoException 564 */ 565 public List<B> loadUsingTemplateAsList(B bean, int startRow, int numRows, int searchType)throws RuntimeDaoException; 566 567 //_____________________________________________________________________ 568 // 569 // USING INDICES 570 //_____________________________________________________________________ 571 /** 572 * Retrieves a array of B bean using the index specified by keyIndex. 573 * @param indexName name of index 574 * @param indexValues key values of index 575 * @return B array 576 * @throws RuntimeDaoException 577 * @see #loadByIndexAsList(int ,Object ...) 578 */ 579 public B[] loadByIndex(String indexName,Object ...indexValues)throws RuntimeDaoException; 580 581 /** 582 * Retrieves a list of B bean using the index specified by indexName. 583 * @param indexName name of index<br> 584 * @param indexValues key values of index 585 * @return a list of B bean 586 * @throws RuntimeDaoException 587 */ 588 public List<B> loadByIndexAsList(String indexName,Object ...indexValues)throws RuntimeDaoException; 589 590 public B loadUniqueByIndex(String indexName,Object ...indexValues)throws RuntimeDaoException; 591 public B loadUniqueByIndexChecked(String indexName,Object ...indexValues)throws ObjectRetrievalException; 592 /** 593 * Deletes rows using key. 594 * @param indexName name of index 595 * @param indexValues key values of index 596 * @return the number of deleted objects 597 * @throws RuntimeDaoException 598 */ 599 public int deleteByIndex(String indexName,Object ...indexValues)throws RuntimeDaoException; 600 //_____________________________________________________________________ 601 // 602 // LISTENER 603 //_____________________________________________________________________ 604 605 //35 606 /** 607 * Registers a unique {@link TableListener} listener.<br> 608 * do nothing if {@code TableListener} instance exists 609 * @param listener 610 * @return 611 */ 612 public TableListener<B> registerListener(TableListener<B> listener); 613 614 //36 615 /** 616 * remove listener. 617 * @param listener 618 */ 619 public void unregisterListener(TableListener<B> listener); 620 621 //37 622 /** 623 * see also {@link TableListener.Event#fire(TableListener.ListenerContainer, Object)} 624 * @param event 625 * @param bean 626 * @throws RuntimeDaoException 627 */ 628 public void fire(TableListener.Event event, B bean) throws RuntimeDaoException; 629 630 //37-1 631 /** 632 * see also #fire(TableListener.Event, B) 633 * @param event 634 * @param bean 635 * @throws IllegalArgumentException invalid event id 636 * @throws RuntimeDaoException 637 */ 638 public void fire(int event, B bean) throws RuntimeDaoException; 639 //_____________________________________________________________________ 640 // 641 // SAVE 642 //_____________________________________________________________________ 643 //12 644 /** 645 * Saves the B bean into the database. 646 * 647 * @param bean the B bean to be saved 648 * @return the inserted or updated bean,or null if bean is null 649 * @throws RuntimeDaoException 650 */ 651 public B save(B bean)throws RuntimeDaoException; 652 653 //15 654 /** 655 * Saves an array of B bean into the database. 656 * 657 * @param beans the array of B bean to be saved 658 * @return always beans saved 659 * @throws RuntimeDaoException 660 */ 661 public B[] save(B[] beans)throws RuntimeDaoException; 662 663 //15-2 664 /** 665 * Saves a collection of B bean into the database. 666 * 667 * @param beans the B bean table to be saved 668 * @return alwarys beans saved 669 * @throws RuntimeDaoException 670 */ 671 public <C extends Collection<B>> C saveAsTransaction(C beans)throws RuntimeDaoException; 672 673 //15-3 674 /** 675 * Saves an array of B bean into the database as transaction. 676 * 677 * @param beans the B bean table to be saved 678 * @return alwarys beans saved 679 * @see #save(BaseBean[]) 680 * @throws RuntimeDaoException 681 */ 682 public B[] saveAsTransaction(B[] beans)throws RuntimeDaoException; 683 684 //15-4 685 /** 686 * Saves a collection of B bean into the database as transaction. 687 * 688 * @param beans the B bean table to be saved 689 * @return alwarys beans saved 690 * @throws RuntimeDaoException 691 */ 692 public <C extends Collection<B>> C save(C beans)throws RuntimeDaoException; 693 694 //3.9 SYNC SAVE 695 /** 696 * Save the B bean and referenced beans and imported beans into the database. 697 * 698 * @param bean the B bean to be saved 699 * @param referenceBeans referenced beans beans<br> 700 * @param importedBeans imported beans <br> 701 * @return the inserted or updated B bean 702 * @throws RuntimeDaoException 703 */ 704 public B save(B bean,Map<String, BaseBean> referenceBeans,Map<String, Collection<BaseBean>> importedBeans)throws RuntimeDaoException; 705 706 //3.11 SYNC SAVE 707 /** 708 * Transaction version for sync save 709 * @see #save(BaseBean ,Map,Map) 710 * @param bean the B bean to be saved 711 * @param referenceBeans referenced beans beans<br> 712 * @param importedBeans imported beans <br> 713 * @return the inserted or updated B bean 714 * @throws RuntimeDaoException 715 */ 716 public B saveAsTransaction(B bean,Map<String, BaseBean> referenceBeans,Map<String, Collection<BaseBean>> importedBeans)throws RuntimeDaoException; 717 718 /** 719 * Load column from table. 720 * @param column column name or java file name of B 721 * @param distinct select distinct values 722 * @param where the sql 'where' clause 723 * @param startRow the start row to be used (first row = 1, last row = -1) 724 * @param numRows the number of rows to be retrieved (all rows = a negative number) 725 * @return an list of column 726 * @throws RuntimeDaoException 727 */ 728 public <T>List<T> loadColumnAsList(String column,boolean distinct,String where,int startRow,int numRows)throws RuntimeDaoException; 729 730 /** 731 * Retrieves the T object referenced by fkName.<br> 732 * @param <T> 733 * @param bean the B object to use 734 * @param fkName foreign key name.<br> 735 * @return the associated T bean or {@code null} if {@code bean} is {@code null} 736 * @throws RuntimeDaoException 737 */ 738 public <T extends BaseBean> T getReferencedBean(B bean,String fkName)throws RuntimeDaoException; 739 740 /** 741 * Associates the B object to the T object by fkName field.<br> 742 * @param <T> see also {@link #getReferencedBean(BaseBean, String)} 743 * @param bean the B object to use 744 * @param beanToSet the T object to associate to the B bean 745 * @param fkName see also {@link #getReferencedBean(BaseBean, String)} 746 * @return always beanToSet saved 747 * @throws RuntimeDaoException 748 */ 749 public <T extends BaseBean> T setReferencedBean(B bean,T beanToSet,String fkName)throws RuntimeDaoException; 750 751 /** 752 * Retrieves imported T objects by fkIndex.<br> 753 * @param <T> 754 * @param bean the B object to use 755 * @param fkName foreign key name.<br> 756 * @return the associated T beans or {@code null} if {@code bean} is {@code null} 757 * @throws RuntimeDaoException 758 */ 759 public <T extends BaseBean> T[] getImportedBeans(B bean,String fkName)throws RuntimeDaoException; 760 761 /** 762 * Retrieves imported T objects by ikIndex.<br> 763 * @param <T> see also {@link #getImportedBeans(BaseBean, String)} 764 * @param bean the B object to use 765 * @param fkname foreign key name.see also {@link #getImportedBeans(BaseBean, String)} 766 * @return the associated T beans or {@code null} if {@code bean} is {@code null} 767 * @throws RuntimeDaoException 768 */ 769 public <T extends BaseBean> List<T> getImportedBeansAsList(B bean,String fkname)throws RuntimeDaoException; 770 771 772 /** 773 * Set the importedBeans associates to the bean by {@code ikIndex}<br> 774 * 775 * @param <T> see also {@link #getImportedBeans(BaseBean, String)} 776 * @param bean the bean object to use 777 * @param importedBeans the T object to associate to bean 778 * @param fkName foreign key name.see also {@link #getImportedBeans(BaseBean, String)} 779 * @return importedBeans always 780 * @throws RuntimeDaoException 781 */ 782 public <T extends BaseBean> T[] setImportedBeans(B bean,T[] importedBeans,String fkName)throws RuntimeDaoException; 783 784 /** 785 * Set the importedBeans associates to the bean by fkIndex<br> 786 * 787 * @param <T> see also {@link #getImportedBeans(BaseBean, String)} 788 * @param bean the bean object to use 789 * @param importedBeans the T object to associate to bean 790 * @param fkName foreign key name. see also {@link #getImportedBeans(BaseBean, String)} 791 * @return importedBeans always 792 * @throws RuntimeDaoException 793 */ 794 public <T extends BaseBean,C extends Collection<T>> C setImportedBeans(B bean,C importedBeans,String fkName)throws RuntimeDaoException; 795 796 /** 797 * delete all imported beans by fkName 798 * @param bean 799 * @param fkName foreign key name 800 * @return deleted row count 801 */ 802 public int deleteImportedBeans(B bean,String fkName)throws RuntimeDaoException; 803}