Source Code Cross Referenced for OracleDelegate.java in  » Project-Management » quartz » org » quartz » impl » jdbcjobstore » oracle » 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 » Project Management » quartz » org.quartz.impl.jdbcjobstore.oracle 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright 2004-2005 OpenSymphony 
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
005:         * use this file except in compliance with the License. You may obtain a copy 
006:         * of the License at 
007:         * 
008:         *   http://www.apache.org/licenses/LICENSE-2.0 
009:         *   
010:         * Unless required by applicable law or agreed to in writing, software 
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
013:         * License for the specific language governing permissions and limitations 
014:         * under the License.
015:         * 
016:         */
017:
018:        /*
019:         * Previously Copyright (c) 2001-2004 James House
020:         */
021:        package org.quartz.impl.jdbcjobstore.oracle;
022:
023:        import java.io.ByteArrayOutputStream;
024:        import java.io.IOException;
025:        import java.io.InputStream;
026:        import java.io.ObjectInputStream;
027:        import java.math.BigDecimal;
028:        import java.sql.Blob;
029:        import java.sql.Connection;
030:        import java.sql.PreparedStatement;
031:        import java.sql.ResultSet;
032:        import java.sql.SQLException;
033:
034:        import org.apache.commons.logging.Log;
035:        import org.quartz.Calendar;
036:        import org.quartz.CronTrigger;
037:        import org.quartz.JobDetail;
038:        import org.quartz.SimpleTrigger;
039:        import org.quartz.Trigger;
040:        import org.quartz.impl.jdbcjobstore.StdJDBCDelegate;
041:
042:        /**
043:         * <p>
044:         * This is a driver delegate for the Oracle JDBC driver. To use this delegate,
045:         * <code>jdbcDriverVendor</code> should be configured as 'Oracle' with any
046:         * <code>jdbcDriverVersion</code>.
047:         * </p>
048:         * 
049:         * @see org.quartz.impl.jdbcjobstore.WebLogicDelegate
050:         * @see org.quartz.impl.jdbcjobstore.oracle.weblogic.WebLogicOracleDelegate
051:         * @author James House
052:         * @author Patrick Lightbody
053:         * @author Eric Mueller
054:         */
055:        public class OracleDelegate extends StdJDBCDelegate {
056:            /**
057:             * <p>
058:             * Create new OrcaleDelegate instance.
059:             * </p>
060:             * 
061:             * @param logger
062:             *          the logger to use during execution
063:             * @param tablePrefix
064:             *          the prefix of all table names
065:             */
066:            public OracleDelegate(Log logger, String tablePrefix,
067:                    String instanceId) {
068:                super (logger, tablePrefix, instanceId);
069:            }
070:
071:            /**
072:             * <p>
073:             * Create new OrcaleDelegate instance.
074:             * </p>
075:             * 
076:             * @param logger
077:             *          the logger to use during execution
078:             * @param tablePrefix
079:             *          the prefix of all table names
080:             * @param useProperties
081:             *          use java.util.Properties for storage
082:             */
083:            public OracleDelegate(Log logger, String tablePrefix,
084:                    String instanceId, Boolean useProperties) {
085:                super (logger, tablePrefix, instanceId, useProperties);
086:            }
087:
088:            public static final String UPDATE_ORACLE_JOB_DETAIL = "UPDATE "
089:                    + TABLE_PREFIX_SUBST + TABLE_JOB_DETAILS + " SET "
090:                    + COL_DESCRIPTION + " = ?, " + COL_JOB_CLASS + " = ?, "
091:                    + COL_IS_DURABLE + " = ?, " + COL_IS_VOLATILE + " = ?, "
092:                    + COL_IS_STATEFUL + " = ?, " + COL_REQUESTS_RECOVERY
093:                    + " = ? " + " WHERE " + COL_JOB_NAME + " = ? AND "
094:                    + COL_JOB_GROUP + " = ?";
095:
096:            public static final String UPDATE_ORACLE_JOB_DETAIL_BLOB = "UPDATE "
097:                    + TABLE_PREFIX_SUBST
098:                    + TABLE_JOB_DETAILS
099:                    + " SET "
100:                    + COL_JOB_DATAMAP
101:                    + " = ? "
102:                    + " WHERE "
103:                    + COL_JOB_NAME
104:                    + " = ? AND " + COL_JOB_GROUP + " = ?";
105:
106:            public static final String UPDATE_ORACLE_JOB_DETAIL_EMPTY_BLOB = "UPDATE "
107:                    + TABLE_PREFIX_SUBST
108:                    + TABLE_JOB_DETAILS
109:                    + " SET "
110:                    + COL_JOB_DATAMAP
111:                    + " = EMPTY_BLOB() "
112:                    + " WHERE "
113:                    + COL_JOB_NAME + " = ? AND " + COL_JOB_GROUP + " = ?";
114:
115:            public static final String SELECT_ORACLE_JOB_DETAIL_BLOB = "SELECT "
116:                    + COL_JOB_DATAMAP
117:                    + " FROM "
118:                    + TABLE_PREFIX_SUBST
119:                    + TABLE_JOB_DETAILS
120:                    + " WHERE "
121:                    + COL_JOB_NAME
122:                    + " = ? AND " + COL_JOB_GROUP + " = ? FOR UPDATE";
123:
124:            public static final String UPDATE_ORACLE_TRIGGER = "UPDATE "
125:                    + TABLE_PREFIX_SUBST + TABLE_TRIGGERS + " SET "
126:                    + COL_JOB_NAME + " = ?, " + COL_JOB_GROUP + " = ?, "
127:                    + COL_IS_VOLATILE + " = ?, " + COL_DESCRIPTION + " = ?, "
128:                    + COL_NEXT_FIRE_TIME + " = ?, " + COL_PREV_FIRE_TIME
129:                    + " = ?, " + COL_TRIGGER_STATE + " = ?, "
130:                    + COL_TRIGGER_TYPE + " = ?, " + COL_START_TIME + " = ?, "
131:                    + COL_END_TIME + " = ?, " + COL_CALENDAR_NAME + " = ?, "
132:                    + COL_MISFIRE_INSTRUCTION + " = ?, " + COL_PRIORITY
133:                    + " = ? WHERE " + COL_TRIGGER_NAME + " = ? AND "
134:                    + COL_TRIGGER_GROUP + " = ?";
135:
136:            public static final String SELECT_ORACLE_TRIGGER_JOB_DETAIL_BLOB = "SELECT "
137:                    + COL_JOB_DATAMAP
138:                    + " FROM "
139:                    + TABLE_PREFIX_SUBST
140:                    + TABLE_TRIGGERS
141:                    + " WHERE "
142:                    + COL_TRIGGER_NAME
143:                    + " = ? AND " + COL_TRIGGER_GROUP + " = ? FOR UPDATE";
144:
145:            public static final String UPDATE_ORACLE_TRIGGER_JOB_DETAIL_BLOB = "UPDATE "
146:                    + TABLE_PREFIX_SUBST
147:                    + TABLE_TRIGGERS
148:                    + " SET "
149:                    + COL_JOB_DATAMAP
150:                    + " = ? "
151:                    + " WHERE "
152:                    + COL_TRIGGER_NAME
153:                    + " = ? AND " + COL_TRIGGER_GROUP + " = ?";
154:
155:            public static final String UPDATE_ORACLE_TRIGGER_JOB_DETAIL_EMPTY_BLOB = "UPDATE "
156:                    + TABLE_PREFIX_SUBST
157:                    + TABLE_TRIGGERS
158:                    + " SET "
159:                    + COL_JOB_DATAMAP
160:                    + " = EMPTY_BLOB() "
161:                    + " WHERE "
162:                    + COL_TRIGGER_NAME
163:                    + " = ? AND "
164:                    + COL_TRIGGER_GROUP
165:                    + " = ?";
166:
167:            public static final String INSERT_ORACLE_CALENDAR = "INSERT INTO "
168:                    + TABLE_PREFIX_SUBST + TABLE_CALENDARS + " ("
169:                    + COL_CALENDAR_NAME + ", " + COL_CALENDAR + ") "
170:                    + " VALUES(?, EMPTY_BLOB())";
171:
172:            public static final String SELECT_ORACLE_CALENDAR_BLOB = "SELECT "
173:                    + COL_CALENDAR + " FROM " + TABLE_PREFIX_SUBST
174:                    + TABLE_CALENDARS + " WHERE " + COL_CALENDAR_NAME
175:                    + " = ? FOR UPDATE";
176:
177:            public static final String UPDATE_ORACLE_CALENDAR_BLOB = "UPDATE "
178:                    + TABLE_PREFIX_SUBST + TABLE_CALENDARS + " SET "
179:                    + COL_CALENDAR + " = ? " + " WHERE " + COL_CALENDAR_NAME
180:                    + " = ?";
181:
182:            //---------------------------------------------------------------------------
183:            // protected methods that can be overridden by subclasses
184:            //---------------------------------------------------------------------------
185:
186:            protected Object getObjectFromBlob(ResultSet rs, String colName)
187:                    throws ClassNotFoundException, IOException, SQLException {
188:
189:                Object obj = null;
190:                InputStream binaryInput = rs.getBinaryStream(colName);
191:                if (binaryInput != null) {
192:                    ObjectInputStream in = new ObjectInputStream(binaryInput);
193:                    try {
194:                        obj = in.readObject();
195:                    } finally {
196:                        in.close();
197:                    }
198:                }
199:
200:                return obj;
201:            }
202:
203:            public int insertJobDetail(Connection conn, JobDetail job)
204:                    throws IOException, SQLException {
205:
206:                ByteArrayOutputStream baos = serializeJobData(job
207:                        .getJobDataMap());
208:                byte[] data = baos.toByteArray();
209:                PreparedStatement ps = null;
210:                ResultSet rs = null;
211:
212:                try {
213:                    ps = conn.prepareStatement(rtp(INSERT_JOB_DETAIL));
214:                    ps.setString(1, job.getName());
215:                    ps.setString(2, job.getGroup());
216:                    ps.setString(3, job.getDescription());
217:                    ps.setString(4, job.getJobClass().getName());
218:                    setBoolean(ps, 5, job.isDurable());
219:                    setBoolean(ps, 6, job.isVolatile());
220:                    setBoolean(ps, 7, job.isStateful());
221:                    setBoolean(ps, 8, job.requestsRecovery());
222:
223:                    ps.setBinaryStream(9, null, 0);
224:                    ps.executeUpdate();
225:                    ps.close();
226:
227:                    ps = conn
228:                            .prepareStatement(rtp(UPDATE_ORACLE_JOB_DETAIL_EMPTY_BLOB));
229:                    ps.setString(1, job.getName());
230:                    ps.setString(2, job.getGroup());
231:                    ps.executeUpdate();
232:                    ps.close();
233:
234:                    ps = conn
235:                            .prepareStatement(rtp(SELECT_ORACLE_JOB_DETAIL_BLOB));
236:                    ps.setString(1, job.getName());
237:                    ps.setString(2, job.getGroup());
238:
239:                    rs = ps.executeQuery();
240:
241:                    int res = 0;
242:
243:                    Blob dbBlob = null;
244:                    if (rs.next()) {
245:                        dbBlob = writeDataToBlob(rs, 1, data);
246:                    } else {
247:                        return res;
248:                    }
249:
250:                    rs.close();
251:                    ps.close();
252:
253:                    ps = conn
254:                            .prepareStatement(rtp(UPDATE_ORACLE_JOB_DETAIL_BLOB));
255:                    ps.setBlob(1, dbBlob);
256:                    ps.setString(2, job.getName());
257:                    ps.setString(3, job.getGroup());
258:
259:                    res = ps.executeUpdate();
260:
261:                    if (res > 0) {
262:                        String[] jobListeners = job.getJobListenerNames();
263:                        for (int i = 0; jobListeners != null
264:                                && i < jobListeners.length; i++) {
265:                            insertJobListener(conn, job, jobListeners[i]);
266:                        }
267:                    }
268:
269:                    return res;
270:                } finally {
271:                    closeResultSet(rs);
272:                    closeStatement(ps);
273:                }
274:
275:            }
276:
277:            protected Object getJobDetailFromBlob(ResultSet rs, String colName)
278:                    throws ClassNotFoundException, IOException, SQLException {
279:
280:                if (canUseProperties()) {
281:                    InputStream binaryInput = rs.getBinaryStream(colName);
282:                    return binaryInput;
283:                }
284:
285:                return getObjectFromBlob(rs, colName);
286:            }
287:
288:            public int updateJobDetail(Connection conn, JobDetail job)
289:                    throws IOException, SQLException {
290:
291:                ByteArrayOutputStream baos = serializeJobData(job
292:                        .getJobDataMap());
293:                byte[] data = baos.toByteArray();
294:
295:                PreparedStatement ps = null;
296:                PreparedStatement ps2 = null;
297:                ResultSet rs = null;
298:
299:                try {
300:                    ps = conn.prepareStatement(rtp(UPDATE_ORACLE_JOB_DETAIL));
301:                    ps.setString(1, job.getDescription());
302:                    ps.setString(2, job.getJobClass().getName());
303:                    setBoolean(ps, 3, job.isDurable());
304:                    setBoolean(ps, 4, job.isVolatile());
305:                    setBoolean(ps, 5, job.isStateful());
306:                    setBoolean(ps, 6, job.requestsRecovery());
307:                    ps.setString(7, job.getName());
308:                    ps.setString(8, job.getGroup());
309:
310:                    ps.executeUpdate();
311:                    ps.close();
312:
313:                    ps = conn
314:                            .prepareStatement(rtp(UPDATE_ORACLE_JOB_DETAIL_EMPTY_BLOB));
315:                    ps.setString(1, job.getName());
316:                    ps.setString(2, job.getGroup());
317:                    ps.executeUpdate();
318:                    ps.close();
319:
320:                    ps = conn
321:                            .prepareStatement(rtp(SELECT_ORACLE_JOB_DETAIL_BLOB));
322:                    ps.setString(1, job.getName());
323:                    ps.setString(2, job.getGroup());
324:
325:                    rs = ps.executeQuery();
326:
327:                    int res = 0;
328:
329:                    if (rs.next()) {
330:                        Blob dbBlob = writeDataToBlob(rs, 1, data);
331:                        ps2 = conn
332:                                .prepareStatement(rtp(UPDATE_ORACLE_JOB_DETAIL_BLOB));
333:
334:                        ps2.setBlob(1, dbBlob);
335:                        ps2.setString(2, job.getName());
336:                        ps2.setString(3, job.getGroup());
337:
338:                        res = ps2.executeUpdate();
339:                    }
340:
341:                    if (res > 0) {
342:                        deleteJobListeners(conn, job.getName(), job.getGroup());
343:                        String[] jobListeners = job.getJobListenerNames();
344:                        for (int i = 0; jobListeners != null
345:                                && i < jobListeners.length; i++) {
346:                            insertJobListener(conn, job, jobListeners[i]);
347:                        }
348:                    }
349:
350:                    return res;
351:
352:                } finally {
353:                    closeResultSet(rs);
354:                    closeStatement(ps);
355:                    closeStatement(ps2);
356:                }
357:            }
358:
359:            public int insertTrigger(Connection conn, Trigger trigger,
360:                    String state, JobDetail jobDetail) throws SQLException,
361:                    IOException {
362:
363:                byte[] data = null;
364:                if (trigger.getJobDataMap().size() > 0) {
365:                    data = serializeJobData(trigger.getJobDataMap())
366:                            .toByteArray();
367:                }
368:
369:                PreparedStatement ps = null;
370:                ResultSet rs = null;
371:
372:                int insertResult = 0;
373:
374:                try {
375:                    ps = conn.prepareStatement(rtp(INSERT_TRIGGER));
376:                    ps.setString(1, trigger.getName());
377:                    ps.setString(2, trigger.getGroup());
378:                    ps.setString(3, trigger.getJobName());
379:                    ps.setString(4, trigger.getJobGroup());
380:                    setBoolean(ps, 5, trigger.isVolatile());
381:                    ps.setString(6, trigger.getDescription());
382:                    ps.setBigDecimal(7, new BigDecimal(String.valueOf(trigger
383:                            .getNextFireTime().getTime())));
384:                    long prevFireTime = -1;
385:                    if (trigger.getPreviousFireTime() != null) {
386:                        prevFireTime = trigger.getPreviousFireTime().getTime();
387:                    }
388:                    ps.setBigDecimal(8, new BigDecimal(String
389:                            .valueOf(prevFireTime)));
390:                    ps.setString(9, state);
391:                    if (trigger.getClass() == SimpleTrigger.class) {
392:                        ps.setString(10, TTYPE_SIMPLE);
393:                    } else if (trigger.getClass() == CronTrigger.class) {
394:                        ps.setString(10, TTYPE_CRON);
395:                    } else {
396:                        ps.setString(10, TTYPE_BLOB);
397:                    }
398:                    ps.setBigDecimal(11, new BigDecimal(String.valueOf(trigger
399:                            .getStartTime().getTime())));
400:                    long endTime = 0;
401:                    if (trigger.getEndTime() != null) {
402:                        endTime = trigger.getEndTime().getTime();
403:                    }
404:                    ps.setBigDecimal(12,
405:                            new BigDecimal(String.valueOf(endTime)));
406:                    ps.setString(13, trigger.getCalendarName());
407:                    ps.setInt(14, trigger.getMisfireInstruction());
408:                    ps.setBinaryStream(15, null, 0);
409:                    ps.setInt(16, trigger.getPriority());
410:
411:                    insertResult = ps.executeUpdate();
412:
413:                    if (data != null) {
414:                        ps.close();
415:
416:                        ps = conn
417:                                .prepareStatement(rtp(UPDATE_ORACLE_TRIGGER_JOB_DETAIL_EMPTY_BLOB));
418:                        ps.setString(1, trigger.getName());
419:                        ps.setString(2, trigger.getGroup());
420:                        ps.executeUpdate();
421:                        ps.close();
422:
423:                        ps = conn
424:                                .prepareStatement(rtp(SELECT_ORACLE_TRIGGER_JOB_DETAIL_BLOB));
425:                        ps.setString(1, trigger.getName());
426:                        ps.setString(2, trigger.getGroup());
427:
428:                        rs = ps.executeQuery();
429:
430:                        int res = 0;
431:
432:                        Blob dbBlob = null;
433:                        if (rs.next()) {
434:                            dbBlob = writeDataToBlob(rs, 1, data);
435:                        } else {
436:                            return res;
437:                        }
438:
439:                        rs.close();
440:                        ps.close();
441:
442:                        ps = conn
443:                                .prepareStatement(rtp(UPDATE_ORACLE_TRIGGER_JOB_DETAIL_BLOB));
444:                        ps.setBlob(1, dbBlob);
445:                        ps.setString(2, trigger.getName());
446:                        ps.setString(3, trigger.getGroup());
447:
448:                        res = ps.executeUpdate();
449:                    }
450:
451:                } finally {
452:                    closeResultSet(rs);
453:                    closeStatement(ps);
454:                }
455:
456:                if (insertResult > 0) {
457:                    String[] trigListeners = trigger.getTriggerListenerNames();
458:                    for (int i = 0; trigListeners != null
459:                            && i < trigListeners.length; i++) {
460:                        insertTriggerListener(conn, trigger, trigListeners[i]);
461:                    }
462:                }
463:
464:                return insertResult;
465:            }
466:
467:            public int updateTrigger(Connection conn, Trigger trigger,
468:                    String state, JobDetail jobDetail) throws SQLException,
469:                    IOException {
470:
471:                // save some clock cycles by unnecessarily writing job data blob ...
472:                boolean updateJobData = trigger.getJobDataMap().isDirty();
473:                byte[] data = null;
474:                if (updateJobData && trigger.getJobDataMap().size() > 0) {
475:                    data = serializeJobData(trigger.getJobDataMap())
476:                            .toByteArray();
477:                }
478:
479:                PreparedStatement ps = null;
480:                PreparedStatement ps2 = null;
481:                ResultSet rs = null;
482:
483:                int insertResult = 0;
484:
485:                try {
486:                    ps = conn.prepareStatement(rtp(UPDATE_ORACLE_TRIGGER));
487:
488:                    ps.setString(1, trigger.getJobName());
489:                    ps.setString(2, trigger.getJobGroup());
490:                    setBoolean(ps, 3, trigger.isVolatile());
491:                    ps.setString(4, trigger.getDescription());
492:                    long nextFireTime = -1;
493:                    if (trigger.getNextFireTime() != null) {
494:                        nextFireTime = trigger.getNextFireTime().getTime();
495:                    }
496:                    ps.setBigDecimal(5, new BigDecimal(String
497:                            .valueOf(nextFireTime)));
498:                    long prevFireTime = -1;
499:                    if (trigger.getPreviousFireTime() != null) {
500:                        prevFireTime = trigger.getPreviousFireTime().getTime();
501:                    }
502:                    ps.setBigDecimal(6, new BigDecimal(String
503:                            .valueOf(prevFireTime)));
504:                    ps.setString(7, state);
505:                    if (trigger.getClass() == SimpleTrigger.class) {
506:                        //                updateSimpleTrigger(conn, (SimpleTrigger)trigger);
507:                        ps.setString(8, TTYPE_SIMPLE);
508:                    } else if (trigger.getClass() == CronTrigger.class) {
509:                        //                updateCronTrigger(conn, (CronTrigger)trigger);
510:                        ps.setString(8, TTYPE_CRON);
511:                    } else {
512:                        //                updateBlobTrigger(conn, trigger);
513:                        ps.setString(8, TTYPE_BLOB);
514:                    }
515:                    ps.setBigDecimal(9, new BigDecimal(String.valueOf(trigger
516:                            .getStartTime().getTime())));
517:                    long endTime = 0;
518:                    if (trigger.getEndTime() != null) {
519:                        endTime = trigger.getEndTime().getTime();
520:                    }
521:                    ps.setBigDecimal(10,
522:                            new BigDecimal(String.valueOf(endTime)));
523:                    ps.setString(11, trigger.getCalendarName());
524:                    ps.setInt(12, trigger.getMisfireInstruction());
525:                    ps.setInt(13, trigger.getPriority());
526:                    ps.setString(14, trigger.getName());
527:                    ps.setString(15, trigger.getGroup());
528:
529:                    insertResult = ps.executeUpdate();
530:
531:                    if (updateJobData) {
532:                        ps.close();
533:
534:                        ps = conn
535:                                .prepareStatement(rtp(UPDATE_ORACLE_TRIGGER_JOB_DETAIL_EMPTY_BLOB));
536:                        ps.setString(1, trigger.getName());
537:                        ps.setString(2, trigger.getGroup());
538:                        ps.executeUpdate();
539:                        ps.close();
540:
541:                        ps = conn
542:                                .prepareStatement(rtp(SELECT_ORACLE_TRIGGER_JOB_DETAIL_BLOB));
543:                        ps.setString(1, trigger.getName());
544:                        ps.setString(2, trigger.getGroup());
545:
546:                        rs = ps.executeQuery();
547:
548:                        int res = 0;
549:
550:                        if (rs.next()) {
551:                            Blob dbBlob = writeDataToBlob(rs, 1, data);
552:                            ps2 = conn
553:                                    .prepareStatement(rtp(UPDATE_ORACLE_TRIGGER_JOB_DETAIL_BLOB));
554:
555:                            ps2.setBlob(1, dbBlob);
556:                            ps2.setString(2, trigger.getName());
557:                            ps2.setString(3, trigger.getGroup());
558:
559:                            res = ps2.executeUpdate();
560:                        }
561:                    }
562:
563:                } finally {
564:                    closeResultSet(rs);
565:                    closeStatement(ps);
566:                    closeStatement(ps2);
567:                }
568:
569:                if (insertResult > 0) {
570:                    deleteTriggerListeners(conn, trigger.getName(), trigger
571:                            .getGroup());
572:
573:                    String[] trigListeners = trigger.getTriggerListenerNames();
574:                    for (int i = 0; trigListeners != null
575:                            && i < trigListeners.length; i++) {
576:                        insertTriggerListener(conn, trigger, trigListeners[i]);
577:                    }
578:                }
579:
580:                return insertResult;
581:            }
582:
583:            public int insertCalendar(Connection conn, String calendarName,
584:                    Calendar calendar) throws IOException, SQLException {
585:                ByteArrayOutputStream baos = serializeObject(calendar);
586:
587:                PreparedStatement ps = null;
588:                PreparedStatement ps2 = null;
589:                ResultSet rs = null;
590:
591:                try {
592:                    ps = conn.prepareStatement(rtp(INSERT_ORACLE_CALENDAR));
593:                    ps.setString(1, calendarName);
594:
595:                    ps.executeUpdate();
596:                    ps.close();
597:
598:                    ps = conn
599:                            .prepareStatement(rtp(SELECT_ORACLE_CALENDAR_BLOB));
600:                    ps.setString(1, calendarName);
601:
602:                    rs = ps.executeQuery();
603:
604:                    if (rs.next()) {
605:                        Blob dbBlob = writeDataToBlob(rs, 1, baos.toByteArray());
606:                        ps2 = conn
607:                                .prepareStatement(rtp(UPDATE_ORACLE_CALENDAR_BLOB));
608:
609:                        ps2.setBlob(1, dbBlob);
610:                        ps2.setString(2, calendarName);
611:
612:                        return ps2.executeUpdate();
613:                    }
614:
615:                    return 0;
616:
617:                } finally {
618:                    closeResultSet(rs);
619:                    closeStatement(ps);
620:                    closeStatement(ps2);
621:                }
622:            }
623:
624:            public int updateCalendar(Connection conn, String calendarName,
625:                    Calendar calendar) throws IOException, SQLException {
626:                ByteArrayOutputStream baos = serializeObject(calendar);
627:
628:                PreparedStatement ps = null;
629:                PreparedStatement ps2 = null;
630:                ResultSet rs = null;
631:
632:                try {
633:                    ps = conn
634:                            .prepareStatement(rtp(SELECT_ORACLE_CALENDAR_BLOB));
635:                    ps.setString(1, calendarName);
636:
637:                    rs = ps.executeQuery();
638:
639:                    if (rs.next()) {
640:                        Blob dbBlob = writeDataToBlob(rs, 1, baos.toByteArray());
641:                        ps2 = conn
642:                                .prepareStatement(rtp(UPDATE_ORACLE_CALENDAR_BLOB));
643:
644:                        ps2.setBlob(1, dbBlob);
645:                        ps2.setString(2, calendarName);
646:
647:                        return ps2.executeUpdate();
648:                    }
649:
650:                    return 0;
651:
652:                } finally {
653:                    closeResultSet(rs);
654:                    closeStatement(ps);
655:                    closeStatement(ps2);
656:                }
657:            }
658:
659:            public int updateJobData(Connection conn, JobDetail job)
660:                    throws IOException, SQLException {
661:
662:                ByteArrayOutputStream baos = serializeJobData(job
663:                        .getJobDataMap());
664:                byte[] data = baos.toByteArray();
665:
666:                PreparedStatement ps = null;
667:                PreparedStatement ps2 = null;
668:                ResultSet rs = null;
669:
670:                try {
671:                    ps = conn
672:                            .prepareStatement(rtp(SELECT_ORACLE_JOB_DETAIL_BLOB));
673:                    ps.setString(1, job.getName());
674:                    ps.setString(2, job.getGroup());
675:
676:                    rs = ps.executeQuery();
677:
678:                    int res = 0;
679:
680:                    if (rs.next()) {
681:                        Blob dbBlob = writeDataToBlob(rs, 1, data);
682:                        ps2 = conn
683:                                .prepareStatement(rtp(UPDATE_ORACLE_JOB_DETAIL_BLOB));
684:
685:                        ps2.setBlob(1, dbBlob);
686:                        ps2.setString(2, job.getName());
687:                        ps2.setString(3, job.getGroup());
688:
689:                        res = ps2.executeUpdate();
690:                    }
691:
692:                    return res;
693:                } finally {
694:                    closeResultSet(rs);
695:                    closeStatement(ps);
696:                    closeStatement(ps2);
697:                }
698:            }
699:
700:            protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data)
701:                    throws SQLException {
702:
703:                Blob blob = rs.getBlob(column); // get blob
704:
705:                if (blob == null) {
706:                    throw new SQLException(
707:                            "Driver's Blob representation is null!");
708:                }
709:
710:                if (blob instanceof  oracle.sql.BLOB) { // is it an oracle blob?
711:                    ((oracle.sql.BLOB) blob).putBytes(1, data);
712:                    return blob;
713:                } else {
714:                    throw new SQLException(
715:                            "Driver's Blob representation is of an unsupported type: "
716:                                    + blob.getClass().getName());
717:                }
718:            }
719:        }
720:
721:        // EOF
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.