Index: lams_common/src/java/org/lamsfoundation/lams/tool/ToolContentIDGenerator.java =================================================================== diff -u -r99535fb4e8de85822dfd8f274ed2a37fec63a1df -r302ccfe6bd6ab0c26e695090e0126914598d72b7 --- lams_common/src/java/org/lamsfoundation/lams/tool/ToolContentIDGenerator.java (.../ToolContentIDGenerator.java) (revision 99535fb4e8de85822dfd8f274ed2a37fec63a1df) +++ lams_common/src/java/org/lamsfoundation/lams/tool/ToolContentIDGenerator.java (.../ToolContentIDGenerator.java) (revision 302ccfe6bd6ab0c26e695090e0126914598d72b7) @@ -13,24 +13,40 @@ /** + *
+ * This generator is designed to create new content id for a particular tool. + *
+ *
+ * It is configured as a Spring singleton bean. Transaction demarcation has
+ * been set to REQUIRED_NEW
to ensure it is always runing within
+ * its own transaction. And THE isolation level is set to
+ * READ_COMMITTED
.
*
+ * We are using MySql auto-increment generator to ensure the data correctness
+ * under concurrency contention.
+ *
* @author Jacky Fang 9/02/2005
*
*/
public class ToolContentIDGenerator
{
private IToolContentDAO toolContentDao;
-
/**
+ * Method injection for Spring configuration.
* @param toolContentDao The toolContentDao to set.
*/
public void setToolContentDao(IToolContentDAO toolContentDao)
{
this.toolContentDao = toolContentDao;
}
- public Long getToolContentIDFor(Tool tool)
+ /**
+ * Get the next tool content id for a tool.
+ * @param tool the target tool.
+ * @return the next id object.
+ */
+ public Long getNextToolContentIDFor(Tool tool)
{
ToolContent newContent = new ToolContent(tool);
toolContentDao.saveToolContent(newContent);
Index: lams_common/test/java/org/lamsfoundation/lams/AbstractLamsCommonTestCase.java
===================================================================
diff -u -rf686b51b897a2e4c136afba6f4ca9b896b493b87 -r302ccfe6bd6ab0c26e695090e0126914598d72b7
--- lams_common/test/java/org/lamsfoundation/lams/AbstractLamsCommonTestCase.java (.../AbstractLamsCommonTestCase.java) (revision f686b51b897a2e4c136afba6f4ca9b896b493b87)
+++ lams_common/test/java/org/lamsfoundation/lams/AbstractLamsCommonTestCase.java (.../AbstractLamsCommonTestCase.java) (revision 302ccfe6bd6ab0c26e695090e0126914598d72b7)
@@ -29,7 +29,7 @@
*/
public abstract class AbstractLamsCommonTestCase extends TestCase
{
- protected ApplicationContext ac;
+ protected ApplicationContext context;
/**
*
@@ -45,7 +45,7 @@
protected void setUp() throws Exception
{
super.setUp();
- ac = new ClassPathXmlApplicationContext(getContextConfigLocation());
+ context = new ClassPathXmlApplicationContext(getContextConfigLocation());
initializeHibernateSession();
}
@@ -66,7 +66,7 @@
protected void initializeHibernateSession() throws HibernateException
{
//hold the hibernate session
- SessionFactory sessionFactory = (SessionFactory) this.ac.getBean("coreSessionFactory");
+ SessionFactory sessionFactory = (SessionFactory) this.context.getBean("coreSessionFactory");
Session s = sessionFactory.openSession();
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(s));
}
@@ -76,7 +76,7 @@
protected void finalizeHibernateSession() throws HibernateException
{
//clean the hibernate session
- SessionFactory sessionFactory = (SessionFactory)this.ac.getBean("coreSessionFactory");
+ SessionFactory sessionFactory = (SessionFactory)this.context.getBean("coreSessionFactory");
SessionHolder holder = (SessionHolder)TransactionSynchronizationManager.getResource(sessionFactory);
if (holder != null) {
Session s = holder.getSession();
@@ -88,7 +88,7 @@
protected Session getSession()
{
- SessionFactory sessionFactory = (SessionFactory)this.ac.getBean("coreSessionFactory");
+ SessionFactory sessionFactory = (SessionFactory)this.context.getBean("coreSessionFactory");
SessionHolder holder = (SessionHolder)TransactionSynchronizationManager.getResource(sessionFactory);
if (holder != null)
return holder.getSession();
Index: lams_common/test/java/org/lamsfoundation/lams/lesson/LessonDataAccessTestCase.java
===================================================================
diff -u -r432eded2e44dafaf043b7a6acb26e448cb6697a4 -r302ccfe6bd6ab0c26e695090e0126914598d72b7
--- lams_common/test/java/org/lamsfoundation/lams/lesson/LessonDataAccessTestCase.java (.../LessonDataAccessTestCase.java) (revision 432eded2e44dafaf043b7a6acb26e448cb6697a4)
+++ lams_common/test/java/org/lamsfoundation/lams/lesson/LessonDataAccessTestCase.java (.../LessonDataAccessTestCase.java) (revision 302ccfe6bd6ab0c26e695090e0126914598d72b7)
@@ -90,18 +90,18 @@
{
super.setUp();
- userDao = (UserDAO) this.ac.getBean("userDAO");
- learningDesignDao = (LearningDesignDAO) this.ac.getBean("learningDesignDAO");
- orgDao = (OrganisationDAO) this.ac.getBean("organisationDAO");
+ userDao = (UserDAO) this.context.getBean("userDAO");
+ learningDesignDao = (LearningDesignDAO) this.context.getBean("learningDesignDAO");
+ orgDao = (OrganisationDAO) this.context.getBean("organisationDAO");
//retrieve test domain data
testUser = userDao.getUserById(TEST_USER_ID);
testLearningDesign = learningDesignDao.getLearningDesignById(TEST_LEARNING_DESIGN_ID);
testOrg = orgDao.getOrganisationById(TEST_ORGANIZATION_ID);
//get lesson related daos
- lessonDao = (LessonDAO)this.ac.getBean("lessonDAO");
- lessonClassDao = (LessonClassDAO)this.ac.getBean("lessonClassDAO");
+ lessonDao = (LessonDAO)this.context.getBean("lessonDAO");
+ lessonClassDao = (LessonClassDAO)this.context.getBean("lessonClassDAO");
}
/**
Index: lams_common/test/java/org/lamsfoundation/lams/tool/TestToolContentIDGenerator.java
===================================================================
diff -u -r99535fb4e8de85822dfd8f274ed2a37fec63a1df -r302ccfe6bd6ab0c26e695090e0126914598d72b7
--- lams_common/test/java/org/lamsfoundation/lams/tool/TestToolContentIDGenerator.java (.../TestToolContentIDGenerator.java) (revision 99535fb4e8de85822dfd8f274ed2a37fec63a1df)
+++ lams_common/test/java/org/lamsfoundation/lams/tool/TestToolContentIDGenerator.java (.../TestToolContentIDGenerator.java) (revision 302ccfe6bd6ab0c26e695090e0126914598d72b7)
@@ -26,7 +26,7 @@
{
super.setUp();
testTool = toolDao.getToolByID(super.TEST_TOOL_ID);
- toolContentIDGenerator = (ToolContentIDGenerator)this.ac.getBean("toolContentIDGenerator");
+ toolContentIDGenerator = (ToolContentIDGenerator)this.context.getBean("toolContentIDGenerator");
}
/*
@@ -50,10 +50,10 @@
{
long id;
long nextId;
- Long newId = toolContentIDGenerator.getToolContentIDFor(testTool);
+ Long newId = toolContentIDGenerator.getNextToolContentIDFor(testTool);
assertNotNull("verify the new id has been created",newId);
id = newId.longValue();
- newId = toolContentIDGenerator.getToolContentIDFor(testTool);
+ newId = toolContentIDGenerator.getNextToolContentIDFor(testTool);
assertNotNull("verify the new id has been created",newId);
nextId = newId.longValue();
assertTrue("verify the new id is larger than old one",nextId==id+1);
Index: lams_common/test/java/org/lamsfoundation/lams/tool/ToolDataAccessTestCase.java
===================================================================
diff -u -r99535fb4e8de85822dfd8f274ed2a37fec63a1df -r302ccfe6bd6ab0c26e695090e0126914598d72b7
--- lams_common/test/java/org/lamsfoundation/lams/tool/ToolDataAccessTestCase.java (.../ToolDataAccessTestCase.java) (revision 99535fb4e8de85822dfd8f274ed2a37fec63a1df)
+++ lams_common/test/java/org/lamsfoundation/lams/tool/ToolDataAccessTestCase.java (.../ToolDataAccessTestCase.java) (revision 302ccfe6bd6ab0c26e695090e0126914598d72b7)
@@ -37,8 +37,8 @@
{
super.setUp();
- toolContentDao = (ToolContentDAO)this.ac.getBean("toolContentDAO");
- toolDao = (ToolDAO)this.ac.getBean("toolDAO");
+ toolContentDao = (ToolContentDAO)this.context.getBean("toolContentDAO");
+ toolDao = (ToolDAO)this.context.getBean("toolDAO");
}
@@ -67,5 +67,4 @@
"applicationContext.xml"};
}
-
}
Index: lams_common/test/java/org/lamsfoundation/lams/tool/toolApplicationContext.xml
===================================================================
diff -u -r99535fb4e8de85822dfd8f274ed2a37fec63a1df -r302ccfe6bd6ab0c26e695090e0126914598d72b7
--- lams_common/test/java/org/lamsfoundation/lams/tool/toolApplicationContext.xml (.../toolApplicationContext.xml) (revision 99535fb4e8de85822dfd8f274ed2a37fec63a1df)
+++ lams_common/test/java/org/lamsfoundation/lams/tool/toolApplicationContext.xml (.../toolApplicationContext.xml) (revision 302ccfe6bd6ab0c26e695090e0126914598d72b7)
@@ -24,7 +24,7 @@