View Javadoc
1 package org.apache.turbine.services.schedule; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache Turbine" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache Turbine", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>;. 55 */ 56 57 import com.workingdogs.village.Record; 58 import java.sql.Connection; 59 import java.util.ArrayList; 60 import java.util.Hashtable; 61 import java.util.List; 62 import org.apache.torque.TorqueException; 63 import org.apache.torque.om.ObjectKey; 64 import org.apache.torque.util.BasePeer; 65 import org.apache.torque.util.Criteria; 66 import org.apache.turbine.util.ObjectUtils; 67 import org.apache.turbine.util.db.map.TurbineMapBuilder; 68 69 /*** 70 * Peer class for JobEntry database access. 71 * 72 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> 73 * @version $Id: JobEntryPeer.java,v 1.3 2002/07/11 07:34:30 mpoeschl Exp $ 74 */ 75 public class JobEntryPeer extends BasePeer 76 { 77 /*** Get the MapBuilder. */ 78 private static final TurbineMapBuilder mapBuilder = 79 (TurbineMapBuilder) getMapBuilder("org.apache.turbine.util.db.map.TurbineMapBuilder"); 80 81 /*** Name of the table. */ 82 private static final String TABLE_NAME = mapBuilder.getTableJobentry(); 83 84 // Table name + column name. 85 public static final String OID = mapBuilder.getJobentry_JobId(); 86 public static final String SECOND = mapBuilder.getJobentry_Second(); 87 public static final String MINUTE = mapBuilder.getJobentry_Minute(); 88 public static final String HOUR = mapBuilder.getJobentry_Hour(); 89 public static final String WEEKDAY = mapBuilder.getJobentry_Weekday(); 90 public static final String DAY_OF_MONTH = mapBuilder.getJobentry_DayOfMonth(); 91 public static final String TASK = mapBuilder.getJobentry_Task(); 92 public static final String EMAIL = mapBuilder.getJobentry_Email(); 93 public static final String PROPERTY = mapBuilder.getJobentry_Property(); 94 95 /*** 96 * Update an existing Job. 97 * 98 * @param Criteria The information to update. 99 * @exception Exception, a generic exception. 100 */ 101 public static void doUpdate(Criteria criteria) 102 throws TorqueException 103 { 104 Criteria selectCriteria = new Criteria(2); 105 selectCriteria.put( OID, criteria.remove(OID) ); 106 BasePeer.doUpdate( selectCriteria, criteria ); 107 } 108 109 /*** 110 * Called from the SchedulerService init() to batch load Jobs into 111 * the queue. 112 * 113 * @param Criteria The information for the where. 114 * @return Vector of JobEntries. 115 * @exception Exception, a generic exception. 116 */ 117 public static List doSelect(Criteria criteria) 118 throws TorqueException 119 { 120 addSelectColumns(criteria); 121 122 List rows = BasePeer.doSelect(criteria); 123 List results = new ArrayList(); 124 125 try 126 { 127 // Populate the object(s). 128 for ( int i=0; i<rows.size(); i++ ) 129 { 130 Record rec = (Record)rows.get(i); 131 int oid = rec.getValue(1).asInt(); 132 int sec = rec.getValue(2).asInt(); 133 int min = rec.getValue(3).asInt(); 134 int hr = rec.getValue(4).asInt(); 135 int wd = rec.getValue(5).asInt(); 136 int d_m = rec.getValue(6).asInt(); 137 String task = rec.getValue(7).asString(); 138 String email = rec.getValue(8).asString(); 139 byte[] objectData = (byte[]) rec.getValue(9).asBytes(); 140 Hashtable tempHash = (Hashtable) ObjectUtils.deserialize(objectData); 141 142 JobEntry je = new JobEntry(sec, min, hr, wd, d_m, task); 143 je.setPrimaryKey(oid); 144 je.setEmail(email); 145 je.setProperty(tempHash); 146 je.setModified(false); 147 148 results.add(je); 149 } 150 } 151 catch (Exception ex) 152 { 153 throw new TorqueException(ex); 154 } 155 return results; 156 } 157 158 /*** 159 * Perform a SQL <code>insert</code>, handling connection details 160 * internally. 161 */ 162 public static ObjectKey doInsert(Criteria criteria) 163 throws TorqueException 164 { 165 criteria.setDbName(mapBuilder.getDatabaseMap().getName()); 166 return BasePeer.doInsert(criteria); 167 } 168 169 /*** 170 * Method to do inserts. This method is to be used during a transaction, 171 * otherwise use the doInsert(Criteria) method. It will take care of 172 * the connection details internally. 173 */ 174 public static ObjectKey doInsert(Criteria criteria, Connection dbCon) 175 throws TorqueException 176 { 177 criteria.setDbName(mapBuilder.getDatabaseMap().getName()); 178 return BasePeer.doInsert(criteria, dbCon); 179 } 180 181 /*** 182 * Add all the columns needed to create a new object. 183 */ 184 protected static void addSelectColumns(Criteria criteria) 185 throws TorqueException 186 { 187 criteria.addSelectColumn(OID) 188 .addSelectColumn(SECOND) 189 .addSelectColumn(MINUTE) 190 .addSelectColumn(HOUR) 191 .addSelectColumn(WEEKDAY) 192 .addSelectColumn(DAY_OF_MONTH) 193 .addSelectColumn(TASK) 194 .addSelectColumn(EMAIL) 195 .addSelectColumn(PROPERTY); 196 } 197 198 /*** 199 * Retrieve a JobEntry based on its id. 200 * 201 * @param oid The JobEntry int id. 202 * @return A JobEntry. 203 * @exception Exception, a generic exception. 204 */ 205 public static JobEntry getJob(int oid) 206 throws Exception 207 { 208 JobEntry je = null; 209 210 Criteria c = new Criteria(9); 211 c.add(OID,new Integer(oid)); 212 213 List results = JobEntryPeer.doSelect(c); 214 215 if (results != null) 216 { 217 je = (JobEntry) results.get(0); 218 } 219 return je; 220 } 221 }

This page was automatically generated by Maven