XML array hack v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 26 Feb 2019 15:57:49 +0100
branchv_0
changeset 2330fb3b92e01c5
parent 232 4061e0c7f907
child 234 305871254838
XML array hack
java/sql-dk/src/info/globalcode/sql/dk/formatting/XmlFormatter.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/XmlFormatter.java	Tue Feb 26 15:49:57 2019 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/XmlFormatter.java	Tue Feb 26 15:57:49 2019 +0100
     1.3 @@ -25,8 +25,10 @@
     1.4  import info.globalcode.sql.dk.configuration.PropertyDeclaration;
     1.5  import static info.globalcode.sql.dk.formatting.AbstractXmlFormatter.qname;
     1.6  import java.sql.Array;
     1.7 +import java.sql.ResultSet;
     1.8  import java.sql.SQLException;
     1.9  import java.sql.SQLXML;
    1.10 +import java.util.ArrayList;
    1.11  import java.util.LinkedHashMap;
    1.12  import java.util.List;
    1.13  import java.util.Map;
    1.14 @@ -171,11 +173,33 @@
    1.15  				printArray(array);
    1.16  				printEndElement();
    1.17  			} catch (SQLException e) {
    1.18 +				// FIXME: rewrite array formatting, remember array mode, don't try sqlArray.getArray() again and again if it has failed
    1.19  				log.log(Level.SEVERE, "Unable to format array", e);
    1.20 +				try {
    1.21 +					ResultSet arrayResultSet = sqlArray.getResultSet();
    1.22 +					//int columnCount = arrayResultSet.getMetaData().getColumnCount();
    1.23 +					ArrayList<Object> arrayList = new ArrayList<>();
    1.24 +					while (arrayResultSet.next()) {
    1.25 +						arrayList.add(arrayResultSet.getObject(2));
    1.26 +						// for (int i = 1; i <= columnCount; i++) {
    1.27 +						// 	log.log(Level.INFO, "Array column {0} = {1}", new Object[]{i, arrayResultSet.getObject(i)});
    1.28 +						// }
    1.29 +					}
    1.30 +
    1.31 +					printStartElement(qname("column"), attributes);
    1.32 +					// FIXME: instanceof SQLXML, see below
    1.33 +					printArray(arrayList.toArray());
    1.34 +					printEndElement();
    1.35 +
    1.36 +				} catch (SQLException e2) {
    1.37 +					// FIXME: fix logging, error recovery
    1.38 +					log.log(Level.SEVERE, "Second level fuck up !!!", e2);
    1.39 +				}
    1.40 +
    1.41  				writeColumnValue(String.valueOf(value));
    1.42  			}
    1.43  
    1.44 -		} else if (value instanceof SQLXML) {
    1.45 +		} else if (value instanceof SQLXML) { // FIXME: move to separate method, to AbstractFormatter?
    1.46  			SQLXML xml = (SQLXML) value;
    1.47  			// TODO: parse DOM/SAX and transplant XML, don't escape (optional)
    1.48  			try {