|
From: <ste...@us...> - 2003-07-28 21:34:31
|
Update of /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/journal
In directory sc8-pr-cvs1:/tmp/cvs-serv5776
Modified Files:
GenericSqlJournal.java
Log Message:
added synchronization in log.
getNextStep and DB update must be a single unit.
Index: GenericSqlJournal.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/journal/GenericSqlJournal.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** GenericSqlJournal.java 14 Jul 2003 22:43:29 -0000 1.8
--- GenericSqlJournal.java 28 Jul 2003 21:34:28 -0000 1.9
***************
*** 661,665 ****
con = (Connection) resource.checkOut();
- long step = getNextStep(con, id);
String pstageName = (stage != null) ? stage : "null";
String additional = "";
--- 661,664 ----
***************
*** 672,676 ****
pstmt = con.prepareStatement(logInsertStmt);
pstmt.setLong(1, id);
- pstmt.setLong(2, step);
pstmt.setLong(3, new Date().getTime());
pstmt.setString(4, operation.toString());
--- 671,674 ----
***************
*** 678,683 ****
pstmt.setString(6, pstageName);
pstmt.setString(7, additional);
- pstmt.executeUpdate();
if (operation.equals(JournalOperation.updateDocument)) {
writeDelta(con, id, step, (PipelineDocument) data);
--- 676,689 ----
pstmt.setString(6, pstageName);
pstmt.setString(7, additional);
+ // without synchronized it is likely to get the same value
+ // from getNextStep several times in multiple threads
+ long step ;
+ synchronized ( this.getClass() ) {
+ step = getNextStep(con, id);
+ pstmt.setLong(2, step);
+ pstmt.executeUpdate();
+ }
+
if (operation.equals(JournalOperation.updateDocument)) {
writeDelta(con, id, step, (PipelineDocument) data);
|