001package org.apache.turbine.services.schedule; 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.om.mapper.RecordMapper; 016import org.apache.torque.om.ObjectKey; 017import org.apache.torque.om.SimpleKey; 018import org.apache.torque.map.TableMap; 019import org.apache.torque.util.TorqueConnection; 020import org.apache.torque.util.Transaction; 021import org.apache.torque.util.ColumnValues; 022import org.apache.torque.util.JdbcTypedValue; 023 024 025 026/** 027 * The skeleton for this class was autogenerated by Torque on: 028 * 029 * [Wed Sep 22 14:43:21 CEST 2021] 030 * 031 * You should not use this class directly. It should not even be 032 * extended; all references should be to JobEntryTorquePeer 033 */ 034 035@SuppressWarnings("unused") 036public abstract class BaseJobEntryTorquePeerImpl 037 extends org.apache.torque.util.AbstractPeerImpl<JobEntryTorque> 038{ 039 /** Serial version */ 040 private static final long serialVersionUID = 1632314601596L; 041 042 043 044 /** 045 * Constructor. 046 * The recordMapper, tableMap and databaseName fields are correctly 047 * initialized. 048 */ 049 public BaseJobEntryTorquePeerImpl() 050 { 051 this(new JobEntryTorqueRecordMapper(), 052 JobEntryTorquePeer.TABLE, 053 JobEntryTorquePeer.DATABASE_NAME); 054 } 055 056 /** 057 * Constructor providing the objects to be injected as parameters. 058 * 059 * @param recordMapper a record mapper to map JDBC result sets to objects 060 * @param tableMap the default table map 061 * @param databaseName the name of the database 062 */ 063 public BaseJobEntryTorquePeerImpl( 064 RecordMapper<JobEntryTorque> recordMapper, 065 TableMap tableMap, 066 String databaseName) 067 { 068 super(recordMapper, tableMap, databaseName); 069 } 070 071 072 /** 073 * Returns a new instance of the Data object class 074 */ 075 public JobEntryTorque getDbObjectInstance() 076 { 077 return new JobEntryTorque(); 078 } 079 080 081 /** 082 * Method to do updates. This method is to be used during a transaction, 083 * otherwise use the doUpdate(Criteria) method. 084 * 085 * @param columnValues the values to update plus the primary key 086 * identifying the row to update. 087 * @param con the connection to use, not null. 088 * 089 * @return the number of affected rows. 090 * 091 * @throws TorqueException Any exceptions caught during processing will be 092 * rethrown wrapped into a TorqueException. 093 */ 094 public int doUpdate(ColumnValues columnValues, Connection con) 095 throws TorqueException 096 { 097 Criteria selectCriteria = new Criteria(getDatabaseName()); 098 correctBooleans(columnValues); 099 100 { 101 JdbcTypedValue pkValue 102 = columnValues.remove(JobEntryTorquePeer.JOB_ID); 103 if (pkValue == null) 104 { 105 throw new TorqueException( 106 "The value for the primary key column " 107 + "JobEntryTorquePeer.JOB_ID" 108 + " must be set"); 109 } 110 if (pkValue.getSqlExpression() == null) 111 { 112 selectCriteria.where( 113 JobEntryTorquePeer.JOB_ID, 114 pkValue.getValue()); 115 } 116 else 117 { 118 selectCriteria.where( 119 JobEntryTorquePeer.JOB_ID, 120 pkValue.getSqlExpression()); 121 } 122 } 123 124 125 int rowCount = doUpdate(selectCriteria, columnValues, con); 126 return rowCount; 127 } 128 129 /** 130 * Deletes a data object, i.e. a row in a table, in the database. 131 * 132 * @param obj the data object to delete in the database, not null. 133 * 134 * @return the number of deleted rows. 135 * 136 * @throws TorqueException Any exceptions caught during processing will be 137 * rethrown wrapped into a TorqueException. 138 */ 139 public int doDelete(JobEntryTorque obj) throws TorqueException 140 { 141 int result = doDelete(buildCriteria(obj.getPrimaryKey())); 142 obj.setDeleted(true); 143 return result; 144 } 145 146 /** 147 * Deletes a data object, i.e. a row in a table, in the database. 148 * This method is to be used during a transaction, otherwise use the 149 * doDelete(JobEntryTorque) method. 150 * 151 * @param obj the data object to delete in the database, not null. 152 * @param con the connection to use, not null. 153 * 154 * @return the number of deleted rows. 155 * 156 * @throws TorqueException Any exceptions caught during processing will be 157 * rethrown wrapped into a TorqueException. 158 */ 159 public int doDelete(JobEntryTorque obj, Connection con) 160 throws TorqueException 161 { 162 int result = doDelete(buildCriteria(obj.getPrimaryKey()), con); 163 obj.setDeleted(true); 164 return result; 165 } 166 167 /** 168 * Deletes data objects, i.e. rows in a table, in the database. 169 * 170 * @param objects the data object to delete in the database, not null, 171 * may not contain null. 172 * 173 * @return the number of deleted rows. 174 * 175 * @throws TorqueException Any exceptions caught during processing will be 176 * rethrown wrapped into a TorqueException. 177 */ 178 public int doDelete(Collection<JobEntryTorque> objects) 179 throws TorqueException 180 { 181 int result = doDelete(buildPkCriteria(objects)); 182 objects.forEach(object -> object.setDeleted(true)); 183 return result; 184 } 185 186 /** 187 * Deletes data objects, i.e. rows in a table, in the database. 188 * This method uses the passed connection to delete the rows; 189 * if a transaction is open in the connection, the deletion happens inside 190 * this transaction. 191 * 192 * @param objects the data objects to delete in the database, not null, 193 * may not contain null. 194 * @param con the connection to use for deleting, not null. 195 * 196 * @return the number of deleted rows. 197 * 198 * @throws TorqueException Any exceptions caught during processing will be 199 * rethrown wrapped into a TorqueException. 200 */ 201 public int doDelete( 202 Collection<JobEntryTorque> objects, 203 Connection con) 204 throws TorqueException 205 { 206 int result = doDelete(buildPkCriteria(objects), con); 207 objects.forEach(object -> object.setDeleted(true)); 208 return result; 209 } 210 211 /** 212 * Build a Criteria object which selects all objects which have a given 213 * primary key. 214 * 215 * @param pk the primary key value to build the criteria from, not null. 216 */ 217 public Criteria buildCriteria(ObjectKey<?> pk) 218 { 219 Criteria criteria = new Criteria(); 220 criteria.and(JobEntryTorquePeer.JOB_ID, pk); 221 return criteria; 222 } 223 224 /** 225 * Build a Criteria object which selects all objects which primary keys 226 * are contained in the passed collection. 227 * 228 * @param pks the primary key values to build the criteria from, not null, 229 * may not contain null. 230 */ 231 public Criteria buildCriteria(Collection<ObjectKey<?>> pks) 232 { 233 Criteria criteria = new Criteria(); 234 criteria.andIn(JobEntryTorquePeer.JOB_ID, pks); 235 return criteria; 236 } 237 238 239 /** 240 * Build a Criteria object which selects all passed objects using their 241 * primary key. Objects which do not yet have a primary key are ignored. 242 * 243 * @param objects the objects to build the criteria from, not null, 244 * may not contain null. 245 */ 246 public Criteria buildPkCriteria( 247 Collection<JobEntryTorque> objects) 248 { 249 return buildCriteria(objects.stream() 250 .map(object -> object.getPrimaryKey()) 251 .collect(Collectors.toList())); 252 } 253 254 /** 255 * Build a Criteria object from the data object for this peer. 256 * The primary key columns are only added if the object is not new. 257 * 258 * @param obj the object to build the criteria from, not null. 259 */ 260 public Criteria buildCriteria(JobEntryTorque obj) 261 { 262 Criteria criteria = new Criteria(getDatabaseName()); 263 if (!obj.isNew()) 264 { 265 criteria.and(JobEntryTorquePeer.JOB_ID, obj.getJobId()); 266 } 267 criteria.and(JobEntryTorquePeer.SECOND, obj.getSecond()); 268 criteria.and(JobEntryTorquePeer.MINUTE, obj.getMinute()); 269 criteria.and(JobEntryTorquePeer.HOUR, obj.getHour()); 270 criteria.and(JobEntryTorquePeer.WEEK_DAY, obj.getWeekDay()); 271 criteria.and(JobEntryTorquePeer.DAY_OF_MONTH, obj.getDayOfMonth()); 272 criteria.and(JobEntryTorquePeer.TASK, obj.getTask()); 273 criteria.and(JobEntryTorquePeer.EMAIL, obj.getEmail()); 274 criteria.and(JobEntryTorquePeer.PROPERTY, obj.getProperty()); 275 return criteria; 276 } 277 278 /** 279 * Build a Criteria object from the data object for this peer, 280 * skipping all binary columns. 281 * 282 * @param obj the object to build the criteria from, not null. 283 */ 284 public Criteria buildSelectCriteria(JobEntryTorque obj) 285 { 286 Criteria criteria = new Criteria(getDatabaseName()); 287 if (!obj.isNew()) 288 { 289 criteria.and(JobEntryTorquePeer.JOB_ID, obj.getJobId()); 290 } 291 criteria.and(JobEntryTorquePeer.SECOND, obj.getSecond()); 292 criteria.and(JobEntryTorquePeer.MINUTE, obj.getMinute()); 293 criteria.and(JobEntryTorquePeer.HOUR, obj.getHour()); 294 criteria.and(JobEntryTorquePeer.WEEK_DAY, obj.getWeekDay()); 295 criteria.and(JobEntryTorquePeer.DAY_OF_MONTH, obj.getDayOfMonth()); 296 criteria.and(JobEntryTorquePeer.TASK, obj.getTask()); 297 criteria.and(JobEntryTorquePeer.EMAIL, obj.getEmail()); 298 return criteria; 299 } 300 301 /** 302 * Returns the contents of the object as ColumnValues object. 303 * Primary key columns which are generated on insertion are not 304 * added to the returned object if they still have their initial 305 * value. Also, columns which have the useDatabaseDefaultValue 306 * flag set to true are also not added to the returned object 307 * if they still have their initial value. 308 * 309 * @throws TorqueException if the table map cannot be retrieved 310 * (should not happen). 311 */ 312 public ColumnValues buildColumnValues(JobEntryTorque jobEntryTorque) 313 throws TorqueException 314 { 315 ColumnValues columnValues = new ColumnValues(); 316 if (!jobEntryTorque.isNew() 317 || jobEntryTorque.getJobId() != 0) 318 { 319 columnValues.put( 320 JobEntryTorquePeer.JOB_ID, 321 new JdbcTypedValue( 322 jobEntryTorque.getJobId(), 323 4)); 324 } 325 columnValues.put( 326 JobEntryTorquePeer.SECOND, 327 new JdbcTypedValue( 328 jobEntryTorque.getSecond(), 329 4)); 330 columnValues.put( 331 JobEntryTorquePeer.MINUTE, 332 new JdbcTypedValue( 333 jobEntryTorque.getMinute(), 334 4)); 335 columnValues.put( 336 JobEntryTorquePeer.HOUR, 337 new JdbcTypedValue( 338 jobEntryTorque.getHour(), 339 4)); 340 columnValues.put( 341 JobEntryTorquePeer.WEEK_DAY, 342 new JdbcTypedValue( 343 jobEntryTorque.getWeekDay(), 344 4)); 345 columnValues.put( 346 JobEntryTorquePeer.DAY_OF_MONTH, 347 new JdbcTypedValue( 348 jobEntryTorque.getDayOfMonth(), 349 4)); 350 columnValues.put( 351 JobEntryTorquePeer.TASK, 352 new JdbcTypedValue( 353 jobEntryTorque.getTask(), 354 12)); 355 columnValues.put( 356 JobEntryTorquePeer.EMAIL, 357 new JdbcTypedValue( 358 jobEntryTorque.getEmail(), 359 12)); 360 columnValues.put( 361 JobEntryTorquePeer.PROPERTY, 362 new JdbcTypedValue( 363 jobEntryTorque.getProperty(), 364 -3)); 365 return columnValues; 366 } 367 368 /** 369 * Retrieve a single object by pk 370 * 371 * @param pk the primary key 372 * @throws TorqueException Any exceptions caught during processing will be 373 * rethrown wrapped into a TorqueException. 374 * @throws NoRowsException Primary key was not found in database. 375 * @throws TooManyRowsException Primary key was not found in database. 376 */ 377 public JobEntryTorque retrieveByPK(int pk) 378 throws TorqueException, NoRowsException, TooManyRowsException 379 { 380 return retrieveByPK(SimpleKey.keyFor(pk)); 381 } 382 383 /** 384 * Retrieve a single object by pk 385 * 386 * @param pk the primary key 387 * @param con the connection to use 388 * @throws TorqueException Any exceptions caught during processing will be 389 * rethrown wrapped into a TorqueException. 390 * @throws NoRowsException Primary key was not found in database. 391 * @throws TooManyRowsException Primary key was not found in database. 392 */ 393 public JobEntryTorque retrieveByPK(int pk, Connection con) 394 throws TorqueException, NoRowsException, TooManyRowsException 395 { 396 return retrieveByPK(SimpleKey.keyFor(pk), con); 397 } 398 399 400 401 402 /** 403 * Retrieve a single object by pk 404 * 405 * @param pk the primary key 406 * @throws TorqueException Any exceptions caught during processing will be 407 * rethrown wrapped into a TorqueException. 408 * @throws NoRowsException Primary key was not found in database. 409 * @throws TooManyRowsException Primary key was not found in database. 410 */ 411 public JobEntryTorque retrieveByPK(ObjectKey<?> pk) 412 throws TorqueException, NoRowsException, TooManyRowsException 413 { 414 try (TorqueConnection connection = Transaction.begin(getDatabaseName())) 415 { 416 JobEntryTorque result = retrieveByPK(pk, connection); 417 Transaction.commit(connection); 418 return result; 419 } 420 } 421 422 /** 423 * Retrieve a single object by pk 424 * 425 * @param pk the primary key 426 * @param con the connection to use 427 * @throws TorqueException Any exceptions caught during processing will be 428 * rethrown wrapped into a TorqueException. 429 * @throws NoRowsException Primary key was not found in database. 430 * @throws TooManyRowsException Primary key was not found in database. 431 */ 432 public JobEntryTorque retrieveByPK(ObjectKey<?> pk, Connection con) 433 throws TorqueException, NoRowsException, TooManyRowsException 434 { 435 Criteria criteria = buildCriteria(pk); 436 JobEntryTorque v = doSelectSingleRecord(criteria, con); 437 if (v == null) 438 { 439 throw new NoRowsException("Failed to select a row."); 440 } 441 442 return v; 443 } 444 445 446 /** 447 * Retrieve multiple objects by pk. 448 * 449 * @param pks List of primary keys. 450 * Entries in pks which do not match entries in the database are ignored. 451 * 452 * @return the list of matching objects, not null. 453 * 454 * @throws TorqueException Any exceptions caught during processing will be 455 * rethrown wrapped into a TorqueException. 456 */ 457 public List<JobEntryTorque> retrieveByTypedPKs(Collection<Integer> pks) 458 throws TorqueException 459 { 460 try (TorqueConnection connection = Transaction.begin(getDatabaseName())) 461 { 462 List<JobEntryTorque> result = retrieveByTypedPKs(pks, connection); 463 Transaction.commit(connection); 464 return result; 465 } 466 } 467 468 /** 469 * Retrieve multiple objects by pk. 470 * 471 * @param pks List of primary keys. 472 * Entries in pks which do not match entries in the database are ignored. 473 * @param dbcon the connection to use 474 * 475 * @return the list of matching objects, not null. 476 * 477 * @throws TorqueException Any exceptions caught during processing will be 478 * rethrown wrapped into a TorqueException. 479 */ 480 public List<JobEntryTorque> retrieveByTypedPKs( 481 Collection<Integer> pks, 482 Connection dbcon) 483 throws TorqueException 484 { 485 if (pks == null || pks.size() == 0) 486 { 487 return new ArrayList<JobEntryTorque>(); 488 } 489 List<ObjectKey<?>> objectKeyList = new ArrayList<ObjectKey<?>>(); 490 for (Integer pk : pks) 491 { 492 objectKeyList.add(SimpleKey.keyFor(pk)); 493 } 494 Criteria criteria = buildCriteria(objectKeyList); 495 List<JobEntryTorque> result = doSelect(criteria, dbcon); 496 return result; 497 } 498 499 /** 500 * Retrieve multiple objects by pk. 501 * 502 * @param pks List of primary keys. 503 * Entries in pks which do not match entries in the database are ignored. 504 * 505 * @return the list of matching objects, not null. 506 * 507 * @throws TorqueException Any exceptions caught during processing will be 508 * rethrown wrapped into a TorqueException. 509 */ 510 public List<JobEntryTorque> retrieveByObjectKeys(Collection<ObjectKey<?>> pks) 511 throws TorqueException 512 { 513 try (TorqueConnection connection = Transaction.begin(getDatabaseName())) 514 { 515 List<JobEntryTorque> result = retrieveByObjectKeys(pks, connection); 516 Transaction.commit(connection); 517 return result; 518 } 519 } 520 521 /** 522 * Retrieve multiple objects by pk. 523 * 524 * @param pks List of primary keys. 525 * Entries in pks which do not match entries in the database are ignored. 526 * @param dbcon the connection to use 527 * 528 * @return the list of matching objects, not null. 529 * 530 * @throws TorqueException Any exceptions caught during processing will be 531 * rethrown wrapped into a TorqueException. 532 */ 533 public List<JobEntryTorque> retrieveByObjectKeys( 534 Collection<ObjectKey<?>> pks, 535 Connection dbcon) 536 throws TorqueException 537 { 538 if (pks == null || pks.size() == 0) 539 { 540 return new ArrayList<JobEntryTorque>(); 541 } 542 Criteria criteria = buildCriteria(pks); 543 List<JobEntryTorque> result = doSelect(criteria, dbcon); 544 return result; 545 } 546 547 548 549 550 551 552}