From: <bla...@us...> - 2008-10-08 19:05:13
|
Revision: 50 http://drawbridge.svn.sourceforge.net/drawbridge/?rev=50&view=rev Author: blamonica Date: 2008-10-08 19:05:02 +0000 (Wed, 08 Oct 2008) Log Message: ----------- Made the schedules a one-to-many relationship, each job can have multiple schedules. Modified Paths: -------------- trunk/drawbridge/WebContent/META-INF/context.xml trunk/drawbridge/src/java/net/sf/drawbridge/controller/job/AddOrEditJobSubmitController.java trunk/drawbridge/src/java/net/sf/drawbridge/dao/drawbridge-dao-spring.xml trunk/drawbridge/src/java/net/sf/drawbridge/dao/hibernate/hbm/Job.hbm.xml trunk/drawbridge/src/java/net/sf/drawbridge/vo/Job.java trunk/drawbridge/src/sql/create_drawbridge_schema.sql trunk/drawbridge/src/test/db.script trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/AddOrEditJobControllerTest.java trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/AddOrEditJobSubmitControllerTest.java trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/DeleteJobSubmitControllerTest.java trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/ManagesJobControllerTest.java trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/RunJobControllerTest.java trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/RunJobSubmitControllerTest.java trunk/drawbridge/src/test/net/sf/drawbridge/dao/JobDaoTest.java Added Paths: ----------- trunk/drawbridge/src/java/net/sf/drawbridge/dao/hibernate/hbm/Schedule.hbm.xml trunk/drawbridge/src/java/net/sf/drawbridge/vo/Schedule.java Modified: trunk/drawbridge/WebContent/META-INF/context.xml =================================================================== --- trunk/drawbridge/WebContent/META-INF/context.xml 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/WebContent/META-INF/context.xml 2008-10-08 19:05:02 UTC (rev 50) @@ -1,4 +1,8 @@ -<Context docBase="drawbridge" path="/drawbridge" reloadable="true" source="org.eclipse.jst.jee.server:drawbridge"> +<Context docBase="drawbridge" path="/drawbridge" reloadable="true" debug="1" source="org.eclipse.jst.jee.server:drawbridge"> + <Resource name="jdbc/DrawbridgeDataSource" auth="Container" type="javax.sql.DataSource" + maxActive="30" maxIdle="30" maxWait="10000" + username="drawbridge_user" password="drawbridge" driverClassName="com.mysql.jdbc.Driver" + url="jdbc:mysql://localhost:3306/drawbridge"/> </Context> Modified: trunk/drawbridge/src/java/net/sf/drawbridge/controller/job/AddOrEditJobSubmitController.java =================================================================== --- trunk/drawbridge/src/java/net/sf/drawbridge/controller/job/AddOrEditJobSubmitController.java 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/java/net/sf/drawbridge/controller/job/AddOrEditJobSubmitController.java 2008-10-08 19:05:02 UTC (rev 50) @@ -80,7 +80,6 @@ null, null, null, null, new Boolean(request.getParameter("active")), - request.getParameter("schedule"), request.getParameter("handler"), request.getParameter("handlerParams")); drawbridgeService.addJob(job); @@ -107,7 +106,6 @@ null, null, null, null, new Boolean(request.getParameter("active")), - request.getParameter("schedule"), request.getParameter("handler"), request.getParameter("handlerParams")); drawbridgeService.updateJob(job); Modified: trunk/drawbridge/src/java/net/sf/drawbridge/dao/drawbridge-dao-spring.xml =================================================================== --- trunk/drawbridge/src/java/net/sf/drawbridge/dao/drawbridge-dao-spring.xml 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/java/net/sf/drawbridge/dao/drawbridge-dao-spring.xml 2008-10-08 19:05:02 UTC (rev 50) @@ -10,6 +10,7 @@ <value>net/sf/drawbridge/dao/hibernate/hbm/RunAsAccount.hbm.xml</value> <value>net/sf/drawbridge/dao/hibernate/hbm/User.hbm.xml</value> <value>net/sf/drawbridge/dao/hibernate/hbm/Group.hbm.xml</value> + <value>net/sf/drawbridge/dao/hibernate/hbm/Schedule.hbm.xml</value> <value>net/sf/drawbridge/dao/hibernate/hbm/Job.hbm.xml</value> </list> </property> Modified: trunk/drawbridge/src/java/net/sf/drawbridge/dao/hibernate/hbm/Job.hbm.xml =================================================================== --- trunk/drawbridge/src/java/net/sf/drawbridge/dao/hibernate/hbm/Job.hbm.xml 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/java/net/sf/drawbridge/dao/hibernate/hbm/Job.hbm.xml 2008-10-08 19:05:02 UTC (rev 50) @@ -59,9 +59,10 @@ <column name="ACTIVE"/> </property> - <property name="schedule" type="string" length="128"> - <column name="SCHEDULE"/> - </property> + <set name="schedule" access="field" lazy="false"> + <key foreign-key="JOB_ID" column="ID"/> + <one-to-many class="net.sf.drawbridge.vo.Schedule"/> + </set> <property name="handler" type="string" length="128"> <column name="HANDLER"/> Added: trunk/drawbridge/src/java/net/sf/drawbridge/dao/hibernate/hbm/Schedule.hbm.xml =================================================================== --- trunk/drawbridge/src/java/net/sf/drawbridge/dao/hibernate/hbm/Schedule.hbm.xml (rev 0) +++ trunk/drawbridge/src/java/net/sf/drawbridge/dao/hibernate/hbm/Schedule.hbm.xml 2008-10-08 19:05:02 UTC (rev 50) @@ -0,0 +1,33 @@ +<?xml version="1.0"?> +<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> + +<hibernate-mapping> + <class name="net.sf.drawbridge.vo.Schedule" optimistic-lock="version" table="DB_SCHEDULE"> + <id name="id" type="long" column="ID"> + <generator class="native"/> + </id> + + <version + column="VERSION" + name="version" + type="integer" + access="field" + /> + + <property name="jobId" type="long" not-null="true"> + <column name="JOB_ID"/> + </property> + + <property name="schedule" type="string" length="128" not-null="true"> + <column name="SCHEDULE"/> + </property> + + <property name="startDate" type="date"> + <column name="START_DATE"/> + </property> + + <property name="stopDate" type="date"> + <column name="STOP_DATE"/> + </property> + </class> +</hibernate-mapping> \ No newline at end of file Modified: trunk/drawbridge/src/java/net/sf/drawbridge/vo/Job.java =================================================================== --- trunk/drawbridge/src/java/net/sf/drawbridge/vo/Job.java 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/java/net/sf/drawbridge/vo/Job.java 2008-10-08 19:05:02 UTC (rev 50) @@ -18,6 +18,10 @@ package net.sf.drawbridge.vo; import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; public class Job extends ValueObject<Long> { @@ -31,7 +35,7 @@ private User approvedBy; private Calendar approvedOn; private String active; - private String schedule; + private Set<Schedule> schedule = new HashSet<Schedule>(2); private String handler; private String handlerParams; @@ -40,7 +44,7 @@ public Job(Long id, String name, RunAsAccount runAs, String query, User submittedBy, Calendar submittedOn, User reviewedBy, Calendar reviewedOn, User approvedBy, Calendar approvedOn, - boolean active, String schedule, String handler, String handlerParams) { + boolean active, String handler, String handlerParams) { super(id); setName(name); setRunAsAccount(runAs); @@ -52,7 +56,6 @@ setApprovedBy(approvedBy); setApprovedOn(approvedOn); setActive(active?"Y":"N"); - setSchedule(schedule); setHandler(handler); setHandlerParams(handlerParams); } @@ -109,18 +112,27 @@ return active; } - public String getSchedule() { - return schedule; + public String getHandler() { + return handler; } - public void setSchedule(String schedule) { - this.schedule = schedule; + public void addSchedule(Schedule s) { + s.setJobId(getId()); + schedule.add(s); } - - public String getHandler() { - return handler; + + public void removeSchedule(Schedule s) { + schedule.remove(s); } - + + public void clearSchedule() { + schedule.clear(); + } + + public Collection<Schedule> getSchedules() { + return Collections.unmodifiableSet(schedule); + } + public void setHandler(String handler) { this.handler = handler; } Added: trunk/drawbridge/src/java/net/sf/drawbridge/vo/Schedule.java =================================================================== --- trunk/drawbridge/src/java/net/sf/drawbridge/vo/Schedule.java (rev 0) +++ trunk/drawbridge/src/java/net/sf/drawbridge/vo/Schedule.java 2008-10-08 19:05:02 UTC (rev 50) @@ -0,0 +1,113 @@ +/* + * This file is part of DrawBridge. + * Copyright 2008 Adam Cresse, Ben La Monica + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation,Inc.,51 Franklin Street,Fifth Floor, Boston, MA 02110-1301, USA. + */ +package net.sf.drawbridge.vo; + +import java.util.Date; + +public class Schedule extends ValueObject<Long> { + private Long jobId; + private String schedule; + private Date startDate; + private Date stopDate; + private long version = 0; + + public Schedule() { } + + public Schedule(long id, long jobId, String schedule, Date startDate, Date stopDate) { + super(id); + setJobId(jobId); + setSchedule(schedule); + setStartDate(startDate); + setStopDate(stopDate); + } + + public Long getJobId() { + return jobId; + } + + public void setJobId(Long jobId) { + this.jobId = jobId; + } + + public String getSchedule() { + return schedule; + } + + public void setSchedule(String schedule) { + this.schedule = schedule; + } + + public Date getStartDate() { + return startDate; + } + + public void setStartDate(Date startDate) { + this.startDate = startDate; + } + + public Date getStopDate() { + return stopDate; + } + + public void setStopDate(Date stopDate) { + this.stopDate = stopDate; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (int) (jobId ^ (jobId >>> 32)); + result = prime * result + + ((schedule == null) ? 0 : schedule.hashCode()); + result = prime * result + + ((startDate == null) ? 0 : startDate.hashCode()); + result = prime * result + + ((stopDate == null) ? 0 : stopDate.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + final Schedule other = (Schedule) obj; + if (jobId != other.jobId) + return false; + if (schedule == null) { + if (other.schedule != null) + return false; + } else if (!schedule.equals(other.schedule)) + return false; + if (startDate == null) { + if (other.startDate != null) + return false; + } else if (!startDate.equals(other.startDate)) + return false; + if (stopDate == null) { + if (other.stopDate != null) + return false; + } else if (!stopDate.equals(other.stopDate)) + return false; + return true; + } +} Modified: trunk/drawbridge/src/sql/create_drawbridge_schema.sql =================================================================== --- trunk/drawbridge/src/sql/create_drawbridge_schema.sql 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/sql/create_drawbridge_schema.sql 2008-10-08 19:05:02 UTC (rev 50) @@ -87,6 +87,17 @@ CONSTRAINT CHK_DB_JOB_ACTIVE CHECK ACTIVE IN ('Y','N') ); +CREATE TABLE DB_SCHEDULE( + ID INTEGER NOT NULL AUTO_INCREMENT, + JOB_ID INTEGER NOT NULL, + START_DATE DATE, + STOP_DATE DATE, + SCHEDULE VARCHAR(128) NOT NULL, + VERSION INTEGER NOT NULL DEFAULT 0, + PRIMARY KEY(ID), + CONSTRAINT FK_DB_SCHEDULE_DB_JOB FOREIGN KEY FK_DB_SCHEDULE_DB_JOB (JOB_ID) REFERENCES DB_JOB(ID) +); + CREATE TABLE DB_PERMISSION_LIST( ID INTEGER NOT NULL, NAME VARCHAR(64) NOT NULL, Modified: trunk/drawbridge/src/test/db.script =================================================================== --- trunk/drawbridge/src/test/db.script 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/test/db.script 2008-10-08 19:05:02 UTC (rev 50) @@ -7,7 +7,8 @@ CREATE MEMORY TABLE DB_DRIVER(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,NAME VARCHAR(32) NOT NULL,CLASS_NAME VARCHAR(128) NOT NULL,CONSTRAINT UNQ_DB_DRIVER UNIQUE(NAME)) CREATE MEMORY TABLE DB_DATABASE(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,NAME VARCHAR(32) NOT NULL,JDBC_URL VARCHAR(128) NOT NULL,DRIVER_ID INTEGER NOT NULL,CONSTRAINT FK_DB_DATABASE_DB_DRIVER FOREIGN KEY(DRIVER_ID) REFERENCES PUBLIC.DB_DRIVER(ID),CONSTRAINT UNQ_DB_DATABASE UNIQUE(NAME)) CREATE MEMORY TABLE DB_RUN_AS(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 2) NOT NULL PRIMARY KEY,USER_NAME VARCHAR(16) NOT NULL,ENC_PASSWORD VARCHAR(32) NOT NULL,DATABASE_ID INTEGER NOT NULL,CONSTRAINT FK_DB_RUN_AS_DB_DATABASE FOREIGN KEY(DATABASE_ID) REFERENCES PUBLIC.DB_DATABASE(ID),CONSTRAINT UNQ_DB_RUN_AS UNIQUE(USER_NAME,DATABASE_ID)) -CREATE MEMORY TABLE DB_JOB(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 2) NOT NULL PRIMARY KEY,NAME VARCHAR(64) NOT NULL,RUN_AS_ID INTEGER NOT NULL,QUERY VARCHAR(1024) NOT NULL,SUBMITTED_BY INTEGER NOT NULL,SUBMITTED_ON TIMESTAMP NOT NULL,REVIEWED_BY INTEGER,REVIEWED_ON TIMESTAMP,APPROVED_BY INTEGER,APPROVED_ON TIMESTAMP,ACTIVE VARCHAR(1) NOT NULL,SCHEDULE VARCHAR(128),HANDLER VARCHAR(128),HANDLER_PARAMS VARCHAR(512),CONSTRAINT FK_DB_JOB_DB_RUN_AS FOREIGN KEY(RUN_AS_ID) REFERENCES PUBLIC.DB_RUN_AS(ID),CONSTRAINT FK_DB_JOB_SUBMITTED_BY FOREIGN KEY(SUBMITTED_BY) REFERENCES PUBLIC.DB_USER(ID),CONSTRAINT FK_DB_JOB_REVIEWED_BY FOREIGN KEY(REVIEWED_BY) REFERENCES PUBLIC.DB_USER(ID),CONSTRAINT FK_DB_JOB_APPROVED_BY FOREIGN KEY(APPROVED_BY) REFERENCES PUBLIC.DB_USER(ID),CONSTRAINT UNQ_DB_JOB UNIQUE(NAME),CONSTRAINT CHK_DB_JOB_ACTIVE CHECK((DB_JOB.ACTIVE) IN (('Y'),('N')))) +CREATE MEMORY TABLE DB_JOB(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 2) NOT NULL PRIMARY KEY,NAME VARCHAR(64) NOT NULL,RUN_AS_ID INTEGER NOT NULL,QUERY VARCHAR(1024) NOT NULL,SUBMITTED_BY INTEGER NOT NULL,SUBMITTED_ON TIMESTAMP NOT NULL,REVIEWED_BY INTEGER,REVIEWED_ON TIMESTAMP,APPROVED_BY INTEGER,APPROVED_ON TIMESTAMP,ACTIVE VARCHAR(1) NOT NULL,HANDLER VARCHAR(128),HANDLER_PARAMS VARCHAR(512),CONSTRAINT FK_DB_JOB_DB_RUN_AS FOREIGN KEY(RUN_AS_ID) REFERENCES PUBLIC.DB_RUN_AS(ID),CONSTRAINT FK_DB_JOB_SUBMITTED_BY FOREIGN KEY(SUBMITTED_BY) REFERENCES PUBLIC.DB_USER(ID),CONSTRAINT FK_DB_JOB_REVIEWED_BY FOREIGN KEY(REVIEWED_BY) REFERENCES PUBLIC.DB_USER(ID),CONSTRAINT FK_DB_JOB_APPROVED_BY FOREIGN KEY(APPROVED_BY) REFERENCES PUBLIC.DB_USER(ID),CONSTRAINT UNQ_DB_JOB UNIQUE(NAME),CONSTRAINT CHK_DB_JOB_ACTIVE CHECK((DB_JOB.ACTIVE) IN (('Y'),('N')))) +CREATE MEMORY TABLE DB_SCHEDULE(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 2) NOT NULL PRIMARY KEY,JOB_ID INTEGER NOT NULL,START_DATE DATE,STOP_DATE DATE,SCHEDULE VARCHAR(128) NOT NULL,VERSION INTEGER DEFAULT 0 NOT NULL,CONSTRAINT FK_DB_SCHEDULE_DB_JOB FOREIGN KEY(JOB_ID) REFERENCES PUBLIC.DB_JOB(ID)) CREATE MEMORY TABLE DB_PERMISSION_LIST(ID INTEGER NOT NULL PRIMARY KEY,NAME VARCHAR(64) NOT NULL,PERMISSION_TYPE VARCHAR(1) NOT NULL,CONSTRAINT UNQ_DB_PERMISSION UNIQUE(NAME,PERMISSION_TYPE),CONSTRAINT CHK_DB_PERMISSION_LIST_PERMISSION_TYPE CHECK((DB_PERMISSION_LIST.PERMISSION_TYPE) IN (('S'),('D'),('R')))) CREATE MEMORY TABLE DB_SYSTEM_PERMISSION(GROUP_ID INTEGER NOT NULL,PERMISSION_ID INTEGER NOT NULL,PRIMARY KEY(GROUP_ID,PERMISSION_ID),CONSTRAINT FK_DB_SYSTEM_PERMISSION_DB_GROUP FOREIGN KEY(GROUP_ID) REFERENCES PUBLIC.DB_GROUP(ID) ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT FK_DB_SYSTEM_PERMISSION_DB_PERMISSION_LIST FOREIGN KEY(PERMISSION_ID) REFERENCES PUBLIC.DB_PERMISSION_LIST(ID) ON DELETE CASCADE ON UPDATE CASCADE) CREATE MEMORY TABLE DB_DATABASE_PERMISSION(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY,GROUP_ID INTEGER NOT NULL,DATABASE_ID INTEGER NOT NULL,PERMISSION_ID INTEGER NOT NULL,CONSTRAINT FK_DB_DATABASE_PERMISSION_DB_GROUP FOREIGN KEY(GROUP_ID) REFERENCES PUBLIC.DB_GROUP(ID) ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT FK_DB_DATABASE_PERMISSION_DB_DATABASE FOREIGN KEY(DATABASE_ID) REFERENCES PUBLIC.DB_DATABASE(ID) ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT FK_DB_DATABASE_PERMISSION_DB_PERMISSION_LIST FOREIGN KEY(PERMISSION_ID) REFERENCES PUBLIC.DB_PERMISSION_LIST(ID) ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT UNQ_DB_GRAP UNIQUE(GROUP_ID,DATABASE_ID,PERMISSION_ID)) @@ -18,6 +19,7 @@ ALTER TABLE DB_DATABASE ALTER COLUMN ID RESTART WITH 1 ALTER TABLE DB_RUN_AS ALTER COLUMN ID RESTART WITH 2 ALTER TABLE DB_JOB ALTER COLUMN ID RESTART WITH 2 +ALTER TABLE DB_SCHEDULE ALTER COLUMN ID RESTART WITH 2 ALTER TABLE DB_DATABASE_PERMISSION ALTER COLUMN ID RESTART WITH 0 SET SCHEMA PUBLIC GRANT DBA TO SA @@ -36,8 +38,10 @@ INSERT INTO DB_DATABASE VALUES(0,'HSQLDB In-Memory Database','jdbc:hsqldb:mem:.',0) INSERT INTO DB_RUN_AS VALUES(0,'sa','base64',0) INSERT INTO DB_RUN_AS VALUES(1,'dev','base64',0) -INSERT INTO DB_JOB VALUES(0,'Job 1',0,'select count(*) from dual',0,'2008-03-19 19:00:00.000000',1,'2008-03-20 18:00:00.000000',1,'2008-03-20 18:00:01.000000','Y','schedule','handler','testKey1=testVal1\u000atestKey2=testVal2') -INSERT INTO DB_JOB VALUES(1,'Job 2',0,'select count(*) from dual',0,'2008-03-19 19:00:00.000000',1,'2008-03-20 18:00:00.000000',1,'2008-03-20 18:00:01.000000','Y','schedule','handler','testKey1=testVal1\u000atestKey2=testVal2') +INSERT INTO DB_JOB VALUES(0,'Job 1',0,'select count(*) from dual',0,'2008-03-19 19:00:00.000000',1,'2008-03-20 18:00:00.000000',1,'2008-03-20 18:00:01.000000','Y','handler','testKey1=testVal1\u000atestKey2=testVal2') +INSERT INTO DB_JOB VALUES(1,'Job 2',0,'select count(*) from dual',0,'2008-03-19 19:00:00.000000',1,'2008-03-20 18:00:00.000000',1,'2008-03-20 18:00:01.000000','Y','handler','testKey1=testVal1\u000atestKey2=testVal2') +INSERT INTO DB_SCHEDULE VALUES(0,0,NULL,NULL,'schedule',0) +INSERT INTO DB_SCHEDULE VALUES(1,1,NULL,NULL,'schedule',0) INSERT INTO DB_PERMISSION_LIST VALUES(1,'ADD USER','S') INSERT INTO DB_PERMISSION_LIST VALUES(2,'EDIT USER','S') INSERT INTO DB_PERMISSION_LIST VALUES(3,'DELETE USER','S') Modified: trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/AddOrEditJobControllerTest.java =================================================================== --- trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/AddOrEditJobControllerTest.java 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/AddOrEditJobControllerTest.java 2008-10-08 19:05:02 UTC (rev 50) @@ -54,7 +54,7 @@ List<String> handlerList=new ArrayList<String>(); handlerList.add("TestResultHandler"); - Job job=new Job(1L,"name",runAsAccount,"query",null,null,null,null,null,null,true,null,null,params); + Job job=new Job(1L,"name",runAsAccount,"query",null,null,null,null,null,null,true,null,params); mockDrawbridgeService.expects(atLeastOnce()).method("getJob").with(eq(new Long(1))).will(returnValue(job)); mockDrawbridgeService.expects(once()).method("listRunAsAccounts").will(returnValue(runAsList)); Modified: trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/AddOrEditJobSubmitControllerTest.java =================================================================== --- trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/AddOrEditJobSubmitControllerTest.java 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/AddOrEditJobSubmitControllerTest.java 2008-10-08 19:05:02 UTC (rev 50) @@ -54,7 +54,7 @@ } public void testShouldAddJobAndReturnSuccessMessage() throws Exception{ - Job job=new Job(null,"name",account,"query",null,null,null,null,null,null,true,"schedule","handler",params); + Job job=new Job(null,"name",account,"query",null,null,null,null,null,null,true,"handler",params); mockDrawbridgeService.expects(once()).method("addJob").with(new JobConstraint(job)); mockDrawbridgeService.expects(once()).method("getRunAsAccount").with(eq(1)).will(returnValue(account)); mockDrawbridgeService.expects(once()).method("getUser").with(eq(new Integer(-1))).will(returnValue(user)); @@ -79,7 +79,7 @@ } public void testShouldEditJobAndReturnSuccessMessage() throws Exception{ - Job job=new Job(1L,"name",account,"query",null,null,null,null,null,null,true,"schedule","handler",params); + Job job=new Job(1L,"name",account,"query",null,null,null,null,null,null,true,"handler",params); mockDrawbridgeService.expects(once()).method("updateJob").with(new JobConstraint(job)); mockDrawbridgeService.expects(once()).method("getRunAsAccount").with(eq(1)).will(returnValue(account)); mockDrawbridgeService.expects(once()).method("getUser").with(eq(new Integer(-1))).will(returnValue(user)); @@ -106,7 +106,7 @@ @SuppressWarnings("unchecked") public void testShouldAddJobAndReturnFailureMessageOnException() throws Exception{ - Job job=new Job(null,"name",account,"query",null,null,null,null,null,null,true,"schedule",null,params); + Job job=new Job(null,"name",account,"query",null,null,null,null,null,null,true,null,params); RuntimeException ex=new RuntimeException("The Spanish Inquisition"); mockDrawbridgeService.expects(once()).method("addJob").with(new JobConstraint(job)).will(throwException(ex)); mockDrawbridgeService.expects(once()).method("getRunAsAccount").with(eq(1)).will(returnValue(account)); @@ -139,7 +139,7 @@ @SuppressWarnings("unchecked") public void testShouldEditJobAndReturnFailureMessageOnException() throws Exception{ - Job job=new Job(1L,"name",account,"query",null,null,null,null,null,null,true,"schedule","handler",params); + Job job=new Job(1L,"name",account,"query",null,null,null,null,null,null,true,"handler",params); RuntimeException ex=new RuntimeException("The Spanish Inquisition"); mockDrawbridgeService.expects(once()).method("updateJob").with(new JobConstraint(job)).will(throwException(ex)); mockDrawbridgeService.expects(once()).method("getRunAsAccount").with(eq(1)).will(returnValue(account)); @@ -185,7 +185,7 @@ job.getRunAsAccount().equals(other.getRunAsAccount()) && job.getQuery().equals(other.getQuery()) && job.isActive()==other.isActive() && - job.getSchedule().equals(other.getSchedule()); + job.getSchedules().equals(other.getSchedules()); } private boolean equals(Object obj1, Object obj2){ Modified: trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/DeleteJobSubmitControllerTest.java =================================================================== --- trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/DeleteJobSubmitControllerTest.java 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/DeleteJobSubmitControllerTest.java 2008-10-08 19:05:02 UTC (rev 50) @@ -50,7 +50,7 @@ User user = new User(2, "acresse", "Adam", "Cresse", true); Database db = new Database(new Integer(1), "name", "jdbcUrl", null); RunAsAccount runAsAccount = new RunAsAccount(2,"userName","password",db); - Job job=new Job(1L,"name",runAsAccount,"query",user,null,null,null,null,null,true,"schedule","handler",params); + Job job=new Job(1L,"name",runAsAccount,"query",user,null,null,null,null,null,true,"handler",params); mockDrawbridgeService.expects(once()).method("getJob").with(eq(new Long(1))).will(returnValue(job)); mockDrawbridgeService.expects(once()).method("deleteJob").with(eq(new Long(1))); Modified: trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/ManagesJobControllerTest.java =================================================================== --- trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/ManagesJobControllerTest.java 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/ManagesJobControllerTest.java 2008-10-08 19:05:02 UTC (rev 50) @@ -47,7 +47,7 @@ List<Job> jobList=new ArrayList<Job>(); Database db = new Database(1,"name", "jdbcUrl", null); RunAsAccount runAsAccount = new RunAsAccount(1,"userName","password",db); - jobList.add(new Job(1L,"name",runAsAccount,"query",null,null,null,null,null,null,true,null,"handler",params)); + jobList.add(new Job(1L,"name",runAsAccount,"query",null,null,null,null,null,null,true,"handler",params)); List<RunAsAccount> runAsList=new ArrayList<RunAsAccount>(); runAsList.add(runAsAccount); Modified: trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/RunJobControllerTest.java =================================================================== --- trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/RunJobControllerTest.java 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/RunJobControllerTest.java 2008-10-08 19:05:02 UTC (rev 50) @@ -50,7 +50,7 @@ Driver driver = new Driver(4,"name","class"); Database database=new Database(3,"name","url",driver); RunAsAccount runAsAccount = new RunAsAccount(2,"userName","password",database); - Job job = new Job(1L,"name",runAsAccount,"query",null,null,null,null,null,null,true,null,"handler",params); + Job job = new Job(1L,"name",runAsAccount,"query",null,null,null,null,null,null,true,"handler",params); List<QueryParam> queryParams=new ArrayList<QueryParam>(); queryParams.add(new QueryParam(Types.VARCHAR,"name","value")); Modified: trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/RunJobSubmitControllerTest.java =================================================================== --- trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/RunJobSubmitControllerTest.java 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/test/net/sf/drawbridge/controller/job/RunJobSubmitControllerTest.java 2008-10-08 19:05:02 UTC (rev 50) @@ -53,7 +53,7 @@ public void testShouldReturnViewWithResults() throws Exception{ RunAsAccount account = new RunAsAccount(2, "username", "password", null); - Job job = new Job(1L,"name",account,"query",null,null,null,null,null,null,true,null,"handler",paramsStr); + Job job = new Job(1L,"name",account,"query",null,null,null,null,null,null,true,"handler",paramsStr); List<QueryParam> queryParams=new ArrayList<QueryParam>(); queryParams.add(new QueryParam(Types.VARCHAR,"name","value")); Modified: trunk/drawbridge/src/test/net/sf/drawbridge/dao/JobDaoTest.java =================================================================== --- trunk/drawbridge/src/test/net/sf/drawbridge/dao/JobDaoTest.java 2008-08-29 03:12:07 UTC (rev 49) +++ trunk/drawbridge/src/test/net/sf/drawbridge/dao/JobDaoTest.java 2008-10-08 19:05:02 UTC (rev 50) @@ -21,12 +21,17 @@ import java.util.Calendar; import java.util.List; +import javax.sql.DataSource; + import junit.framework.TestCase; import net.sf.drawbridge.test.TestBeanFactory; import net.sf.drawbridge.vo.Job; import net.sf.drawbridge.vo.RunAsAccount; import net.sf.drawbridge.vo.User; +import org.hibernate.SessionFactory; +import org.hibernate.StaleObjectStateException; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.AbstractPlatformTransactionManager; import org.springframework.transaction.support.DefaultTransactionDefinition; @@ -40,12 +45,18 @@ private RunAsAccountDao runAsAccountDao; private AbstractPlatformTransactionManager txManager; + + private JdbcTemplate jdbc; private String params="testKey1=testVal1\ntestKey2=testVal2"; + private SessionFactory sessionFactory; + protected void setUp() { txManager = (AbstractPlatformTransactionManager) TestBeanFactory.getBean("TxManager"); target = (JobDao) TestBeanFactory.getBean("JobDao"); + sessionFactory = (SessionFactory) TestBeanFactory.getBean("SessionFactory"); + jdbc = new JdbcTemplate((DataSource) TestBeanFactory.getBean("DataSource")); runAsAccountDao = (RunAsAccountDao) TestBeanFactory.getBean("RunAsAccountDao"); userDao = (UserDao) TestBeanFactory.getBean("UserDao"); } @@ -64,7 +75,8 @@ assertEquals("approvedBy", new Integer(1), result.getApprovedBy().getId()); assertEquals("approvedOn", "03-20-2008 18:00:01", df.format(result.getApprovedOn().getTime())); assertTrue("active", result.isActive()); - assertEquals("schedule", "schedule", result.getSchedule()); + assertEquals("schedule", 1, result.getSchedules().size()); + assertEquals("schedule", "schedule", result.getSchedules().iterator().next().getSchedule()); assertEquals("handler", "handler", result.getHandler()); assertEquals("handlerParams", params, result.getHandlerParams()); } @@ -74,7 +86,7 @@ try { User submitter = userDao.get(0); RunAsAccount account = runAsAccountDao.get(0); - Job job = new Job(null, "A new job", account, "select count(*) from dual", submitter, Calendar.getInstance(), null, null, null, null, true, "schedule", "handler", params); + Job job = new Job(null, "A new job", account, "select count(*) from dual", submitter, Calendar.getInstance(), null, null, null, null, true, "handler", params); target.create(job); assertNotNull("id is still null", job.getId()); } finally { @@ -125,5 +137,19 @@ public void testShouldRetrieveAllJobsBasedOnDatabaseId() throws Exception { assertEquals(2, target.getJobsForDatabase(0).size()); } - + + public void testShouldThrowStaleObjectExceptionIfVersionChangesInScheduleRow() throws Exception { + TransactionStatus tx = txManager.getTransaction(new DefaultTransactionDefinition()); + try { + Job job = target.get(0L); + jdbc.update("update DB_SCHEDULE set VERSION=3 where ID=" + job.getId()); + job.getSchedules().iterator().next().setSchedule("blah"); + sessionFactory.getCurrentSession().flush(); + fail("should have thrown a stale object exception"); + } catch (StaleObjectStateException e) { + // success + } finally { + txManager.rollback(tx); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |