Clover coverage report - Ledge Components - SNAPSHOT
Coverage timestamp: Fri Nov 17 2006 05:13:20 CET
file stats: LOC: 249   Methods: 8
NCLOC: 157   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DBJobDescriptor.java 50% 81.7% 100% 74.5%
coverage coverage
 1    //
 2    //Copyright (c) 2003, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
 3    //All rights reserved.
 4    //
 5    //Redistribution and use in source and binary forms, with or without modification,
 6    //are permitted provided that the following conditions are met:
 7    //
 8    //* Redistributions of source code must retain the above copyright notice,
 9    //this list of conditions and the following disclaimer.
 10    //* Redistributions in binary form must reproduce the above copyright notice,
 11    //this list of conditions and the following disclaimer in the documentation
 12    //and/or other materials provided with the distribution.
 13    //* Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
 14    //nor the names of its contributors may be used to endorse or promote products
 15    //derived from this software without specific prior written permission.
 16    //
 17    //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 18    //AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19    //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 20    //IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 21    //INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 22    //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 23    //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 24    //WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 25    //ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 26    //POSSIBILITY OF SUCH DAMAGE.
 27    //
 28   
 29    package org.objectledge.scheduler.db;
 30   
 31    import org.objectledge.database.persistence.InputRecord;
 32    import org.objectledge.database.persistence.OutputRecord;
 33    import org.objectledge.database.persistence.Persistence;
 34    import org.objectledge.database.persistence.PersistenceException;
 35    import org.objectledge.database.persistence.Persistent;
 36    import org.objectledge.scheduler.AbstractJobDescriptor;
 37    import org.objectledge.scheduler.AbstractScheduler;
 38    import org.objectledge.scheduler.InvalidScheduleException;
 39    import org.objectledge.scheduler.JobModificationException;
 40    import org.objectledge.scheduler.Schedule;
 41   
 42    /**
 43    * Persistent scheduled job descriptor based on database.
 44    *
 45    * @author <a href="mailto:pablo@caltha.pl">Pawel Potempski</a>
 46    */
 47    public class DBJobDescriptor extends AbstractJobDescriptor
 48    implements Persistent
 49    {
 50    // constants /////////////////////////////////////////////////////////////
 51   
 52    /** The table name. */
 53    public static final String TABLE_NAME = "ledge_scheduler";
 54   
 55    /** The key columns. */
 56    public static final String[] KEY_COLUMNS = new String[] { "job_id" };
 57   
 58    // instance variables ////////////////////////////////////////////////////
 59   
 60    /** The persistence. */
 61    private Persistence persistence;
 62   
 63    /** The scheduler */
 64    private AbstractScheduler scheduler;
 65   
 66    /** The job id. */
 67    private long jobId = -1L;
 68   
 69    /**
 70    * Constructor.
 71    *
 72    * @param persistence the persitence component.
 73    * @param scheduler the scheduler component.
 74    */
 75  1426 DBJobDescriptor(Persistence persistence, AbstractScheduler scheduler)
 76    {
 77  1426 this.persistence = persistence;
 78  1426 this.scheduler = scheduler;
 79    }
 80   
 81    // Persistent interface //////////////////////////////////////////////////
 82   
 83    /**
 84    * Returns the name of the table this type is mapped to.
 85    *
 86    * @return the name of the table.
 87    */
 88  1150 public String getTable()
 89    {
 90  1150 return TABLE_NAME;
 91    }
 92   
 93    /**
 94    * Returns the names of the key columns.
 95    *
 96    * @return the names of the key columns.
 97    */
 98  2116 public String[] getKeyColumns()
 99    {
 100  2116 return KEY_COLUMNS;
 101    }
 102   
 103    /**
 104    * {@inheritDoc}
 105    */
 106  368 public void getData(OutputRecord record) throws PersistenceException
 107    {
 108  368 record.setLong("job_id", jobId);
 109  368 record.setString("job_name", getName());
 110  368 record.setString("schedule_type", getSchedule().getType());
 111  368 record.setString("schedule_config", getSchedule().getConfig());
 112  368 record.setString("job_class_name", getJobClassName());
 113  368 if (getArgument() != null)
 114    {
 115  0 record.setString("argument", getArgument());
 116    }
 117    else
 118    {
 119  368 record.setNull("argument");
 120    }
 121  368 record.setInteger("run_count", getRunCount());
 122  368 record.setInteger("run_count_limit", getRunCountLimit());
 123  368 if (getLastRunTime() != null)
 124    {
 125  0 record.setTimestamp("last_run_time", getLastRunTime());
 126    }
 127    else
 128    {
 129  368 record.setNull("last_run_time");
 130    }
 131  368 if (getTimeLimitStart() != null)
 132    {
 133  0 record.setTimestamp("run_time_limit_start", getTimeLimitStart());
 134    }
 135    else
 136    {
 137  368 record.setNull("run_time_limit_start");
 138    }
 139  368 if (getTimeLimitEnd() != null)
 140    {
 141  0 record.setTimestamp("run_time_limit_end", getTimeLimitEnd());
 142    }
 143    else
 144    {
 145  368 record.setNull("run_time_limit_end");
 146    }
 147  368 record.setBoolean("reentrant", isReentrant());
 148  368 record.setBoolean("enabled", isEnabled());
 149    }
 150   
 151    /**
 152    * {@inheritDoc}
 153    */
 154  828 public void setData(InputRecord record) throws PersistenceException
 155    {
 156  828 jobId = record.getLong("job_id");
 157  828 String name = record.getString("job_name");
 158  828 String scheduleType = record.getString("schedule_type");
 159  828 String scheduleConfig = record.getString("schedule_config");
 160  828 String jobClassName = record.getString("job_class_name");
 161  828 Schedule schedule = null;
 162  828 try
 163    {
 164  828 schedule = scheduler.createSchedule(scheduleType, scheduleConfig);
 165    }
 166    catch (InvalidScheduleException e)
 167    {
 168  0 throw new PersistenceException("failed to create schedule", e);
 169    }
 170  828 try
 171    {
 172  828 super.init(name, schedule, jobClassName);
 173  828 if (!record.isNull("argument"))
 174    {
 175  0 argument = record.getString("argument");
 176    }
 177  828 if (!record.isNull("run_count"))
 178    {
 179  828 runCount = record.getInteger("run_count");
 180    }
 181  828 if (!record.isNull("run_count_limit"))
 182    {
 183  828 runCountLimit = record.getInteger("run_count_limit");
 184    }
 185  828 if (!record.isNull("last_run_time"))
 186    {
 187  0 lastRunTime = record.getDate("last_run_time");
 188    }
 189  828 if (!record.isNull("run_time_limit_start"))
 190    {
 191  0 runTimeLimitStart = record.getDate("run_time_limit_start");
 192    }
 193  828 if (!record.isNull("run_time_limit_end"))
 194    {
 195  0 runTimeLimitEnd = record.getDate("run_time_limit_end");
 196    }
 197  828 if (!record.isNull("auto_clean"))
 198    {
 199  828 autoClean = record.getBoolean("auto_clean");
 200    }
 201  828 if (!record.isNull("reentrant"))
 202    {
 203  828 reentrant = record.getBoolean("reentrant");
 204    }
 205  828 if (!record.isNull("enabled"))
 206    {
 207  828 enabled = record.getBoolean("enabled");
 208    }
 209    }
 210    catch (Exception e)
 211    {
 212  0 throw new PersistenceException("Failed to initialize scheduled job", e);
 213    }
 214    }
 215   
 216    /**
 217    * {@inheritDoc}
 218    */
 219  322 public boolean getSaved()
 220    {
 221  322 return jobId != -1L;
 222    }
 223   
 224    /**
 225    * {@inheritDoc}
 226    */
 227  966 public void setSaved(long id)
 228    {
 229  966 this.jobId = id;
 230    }
 231   
 232    // implementation ////////////////////////////////////////////////////////
 233   
 234    /**
 235    * {@inheritDoc}
 236    */
 237  184 protected void saveChanges() throws JobModificationException
 238    {
 239  184 try
 240    {
 241  184 persistence.save(this);
 242    }
 243    catch (PersistenceException e)
 244    {
 245  0 throw new JobModificationException("failed to save job state", e);
 246    }
 247    }
 248   
 249    }