|
From: <tr...@us...> - 2003-09-03 03:25:39
|
Update of /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/journal
In directory sc8-pr-cvs1:/tmp/cvs-serv10506/sql/src/com/babeldoc/sql/journal
Modified Files:
GenericSqlJournal.java PostgreSqlJournal.java
Log Message:
LARGE, EXTENSIVE UPDATE.
1. All journal classes are now IConfigurable
2. J2ee journal classes using IConfigurable and are consistent
3. Somewhat of a cleanup around the journal code.
Index: GenericSqlJournal.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/journal/GenericSqlJournal.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** GenericSqlJournal.java 15 Aug 2003 00:25:30 -0000 1.10
--- GenericSqlJournal.java 3 Sep 2003 03:25:32 -0000 1.11
***************
*** 68,73 ****
import com.babeldoc.core.I18n;
import com.babeldoc.core.LogService;
- import com.babeldoc.core.config.ConfigService;
- import com.babeldoc.core.config.IConfig;
import com.babeldoc.core.journal.*;
import com.babeldoc.core.journal.query.JournalQuery;
--- 68,71 ----
***************
*** 75,82 ****
import com.babeldoc.core.journal.query.QueryOption;
import com.babeldoc.core.journal.query.QueryTicket;
import com.babeldoc.core.pipeline.PipelineDocument;
import com.babeldoc.core.resource.IResource;
import com.babeldoc.core.resource.ResourceFactory;
-
import com.babeldoc.sql.util.SqlQueryManager;
import com.babeldoc.sql.util.TableKeyHelper;
--- 73,82 ----
import com.babeldoc.core.journal.query.QueryOption;
import com.babeldoc.core.journal.query.QueryTicket;
+ import com.babeldoc.core.option.IConfigInfo;
+ import com.babeldoc.core.option.ConfigOption;
+ import com.babeldoc.core.option.IConfigOptionType;
import com.babeldoc.core.pipeline.PipelineDocument;
import com.babeldoc.core.resource.IResource;
import com.babeldoc.core.resource.ResourceFactory;
import com.babeldoc.sql.util.SqlQueryManager;
import com.babeldoc.sql.util.TableKeyHelper;
***************
*** 84,91 ****
import java.io.InputStream;
import java.io.ObjectInputStream;
-
import java.sql.*;
-
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
--- 84,90 ----
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.sql.*;
import java.util.ArrayList;
+ import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
***************
*** 121,143 ****
public static final String LOG_QUERY_ALL_OTHER_VALUES = "queryOtherTicketValues";
! /** The name of the resource forthis sql journal */
! protected static IResource resource;
!
! static {
! try {
! /**
! * configuarion variables
! */
! com.babeldoc.core.LogService.getInstance().logDebug(com.babeldoc.core.I18n.get(
! "sql.401"));
! IConfig config = ConfigService.getInstance().getConfig(CONFIG_FILENAME);
! com.babeldoc.core.LogService.getInstance().logDebug(com.babeldoc.core.I18n.get(
! "sql.402") + config.getString(RESOURCE_NAME));
! resource = ResourceFactory.getResource(config.getString(RESOURCE_NAME));
! } catch (Exception e) {
! com.babeldoc.core.LogService.getInstance().logError("Static{}", e);
! }
! }
/**
--- 120,128 ----
public static final String LOG_QUERY_ALL_OTHER_VALUES = "queryOtherTicketValues";
! /** The name of the resource for this sql journal */
! private IResource resource;
! /** Keep the configuration information handy */
! private SqlJournalInfo info;
/**
***************
*** 160,164 ****
try {
// Get the results from the db and place on stack
! con = (Connection) resource.checkOut();
String query = SqlQueryManager.getSqlQuery(LOG_QUERY_ALL_OTHER_VALUES);
--- 145,149 ----
try {
// Get the results from the db and place on stack
! con = (Connection) getResource().checkOut();
String query = SqlQueryManager.getSqlQuery(LOG_QUERY_ALL_OTHER_VALUES);
***************
*** 191,195 ****
}
! resource.checkIn(con);
} catch (Exception ex) {
LogService.getInstance().logError(I18n.get("sql.403"), ex);
--- 176,180 ----
}
! getResource().checkIn(con);
} catch (Exception ex) {
LogService.getInstance().logError(I18n.get("sql.403"), ex);
***************
*** 221,225 ****
// Get the results from the db and place on stack
! con = (Connection) resource.checkOut();
pstmt = con.prepareStatement(query);
pstmt.setLong(1, tickval);
--- 206,210 ----
// Get the results from the db and place on stack
! con = (Connection) getResource().checkOut();
pstmt = con.prepareStatement(query);
pstmt.setLong(1, tickval);
***************
*** 242,246 ****
}
! resource.checkIn(con);
} catch (Exception ex) {
LogService.getInstance().logError(ex);
--- 227,231 ----
}
! getResource().checkIn(con);
} catch (Exception ex) {
LogService.getInstance().logError(ex);
***************
*** 265,269 ****
try {
! con = (Connection) (resource.checkOut());
doc = (PipelineDocument) (readDelta(con,
((JournalTicket) ticket).getValue(), step));
--- 250,254 ----
try {
! con = (Connection) (getResource().checkOut());
doc = (PipelineDocument) (readDelta(con,
((JournalTicket) ticket).getValue(), step));
***************
*** 274,278 ****
} finally {
try {
! resource.checkIn(con);
} catch (Exception e) {
LogService.getInstance().logError(e);
--- 259,263 ----
} finally {
try {
! getResource().checkIn(con);
} catch (Exception e) {
LogService.getInstance().logError(e);
***************
*** 320,324 ****
// Get the results from the db and place on stack
! con = (Connection) resource.checkOut();
stmt = con.createStatement();
--- 305,309 ----
// Get the results from the db and place on stack
! con = (Connection) getResource().checkOut();
stmt = con.createStatement();
***************
*** 340,344 ****
}
! resource.checkIn(con);
} catch (Exception ex) {
LogService.getInstance().logError(ex);
--- 325,329 ----
}
! getResource().checkIn(con);
} catch (Exception ex) {
LogService.getInstance().logError(ex);
***************
*** 373,379 ****
try {
//getLog().debug("[GenericSqlJournal.forkTicket] called");
! Connection con = (Connection) resource.checkOut();
long nextVal = TableKeyHelper.getNextId(con, "LOG").longValue();
! resource.checkIn(con);
IJournalTicket ticket = new JournalTicket(nextVal);
--- 358,364 ----
try {
//getLog().debug("[GenericSqlJournal.forkTicket] called");
! Connection con = (Connection) getResource().checkOut();
long nextVal = TableKeyHelper.getNextId(con, "LOG").longValue();
! getResource().checkIn(con);
IJournalTicket ticket = new JournalTicket(nextVal);
***************
*** 401,407 ****
try {
//getLog().debug("[GenericSqlJournal.newTicket] called");
! Connection con = (Connection) resource.checkOut();
long nextVal = TableKeyHelper.getNextId(con, "LOG").longValue();
! resource.checkIn(con);
IJournalTicket ticket = new JournalTicket(nextVal);
--- 386,392 ----
try {
//getLog().debug("[GenericSqlJournal.newTicket] called");
! Connection con = (Connection) getResource().checkOut();
long nextVal = TableKeyHelper.getNextId(con, "LOG").longValue();
! getResource().checkIn(con);
IJournalTicket ticket = new JournalTicket(nextVal);
***************
*** 659,663 ****
try {
! con = (Connection) resource.checkOut();
String pstageName = (stage != null) ? stage : "null";
--- 644,648 ----
try {
! con = (Connection) getResource().checkOut();
String pstageName = (stage != null) ? stage : "null";
***************
*** 697,701 ****
}
! resource.checkIn(con);
} catch (Exception se) {
LogService.getInstance().logError(I18n.get("sql.403"), se);
--- 682,686 ----
}
! getResource().checkIn(con);
} catch (Exception se) {
LogService.getInstance().logError(I18n.get("sql.403"), se);
***************
*** 812,814 ****
--- 797,863 ----
}
}
+
+ /**
+ * Get the configuraiton information object for this class
+ *
+ * @return
+ */
+ public IConfigInfo getInfo() {
+ if(info==null) {
+ info = new SqlJournalInfo();
+ }
+ return info;
+ }
+
+ /**
+ * Get the resource for this journal.
+ *
+ * @return
+ */
+ protected IResource getResource() {
+ if(resource==null) {
+ String resourceName = getInfo().getStrValue(RESOURCE_NAME);
+ resource = ResourceFactory.getResource(resourceName);
+ }
+ return resource;
+ }
}
+
+ /**
+ * Configuration information
+ *
+ * @author bmcdonald
+ * @version 1.1
+ */
+ class SqlJournalInfo extends JournalConfigInfo {
+ /**
+ * This method returns type specific options
+ *
+ * @return comments
+ */
+ public Collection getTypeSpecificOptions() {
+ Collection options = new ArrayList();
+
+ options.add(new ConfigOption(GenericSqlJournal.RESOURCE_NAME, IConfigOptionType.FILENAME, null, true,
+ "The journal log file. Each operation is logged to this file."));
+ return options;
+ }
+
+ /**
+ * Return description of this worker
+ *
+ * @return description
+ */
+ public String getDescription() {
+ return "The Sql Journal stores its configuration information in a RDBMS";
+ }
+
+ /**
+ * return the name
+ *
+ * @return
+ */
+ public String getName() {
+ return "sql";
+ }
+ }
\ No newline at end of file
Index: PostgreSqlJournal.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/journal/PostgreSqlJournal.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PostgreSqlJournal.java 15 Aug 2003 21:22:04 -0000 1.1
--- PostgreSqlJournal.java 3 Sep 2003 03:25:32 -0000 1.2
***************
*** 28,244 ****
* @author <a href="mailto:kg...@ga...">Ken Geis</a>
*/
! public class PostgreSqlJournal extends GenericSqlJournal
! {
! public final static String DELTA_MAKEROW =
! "journalAddBlankDataRow-postgresql";
! public final static String LOG_KEY_GET = "logKeyGet-postgresql";
!
! /**
! * Write a document to the rdbms. Same as in MySqlJournal, but it's
! * probably not a good idea to just subclass it.
! *
! * @param con the connection
! * @param id the log id
! * @param step the log step
! */
! protected void writeDelta (Connection conn, long id, long step,
! PipelineDocument doc) throws SQLException
! {
!
! String insertStmt = SqlQueryManager.getSqlQuery(DELTA_MAKEROW);
! PreparedStatement stmt = null;
! ResultSet rs = null;
! ByteArrayOutputStream baos = null;
!
! try
! {
! // Write the document object to an array of bytes
! baos = new ByteArrayOutputStream();
!
! ObjectOutputStream oos = new ObjectOutputStream(baos);
! oos.writeObject(doc);
! oos.flush();
!
! byte[] docData = baos.toByteArray();
!
! // Now write the row
! stmt = conn.prepareStatement(insertStmt);
! stmt.setLong(1, id);
! stmt.setLong(2, step);
! stmt.setBytes(3, docData);
! stmt.execute();
!
! writeExtraData(conn, id, step, doc);
! }
! catch (Exception e)
! {
! throw new SQLException(e.toString());
! }
! finally
! {
! try
! {
! if (rs != null) rs.close();
! }
! catch (Exception ex)
! {
! LogService.getInstance().logError(I18n.get("sql.403"), ex);
! }
!
! try
! {
! if (stmt != null) stmt.close();
! }
! catch (Exception ex)
! {
! LogService.getInstance().logError(I18n.get("sql.403"), ex);
! }
!
! try
! {
! if (baos != null) baos.close();
! }
! catch (Exception ex)
! {
! LogService.getInstance().logError(I18n.get("sql.403"), ex);
! }
! }
}
! /**
! * getTicketsProcessQueryString concoct the query string from the bits and
! * pieces. Calls back to the getTicketsProcess...
! *
! * @param jQuery
! * @return
! */
! protected StringBuffer getTicketsProcessQueryString (JournalQuery jQuery)
! {
!
! StringBuffer query = super.getTicketsProcessQueryString(jQuery);
!
! // Limit stuff
! if (jQuery.getStartIndex() > 0)
! {
! query.append(" limit " + jQuery.getStartIndex() +
! " offset " + jQuery.getNumResults());
!
! // HACK ALERT - need to do this to stop the parent skipping
! // on the result set.
! //
! // The above comment was taken from the MySQL implementation.
! // I don't know how it effects PostgreSQL.
! jQuery.setStartIndex(0);
! }
!
! return query;
}
-
- /**
- * Get a ticket for tracking a document. This implementation logs the
- * operation to the log file and creates a directory for operations on
- * the ticket.
- *
- * @return
- * @throws JournalException
- */
- public IJournalTicket newTicket () throws JournalException
- {
- try
- {
- //getLog().debug("[PostgreSqlJournal.newTicket] called");
- long nextVal = getNewLogID();
-
- IJournalTicket ticket = new JournalTicket(nextVal);
-
- // Log the operation
- log(ticket, JournalOperation.newTicket, null, null, null);
! return ticket;
! }
! catch (Exception ex)
! {
! throw new JournalException("[GenericSqlJournal.newTicket]", ex);
! }
}
!
! /**
! * Get a ticket for tracking a document. This implementation logs the
! * operation to the log file and creates a directory for operations on
! * the ticket.
! *
! * @param parentTicket
! * @return
! * @throws JournalException
! */
! public IJournalTicket forkTicket (IJournalTicket parentTicket)
! throws JournalException
! {
! try
! {
! long nextVal = getNewLogID();
!
! IJournalTicket ticket = new JournalTicket(nextVal);
!
! // Log the operation
! log(ticket, JournalOperation.forkTicket, parentTicket.toString(),
! null, null);
!
! return ticket;
! } catch (Exception ex) {
! throw new JournalException("[GenericSqlJournal.forkTicket]", ex);
! }
}
!
! protected long getNewLogID ()
! throws SQLException, ResourceException
! {
! Connection conn = null;
! PreparedStatement stmt = null;
! ResultSet rs = null;
!
! try
! {
! String SQL = SqlQueryManager.getSqlQuery(LOG_KEY_GET);
! //getLog().debug("[PostgreSqlJournal.newTicket] called");
! conn = (Connection) resource.checkOut();
! stmt = conn.prepareStatement(SQL);
! rs = stmt.executeQuery();
! rs.next();
! long nextVal = rs.getLong(1);
!
! return nextVal;
! }
! finally
! {
! try
! {
! if (rs != null) rs.close();
! }
! catch (Exception ex)
! {
! LogService.getInstance().logError(I18n.get("sql.403"), ex);
! }
!
! try
! {
! if (stmt != null) stmt.close();
! }
! catch (Exception ex)
! {
! LogService.getInstance().logError(I18n.get("sql.403"), ex);
! }
!
! try
! {
! if (conn != null) resource.checkIn(conn);
! }
! catch (Exception ex)
! {
! LogService.getInstance().logError(I18n.get("sql.403"), ex);
! }
! }
}
!
}
--- 28,207 ----
* @author <a href="mailto:kg...@ga...">Ken Geis</a>
*/
! public class PostgreSqlJournal extends GenericSqlJournal {
! public final static String DELTA_MAKEROW =
! "journalAddBlankDataRow-postgresql";
! public final static String LOG_KEY_GET = "logKeyGet-postgresql";
!
! /**
! * Write a document to the rdbms. Same as in MySqlJournal, but it's
! * probably not a good idea to just subclass it.
! *
! * @param conn the connection
! * @param id the log id
! * @param step the log step
! */
! protected void writeDelta(Connection conn, long id, long step,
! PipelineDocument doc) throws SQLException {
!
! String insertStmt = SqlQueryManager.getSqlQuery(DELTA_MAKEROW);
! PreparedStatement stmt = null;
! ResultSet rs = null;
! ByteArrayOutputStream baos = null;
!
! try {
! // Write the document object to an array of bytes
! baos = new ByteArrayOutputStream();
!
! ObjectOutputStream oos = new ObjectOutputStream(baos);
! oos.writeObject(doc);
! oos.flush();
!
! byte[] docData = baos.toByteArray();
!
! // Now write the row
! stmt = conn.prepareStatement(insertStmt);
! stmt.setLong(1, id);
! stmt.setLong(2, step);
! stmt.setBytes(3, docData);
! stmt.execute();
!
! writeExtraData(conn, id, step, doc);
! } catch (Exception e) {
! throw new SQLException(e.toString());
! } finally {
! try {
! if (rs != null) rs.close();
! } catch (Exception ex) {
! LogService.getInstance().logError(I18n.get("sql.403"), ex);
! }
!
! try {
! if (stmt != null) stmt.close();
! } catch (Exception ex) {
! LogService.getInstance().logError(I18n.get("sql.403"), ex);
! }
!
! try {
! if (baos != null) baos.close();
! } catch (Exception ex) {
! LogService.getInstance().logError(I18n.get("sql.403"), ex);
! }
}
+ }
! /**
! * getTicketsProcessQueryString concoct the query string from the bits and
! * pieces. Calls back to the getTicketsProcess...
! *
! * @param jQuery
! * @return
! */
! protected StringBuffer getTicketsProcessQueryString(JournalQuery jQuery) {
!
! StringBuffer query = super.getTicketsProcessQueryString(jQuery);
!
! // Limit stuff
! if (jQuery.getStartIndex() > 0) {
! query.append(" limit " + jQuery.getStartIndex() +
! " offset " + jQuery.getNumResults());
!
! // HACK ALERT - need to do this to stop the parent skipping
! // on the result set.
! //
! // The above comment was taken from the MySQL implementation.
! // I don't know how it effects PostgreSQL.
! jQuery.setStartIndex(0);
}
! return query;
! }
!
! /**
! * Get a ticket for tracking a document. This implementation logs the
! * operation to the log file and creates a directory for operations on
! * the ticket.
! *
! * @return
! * @throws JournalException
! */
! public IJournalTicket newTicket() throws JournalException {
! try {
! //getLog().debug("[PostgreSqlJournal.newTicket] called");
! long nextVal = getNewLogID();
!
! IJournalTicket ticket = new JournalTicket(nextVal);
!
! // Log the operation
! log(ticket, JournalOperation.newTicket, null, null, null);
!
! return ticket;
! } catch (Exception ex) {
! throw new JournalException("[GenericSqlJournal.newTicket]", ex);
}
! }
!
! /**
! * Get a ticket for tracking a document. This implementation logs the
! * operation to the log file and creates a directory for operations on
! * the ticket.
! *
! * @param parentTicket
! * @return
! * @throws JournalException
! */
! public IJournalTicket forkTicket(IJournalTicket parentTicket)
! throws JournalException {
! try {
! long nextVal = getNewLogID();
!
! IJournalTicket ticket = new JournalTicket(nextVal);
!
! // Log the operation
! log(ticket, JournalOperation.forkTicket, parentTicket.toString(),
! null, null);
!
! return ticket;
! } catch (Exception ex) {
! throw new JournalException("[GenericSqlJournal.forkTicket]", ex);
}
! }
! protected long getNewLogID()
! throws SQLException, ResourceException {
! Connection conn = null;
! PreparedStatement stmt = null;
! ResultSet rs = null;
!
! try {
! String SQL = SqlQueryManager.getSqlQuery(LOG_KEY_GET);
!
! //getLog().debug("[PostgreSqlJournal.newTicket] called");
! conn = (Connection) getResource().checkOut();
! stmt = conn.prepareStatement(SQL);
! rs = stmt.executeQuery();
! rs.next();
! long nextVal = rs.getLong(1);
!
! return nextVal;
! } finally {
! try {
! if (rs != null) rs.close();
! } catch (Exception ex) {
! LogService.getInstance().logError(I18n.get("sql.403"), ex);
! }
!
! try {
! if (stmt != null) stmt.close();
! } catch (Exception ex) {
! LogService.getInstance().logError(I18n.get("sql.403"), ex);
! }
!
! try {
! if (conn != null) getResource().checkIn(conn);
! } catch (Exception ex) {
! LogService.getInstance().logError(I18n.get("sql.403"), ex);
! }
}
! }
!
}
|