001package org.apache.fulcrum.security.torque.om; 002 003import java.sql.Connection; 004import java.util.ArrayList; 005import java.util.Collection; 006import java.util.List; 007import java.util.Map; 008import java.util.Objects; 009import java.util.stream.Collectors; 010 011import org.apache.torque.NoRowsException; 012import org.apache.torque.TooManyRowsException; 013import org.apache.torque.TorqueException; 014import org.apache.torque.criteria.Criteria; 015import org.apache.torque.criteria.Criterion; 016import org.apache.torque.om.mapper.RecordMapper; 017import org.apache.torque.om.mapper.CompositeMapper; 018import org.apache.torque.om.ObjectKey; 019import org.apache.torque.om.SimpleKey; 020import org.apache.torque.map.TableMap; 021import org.apache.torque.util.TorqueConnection; 022import org.apache.torque.util.Transaction; 023import org.apache.torque.util.ColumnValues; 024import org.apache.torque.util.JdbcTypedValue; 025 026 027 028/** 029 * The skeleton for this class was autogenerated by Torque on: 030 * 031 * [Thu Nov 04 13:34:23 CET 2021] 032 * 033 * You should not use this class directly. It should not even be 034 * extended; all references should be to TorqueDynamicUserGroupPeer 035 */ 036 037@SuppressWarnings("unused") 038public abstract class BaseTorqueDynamicUserGroupPeerImpl 039 extends org.apache.torque.util.AbstractPeerImpl<TorqueDynamicUserGroup> 040{ 041 /** Serial version */ 042 private static final long serialVersionUID = 1636029263279L; 043 044 045 046 /** 047 * Constructor. 048 * The recordMapper, tableMap and databaseName fields are correctly 049 * initialized. 050 */ 051 public BaseTorqueDynamicUserGroupPeerImpl() 052 { 053 this(new TorqueDynamicUserGroupRecordMapper(), 054 TorqueDynamicUserGroupPeer.TABLE, 055 TorqueDynamicUserGroupPeer.DATABASE_NAME); 056 } 057 058 /** 059 * Constructor providing the objects to be injected as parameters. 060 * 061 * @param recordMapper a record mapper to map JDBC result sets to objects 062 * @param tableMap the default table map 063 * @param databaseName the name of the database 064 */ 065 public BaseTorqueDynamicUserGroupPeerImpl( 066 RecordMapper<TorqueDynamicUserGroup> recordMapper, 067 TableMap tableMap, 068 String databaseName) 069 { 070 super(recordMapper, tableMap, databaseName); 071 } 072 073 074 /** 075 * Returns a new instance of the Data object class 076 */ 077 public TorqueDynamicUserGroup getDbObjectInstance() 078 { 079 return new TorqueDynamicUserGroup(); 080 } 081 082 083 /** 084 * Method to do updates. This method is to be used during a transaction, 085 * otherwise use the doUpdate(Criteria) method. 086 * 087 * @param columnValues the values to update plus the primary key 088 * identifying the row to update. 089 * @param con the connection to use, not null. 090 * 091 * @return the number of affected rows. 092 * 093 * @throws TorqueException Any exceptions caught during processing will be 094 * rethrown wrapped into a TorqueException. 095 */ 096 public int doUpdate(ColumnValues columnValues, Connection con) 097 throws TorqueException 098 { 099 Criteria selectCriteria = new Criteria(getDatabaseName()); 100 correctBooleans(columnValues); 101 102 { 103 JdbcTypedValue pkValue 104 = columnValues.remove(TorqueDynamicUserGroupPeer.USER_ID); 105 if (pkValue == null) 106 { 107 throw new TorqueException( 108 "The value for the primary key column " 109 + "TorqueDynamicUserGroupPeer.USER_ID" 110 + " must be set"); 111 } 112 if (pkValue.getSqlExpression() == null) 113 { 114 selectCriteria.where( 115 TorqueDynamicUserGroupPeer.USER_ID, 116 pkValue.getValue()); 117 } 118 else 119 { 120 selectCriteria.where( 121 TorqueDynamicUserGroupPeer.USER_ID, 122 pkValue.getSqlExpression()); 123 } 124 } 125 { 126 JdbcTypedValue pkValue 127 = columnValues.remove(TorqueDynamicUserGroupPeer.GROUP_ID); 128 if (pkValue == null) 129 { 130 throw new TorqueException( 131 "The value for the primary key column " 132 + "TorqueDynamicUserGroupPeer.GROUP_ID" 133 + " must be set"); 134 } 135 if (pkValue.getSqlExpression() == null) 136 { 137 selectCriteria.where( 138 TorqueDynamicUserGroupPeer.GROUP_ID, 139 pkValue.getValue()); 140 } 141 else 142 { 143 selectCriteria.where( 144 TorqueDynamicUserGroupPeer.GROUP_ID, 145 pkValue.getSqlExpression()); 146 } 147 } 148 149 150 int rowCount = doUpdate(selectCriteria, columnValues, con); 151 return rowCount; 152 } 153 154 /** 155 * Deletes a data object, i.e. a row in a table, in the database. 156 * 157 * @param obj the data object to delete in the database, not null. 158 * 159 * @return the number of deleted rows. 160 * 161 * @throws TorqueException Any exceptions caught during processing will be 162 * rethrown wrapped into a TorqueException. 163 */ 164 public int doDelete(TorqueDynamicUserGroup obj) throws TorqueException 165 { 166 int result = doDelete(buildCriteria(obj.getPrimaryKey())); 167 obj.setDeleted(true); 168 return result; 169 } 170 171 /** 172 * Deletes a data object, i.e. a row in a table, in the database. 173 * This method is to be used during a transaction, otherwise use the 174 * doDelete(TorqueDynamicUserGroup) method. 175 * 176 * @param obj the data object to delete in the database, not null. 177 * @param con the connection to use, not null. 178 * 179 * @return the number of deleted rows. 180 * 181 * @throws TorqueException Any exceptions caught during processing will be 182 * rethrown wrapped into a TorqueException. 183 */ 184 public int doDelete(TorqueDynamicUserGroup obj, Connection con) 185 throws TorqueException 186 { 187 int result = doDelete(buildCriteria(obj.getPrimaryKey()), con); 188 obj.setDeleted(true); 189 return result; 190 } 191 192 /** 193 * Deletes data objects, i.e. rows in a table, in the database. 194 * 195 * @param objects the data object to delete in the database, not null, 196 * may not contain null. 197 * 198 * @return the number of deleted rows. 199 * 200 * @throws TorqueException Any exceptions caught during processing will be 201 * rethrown wrapped into a TorqueException. 202 */ 203 public int doDelete(Collection<TorqueDynamicUserGroup> objects) 204 throws TorqueException 205 { 206 int result = doDelete(buildPkCriteria(objects)); 207 objects.forEach(object -> object.setDeleted(true)); 208 return result; 209 } 210 211 /** 212 * Deletes data objects, i.e. rows in a table, in the database. 213 * This method uses the passed connection to delete the rows; 214 * if a transaction is open in the connection, the deletion happens inside 215 * this transaction. 216 * 217 * @param objects the data objects to delete in the database, not null, 218 * may not contain null. 219 * @param con the connection to use for deleting, not null. 220 * 221 * @return the number of deleted rows. 222 * 223 * @throws TorqueException Any exceptions caught during processing will be 224 * rethrown wrapped into a TorqueException. 225 */ 226 public int doDelete( 227 Collection<TorqueDynamicUserGroup> objects, 228 Connection con) 229 throws TorqueException 230 { 231 int result = doDelete(buildPkCriteria(objects), con); 232 objects.forEach(object -> object.setDeleted(true)); 233 return result; 234 } 235 236 /** 237 * Build a Criteria object which selects all objects which have a given 238 * primary key. 239 * 240 * @param pk the primary key value to build the criteria from, not null. 241 */ 242 public Criteria buildCriteria(ObjectKey<?> pk) 243 { 244 Criteria criteria = new Criteria(); 245 SimpleKey<?>[] keys = (SimpleKey[])pk.getValue(); 246 criteria.and(TorqueDynamicUserGroupPeer.USER_ID, keys[0]); 247 criteria.and(TorqueDynamicUserGroupPeer.GROUP_ID, keys[1]); 248 return criteria; 249 } 250 251 /** 252 * Build a Criteria object which selects all objects which primary keys 253 * are contained in the passed collection. 254 * 255 * @param pks the primary key values to build the criteria from, not null, 256 * may not contain null. 257 */ 258 public Criteria buildCriteria(Collection<ObjectKey<?>> pks) 259 { 260 Criteria criteria = new Criteria(); 261 for (ObjectKey<?> pk : pks) 262 { 263 SimpleKey<?>[] keys = (SimpleKey[])pk.getValue(); 264 Criterion c0 = new Criterion( 265 TorqueDynamicUserGroupPeer.USER_ID, keys[0], Criteria.EQUAL); 266 Criterion c1 = new Criterion( 267 TorqueDynamicUserGroupPeer.GROUP_ID, keys[1], Criteria.EQUAL); 268 c0.and(c1); 269 criteria.or(c0); 270 } 271 return criteria; 272 } 273 274 275 /** 276 * Build a Criteria object which selects all passed objects using their 277 * primary key. Objects which do not yet have a primary key are ignored. 278 * 279 * @param objects the objects to build the criteria from, not null, 280 * may not contain null. 281 */ 282 public Criteria buildPkCriteria( 283 Collection<TorqueDynamicUserGroup> objects) 284 { 285 return buildCriteria(objects.stream() 286 .map(object -> object.getPrimaryKey()) 287 .collect(Collectors.toList())); 288 } 289 290 /** 291 * Build a Criteria object from the data object for this peer. 292 * 293 * @param obj the object to build the criteria from, not null. 294 */ 295 public Criteria buildCriteria(TorqueDynamicUserGroup obj) 296 { 297 Criteria criteria = new Criteria(getDatabaseName()); 298 criteria.and(TorqueDynamicUserGroupPeer.USER_ID, obj.getUserId()); 299 criteria.and(TorqueDynamicUserGroupPeer.GROUP_ID, obj.getGroupId()); 300 return criteria; 301 } 302 303 /** 304 * Build a Criteria object from the data object for this peer, 305 * skipping all binary columns. 306 * 307 * @param obj the object to build the criteria from, not null. 308 */ 309 public Criteria buildSelectCriteria(TorqueDynamicUserGroup obj) 310 { 311 Criteria criteria = new Criteria(getDatabaseName()); 312 criteria.and(TorqueDynamicUserGroupPeer.USER_ID, obj.getUserId()); 313 criteria.and(TorqueDynamicUserGroupPeer.GROUP_ID, obj.getGroupId()); 314 return criteria; 315 } 316 317 /** 318 * Returns the contents of the object as ColumnValues object. 319 * Primary key columns which are generated on insertion are not 320 * added to the returned object if they still have their initial 321 * value. Also, columns which have the useDatabaseDefaultValue 322 * flag set to true are also not added to the returned object 323 * if they still have their initial value. 324 * 325 * @throws TorqueException if the table map cannot be retrieved 326 * (should not happen). 327 */ 328 public ColumnValues buildColumnValues(TorqueDynamicUserGroup torqueDynamicUserGroup) 329 throws TorqueException 330 { 331 ColumnValues columnValues = new ColumnValues(); 332 columnValues.put( 333 TorqueDynamicUserGroupPeer.USER_ID, 334 new JdbcTypedValue( 335 torqueDynamicUserGroup.getUserId(), 336 4)); 337 columnValues.put( 338 TorqueDynamicUserGroupPeer.GROUP_ID, 339 new JdbcTypedValue( 340 torqueDynamicUserGroup.getGroupId(), 341 4)); 342 return columnValues; 343 } 344 345 /** 346 * retrieve object using using pk values. 347 * 348 * @param userId Integer 349 * @param groupId Integer 350 */ 351 public TorqueDynamicUserGroup retrieveByPK( 352 Integer userId, 353 Integer groupId) 354 throws TorqueException 355 { 356 try (TorqueConnection connection = Transaction.begin(getDatabaseName())) 357 { 358 TorqueDynamicUserGroup result = retrieveByPK( 359 userId, 360 groupId, 361 connection); 362 Transaction.commit(connection); 363 return result; 364 } 365 } 366 367 /** 368 * retrieve object using using pk values. 369 * 370 * @param userId Integer 371 * @param groupId Integer 372 * @param con Connection 373 */ 374 public TorqueDynamicUserGroup retrieveByPK( 375 Integer userId, 376 Integer groupId, 377 Connection con) throws TorqueException 378 { 379 380 Criteria criteria = new Criteria(); 381 criteria.and(TorqueDynamicUserGroupPeer.USER_ID, userId); 382 criteria.and(TorqueDynamicUserGroupPeer.GROUP_ID, groupId); 383 TorqueDynamicUserGroup v = doSelectSingleRecord(criteria, con); 384 if (v == null) 385 { 386 throw new NoRowsException("Failed to select a row."); 387 } 388 389 return v; 390 } 391 392 /** 393 * Retrieve a single object by pk 394 * 395 * @param pk the primary key 396 * @throws TorqueException Any exceptions caught during processing will be 397 * rethrown wrapped into a TorqueException. 398 * @throws NoRowsException Primary key was not found in database. 399 * @throws TooManyRowsException Primary key was not found in database. 400 */ 401 public TorqueDynamicUserGroup retrieveByPK(ObjectKey<?> pk) 402 throws TorqueException, NoRowsException, TooManyRowsException 403 { 404 try (TorqueConnection connection = Transaction.begin(getDatabaseName())) 405 { 406 TorqueDynamicUserGroup result = retrieveByPK(pk, connection); 407 Transaction.commit(connection); 408 return result; 409 } 410 } 411 412 /** 413 * Retrieve a single object by pk 414 * 415 * @param pk the primary key 416 * @param con the connection to use 417 * @throws TorqueException Any exceptions caught during processing will be 418 * rethrown wrapped into a TorqueException. 419 * @throws NoRowsException Primary key was not found in database. 420 * @throws TooManyRowsException Primary key was not found in database. 421 */ 422 public TorqueDynamicUserGroup retrieveByPK(ObjectKey<?> pk, Connection con) 423 throws TorqueException, NoRowsException, TooManyRowsException 424 { 425 Criteria criteria = buildCriteria(pk); 426 TorqueDynamicUserGroup v = doSelectSingleRecord(criteria, con); 427 if (v == null) 428 { 429 throw new NoRowsException("Failed to select a row."); 430 } 431 432 return v; 433 } 434 435 436 /** 437 * Retrieve multiple objects by pk. 438 * 439 * @param pks List of primary keys. 440 * Entries in pks which do not match entries in the database are ignored. 441 * 442 * @return the list of matching objects, not null. 443 * 444 * @throws TorqueException Any exceptions caught during processing will be 445 * rethrown wrapped into a TorqueException. 446 */ 447 public List<TorqueDynamicUserGroup> retrieveByObjectKeys(Collection<ObjectKey<?>> pks) 448 throws TorqueException 449 { 450 try (TorqueConnection connection = Transaction.begin(getDatabaseName())) 451 { 452 List<TorqueDynamicUserGroup> result = retrieveByObjectKeys(pks, connection); 453 Transaction.commit(connection); 454 return result; 455 } 456 } 457 458 /** 459 * Retrieve multiple objects by pk. 460 * 461 * @param pks List of primary keys. 462 * Entries in pks which do not match entries in the database are ignored. 463 * @param dbcon the connection to use 464 * 465 * @return the list of matching objects, not null. 466 * 467 * @throws TorqueException Any exceptions caught during processing will be 468 * rethrown wrapped into a TorqueException. 469 */ 470 public List<TorqueDynamicUserGroup> retrieveByObjectKeys( 471 Collection<ObjectKey<?>> pks, 472 Connection dbcon) 473 throws TorqueException 474 { 475 if (pks == null || pks.size() == 0) 476 { 477 return new ArrayList<TorqueDynamicUserGroup>(); 478 } 479 Criteria criteria = buildCriteria(pks); 480 List<TorqueDynamicUserGroup> result = doSelect(criteria, dbcon); 481 return result; 482 } 483 484 485 /** 486 * Selects a collection of dbObjectClassName objects pre-filled with their 487 * TorqueDynamicUser objects. 488 * 489 * @throws TorqueException Any exceptions caught during processing will be 490 * rethrown wrapped into a TorqueException. 491 */ 492 public List<TorqueDynamicUserGroup> doSelectJoinTorqueDynamicUser(Criteria criteria) 493 throws TorqueException 494 { 495 try (TorqueConnection connection = Transaction.begin(getDatabaseName())) 496 { 497 List<TorqueDynamicUserGroup> result 498 = TorqueDynamicUserGroupPeer.doSelectJoinTorqueDynamicUser(criteria, connection); 499 Transaction.commit(connection); 500 return result; 501 } 502 } 503 504 /** 505 * Selects a collection of TorqueDynamicUserGroup objects pre-filled with their 506 * TorqueDynamicUser objects. 507 * 508 * @throws TorqueException Any exceptions caught during processing will be 509 * rethrown wrapped into a TorqueException. 510 */ 511 public List<TorqueDynamicUserGroup> doSelectJoinTorqueDynamicUser( 512 Criteria criteria, Connection conn) 513 throws TorqueException 514 { 515 setDbName(criteria); 516 517 addSelectColumns(criteria); 518 org.apache.fulcrum.security.torque.om.TorqueDynamicUserPeer.addSelectColumns(criteria); 519 520 CompositeMapper compositeMapper = new CompositeMapper(); 521 compositeMapper.addMapper( 522 new TorqueDynamicUserGroupRecordMapper(), 523 0); 524 compositeMapper.addMapper( 525 new TorqueDynamicUserRecordMapper(), 526 TorqueDynamicUserGroupPeer.numColumns); 527 criteria.addJoin(TorqueDynamicUserGroupPeer.USER_ID, 528 org.apache.fulcrum.security.torque.om.TorqueDynamicUserPeer.USER_ID); 529 530 correctBooleans(criteria); 531 532 List<TorqueDynamicUserGroup> result = new ArrayList<TorqueDynamicUserGroup>(); 533 List<List<Object>> rawResult = doSelect( 534 criteria, compositeMapper, conn); 535 for (List<Object> rawResultRow : rawResult) 536 { 537 TorqueDynamicUserGroup obj1 = (TorqueDynamicUserGroup) rawResultRow.get(0); 538 TorqueDynamicUser obj2 = (TorqueDynamicUser) rawResultRow.get(1); 539 540 boolean newObject = true; 541 for (int j = 0; j < result.size(); j++) 542 { 543 TorqueDynamicUserGroup temp_obj1 = result.get(j); 544 org.apache.fulcrum.security.torque.om.TorqueDynamicUser temp_obj2 = temp_obj1.getTorqueDynamicUser(); 545 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 546 { 547 newObject = false; 548 temp_obj2.addTorqueDynamicUserGroup(obj1); 549 break; 550 } 551 } 552 if (newObject) 553 { 554 obj2.initTorqueDynamicUserGroups(); 555 obj2.addTorqueDynamicUserGroup(obj1); 556 } 557 result.add(obj1); 558 } 559 return result; 560 } 561 /** 562 * Selects a collection of dbObjectClassName objects pre-filled with their 563 * TorqueDynamicGroup objects. 564 * 565 * @throws TorqueException Any exceptions caught during processing will be 566 * rethrown wrapped into a TorqueException. 567 */ 568 public List<TorqueDynamicUserGroup> doSelectJoinTorqueDynamicGroup(Criteria criteria) 569 throws TorqueException 570 { 571 try (TorqueConnection connection = Transaction.begin(getDatabaseName())) 572 { 573 List<TorqueDynamicUserGroup> result 574 = TorqueDynamicUserGroupPeer.doSelectJoinTorqueDynamicGroup(criteria, connection); 575 Transaction.commit(connection); 576 return result; 577 } 578 } 579 580 /** 581 * Selects a collection of TorqueDynamicUserGroup objects pre-filled with their 582 * TorqueDynamicGroup objects. 583 * 584 * @throws TorqueException Any exceptions caught during processing will be 585 * rethrown wrapped into a TorqueException. 586 */ 587 public List<TorqueDynamicUserGroup> doSelectJoinTorqueDynamicGroup( 588 Criteria criteria, Connection conn) 589 throws TorqueException 590 { 591 setDbName(criteria); 592 593 addSelectColumns(criteria); 594 org.apache.fulcrum.security.torque.om.TorqueDynamicGroupPeer.addSelectColumns(criteria); 595 596 CompositeMapper compositeMapper = new CompositeMapper(); 597 compositeMapper.addMapper( 598 new TorqueDynamicUserGroupRecordMapper(), 599 0); 600 compositeMapper.addMapper( 601 new TorqueDynamicGroupRecordMapper(), 602 TorqueDynamicUserGroupPeer.numColumns); 603 criteria.addJoin(TorqueDynamicUserGroupPeer.GROUP_ID, 604 org.apache.fulcrum.security.torque.om.TorqueDynamicGroupPeer.GROUP_ID); 605 606 correctBooleans(criteria); 607 608 List<TorqueDynamicUserGroup> result = new ArrayList<TorqueDynamicUserGroup>(); 609 List<List<Object>> rawResult = doSelect( 610 criteria, compositeMapper, conn); 611 for (List<Object> rawResultRow : rawResult) 612 { 613 TorqueDynamicUserGroup obj1 = (TorqueDynamicUserGroup) rawResultRow.get(0); 614 TorqueDynamicGroup obj2 = (TorqueDynamicGroup) rawResultRow.get(1); 615 616 boolean newObject = true; 617 for (int j = 0; j < result.size(); j++) 618 { 619 TorqueDynamicUserGroup temp_obj1 = result.get(j); 620 org.apache.fulcrum.security.torque.om.TorqueDynamicGroup temp_obj2 = temp_obj1.getTorqueDynamicGroup(); 621 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 622 { 623 newObject = false; 624 temp_obj2.addTorqueDynamicUserGroup(obj1); 625 break; 626 } 627 } 628 if (newObject) 629 { 630 obj2.initTorqueDynamicUserGroups(); 631 obj2.addTorqueDynamicUserGroup(obj1); 632 } 633 result.add(obj1); 634 } 635 return result; 636 } 637 638 639 640 641}