1 package org.apache.turbine.services.schedule;
2
3 import java.sql.Blob;
4 import java.sql.Clob;
5 import java.sql.Connection;
6 import java.sql.SQLException;
7 import java.sql.ResultSet;
8 import java.sql.PreparedStatement;
9 import java.sql.Types;
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.io.ByteArrayInputStream;
13 import java.io.ByteArrayOutputStream;
14 import java.io.Reader;
15 import java.io.StringReader;
16 import java.io.StringWriter;
17 import java.util.ArrayList;
18 import java.util.Collection;
19 import java.util.Date;
20 import java.util.Iterator;
21 import java.util.LinkedList;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.HashMap;
25 import java.util.Set;
26 import java.util.HashSet;
27
28 import org.apache.commons.lang.ObjectUtils;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.torque.NoRowsException;
32 import org.apache.torque.OptimisticLockingFailedException;
33 import org.apache.torque.TooManyRowsException;
34 import org.apache.torque.Torque;
35 import org.apache.torque.TorqueException;
36 import org.apache.torque.TorqueRuntimeException;
37 import org.apache.torque.criteria.Criteria;
38 import org.apache.torque.criteria.Criterion;
39 import org.apache.torque.om.mapper.RecordMapper;
40 import org.apache.torque.om.mapper.CompositeMapper;
41 import org.apache.torque.om.DateKey;
42 import org.apache.torque.om.NumberKey;
43 import org.apache.torque.om.StringKey;
44 import org.apache.torque.om.ObjectKey;
45 import org.apache.torque.om.SimpleKey;
46 import org.apache.torque.om.ComboKey;
47 import org.apache.torque.map.TableMap;
48 import org.apache.torque.util.Transaction;
49 import org.apache.torque.util.ColumnValues;
50 import org.apache.torque.util.JdbcTypedValue;
51
52
53
54
55
56
57
58
59
60
61
62
63 public abstract class BaseJobEntryTorquePeerImpl
64 extends org.apache.torque.util.BasePeerImpl<JobEntryTorque>
65 {
66
67 private static Log log = LogFactory.getLog(BaseJobEntryTorquePeerImpl.class);
68
69
70 private static final long serialVersionUID = 1520250005060L;
71
72
73
74
75
76
77
78
79 public BaseJobEntryTorquePeerImpl()
80 {
81 this(new JobEntryTorqueRecordMapper(),
82 JobEntryTorquePeer.TABLE,
83 JobEntryTorquePeer.DATABASE_NAME);
84 }
85
86
87
88
89
90
91
92
93 public BaseJobEntryTorquePeerImpl(
94 RecordMapper<JobEntryTorque> recordMapper,
95 TableMap tableMap,
96 String databaseName)
97 {
98 super(recordMapper, tableMap, databaseName);
99 }
100
101
102
103
104
105
106
107
108
109
110
111 public List<JobEntryTorque> doSelect(JobEntryTorque obj)
112 throws TorqueException
113 {
114 return doSelect(buildSelectCriteria(obj));
115 }
116
117
118
119
120
121
122
123
124
125
126 public JobEntryTorque doSelectSingleRecord(
127 JobEntryTorque obj)
128 throws TorqueException
129 {
130 List<JobEntryTorque> jobEntryTorqueList = doSelect(obj);
131 JobEntryTorque jobEntryTorque = null;
132 if (jobEntryTorqueList.size() > 1)
133 {
134 throw new TooManyRowsException("Object " + obj
135 + " matched more than one record");
136 }
137 if (!jobEntryTorqueList.isEmpty())
138 {
139 jobEntryTorque = jobEntryTorqueList.get(0);
140 }
141 return jobEntryTorque;
142 }
143
144
145
146
147 public JobEntryTorque getDbObjectInstance()
148 {
149 return new JobEntryTorque();
150 }
151
152
153
154
155
156
157
158
159
160
161
162
163 public ObjectKey doInsert(ColumnValues columnValues) throws TorqueException
164 {
165 Connection connection = null;
166 try
167 {
168 connection = Transaction.begin(
169 JobEntryTorquePeer.DATABASE_NAME);
170 ObjectKey result = doInsert(columnValues, connection);
171 Transaction.commit(connection);
172 connection = null;
173 return result;
174 }
175 finally
176 {
177 if (connection != null)
178 {
179 Transaction.safeRollback(connection);
180 }
181 }
182 }
183
184
185
186
187
188
189
190
191
192
193
194
195
196 public ObjectKey doInsert(ColumnValues columnValues, Connection con)
197 throws TorqueException
198 {
199 correctBooleans(columnValues);
200 return super.doInsert(columnValues, con);
201 }
202
203
204
205
206
207
208
209 public void doInsert(JobEntryTorque obj) throws TorqueException
210 {
211 obj.setPrimaryKey(doInsert(buildColumnValues(obj)));
212 obj.setNew(false);
213 obj.setModified(false);
214 }
215
216
217
218
219
220
221
222
223
224
225
226 public void doInsert(JobEntryTorque obj, Connection con)
227 throws TorqueException
228 {
229 ObjectKey primaryKey = doInsert(buildColumnValues(obj), con);
230 if (primaryKey != null)
231 {
232 obj.setPrimaryKey(primaryKey);
233 }
234 obj.setNew(false);
235 obj.setModified(false);
236 }
237
238
239
240
241
242
243
244
245
246
247
248
249 public int doUpdate(ColumnValues columnValues) throws TorqueException
250 {
251 Connection connection = null;
252 try
253 {
254 connection = Transaction.begin(
255 JobEntryTorquePeer.DATABASE_NAME);
256 int result = doUpdate(columnValues, connection);
257 Transaction.commit(connection);
258 connection = null;
259 return result;
260 }
261 finally
262 {
263 if (connection != null)
264 {
265 Transaction.safeRollback(connection);
266 }
267 }
268 }
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283 public int doUpdate(ColumnValues columnValues, Connection con)
284 throws TorqueException
285 {
286 Criteria selectCriteria
287 = new Criteria(JobEntryTorquePeer.DATABASE_NAME);
288 correctBooleans(columnValues);
289
290 selectCriteria.where(
291 JobEntryTorquePeer.JOB_ID,
292 columnValues.remove(JobEntryTorquePeer.JOB_ID).getValue());
293
294
295 int rowCount = doUpdate(selectCriteria, columnValues, con);
296 return rowCount;
297 }
298
299
300
301
302
303
304
305
306
307
308
309
310 public int doUpdate(JobEntryTorque obj) throws TorqueException
311 {
312 ColumnValues columnValues = buildColumnValues(obj);
313 int result = doUpdate(columnValues);
314 obj.setModified(false);
315 return result;
316 }
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332 public int doUpdate(JobEntryTorque obj, Connection con)
333 throws TorqueException
334 {
335 ColumnValues columnValues = buildColumnValues(obj);
336 int result = doUpdate(columnValues, con);
337 obj.setModified(false);
338 return result;
339 }
340
341
342
343
344
345
346
347
348
349
350
351 public int doDelete(JobEntryTorque obj) throws TorqueException
352 {
353 int result = doDelete(buildCriteria(obj.getPrimaryKey()));
354 obj.setDeleted(true);
355 return result;
356 }
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371 public int doDelete(JobEntryTorque obj, Connection con)
372 throws TorqueException
373 {
374 int result = doDelete(buildCriteria(obj.getPrimaryKey()), con);
375 obj.setDeleted(true);
376 return result;
377 }
378
379
380
381
382
383
384
385
386
387
388
389
390 public int doDelete(Collection<JobEntryTorque> objects)
391 throws TorqueException
392 {
393 int result = doDelete(buildPkCriteria(objects));
394 for (JobEntryTorque object : objects)
395 {
396 object.setDeleted(true);
397 }
398 return result;
399 }
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416 public int doDelete(
417 Collection<JobEntryTorque> objects,
418 Connection con)
419 throws TorqueException
420 {
421 int result = doDelete(buildPkCriteria(objects), con);
422 for (JobEntryTorque object : objects)
423 {
424 object.setDeleted(true);
425 }
426 return result;
427 }
428
429
430
431
432
433
434
435
436
437
438
439 public int doDelete(ObjectKey pk) throws TorqueException
440 {
441 Connection connection = null;
442 try
443 {
444 connection = Transaction.begin(
445 JobEntryTorquePeer.DATABASE_NAME);
446 int deletedRows = doDelete(pk, connection);
447 Transaction.commit(connection);
448 connection = null;
449 return deletedRows;
450 }
451 finally
452 {
453 if (connection != null)
454 {
455 Transaction.safeRollback(connection);
456 }
457 }
458 }
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473 public int doDelete(ObjectKey pk, Connection con)
474 throws TorqueException
475 {
476 return doDelete(buildCriteria(pk), con);
477 }
478
479
480
481
482
483
484
485 public Criteria buildCriteria(ObjectKey pk)
486 {
487 Criteria criteria = new Criteria();
488 criteria.and(JobEntryTorquePeer.JOB_ID, pk);
489 return criteria;
490 }
491
492
493
494
495
496
497
498
499 public Criteria buildCriteria(Collection<ObjectKey> pks)
500 {
501 Criteria criteria = new Criteria();
502 criteria.andIn(JobEntryTorquePeer.JOB_ID, pks);
503 return criteria;
504 }
505
506
507
508
509
510
511
512
513
514 public Criteria buildPkCriteria(
515 Collection<JobEntryTorque> objects)
516 {
517 List<ObjectKey> pks = new ArrayList<ObjectKey>(objects.size());
518 for (JobEntryTorque object : objects)
519 {
520 ObjectKey pk = object.getPrimaryKey();
521 if (pk != null)
522 {
523 pks.add(pk);
524 }
525 }
526 return buildCriteria(pks);
527 }
528
529
530
531
532
533
534
535 public Criteria buildCriteria(JobEntryTorque obj)
536 {
537 Criteria criteria = new Criteria(JobEntryTorquePeer.DATABASE_NAME);
538 if (!obj.isNew())
539 {
540 criteria.and(JobEntryTorquePeer.JOB_ID, obj.getJobId());
541 }
542 criteria.and(JobEntryTorquePeer.SECOND, obj.getSecond());
543 criteria.and(JobEntryTorquePeer.MINUTE, obj.getMinute());
544 criteria.and(JobEntryTorquePeer.HOUR, obj.getHour());
545 criteria.and(JobEntryTorquePeer.WEEK_DAY, obj.getWeekDay());
546 criteria.and(JobEntryTorquePeer.DAY_OF_MONTH, obj.getDayOfMonth());
547 criteria.and(JobEntryTorquePeer.TASK, obj.getTask());
548 criteria.and(JobEntryTorquePeer.EMAIL, obj.getEmail());
549 criteria.and(JobEntryTorquePeer.PROPERTY, obj.getProperty());
550 return criteria;
551 }
552
553
554
555
556
557
558
559 public Criteria buildSelectCriteria(JobEntryTorque obj)
560 {
561 Criteria criteria = new Criteria(JobEntryTorquePeer.DATABASE_NAME);
562 if (!obj.isNew())
563 {
564 criteria.and(JobEntryTorquePeer.JOB_ID, obj.getJobId());
565 }
566 criteria.and(JobEntryTorquePeer.SECOND, obj.getSecond());
567 criteria.and(JobEntryTorquePeer.MINUTE, obj.getMinute());
568 criteria.and(JobEntryTorquePeer.HOUR, obj.getHour());
569 criteria.and(JobEntryTorquePeer.WEEK_DAY, obj.getWeekDay());
570 criteria.and(JobEntryTorquePeer.DAY_OF_MONTH, obj.getDayOfMonth());
571 criteria.and(JobEntryTorquePeer.TASK, obj.getTask());
572 criteria.and(JobEntryTorquePeer.EMAIL, obj.getEmail());
573 return criteria;
574 }
575
576
577
578
579
580
581
582
583
584
585
586
587 public ColumnValues buildColumnValues(JobEntryTorque jobEntryTorque)
588 throws TorqueException
589 {
590 ColumnValues columnValues = new ColumnValues();
591 if (!jobEntryTorque.isNew()
592 || jobEntryTorque.getJobId() != 0)
593 {
594 columnValues.put(
595 JobEntryTorquePeer.JOB_ID,
596 new JdbcTypedValue(
597 jobEntryTorque.getJobId(),
598 4));
599 }
600 columnValues.put(
601 JobEntryTorquePeer.SECOND,
602 new JdbcTypedValue(
603 jobEntryTorque.getSecond(),
604 4));
605 columnValues.put(
606 JobEntryTorquePeer.MINUTE,
607 new JdbcTypedValue(
608 jobEntryTorque.getMinute(),
609 4));
610 columnValues.put(
611 JobEntryTorquePeer.HOUR,
612 new JdbcTypedValue(
613 jobEntryTorque.getHour(),
614 4));
615 columnValues.put(
616 JobEntryTorquePeer.WEEK_DAY,
617 new JdbcTypedValue(
618 jobEntryTorque.getWeekDay(),
619 4));
620 columnValues.put(
621 JobEntryTorquePeer.DAY_OF_MONTH,
622 new JdbcTypedValue(
623 jobEntryTorque.getDayOfMonth(),
624 4));
625 columnValues.put(
626 JobEntryTorquePeer.TASK,
627 new JdbcTypedValue(
628 jobEntryTorque.getTask(),
629 12));
630 columnValues.put(
631 JobEntryTorquePeer.EMAIL,
632 new JdbcTypedValue(
633 jobEntryTorque.getEmail(),
634 12));
635 columnValues.put(
636 JobEntryTorquePeer.PROPERTY,
637 new JdbcTypedValue(
638 jobEntryTorque.getProperty(),
639 -3));
640 return columnValues;
641 }
642
643
644
645
646
647
648
649
650
651
652 public JobEntryTorque retrieveByPK(int pk)
653 throws TorqueException, NoRowsException, TooManyRowsException
654 {
655 return retrieveByPK(SimpleKey.keyFor(pk));
656 }
657
658
659
660
661
662
663
664
665
666
667
668 public JobEntryTorque retrieveByPK(int pk, Connection con)
669 throws TorqueException, NoRowsException, TooManyRowsException
670 {
671 return retrieveByPK(SimpleKey.keyFor(pk), con);
672 }
673
674
675
676
677
678
679
680
681
682
683
684
685
686 public JobEntryTorque retrieveByPK(ObjectKey pk)
687 throws TorqueException, NoRowsException, TooManyRowsException
688 {
689 Connection connection = null;
690 try
691 {
692 connection = Transaction.begin(JobEntryTorquePeer.DATABASE_NAME);
693 JobEntryTorque result = retrieveByPK(pk, connection);
694 Transaction.commit(connection);
695 connection = null;
696 return result;
697 }
698 finally
699 {
700 if (connection != null)
701 {
702 Transaction.safeRollback(connection);
703 }
704 }
705 }
706
707
708
709
710
711
712
713
714
715
716
717 public JobEntryTorque retrieveByPK(ObjectKey pk, Connection con)
718 throws TorqueException, NoRowsException, TooManyRowsException
719 {
720 Criteria criteria = buildCriteria(pk);
721 List<JobEntryTorque> v = doSelect(criteria, con);
722 if (v.size() == 0)
723 {
724 throw new NoRowsException("Failed to select a row.");
725 }
726 else if (v.size() > 1)
727 {
728 throw new TooManyRowsException("Failed to select only one row.");
729 }
730 else
731 {
732 return (JobEntryTorque)v.get(0);
733 }
734 }
735
736
737
738
739
740
741
742
743
744 public List<JobEntryTorque> retrieveByPKs(Collection<ObjectKey> pks)
745 throws TorqueException
746 {
747 Connection connection = null;
748 try
749 {
750 connection = Transaction.begin(JobEntryTorquePeer.DATABASE_NAME);
751 List<JobEntryTorque> result = retrieveByPKs(pks, connection);
752 Transaction.commit(connection);
753 connection = null;
754 return result;
755 }
756 finally
757 {
758 if (connection != null)
759 {
760 Transaction.safeRollback(connection);
761 }
762 }
763 }
764
765
766
767
768
769
770
771
772
773 public List<JobEntryTorque> retrieveByPKs(
774 Collection<ObjectKey> pks,
775 Connection dbcon)
776 throws TorqueException
777 {
778 if (pks == null || pks.size() == 0)
779 {
780 return new ArrayList<JobEntryTorque>();
781 }
782 Criteria criteria = buildCriteria(pks);
783 List<JobEntryTorque> result = doSelect(criteria, dbcon);
784 return result;
785 }
786
787
788
789
790
791
792 }