Update of /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/pipeline/stage
In directory sc8-pr-cvs1:/tmp/cvs-serv31427/src/com/babeldoc/sql/pipeline/stage
Modified Files:
SqlEnrichPipelineStage.java SqlQueryPipelineStage.java
SqlWriterPipelineStage.java
Log Message:
SqlQuery now uses DOM4J. Added the missing internationalization strings.
Index: SqlEnrichPipelineStage.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/pipeline/stage/SqlEnrichPipelineStage.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** SqlEnrichPipelineStage.java 16 Jul 2003 02:12:20 -0000 1.13
--- SqlEnrichPipelineStage.java 13 Aug 2003 22:44:30 -0000 1.14
***************
*** 148,152 ****
/**
! * execute the sql statement and convert to a hashmap of name/value pairs.
* Each name is the column/label of the result and the value is the value
* for its corresponding column/label.
--- 148,152 ----
/**
! * execute the sql statement and toXml to a hashmap of name/value pairs.
* Each name is the column/label of the result and the value is the value
* for its corresponding column/label.
Index: SqlQueryPipelineStage.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/pipeline/stage/SqlQueryPipelineStage.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** SqlQueryPipelineStage.java 16 Jul 2003 02:10:57 -0000 1.3
--- SqlQueryPipelineStage.java 13 Aug 2003 22:44:30 -0000 1.4
***************
*** 81,84 ****
--- 81,92 ----
import java.util.ArrayList;
import java.util.Collection;
+ import java.io.StringWriter;
+ import java.io.IOException;
+
+ import org.dom4j.Document;
+ import org.dom4j.DocumentFactory;
+ import org.dom4j.Element;
+ import org.dom4j.io.OutputFormat;
+ import org.dom4j.io.XMLWriter;
/**
***************
*** 97,114 ****
// Various constants for the xml document
- public static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
- public static final String ROOT_ELEMENT_START = "<queryresults>\n";
- public static final String ROW_ELEMENT_START = "<row>\n";
- public static final String COLUMN_ELEMNENT_END = "</column>\n";
- public static final String ROW_ELEMENT_END = "</row>\n";
- public static final String ROOT_ELEMENT_END = "</queryresults>\n";
public static final String XML_MIME_TYPE = "text/xml";
! public static final String COLUMN_ELEMENT_START1 = "<column column-name=\"";
! public static final String COLUMN_ELEMENT_START2 = "\" column-number=\"";
! public static final String COLUMN_ELEMENT_START3 = "\">";
! public static final String QUERY_ELEMENT_START1 = "<query query-name=\"";
! public static final String QUERY_ELEMENT_START2 = "\" query-number=\"";
! public static final String QUERY_ELEMENT_START3 = "\">\n";
! public static final String QUERY_ELEMENT_END = "</query>\n";
/**
--- 105,118 ----
// Various constants for the xml document
public static final String XML_MIME_TYPE = "text/xml";
! public static final String QUERY_RESULTS = "queryresults";
! public static final String QUERY = "query";
! public static final String QUERY_NAME = "query-name";
! public static final String QUERY_NUMBER = "query-number";
! public static final String ROW = "row";
! public static final String ROW_NUMBER = "row-number";
! public static final String COLUMN = "column";
! public static final String COLUMN_NAME = "column-name";
! public static final String COLUMN_NUMBER = "column-number";
/**
***************
*** 122,126 ****
public String getDescription() {
! return I18n.get("sql.900");
}
--- 126,130 ----
public String getDescription() {
! return I18n.get("sql.pipeline.stage.query.desc");
}
***************
*** 128,139 ****
ArrayList options = new ArrayList();
options.add(new ConfigOption(RESOURCE_NAME, IConfigOptionType.STRING,
! null, true, I18n.get("sql.901")));
IConfigOptionType queries = new ComplexConfigOptionType(new ConfigOption[]{
! new ConfigOption(SQL, IConfigOptionType.MULTI, null, false, I18n.get("sql.902"))
});
options.add(new ConfigOption(SQL, queries,
! null, false, I18n.get("sql.106")));
return options;
--- 132,144 ----
ArrayList options = new ArrayList();
options.add(new ConfigOption(RESOURCE_NAME, IConfigOptionType.STRING,
! null, true, I18n.get("sql.pipeline.stage.query.option.resource")));
IConfigOptionType queries = new ComplexConfigOptionType(new ConfigOption[]{
! new ConfigOption(SQL, IConfigOptionType.MULTI, null, false,
! I18n.get("sql.pipeline.stage.query.option.sql"))
});
options.add(new ConfigOption(SQL, queries,
! null, false, I18n.get("sql.pipeline.stage.query.option.sql")));
return options;
***************
*** 167,174 ****
* @throws PipelineException
*/
! private PipelineDocument createQueryDocument(NameValuePair[] queries) throws PipelineException {
! StringBuffer xml = new StringBuffer();
! xml.append(XML_HEADER);
! xml.append(ROOT_ELEMENT_START);
Connection conn = null;
--- 172,179 ----
* @throws PipelineException
*/
! private PipelineDocument createQueryDocument(NameValuePair[] queries)
! throws PipelineException {
! Document document = DocumentFactory.getInstance().createDocument();
! Element root = document.addElement(QUERY_RESULTS);
Connection conn = null;
***************
*** 181,204 ****
// Iterate through sqls
if ((queries != null) && (queries.length > 0)) {
for (int i = 0; i < queries.length; ++i) {
String queryName = queries[i].getName();
! xml.append(QUERY_ELEMENT_START1+queryName+QUERY_ELEMENT_START2+i+QUERY_ELEMENT_START3);
sql = queries[i].getValue();
stmt = conn.createStatement();
LogService.getInstance().logDebug("Executing " + sql);
rs = stmt.executeQuery(sql);
! ResultSetMetaData metaData = rs.getMetaData();
! while (rs.next()) {
! xml.append(ROW_ELEMENT_START);
! for (int j = 1, count = metaData.getColumnCount(); j <= count; j++) {
! String name = metaData.getColumnLabel(j).toLowerCase();
! Object value = rs.getObject(j);
! xml.append(COLUMN_ELEMENT_START1+name+COLUMN_ELEMENT_START2+j+COLUMN_ELEMENT_START3);
! xml.append(value);
! xml.append(COLUMN_ELEMNENT_END);
! }
! xml.append(ROW_ELEMENT_END);
! }
! xml.append(QUERY_ELEMENT_END);
}
}
--- 186,200 ----
// Iterate through sqls
if ((queries != null) && (queries.length > 0)) {
+ Element queryElement = root.addElement(QUERY);
for (int i = 0; i < queries.length; ++i) {
String queryName = queries[i].getName();
! queryElement.addAttribute(QUERY_NAME, queryName);
! queryElement.addAttribute(QUERY_NUMBER, Integer.toString(i));
!
sql = queries[i].getValue();
stmt = conn.createStatement();
LogService.getInstance().logDebug("Executing " + sql);
rs = stmt.executeQuery(sql);
! handleRows(rs, queryElement);
}
}
***************
*** 229,239 ****
}
}
! xml.append(ROOT_ELEMENT_END);
! PipelineDocument newDoc = new PipelineDocument(this.getDocument(), xml.toString().getBytes());
newDoc.setMimeType(XML_MIME_TYPE);
return newDoc;
}
-
/**
--- 225,262 ----
}
}
! PipelineDocument newDoc = createPipelineDocument(document);
! return newDoc;
! }
! private void handleRows(ResultSet rs, Element queryElement) throws SQLException {
! ResultSetMetaData metaData = rs.getMetaData();
! int rowNum = 0;
! while (rs.next()) {
! Element rowElement = queryElement.addElement(ROW);
! rowElement.addAttribute(ROW_NUMBER, Integer.toString(rowNum++));
! for (int j = 1, count = metaData.getColumnCount(); j <= count; j++) {
! String name = metaData.getColumnLabel(j).toLowerCase();
! Object value = rs.getObject(j);
! Element columnElement = rowElement.addElement(COLUMN);
! columnElement.addAttribute(COLUMN_NAME, name);
! columnElement.addAttribute(COLUMN_NUMBER, Integer.toString(j));
! columnElement.setText(value.toString());
! }
! }
! }
!
! private PipelineDocument createPipelineDocument(Document document) {
! OutputFormat outformat = OutputFormat.createCompactFormat();
! StringWriter stringWriter = new StringWriter();
! XMLWriter writer = new XMLWriter(stringWriter, outformat);
! try {
! writer.write(document);
! writer.flush();
! } catch (IOException e) {
! }
! PipelineDocument newDoc = new PipelineDocument(this.getDocument(), stringWriter.toString().getBytes());
newDoc.setMimeType(XML_MIME_TYPE);
return newDoc;
}
/**
Index: SqlWriterPipelineStage.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/pipeline/stage/SqlWriterPipelineStage.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** SqlWriterPipelineStage.java 27 Jun 2003 02:05:59 -0000 1.13
--- SqlWriterPipelineStage.java 13 Aug 2003 22:44:30 -0000 1.14
***************
*** 284,288 ****
if (batchSupported) {
stmt.addBatch(command);
! LogService.getInstance().logDebug("Command " + command +
" added to batch list");
currentBatchSize++;
--- 284,288 ----
if (batchSupported) {
stmt.addBatch(command);
! LogService.getInstance().logDebug("LightConfigCommand " + command +
" added to batch list");
currentBatchSize++;
|