|
From: SVN by r. <sv...@ca...> - 2009-12-17 15:44:59
|
Author: roy
Date: 2009-12-17 16:44:46 +0100 (Thu, 17 Dec 2009)
New Revision: 441
Modified:
src/main/java/nl/improved/sqlclient/commands/ReadCommand.java
Log:
oracle number fixes
fixes to encoding
Modified: src/main/java/nl/improved/sqlclient/commands/ReadCommand.java
===================================================================
--- src/main/java/nl/improved/sqlclient/commands/ReadCommand.java 2009-12-16 15:15:46 UTC (rev 440)
+++ src/main/java/nl/improved/sqlclient/commands/ReadCommand.java 2009-12-17 15:44:46 UTC (rev 441)
@@ -4,7 +4,9 @@
import javax.xml.parsers.SAXParser;
import nl.improved.sqlclient.*;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
@@ -18,6 +20,7 @@
import java.util.Vector;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
@@ -33,6 +36,9 @@
static void setAutoCommit(boolean b) {
autoCommit = b;
}
+ static boolean getAutoCommit() {
+ return autoCommit;
+ }
private String fileName;
private ReadCommandContentHandler contentHandler;
@@ -102,7 +108,6 @@
pstmt.setObject(i+1, o);
}
}
- output(valuesList.toString());
// execute query...
pstmt.executeUpdate();
valuesList.clear();
@@ -132,7 +137,6 @@
valuesList.add(NULL_DATE);
} else {
try {
- //pstmt.setDate(colNr + 1, new Date(formatter.parse(nodeValue).getTime()));
valuesList.add(new Date(formatter.parse(nodeValue.replace("\n", "").trim()).getTime()));
} catch (ParseException ex) {
throw new IOException("Row: "+ rowCount+" Failed to parse date :"+ nodeValue);
@@ -151,13 +155,22 @@
try {
int iType = Integer.parseInt(typeString);
switch (iType) {
+ case Types.NUMERIC:
case Types.INTEGER:
case Types.SMALLINT:
case Types.BIGINT:
- valuesList.add(Integer.parseInt(nodeValue));
+ if (nodeValue == null || nodeValue.equals("")) {
+ valuesList.add(null);
+ } else {
+ valuesList.add(Integer.parseInt(nodeValue));
+ }
break;
case Types.DOUBLE:
- valuesList.add(Double.parseDouble(nodeValue));
+ if (nodeValue == null || nodeValue.equals("")) {
+ valuesList.add(null);
+ } else {
+ valuesList.add(Double.parseDouble(nodeValue));
+ }
break;
case Types.VARCHAR:
case Types.CHAR:
@@ -170,24 +183,33 @@
valuesList.add(nodeValue);
}
} catch(Exception e) {
- throw new IllegalArgumentException("Row :"+ rowCount +": Warning invalid type read: '" + typeString+"'");
+ throw new IllegalArgumentException("Row :"+ rowCount +": Warning invalid type read: '" + typeString+"'", e);
}
}
}
}
};
- //reader.setContentHandler(contentHandler);
- parser.parse(new File(fileName), contentHandler);
+ InputStreamReader ir = new InputStreamReader(new FileInputStream(fileName), ENCODING);
+ InputSource source = new InputSource(ir);
+ parser.parse(source, contentHandler);
int rowCount= contentHandler.rowCount;
contentHandler = null;
- return new SimpleCommandResult(true, "Read from " + fileName + " done. (" + rowCount + " rows imported)");
+ if (autoCommit && c != null) {
+ c.commit();
+ return new SimpleCommandResult(true, "Read from " + fileName + " done. (" + rowCount + " rows comitted)");
+ } else {
+ return new SimpleCommandResult(true, "Read from " + fileName + " done. (" + rowCount + " rows imported)");
+ }
} catch (AbortException e) {
int rowCount= contentHandler.rowCount;
contentHandler = null;
return new SimpleCommandResult(true, "Read from " + fileName + " aborted. (" + rowCount + " rows imported)");
} catch (Exception e) {
- int rowCount= contentHandler.rowCount;
- contentHandler = null;
+ int rowCount= -1;
+ if (contentHandler != null) {
+ rowCount= contentHandler.rowCount;
+ contentHandler = null;
+ }
throw new IllegalStateException("Row: "+ rowCount+" Failed to read dump (" + fileName + "): " + e.toString(), e);
}
}
@@ -278,7 +300,8 @@
public void endElement(String uri, String localName, String qName) throws SAXException {
if (nameTree.get(nameTree.size()-1).name.equals(qName)) {
try {
- handleElement(nameTree.remove(nameTree.size() - 1), content.toString());
+ String s = new String(content.toString().getBytes(ENCODING)); // fix encoding
+ handleElement(nameTree.remove(nameTree.size() - 1), s);
} catch (SQLException e) {
throw new IllegalStateException("Failed to execute update query for dump(" + fileName + "): " + e.toString(), e);
} catch (IOException e) {
@@ -304,10 +327,12 @@
@Override
public void processingInstruction(String target, String data) throws SAXException {
+ System.out.println(data);
}
@Override
public void skippedEntity(String name) throws SAXException {
+ System.out.println(name);
}
}
|