1 package org.apache.turbine.services.security.torque.om;
2
3 import java.math.BigDecimal;
4 import java.sql.Connection;
5 import java.sql.SQLException;
6 import java.util.ArrayList;
7 import java.util.Date;
8 import java.util.Iterator;
9 import java.util.LinkedList;
10 import java.util.List;
11
12 import org.apache.torque.NoRowsException;
13 import org.apache.torque.TooManyRowsException;
14 import org.apache.torque.Torque;
15 import org.apache.torque.TorqueException;
16 import org.apache.torque.TorqueRuntimeException;
17 import org.apache.torque.map.MapBuilder;
18 import org.apache.torque.map.TableMap;
19 import org.apache.torque.om.DateKey;
20 import org.apache.torque.om.NumberKey;
21 import org.apache.torque.om.StringKey;
22 import org.apache.torque.om.ObjectKey;
23 import org.apache.torque.om.SimpleKey;
24 import org.apache.torque.util.BasePeer;
25 import org.apache.torque.util.Criteria;
26
27 import com.workingdogs.village.DataSetException;
28 import com.workingdogs.village.QueryDataSet;
29 import com.workingdogs.village.Record;
30
31
32 import org.apache.turbine.services.security.torque.om.map.*;
33
34
35
36
37
38
39
40
41
42
43 public abstract class BaseTurbineUserPeer
44 extends BasePeer
45 {
46
47 private static final long serialVersionUID = 1308842746584L;
48
49
50
51 public static final String DATABASE_NAME;
52
53
54 public static final String TABLE_NAME;
55
56
57
58
59
60
61
62 public static MapBuilder getMapBuilder()
63 throws TorqueException
64 {
65 return Torque.getMapBuilder(TurbineUserMapBuilder.CLASS_NAME);
66 }
67
68
69 public static final String USER_ID;
70
71 public static final String LOGIN_NAME;
72
73 public static final String PASSWORD_VALUE;
74
75 public static final String FIRST_NAME;
76
77 public static final String LAST_NAME;
78
79 public static final String EMAIL;
80
81 public static final String CONFIRM_VALUE;
82
83 public static final String MODIFIED;
84
85 public static final String CREATED;
86
87 public static final String LAST_LOGIN;
88
89 public static final String OBJECTDATA;
90
91 static
92 {
93 DATABASE_NAME = "default";
94 TABLE_NAME = "TURBINE_USER";
95
96 USER_ID = "TURBINE_USER.USER_ID";
97 LOGIN_NAME = "TURBINE_USER.LOGIN_NAME";
98 PASSWORD_VALUE = "TURBINE_USER.PASSWORD_VALUE";
99 FIRST_NAME = "TURBINE_USER.FIRST_NAME";
100 LAST_NAME = "TURBINE_USER.LAST_NAME";
101 EMAIL = "TURBINE_USER.EMAIL";
102 CONFIRM_VALUE = "TURBINE_USER.CONFIRM_VALUE";
103 MODIFIED = "TURBINE_USER.MODIFIED";
104 CREATED = "TURBINE_USER.CREATED";
105 LAST_LOGIN = "TURBINE_USER.LAST_LOGIN";
106 OBJECTDATA = "TURBINE_USER.OBJECTDATA";
107 if (Torque.isInit())
108 {
109 try
110 {
111 Torque.getMapBuilder(TurbineUserMapBuilder.CLASS_NAME);
112 }
113 catch (TorqueException e)
114 {
115 log.error("Could not initialize Peer", e);
116 throw new TorqueRuntimeException(e);
117 }
118 }
119 else
120 {
121 Torque.registerMapBuilder(TurbineUserMapBuilder.CLASS_NAME);
122 }
123 }
124
125
126 public static final int numColumns = 11;
127
128
129 protected static final String CLASSNAME_DEFAULT =
130 "org.apache.turbine.services.security.torque.om.TurbineUser";
131
132
133 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
134
135
136
137
138
139
140
141 private static Class initClass(String className)
142 {
143 Class c = null;
144 try
145 {
146 c = Class.forName(className);
147 }
148 catch (Throwable t)
149 {
150 log.error("A FATAL ERROR has occurred which should not "
151 + "have happened under any circumstance. Please notify "
152 + "the Torque developers <torque-dev@db.apache.org> "
153 + "and give as many details as possible (including the error "
154 + "stack trace).", t);
155
156
157 if (t instanceof Error)
158 {
159 throw (Error) t.fillInStackTrace();
160 }
161 }
162 return c;
163 }
164
165
166
167
168
169
170
171
172
173
174
175 public static List<TurbineUser> resultSet2Objects(java.sql.ResultSet results)
176 throws TorqueException
177 {
178 try
179 {
180 QueryDataSet qds = null;
181 List<Record> rows = null;
182 try
183 {
184 qds = new QueryDataSet(results);
185 rows = getSelectResults(qds);
186 }
187 finally
188 {
189 if (qds != null)
190 {
191 qds.close();
192 }
193 }
194
195 return populateObjects(rows);
196 }
197 catch (SQLException e)
198 {
199 throw new TorqueException(e);
200 }
201 catch (DataSetException e)
202 {
203 throw new TorqueException(e);
204 }
205 }
206
207
208
209
210
211
212
213
214
215
216 public static ObjectKey doInsert(Criteria criteria)
217 throws TorqueException
218 {
219 return BaseTurbineUserPeer
220 .doInsert(criteria, (Connection) null);
221 }
222
223
224
225
226
227
228
229
230
231
232
233 public static ObjectKey doInsert(Criteria criteria, Connection con)
234 throws TorqueException
235 {
236 correctBooleans(criteria);
237
238 setDbName(criteria);
239
240 if (con == null)
241 {
242 return BasePeer.doInsert(criteria);
243 }
244 else
245 {
246 return BasePeer.doInsert(criteria, con);
247 }
248 }
249
250
251
252
253
254
255
256
257 public static void addSelectColumns(Criteria criteria)
258 throws TorqueException
259 {
260 criteria.addSelectColumn(USER_ID);
261 criteria.addSelectColumn(LOGIN_NAME);
262 criteria.addSelectColumn(PASSWORD_VALUE);
263 criteria.addSelectColumn(FIRST_NAME);
264 criteria.addSelectColumn(LAST_NAME);
265 criteria.addSelectColumn(EMAIL);
266 criteria.addSelectColumn(CONFIRM_VALUE);
267 criteria.addSelectColumn(MODIFIED);
268 criteria.addSelectColumn(CREATED);
269 criteria.addSelectColumn(LAST_LOGIN);
270 criteria.addSelectColumn(OBJECTDATA);
271 }
272
273
274
275
276
277
278
279
280
281
282 public static void correctBooleans(Criteria criteria) throws TorqueException
283 {
284 correctBooleans(criteria, getTableMap());
285 }
286
287
288
289
290
291
292
293
294
295
296 public static TurbineUser row2Object(Record row,
297 int offset,
298 Class cls)
299 throws TorqueException
300 {
301 try
302 {
303 TurbineUser obj = (TurbineUser) cls.newInstance();
304 TurbineUserPeer.populateObject(row, offset, obj);
305 obj.setModified(false);
306 obj.setNew(false);
307
308 return obj;
309 }
310 catch (InstantiationException e)
311 {
312 throw new TorqueException(e);
313 }
314 catch (IllegalAccessException e)
315 {
316 throw new TorqueException(e);
317 }
318 }
319
320
321
322
323
324
325
326
327
328
329 public static void populateObject(Record row,
330 int offset,
331 TurbineUser obj)
332 throws TorqueException
333 {
334 try
335 {
336 obj.setUserId(row.getValue(offset + 0).asInt());
337 obj.setUserName(row.getValue(offset + 1).asString());
338 obj.setPassword(row.getValue(offset + 2).asString());
339 obj.setFirstName(row.getValue(offset + 3).asString());
340 obj.setLastName(row.getValue(offset + 4).asString());
341 obj.setEmail(row.getValue(offset + 5).asString());
342 obj.setConfirmed(row.getValue(offset + 6).asString());
343 obj.setModified(row.getValue(offset + 7).asUtilDate());
344 obj.setCreateDate(row.getValue(offset + 8).asUtilDate());
345 obj.setLastLogin(row.getValue(offset + 9).asUtilDate());
346 obj.setObjectdata(row.getValue(offset + 10).asBytes());
347 }
348 catch (DataSetException e)
349 {
350 throw new TorqueException(e);
351 }
352 }
353
354
355
356
357
358
359
360
361
362 public static List<TurbineUser> doSelect(Criteria criteria) throws TorqueException
363 {
364 return populateObjects(doSelectVillageRecords(criteria));
365 }
366
367
368
369
370
371
372
373
374
375
376 public static List<TurbineUser> doSelect(Criteria criteria, Connection con)
377 throws TorqueException
378 {
379 return populateObjects(doSelectVillageRecords(criteria, con));
380 }
381
382
383
384
385
386
387
388
389
390
391
392 public static List<Record> doSelectVillageRecords(Criteria criteria)
393 throws TorqueException
394 {
395 return BaseTurbineUserPeer
396 .doSelectVillageRecords(criteria, (Connection) null);
397 }
398
399
400
401
402
403
404
405
406
407
408 public static List<Record> doSelectVillageRecords(Criteria criteria, Connection con)
409 throws TorqueException
410 {
411 if (criteria.getSelectColumns().size() == 0)
412 {
413 addSelectColumns(criteria);
414 }
415 correctBooleans(criteria);
416
417 setDbName(criteria);
418
419
420
421 if (con == null)
422 {
423 return BasePeer.doSelect(criteria);
424 }
425 else
426 {
427 return BasePeer.doSelect(criteria, con);
428 }
429 }
430
431
432
433
434
435
436
437
438 public static List<TurbineUser> populateObjects(List<Record> records)
439 throws TorqueException
440 {
441 List<TurbineUser> results = new ArrayList<TurbineUser>(records.size());
442
443
444 for (int i = 0; i < records.size(); i++)
445 {
446 Record row = records.get(i);
447 results.add(TurbineUserPeer.row2Object(row, 1,
448 TurbineUserPeer.getOMClass()));
449 }
450 return results;
451 }
452
453
454
455
456
457
458
459
460
461
462 public static Class getOMClass()
463 throws TorqueException
464 {
465 return CLASS_DEFAULT;
466 }
467
468
469
470
471
472
473
474
475
476 public static void doUpdate(Criteria criteria) throws TorqueException
477 {
478 BaseTurbineUserPeer
479 .doUpdate(criteria, (Connection) null);
480 }
481
482
483
484
485
486
487
488
489
490
491
492
493 public static void doUpdate(Criteria criteria, Connection con)
494 throws TorqueException
495 {
496 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
497 correctBooleans(criteria);
498
499
500 selectCriteria.put(USER_ID, criteria.remove(USER_ID));
501
502
503
504
505
506
507
508
509
510
511
512 setDbName(criteria);
513
514 if (con == null)
515 {
516 BasePeer.doUpdate(selectCriteria, criteria);
517 }
518 else
519 {
520 BasePeer.doUpdate(selectCriteria, criteria, con);
521 }
522 }
523
524
525
526
527
528
529
530
531 public static void doDelete(Criteria criteria) throws TorqueException
532 {
533 TurbineUserPeer
534 .doDelete(criteria, (Connection) null);
535 }
536
537
538
539
540
541
542
543
544
545
546
547 public static void doDelete(Criteria criteria, Connection con)
548 throws TorqueException
549 {
550 correctBooleans(criteria);
551
552 setDbName(criteria);
553
554 if (con == null)
555 {
556 BasePeer.doDelete(criteria, TABLE_NAME);
557 }
558 else
559 {
560 BasePeer.doDelete(criteria, TABLE_NAME, con);
561 }
562 }
563
564
565
566
567
568
569
570 public static List<TurbineUser> doSelect(TurbineUser obj) throws TorqueException
571 {
572 return doSelect(buildSelectCriteria(obj));
573 }
574
575
576
577
578
579
580
581 public static void doInsert(TurbineUser obj) throws TorqueException
582 {
583 obj.setPrimaryKey(doInsert(buildCriteria(obj)));
584 obj.setNew(false);
585 obj.setModified(false);
586 }
587
588
589
590
591
592
593 public static void doUpdate(TurbineUser obj) throws TorqueException
594 {
595 doUpdate(buildCriteria(obj));
596 obj.setModified(false);
597 }
598
599
600
601
602
603
604 public static void doDelete(TurbineUser obj) throws TorqueException
605 {
606 doDelete(buildSelectCriteria(obj));
607 }
608
609
610
611
612
613
614
615
616
617
618
619 public static void doInsert(TurbineUser obj, Connection con)
620 throws TorqueException
621 {
622 obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
623 obj.setNew(false);
624 obj.setModified(false);
625 }
626
627
628
629
630
631
632
633
634
635
636
637 public static void doUpdate(TurbineUser obj, Connection con)
638 throws TorqueException
639 {
640 doUpdate(buildCriteria(obj), con);
641 obj.setModified(false);
642 }
643
644
645
646
647
648
649
650
651
652
653
654 public static void doDelete(TurbineUser obj, Connection con)
655 throws TorqueException
656 {
657 doDelete(buildSelectCriteria(obj), con);
658 }
659
660
661
662
663
664
665
666
667 public static void doDelete(ObjectKey pk) throws TorqueException
668 {
669 BaseTurbineUserPeer
670 .doDelete(pk, (Connection) null);
671 }
672
673
674
675
676
677
678
679
680
681
682
683 public static void doDelete(ObjectKey pk, Connection con)
684 throws TorqueException
685 {
686 doDelete(buildCriteria(pk), con);
687 }
688
689
690 public static Criteria buildCriteria( ObjectKey pk )
691 {
692 Criteria criteria = new Criteria();
693 criteria.add(USER_ID, pk);
694 return criteria;
695 }
696
697
698 public static Criteria buildCriteria( TurbineUser obj )
699 {
700 Criteria criteria = new Criteria(DATABASE_NAME);
701 if (!obj.isNew())
702 criteria.add(USER_ID, obj.getUserId());
703 criteria.add(LOGIN_NAME, obj.getUserName());
704 criteria.add(PASSWORD_VALUE, obj.getPassword());
705 criteria.add(FIRST_NAME, obj.getFirstName());
706 criteria.add(LAST_NAME, obj.getLastName());
707 criteria.add(EMAIL, obj.getEmail());
708 criteria.add(CONFIRM_VALUE, obj.getConfirmed());
709 criteria.add(MODIFIED, obj.getModified());
710 criteria.add(CREATED, obj.getCreateDate());
711 criteria.add(LAST_LOGIN, obj.getLastLogin());
712 criteria.add(OBJECTDATA, obj.getObjectdata());
713 return criteria;
714 }
715
716
717 public static Criteria buildSelectCriteria( TurbineUser obj )
718 {
719 Criteria criteria = new Criteria(DATABASE_NAME);
720 if (!obj.isNew())
721 {
722 criteria.add(USER_ID, obj.getUserId());
723 }
724 criteria.add(LOGIN_NAME, obj.getUserName());
725 criteria.add(PASSWORD_VALUE, obj.getPassword());
726 criteria.add(FIRST_NAME, obj.getFirstName());
727 criteria.add(LAST_NAME, obj.getLastName());
728 criteria.add(EMAIL, obj.getEmail());
729 criteria.add(CONFIRM_VALUE, obj.getConfirmed());
730 criteria.add(MODIFIED, obj.getModified());
731 criteria.add(CREATED, obj.getCreateDate());
732 criteria.add(LAST_LOGIN, obj.getLastLogin());
733 return criteria;
734 }
735
736
737
738
739
740
741
742
743
744
745
746 public static TurbineUser retrieveByPK(int pk)
747 throws TorqueException, NoRowsException, TooManyRowsException
748 {
749 return retrieveByPK(SimpleKey.keyFor(pk));
750 }
751
752
753
754
755
756
757
758
759
760
761
762 public static TurbineUser retrieveByPK(int pk, Connection con)
763 throws TorqueException, NoRowsException, TooManyRowsException
764 {
765 return retrieveByPK(SimpleKey.keyFor(pk), con);
766 }
767
768
769
770
771
772
773
774
775
776
777 public static TurbineUser retrieveByPK(ObjectKey pk)
778 throws TorqueException, NoRowsException, TooManyRowsException
779 {
780 Connection db = null;
781 TurbineUser retVal = null;
782 try
783 {
784 db = Torque.getConnection(DATABASE_NAME);
785 retVal = retrieveByPK(pk, db);
786 }
787 finally
788 {
789 Torque.closeConnection(db);
790 }
791 return retVal;
792 }
793
794
795
796
797
798
799
800
801
802
803
804 public static TurbineUser retrieveByPK(ObjectKey pk, Connection con)
805 throws TorqueException, NoRowsException, TooManyRowsException
806 {
807 Criteria criteria = buildCriteria(pk);
808 List<TurbineUser> v = doSelect(criteria, con);
809 if (v.size() == 0)
810 {
811 throw new NoRowsException("Failed to select a row.");
812 }
813 else if (v.size() > 1)
814 {
815 throw new TooManyRowsException("Failed to select only one row.");
816 }
817 else
818 {
819 return (TurbineUser)v.get(0);
820 }
821 }
822
823
824
825
826
827
828
829
830 public static List<TurbineUser> retrieveByPKs(List<ObjectKey> pks)
831 throws TorqueException
832 {
833 Connection db = null;
834 List<TurbineUser> retVal = null;
835 try
836 {
837 db = Torque.getConnection(DATABASE_NAME);
838 retVal = retrieveByPKs(pks, db);
839 }
840 finally
841 {
842 Torque.closeConnection(db);
843 }
844 return retVal;
845 }
846
847
848
849
850
851
852
853
854
855 public static List<TurbineUser> retrieveByPKs( List<ObjectKey> pks, Connection dbcon )
856 throws TorqueException
857 {
858 List<TurbineUser> objs = null;
859 if (pks == null || pks.size() == 0)
860 {
861 objs = new LinkedList<TurbineUser>();
862 }
863 else
864 {
865 Criteria criteria = new Criteria();
866 criteria.addIn( USER_ID, pks );
867 objs = doSelect(criteria, dbcon);
868 }
869 return objs;
870 }
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887 public static TableMap getTableMap()
888 throws TorqueException
889 {
890 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
891 }
892
893 private static void setDbName(Criteria crit)
894 {
895
896
897
898 if (crit.getDbName() == Torque.getDefaultDB())
899 {
900 crit.setDbName(DATABASE_NAME);
901 }
902 }
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919 public static List<Record> executeQuery(String queryString) throws TorqueException
920 {
921 return BasePeer.executeQuery(queryString);
922 }
923
924
925
926
927
928
929
930
931
932
933
934
935
936 public static List<Record> executeQuery(String queryString, String dbName)
937 throws TorqueException
938 {
939 return BasePeer.executeQuery(queryString,dbName);
940 }
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955 public static List<Record> executeQuery(
956 String queryString,
957 String dbName,
958 boolean singleRecord)
959 throws TorqueException
960 {
961 return BasePeer.executeQuery(queryString,dbName,singleRecord);
962 }
963
964
965
966
967
968
969
970
971
972
973
974
975
976 public static List<Record> executeQuery(
977 String queryString,
978 boolean singleRecord,
979 Connection con)
980 throws TorqueException
981 {
982 return BasePeer.executeQuery(queryString,singleRecord,con);
983 }
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999 public static List<Record> executeQuery(
1000 String queryString,
1001 int start,
1002 int numberOfResults,
1003 String dbName,
1004 boolean singleRecord)
1005 throws TorqueException
1006 {
1007 return BasePeer.executeQuery(queryString,start,numberOfResults,dbName,singleRecord);
1008 }
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024 public static List<Record> executeQuery(
1025 String queryString,
1026 int start,
1027 int numberOfResults,
1028 boolean singleRecord,
1029 Connection con)
1030 throws TorqueException
1031 {
1032 return BasePeer.executeQuery(queryString,start,numberOfResults,singleRecord,con);
1033 }
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046 public static List<Record> getSelectResults(QueryDataSet qds)
1047 throws TorqueException
1048 {
1049 return BasePeer.getSelectResults(qds);
1050 }
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064 public static List<Record> getSelectResults(QueryDataSet qds, boolean singleRecord)
1065 throws TorqueException
1066 {
1067 return BasePeer.getSelectResults(qds,singleRecord);
1068 }
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084 public static List<Record> getSelectResults(
1085 QueryDataSet qds,
1086 int numberOfResults,
1087 boolean singleRecord)
1088 throws TorqueException
1089 {
1090 return BasePeer.getSelectResults(qds,numberOfResults,singleRecord);
1091 }
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110 public static List getSelectResults(
1111 QueryDataSet qds,
1112 int start,
1113 int numberOfResults,
1114 boolean singleRecord)
1115 throws TorqueException
1116 {
1117 return BasePeer.getSelectResults(qds,start,numberOfResults,singleRecord);
1118 }
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130 public static List<Record> doPSSelect(Criteria criteria, Connection con)
1131 throws TorqueException
1132 {
1133 return BasePeer.doPSSelect(criteria,con);
1134 }
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145 public static List<Record> doPSSelect(Criteria criteria) throws TorqueException
1146 {
1147 return BasePeer.doPSSelect(criteria);
1148 }
1149 }