|
From: <de...@us...> - 2003-10-01 08:33:38
|
Update of /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker
In directory sc8-pr-cvs1:/tmp/cvs-serv19227/modules/scanner/src/com/babeldoc/scanner/worker
Modified Files:
SqlScanner.java
Log Message:
Added updateStatement config option for updating database after select statement executed. It can be used for marking rows as processed. See feature request #810269 submitted by Klaas Eikelboom
Index: SqlScanner.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker/SqlScanner.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** SqlScanner.java 24 Sep 2003 13:12:41 -0000 1.14
--- SqlScanner.java 1 Oct 2003 08:33:35 -0000 1.15
***************
*** 66,69 ****
--- 66,76 ----
package com.babeldoc.scanner.worker;
+ import java.sql.Connection;
+ import java.sql.ResultSet;
+ import java.sql.Statement;
+ import java.util.ArrayList;
+ import java.util.Collection;
+ import java.util.HashMap;
+
import com.babeldoc.core.I18n;
import com.babeldoc.core.LogService;
***************
*** 75,95 ****
import com.babeldoc.core.resource.ResourceException;
import com.babeldoc.core.resource.ResourceFactory;
!
! import com.babeldoc.scanner.*;
!
! import java.sql.Connection;
! import java.sql.ResultSet;
! import java.sql.Statement;
!
! import java.util.ArrayList;
! import java.util.Collection;
! import java.util.HashMap;
/**
* Scanner that scans SQL databases. The document can be constructed from the
! * results in a number of ways: 1. Document as csv 2. Document as xml 3. A
! * Document for every row
! *
* @author dejank
* @version 1.0
--- 82,102 ----
import com.babeldoc.core.resource.ResourceException;
import com.babeldoc.core.resource.ResourceFactory;
! import com.babeldoc.scanner.ScannerConfigurationException;
! import com.babeldoc.scanner.ScannerException;
! import com.babeldoc.scanner.ScannerWorker;
! import com.babeldoc.scanner.ScannerWorkerInfo;
/**
* Scanner that scans SQL databases. The document can be constructed from the
! * select results in a number of ways:
! * <ul>
! * <li>One document as csv document made of all results returned</li>
! * <li>One document as xml document made of all results returned</li>
! * <li>One document for every returned row (only first column will be included)</li>
! * </ul>
! * After selecting results an update statement can be executed (if provided) so
! * rows can be marked as processed (thanks Klaas Eikelboom!)
! *
* @author dejank
* @version 1.0
***************
*** 99,102 ****
--- 106,110 ----
public static final String RESOURCE_NAME = "resourceName";
public static final String SQL_STATEMENT = "sqlStatement";
+ public static final String UPDATE_STATEMENT = "updateStatement";
public static final String DOCUMENT_TYPE = "documentType";
public static final String FIELD_SEPARATOR = "cvsFieldSeparator";
***************
*** 123,126 ****
--- 131,135 ----
private String rowTag = DEFAULT_XML_ROW_TAG;
private String sqlStatement = null;
+ private String updateStatement = null;
***************
*** 209,213 ****
*/
public void doScan() throws ScannerException {
! getMessagesFromSql();
}
--- 218,222 ----
*/
public void doScan() throws ScannerException {
! getDocumentsFromSql();
}
***************
*** 225,229 ****
sqlStatement = this.getInfo().getStrValue(SQL_STATEMENT);
!
if (sqlStatement.equals("")) {
throw new ScannerConfigurationException(I18n.get("scanner.057"), null);
--- 234,238 ----
sqlStatement = this.getInfo().getStrValue(SQL_STATEMENT);
! updateStatement = this.getInfo().getStrValue(UPDATE_STATEMENT);
if (sqlStatement.equals("")) {
throw new ScannerConfigurationException(I18n.get("scanner.057"), null);
***************
*** 270,280 ****
/**
! * Get the messages.
*
* @throws ScannerException DOCUMENT ME!
*/
! private void getMessagesFromSql() throws ScannerException {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
--- 279,290 ----
/**
! * This is main method which generates documents from underlying database.
*
* @throws ScannerException DOCUMENT ME!
*/
! private void getDocumentsFromSql() throws ScannerException {
Connection conn = null;
Statement stmt = null;
+ Statement updstmt = null;
ResultSet rs = null;
***************
*** 291,294 ****
--- 301,310 ----
handleSimpleDocuments(rs);
}
+ if(updateStatement != null) {
+ updstmt = conn.createStatement();
+ updstmt.execute(updateStatement);
+ conn.commit();
+ }
+
} catch (Exception e) {
throw new ScannerException(I18n.get("scanner.059"), e);
***************
*** 307,310 ****
--- 323,334 ----
} catch (Exception ignoreThis) {
}
+
+ try {
+ if (updstmt != null) {
+ updstmt.close();
+ }
+ } catch (Exception ignoreThis) {
+ }
+
try {
***************
*** 367,370 ****
--- 391,399 ----
options.add(new ConfigOption(SqlScanner.SQL_STATEMENT,
IConfigOptionType.STRING, null, true, I18n.get("scanner.063")));
+
+ options.add(new ConfigOption(SqlScanner.UPDATE_STATEMENT,
+ IConfigOptionType.STRING, null, false,
+ I18n.get("scanner.SqlScanner.option.updateStatement")));
+
String[] docTypes = { SqlScanner.DOC_TYPE_SIMPLE, SqlScanner.DOC_TYPE_CSV, SqlScanner.DOC_TYPE_XML };
|