Source Code Cross Referenced for ContactModel.java in  » J2EE » Sofia » com » salmonllc » examples » example8 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Sofia » com.salmonllc.examples.example8 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.salmonllc.examples.example8;
002:
003:        import com.salmonllc.sql.*;
004:
005:        //$CUSTOMIMPORTS$
006:        //Put custom imports between these comments, otherwise they will be overwritten if the model is regenerated
007:        import com.salmonllc.util.*;
008:        import javax.servlet.http.HttpServletRequest;
009:
010:        import java.sql.SQLException;
011:        import java.sql.Statement;
012:        import java.sql.ResultSet;
013:
014:        //$ENDCUSTOMIMPORTS$
015:
016:        /**
017:         * ContactModel: A SOFIA generated model
018:         */
019:        public class ContactModel extends DataStore implements  Remotable {
020:
021:            //constants for columns
022:            public static final String CONTACT_CONTACT_ID = "contact.contact_id";
023:            public static final String CONTACT_FIRST_NAME = "contact.first_name";
024:            public static final String CONTACT_LAST_NAME = "contact.last_name";
025:            public static final String CONTACT_ADDRESS = "contact.address";
026:            public static final String CONTACT_CITY = "contact.city";
027:            public static final String CONTACT_STATE = "contact.state";
028:            public static final String CONTACT_ZIP = "contact.zip";
029:            public static final String CONTACT_MAIN_PHONE = "contact.main_phone";
030:            public static final String CONTACT_ALT_PHONE = "contact.alt_phone";
031:            public static final String CONTACT_CELL_PHONE = "contact.cell_phone";
032:            public static final String CONTACT_EMAIL_ADDRESS = "contact.email_address";
033:
034:            //$CUSTOMVARS$
035:            //Put custom instance variables between these comments, otherwise they will be overwritten if the model is regenerated
036:            private int _nextID = -1;
037:
038:            //$ENDCUSTOMVARS$
039:
040:            /**
041:             * Create a new ContactModel object.
042:             * @param appName The SOFIA application name
043:             */
044:            public ContactModel(String appName) {
045:                this (appName, null);
046:            }
047:
048:            /**
049:             * Create a new ContactModel object.
050:             * @param appName The SOFIA application name
051:             * @param profile The database profile to use
052:             */
053:            public ContactModel(String appName, String profile) {
054:                super (appName, profile);
055:
056:                try {
057:
058:                    //add aliases
059:                    addTableAlias(computeTableName("contact"), null);
060:
061:                    //add columns
062:                    addColumn(computeTableName("contact"), "contact_id",
063:                            DataStore.DATATYPE_INT, true, true,
064:                            CONTACT_CONTACT_ID);
065:                    addColumn(computeTableName("contact"), "first_name",
066:                            DataStore.DATATYPE_STRING, false, true,
067:                            CONTACT_FIRST_NAME);
068:                    addColumn(computeTableName("contact"), "last_name",
069:                            DataStore.DATATYPE_STRING, false, true,
070:                            CONTACT_LAST_NAME);
071:                    addColumn(computeTableName("contact"), "address",
072:                            DataStore.DATATYPE_STRING, false, true,
073:                            CONTACT_ADDRESS);
074:                    addColumn(computeTableName("contact"), "city",
075:                            DataStore.DATATYPE_STRING, false, true,
076:                            CONTACT_CITY);
077:                    addColumn(computeTableName("contact"), "state",
078:                            DataStore.DATATYPE_STRING, false, true,
079:                            CONTACT_STATE);
080:                    addColumn(computeTableName("contact"), "zip",
081:                            DataStore.DATATYPE_STRING, false, true, CONTACT_ZIP);
082:                    addColumn(computeTableName("contact"), "main_phone",
083:                            DataStore.DATATYPE_STRING, false, true,
084:                            CONTACT_MAIN_PHONE);
085:                    addColumn(computeTableName("contact"), "alt_phone",
086:                            DataStore.DATATYPE_STRING, false, true,
087:                            CONTACT_ALT_PHONE);
088:                    addColumn(computeTableName("contact"), "cell_phone",
089:                            DataStore.DATATYPE_STRING, false, true,
090:                            CONTACT_CELL_PHONE);
091:                    addColumn(computeTableName("contact"), "email_address",
092:                            DataStore.DATATYPE_STRING, false, true,
093:                            CONTACT_EMAIL_ADDRESS);
094:
095:                    //set order by
096:                    setOrderBy(computeTableAndFieldName("contact.last_name")
097:                            + " ASC,"
098:                            + computeTableAndFieldName("contact.first_name")
099:                            + " ASC");
100:
101:                    //add validations
102:                    addRequiredRule(CONTACT_FIRST_NAME,
103:                            "First Name must have a value.");
104:                    addRequiredRule(CONTACT_LAST_NAME,
105:                            "Last Name must have a value.");
106:                    addExpressionRule(
107:                            CONTACT_CITY,
108:                            "if (contact.address == null, true, contact.city != null)",
109:                            "Please enter a city for the address");
110:                    addExpressionRule(
111:                            CONTACT_STATE,
112:                            "if (contact.address == null, true, contact.state != null)",
113:                            "Please enter a state for the address");
114:                    addExpressionRule(
115:                            CONTACT_ZIP,
116:                            "if (contact.address == null, true, contact.zip != null)",
117:                            "Please enter a zip code for the address");
118:                    addExpressionRule(
119:                            CONTACT_ZIP,
120:                            "if (contact.zip == null, true, contact.zip.length() == 5)",
121:                            "Zip should be five digits");
122:                    addRequiredRule(CONTACT_MAIN_PHONE,
123:                            "Main Phone must have a value.");
124:                } catch (DataStoreException e) {
125:                    com.salmonllc.util.MessageLog.writeErrorMessage(e, this );
126:                }
127:
128:                //$CUSTOMCONSTRUCTOR$
129:                //Put custom constructor code between these comments, otherwise it be overwritten if the model is regenerated
130:                try {
131:                    //add some custom validation rules
132:                    addExpressionRule(CONTACT_MAIN_PHONE, new PhoneValidation(
133:                            CONTACT_MAIN_PHONE, true),
134:                            "Main Phone must be at least ten digits.", false);
135:                    addExpressionRule(CONTACT_ALT_PHONE, new PhoneValidation(
136:                            CONTACT_ALT_PHONE, false),
137:                            "Alt Phone must be at least ten digits.", false);
138:                    addExpressionRule(CONTACT_CELL_PHONE, new PhoneValidation(
139:                            CONTACT_CELL_PHONE, false),
140:                            "Cell Phone must be at least ten digits.", false);
141:                    addExpressionRule(CONTACT_EMAIL_ADDRESS,
142:                            new EMailValidation(CONTACT_EMAIL_ADDRESS),
143:                            "Invalid email address entered.", false);
144:                    setAutoValidate(true);
145:                } catch (Exception ex) {
146:                }
147:                //$ENDCUSTOMCONSTRUCTOR$
148:
149:            }
150:
151:            /**
152:             * Retrieve the value of the contact.contact_id column for the current row.
153:             * @return int
154:             * @throws DataStoreException
155:             */
156:            public int getContactContactId() throws DataStoreException {
157:                return getInt(CONTACT_CONTACT_ID);
158:            }
159:
160:            /**
161:             * Retrieve the value of the contact.contact_id column for the specified row.
162:             * @param row which row in the table
163:             * @return int
164:             * @throws DataStoreException
165:             */
166:            public int getContactContactId(int row) throws DataStoreException {
167:                return getInt(row, CONTACT_CONTACT_ID);
168:            }
169:
170:            /**
171:             * Set the value of the contact.contact_id column for the current row.
172:             * @param newValue the new item value
173:             * @throws DataStoreException
174:             */
175:            public void setContactContactId(int newValue)
176:                    throws DataStoreException {
177:                setInt(CONTACT_CONTACT_ID, newValue);
178:            }
179:
180:            /**
181:             * Set the value of the contact.contact_id column for the specified row.
182:             * @param row which row in the table
183:             * @param newValue the new item value
184:             * @throws DataStoreException
185:             */
186:            public void setContactContactId(int row, int newValue)
187:                    throws DataStoreException {
188:                setInt(row, CONTACT_CONTACT_ID, newValue);
189:            }
190:
191:            /**
192:             * Retrieve the value of the contact.first_name column for the current row.
193:             * @return String
194:             * @throws DataStoreException
195:             */
196:            public String getContactFirstName() throws DataStoreException {
197:                return getString(CONTACT_FIRST_NAME);
198:            }
199:
200:            /**
201:             * Retrieve the value of the contact.first_name column for the specified row.
202:             * @param row which row in the table
203:             * @return String
204:             * @throws DataStoreException
205:             */
206:            public String getContactFirstName(int row)
207:                    throws DataStoreException {
208:                return getString(row, CONTACT_FIRST_NAME);
209:            }
210:
211:            /**
212:             * Set the value of the contact.first_name column for the current row.
213:             * @param newValue the new item value
214:             * @throws DataStoreException
215:             */
216:            public void setContactFirstName(String newValue)
217:                    throws DataStoreException {
218:                setString(CONTACT_FIRST_NAME, newValue);
219:            }
220:
221:            /**
222:             * Set the value of the contact.first_name column for the specified row.
223:             * @param row which row in the table
224:             * @param newValue the new item value
225:             * @throws DataStoreException
226:             */
227:            public void setContactFirstName(int row, String newValue)
228:                    throws DataStoreException {
229:                setString(row, CONTACT_FIRST_NAME, newValue);
230:            }
231:
232:            /**
233:             * Retrieve the value of the contact.last_name column for the current row.
234:             * @return String
235:             * @throws DataStoreException
236:             */
237:            public String getContactLastName() throws DataStoreException {
238:                return getString(CONTACT_LAST_NAME);
239:            }
240:
241:            /**
242:             * Retrieve the value of the contact.last_name column for the specified row.
243:             * @param row which row in the table
244:             * @return String
245:             * @throws DataStoreException
246:             */
247:            public String getContactLastName(int row) throws DataStoreException {
248:                return getString(row, CONTACT_LAST_NAME);
249:            }
250:
251:            /**
252:             * Set the value of the contact.last_name column for the current row.
253:             * @param newValue the new item value
254:             * @throws DataStoreException
255:             */
256:            public void setContactLastName(String newValue)
257:                    throws DataStoreException {
258:                setString(CONTACT_LAST_NAME, newValue);
259:            }
260:
261:            /**
262:             * Set the value of the contact.last_name column for the specified row.
263:             * @param row which row in the table
264:             * @param newValue the new item value
265:             * @throws DataStoreException
266:             */
267:            public void setContactLastName(int row, String newValue)
268:                    throws DataStoreException {
269:                setString(row, CONTACT_LAST_NAME, newValue);
270:            }
271:
272:            /**
273:             * Retrieve the value of the contact.address column for the current row.
274:             * @return String
275:             * @throws DataStoreException
276:             */
277:            public String getContactAddress() throws DataStoreException {
278:                return getString(CONTACT_ADDRESS);
279:            }
280:
281:            /**
282:             * Retrieve the value of the contact.address column for the specified row.
283:             * @param row which row in the table
284:             * @return String
285:             * @throws DataStoreException
286:             */
287:            public String getContactAddress(int row) throws DataStoreException {
288:                return getString(row, CONTACT_ADDRESS);
289:            }
290:
291:            /**
292:             * Set the value of the contact.address column for the current row.
293:             * @param newValue the new item value
294:             * @throws DataStoreException
295:             */
296:            public void setContactAddress(String newValue)
297:                    throws DataStoreException {
298:                setString(CONTACT_ADDRESS, newValue);
299:            }
300:
301:            /**
302:             * Set the value of the contact.address column for the specified row.
303:             * @param row which row in the table
304:             * @param newValue the new item value
305:             * @throws DataStoreException
306:             */
307:            public void setContactAddress(int row, String newValue)
308:                    throws DataStoreException {
309:                setString(row, CONTACT_ADDRESS, newValue);
310:            }
311:
312:            /**
313:             * Retrieve the value of the contact.city column for the current row.
314:             * @return String
315:             * @throws DataStoreException
316:             */
317:            public String getContactCity() throws DataStoreException {
318:                return getString(CONTACT_CITY);
319:            }
320:
321:            /**
322:             * Retrieve the value of the contact.city column for the specified row.
323:             * @param row which row in the table
324:             * @return String
325:             * @throws DataStoreException
326:             */
327:            public String getContactCity(int row) throws DataStoreException {
328:                return getString(row, CONTACT_CITY);
329:            }
330:
331:            /**
332:             * Set the value of the contact.city column for the current row.
333:             * @param newValue the new item value
334:             * @throws DataStoreException
335:             */
336:            public void setContactCity(String newValue)
337:                    throws DataStoreException {
338:                setString(CONTACT_CITY, newValue);
339:            }
340:
341:            /**
342:             * Set the value of the contact.city column for the specified row.
343:             * @param row which row in the table
344:             * @param newValue the new item value
345:             * @throws DataStoreException
346:             */
347:            public void setContactCity(int row, String newValue)
348:                    throws DataStoreException {
349:                setString(row, CONTACT_CITY, newValue);
350:            }
351:
352:            /**
353:             * Retrieve the value of the contact.state column for the current row.
354:             * @return String
355:             * @throws DataStoreException
356:             */
357:            public String getContactState() throws DataStoreException {
358:                return getString(CONTACT_STATE);
359:            }
360:
361:            /**
362:             * Retrieve the value of the contact.state column for the specified row.
363:             * @param row which row in the table
364:             * @return String
365:             * @throws DataStoreException
366:             */
367:            public String getContactState(int row) throws DataStoreException {
368:                return getString(row, CONTACT_STATE);
369:            }
370:
371:            /**
372:             * Set the value of the contact.state column for the current row.
373:             * @param newValue the new item value
374:             * @throws DataStoreException
375:             */
376:            public void setContactState(String newValue)
377:                    throws DataStoreException {
378:                setString(CONTACT_STATE, newValue);
379:            }
380:
381:            /**
382:             * Set the value of the contact.state column for the specified row.
383:             * @param row which row in the table
384:             * @param newValue the new item value
385:             * @throws DataStoreException
386:             */
387:            public void setContactState(int row, String newValue)
388:                    throws DataStoreException {
389:                setString(row, CONTACT_STATE, newValue);
390:            }
391:
392:            /**
393:             * Retrieve the value of the contact.zip column for the current row.
394:             * @return String
395:             * @throws DataStoreException
396:             */
397:            public String getContactZip() throws DataStoreException {
398:                return getString(CONTACT_ZIP);
399:            }
400:
401:            /**
402:             * Retrieve the value of the contact.zip column for the specified row.
403:             * @param row which row in the table
404:             * @return String
405:             * @throws DataStoreException
406:             */
407:            public String getContactZip(int row) throws DataStoreException {
408:                return getString(row, CONTACT_ZIP);
409:            }
410:
411:            /**
412:             * Set the value of the contact.zip column for the current row.
413:             * @param newValue the new item value
414:             * @throws DataStoreException
415:             */
416:            public void setContactZip(String newValue)
417:                    throws DataStoreException {
418:                setString(CONTACT_ZIP, newValue);
419:            }
420:
421:            /**
422:             * Set the value of the contact.zip column for the specified row.
423:             * @param row which row in the table
424:             * @param newValue the new item value
425:             * @throws DataStoreException
426:             */
427:            public void setContactZip(int row, String newValue)
428:                    throws DataStoreException {
429:                setString(row, CONTACT_ZIP, newValue);
430:            }
431:
432:            /**
433:             * Retrieve the value of the contact.main_phone column for the current row.
434:             * @return String
435:             * @throws DataStoreException
436:             */
437:            public String getContactMainPhone() throws DataStoreException {
438:                return getString(CONTACT_MAIN_PHONE);
439:            }
440:
441:            /**
442:             * Retrieve the value of the contact.main_phone column for the specified row.
443:             * @param row which row in the table
444:             * @return String
445:             * @throws DataStoreException
446:             */
447:            public String getContactMainPhone(int row)
448:                    throws DataStoreException {
449:                return getString(row, CONTACT_MAIN_PHONE);
450:            }
451:
452:            /**
453:             * Set the value of the contact.main_phone column for the current row.
454:             * @param newValue the new item value
455:             * @throws DataStoreException
456:             */
457:            public void setContactMainPhone(String newValue)
458:                    throws DataStoreException {
459:                setString(CONTACT_MAIN_PHONE, newValue);
460:            }
461:
462:            /**
463:             * Set the value of the contact.main_phone column for the specified row.
464:             * @param row which row in the table
465:             * @param newValue the new item value
466:             * @throws DataStoreException
467:             */
468:            public void setContactMainPhone(int row, String newValue)
469:                    throws DataStoreException {
470:                setString(row, CONTACT_MAIN_PHONE, newValue);
471:            }
472:
473:            /**
474:             * Retrieve the value of the contact.alt_phone column for the current row.
475:             * @return String
476:             * @throws DataStoreException
477:             */
478:            public String getContactAltPhone() throws DataStoreException {
479:                return getString(CONTACT_ALT_PHONE);
480:            }
481:
482:            /**
483:             * Retrieve the value of the contact.alt_phone column for the specified row.
484:             * @param row which row in the table
485:             * @return String
486:             * @throws DataStoreException
487:             */
488:            public String getContactAltPhone(int row) throws DataStoreException {
489:                return getString(row, CONTACT_ALT_PHONE);
490:            }
491:
492:            /**
493:             * Set the value of the contact.alt_phone column for the current row.
494:             * @param newValue the new item value
495:             * @throws DataStoreException
496:             */
497:            public void setContactAltPhone(String newValue)
498:                    throws DataStoreException {
499:                setString(CONTACT_ALT_PHONE, newValue);
500:            }
501:
502:            /**
503:             * Set the value of the contact.alt_phone column for the specified row.
504:             * @param row which row in the table
505:             * @param newValue the new item value
506:             * @throws DataStoreException
507:             */
508:            public void setContactAltPhone(int row, String newValue)
509:                    throws DataStoreException {
510:                setString(row, CONTACT_ALT_PHONE, newValue);
511:            }
512:
513:            /**
514:             * Retrieve the value of the contact.cell_phone column for the current row.
515:             * @return String
516:             * @throws DataStoreException
517:             */
518:            public String getContactCellPhone() throws DataStoreException {
519:                return getString(CONTACT_CELL_PHONE);
520:            }
521:
522:            /**
523:             * Retrieve the value of the contact.cell_phone column for the specified row.
524:             * @param row which row in the table
525:             * @return String
526:             * @throws DataStoreException
527:             */
528:            public String getContactCellPhone(int row)
529:                    throws DataStoreException {
530:                return getString(row, CONTACT_CELL_PHONE);
531:            }
532:
533:            /**
534:             * Set the value of the contact.cell_phone column for the current row.
535:             * @param newValue the new item value
536:             * @throws DataStoreException
537:             */
538:            public void setContactCellPhone(String newValue)
539:                    throws DataStoreException {
540:                setString(CONTACT_CELL_PHONE, newValue);
541:            }
542:
543:            /**
544:             * Set the value of the contact.cell_phone column for the specified row.
545:             * @param row which row in the table
546:             * @param newValue the new item value
547:             * @throws DataStoreException
548:             */
549:            public void setContactCellPhone(int row, String newValue)
550:                    throws DataStoreException {
551:                setString(row, CONTACT_CELL_PHONE, newValue);
552:            }
553:
554:            /**
555:             * Retrieve the value of the contact.email_address column for the current row.
556:             * @return String
557:             * @throws DataStoreException
558:             */
559:            public String getContactEmailAddress() throws DataStoreException {
560:                return getString(CONTACT_EMAIL_ADDRESS);
561:            }
562:
563:            /**
564:             * Retrieve the value of the contact.email_address column for the specified row.
565:             * @param row which row in the table
566:             * @return String
567:             * @throws DataStoreException
568:             */
569:            public String getContactEmailAddress(int row)
570:                    throws DataStoreException {
571:                return getString(row, CONTACT_EMAIL_ADDRESS);
572:            }
573:
574:            /**
575:             * Set the value of the contact.email_address column for the current row.
576:             * @param newValue the new item value
577:             * @throws DataStoreException
578:             */
579:            public void setContactEmailAddress(String newValue)
580:                    throws DataStoreException {
581:                setString(CONTACT_EMAIL_ADDRESS, newValue);
582:            }
583:
584:            /**
585:             * Set the value of the contact.email_address column for the specified row.
586:             * @param row which row in the table
587:             * @param newValue the new item value
588:             * @throws DataStoreException
589:             */
590:            public void setContactEmailAddress(int row, String newValue)
591:                    throws DataStoreException {
592:                setString(row, CONTACT_EMAIL_ADDRESS, newValue);
593:            }
594:
595:            //$CUSTOMMETHODS$
596:            //Put custom methods between these comments, otherwise they will be overwritten if the model is regenerated
597:            /**
598:             * This method gets fired before each remote request to the DataStore is made (including the create method).
599:             * @return true if the request should be granted and false if the request should be denied.
600:             * @param reqType The type of request being made. See operation constants for valid values.
601:             * @param req javax.servlet.http.HttpServletRequest The servlet request used.
602:             * @param sessionValid true if this request came from a valid session or false if a new one had to be created.
603:             * @param userID The user id making the request
604:             * @param password The password of the user id making the request
605:             * @param criteria The selection criteria passed from the request
606:             */
607:            public boolean request(String reqType, HttpServletRequest req,
608:                    boolean sessionValid, String userID, String password,
609:                    String criteria) throws DataStoreException {
610:                //allow all requests
611:                return true;
612:            }
613:
614:            /**
615:             * Override the update method so that the contact id is generated for all new rows and every modified row is validated.
616:             */
617:            public void update(DBConnection conn, boolean handleTrans)
618:                    throws DataStoreException, SQLException {
619:                _nextID = -1;
620:                for (int i = 0; i < getRowCount(); i++) {
621:                    if (getRowStatus(i) == STATUS_NEW_MODIFIED)
622:                        generateContactID(conn, i);
623:                }
624:                super .update(conn, handleTrans);
625:            }
626:
627:            /**
628:             * This method generates the next contact id using the max function in sql.
629:             * The "getMax" technique generally should not be used in a real world application due to concurrency considerations
630:             * but is used here for the sake of simplicity.
631:             */
632:            private void generateContactID(DBConnection conn, int row)
633:                    throws DataStoreException {
634:                if (getContactContactId() > 0)
635:                    return;
636:
637:                if (_nextID != -1) {
638:                    setContactContactId(row, _nextID++);
639:                    return;
640:                }
641:
642:                int nextID = 1;
643:                try {
644:                    String selectID = "select max(contact_id) from contact";
645:
646:                    Statement st = conn.createStatement();
647:
648:                    ResultSet r = st.executeQuery(selectID);
649:                    if (r.next())
650:                        nextID = r.getInt(1) + 1;
651:
652:                    r.close();
653:                    st.close();
654:                } catch (Exception e) {
655:                    MessageLog.writeErrorMessage("getNextContactID", e, this );
656:                }
657:                setContactContactId(row, nextID);
658:                _nextID = nextID + 1;
659:            }
660:            //$ENDCUSTOMMETHODS$
661:
662:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.