From: David G. <dgl...@us...> - 2004-09-03 16:57:14
|
Update of /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/journal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22496/babeldoc/modules/sql/src/com/babeldoc/sql/journal Added Files: SqlServerJournal.java Log Message: Added journal support for Sql Server --- NEW FILE: SqlServerJournal.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. * ==================================================================== * * Babeldoc: The Universal Document Processor * * $Header: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/journal/SqlServerJournal.java,v 1.1 2004/09/03 16:57:04 dglick02 Exp $ * $DateTime$ * $Author: dglick02 $ * */ package com.babeldoc.sql.journal; import com.babeldoc.core.I18n; import com.babeldoc.core.LogService; import com.babeldoc.core.pipeline.PipelineDocument; import com.babeldoc.core.journal.query.JournalQuery; import com.babeldoc.sql.util.SqlQueryManager; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; /** * * Copied from MySqlServer.java. Rather then simply extend MySqlServer, it makes sense * to keep the database-specific classes totally separate so that one can change * MySqlServer without affecting this module, which could otherwise break. Propagating * bug fixes, you say? This is based on Bruce McDonald code, man; there are no bugs. * @author David Glick * @version 1.0 */ public class SqlServerJournal extends GenericSqlJournal { public static final String DELTA_MAKEROW = "journalAddBlankDataRow-sqlserver"; /** * getTicketsProcessQueryString concoct the query string from the bits and * pieces. Calls back to the getTicketsProcess... * * @param jQuery * * @return */ protected StringBuffer getTicketsProcessQueryString(JournalQuery jQuery) { boolean whereAdded; StringBuffer query = new StringBuffer(SqlQueryManager.getSqlQuery( LOG_QUERY_TICKETS)); whereAdded = getTicketsProcessDates(jQuery.getStartDate(), jQuery.getEndDate(), query); whereAdded = getTicketsProcessJournalOperations(whereAdded, query, jQuery.getJournalOperations()); getTicketsProcessQueryOptions(jQuery.getQueryOptions(), query); // Limit stuff if (jQuery.getStartIndex() > 0) { query.append(" limit " + jQuery.getStartIndex() + ", " + jQuery.getNumResults()); // HACK ALERT - need to do this to stop the parent skipping // on the result set. jQuery.setStartIndex(0); } return query; } /** * writeDelta - Write a document to the rdbms. * * @param con the connection * @param id the log id * @param step the log step * @param doc DOCUMENT ME! * * @throws SQLException DOCUMENT ME! */ protected void writeDelta(Connection con, long id, long step, PipelineDocument doc) throws SQLException { String insertStmt = SqlQueryManager.getSqlQuery(DELTA_MAKEROW); PreparedStatement pstmt = null; ResultSet rset = 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 pstmt = con.prepareStatement(insertStmt); pstmt.setLong(1, id); pstmt.setLong(2, step); pstmt.setBytes(3, docData); pstmt.execute(); writeExtraData(con, id, step, doc); } catch (Exception e) { throw new SQLException(e.toString()); } finally { try { if (rset != null) { rset.close(); } if (pstmt != null) { pstmt.close(); } if (baos != null) { baos.close(); } } catch (Exception e) { LogService.getInstance().logError(I18n.get("014003"), e); } } } } |