annotate src/main/java/org/monetdb/util/XMLExporter.java @ 391:f523727db392

Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.* This naming complies to the Java Package Naming convention as MonetDB's main website is www.monetdb.org.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 12 Nov 2020 22:02:01 +0100 (2020-11-12)
parents src/main/java/nl/cwi/monetdb/util/XMLExporter.java@54137aeb1f92
children bf9f6b6ecf40
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
1 /*
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
2 * This Source Code Form is subject to the terms of the Mozilla Public
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
5 *
350
54137aeb1f92 Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 321
diff changeset
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
7 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
8
391
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 350
diff changeset
9 package org.monetdb.util;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
10
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
11 import java.sql.ResultSet;
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
12 import java.sql.SQLException;
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
13 import java.sql.Timestamp;
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
14 import java.sql.Types;
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
15 import java.text.SimpleDateFormat;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
16
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
17 public final class XMLExporter extends Exporter {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
18 private boolean useNil;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
19
309
8a96a4a13528 Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 307
diff changeset
20 public static final short TYPE_NIL = 1;
8a96a4a13528 Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 307
diff changeset
21 public static final short VALUE_OMIT = 0;
8a96a4a13528 Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 307
diff changeset
22 public static final short VALUE_XSI = 1;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
23
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
24 public XMLExporter(final java.io.PrintWriter out) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
25 super(out);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
26 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
27
312
df815a403bf4 Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 311
diff changeset
28 /**
df815a403bf4 Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 311
diff changeset
29 * A helper method to generate XML xsd schema code for a given table.
df815a403bf4 Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 311
diff changeset
30 * This method performs all required lookups to find all relations and
df815a403bf4 Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 311
diff changeset
31 * column information.
df815a403bf4 Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 311
diff changeset
32 *
df815a403bf4 Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 311
diff changeset
33 * @param dbmd a DatabaseMetaData object to query on (not null)
df815a403bf4 Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 311
diff changeset
34 * @param type the type of the object, e.g. VIEW, TABLE (not null)
df815a403bf4 Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 311
diff changeset
35 * @param schema the schema the object is in (not null)
df815a403bf4 Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 311
diff changeset
36 * @param name the table to describe (not null)
df815a403bf4 Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 311
diff changeset
37 * @throws SQLException if a database related error occurs
df815a403bf4 Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 311
diff changeset
38 */
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
39 public void dumpSchema(
309
8a96a4a13528 Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 307
diff changeset
40 final java.sql.DatabaseMetaData dbmd,
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
41 final String type,
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
42 final String schema,
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
43 final String name)
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
44 throws SQLException
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
45 {
309
8a96a4a13528 Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 307
diff changeset
46 // handle views directly
318
13a9d5316e37 Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 315
diff changeset
47 if (type.endsWith("VIEW")) { // for types: VIEW and SYSTEM VIEW
13a9d5316e37 Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 315
diff changeset
48 final String viewDDL = fetchSysTablesQueryValue(dbmd.getConnection(), schema, name);
13a9d5316e37 Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 315
diff changeset
49 if (viewDDL != null)
13a9d5316e37 Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 315
diff changeset
50 out.println("<!-- " + viewDDL + " -->");
13a9d5316e37 Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 315
diff changeset
51 else
321
dbd8e9a8566f Fixed JdbcClient program. It now allows you to describe tables or view which contains whitespaces by using double quotes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 318
diff changeset
52 out.println("<!-- unknown " + type + " " + dq(schema) + "." + dq(name) + ": no SQL view definition found! -->");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
53 return;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
54 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
55
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
56 out.println("<xsd:schema>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
57
315
4793f9b80bb3 Removed the catalog parameter from the Exporter.dumpSchema method as it is always null for MonetDB.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 314
diff changeset
58 final ResultSet cols = dbmd.getColumns(null, schema, name, null);
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
59 final int colNmIndex = cols.findColumn("COLUMN_NAME");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
60 final int colTypeNmIndex = cols.findColumn("TYPE_NAME");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
61 final int datatypeIndex = cols.findColumn("DATA_TYPE");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
62 final int sizeIndex = cols.findColumn("COLUMN_SIZE");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
63 final int digitsIndex = cols.findColumn("DECIMAL_DIGITS");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
64
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
65 String ident;
309
8a96a4a13528 Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 307
diff changeset
66 final java.util.HashSet<String> types = new java.util.HashSet<String>();
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
67 // walk through the ResultSet and create the types
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
68 // for a bit of a clue on the types, see this url:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
69 // http://books.xmlschemata.org/relaxng/relax-CHP-19.html
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
70 while (cols.next()) {
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
71 switch (cols.getInt(datatypeIndex)) {
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
72 case Types.CHAR:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
73 ident = "CHAR_" + cols.getString(sizeIndex);
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
74 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
75 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
76 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
77
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
78 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
79 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
80 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
81 out.println(" <xsd:restriction base=\"xsd:string\">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
82 out.print(" <xsd:length value=");
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
83 out.print(dq(cols.getString(sizeIndex)));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
84 out.println(" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
85 out.println(" </xsd:restriction>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
86 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
87 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
88 case Types.VARCHAR:
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
89 case Types.LONGVARCHAR:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
90 ident = "VARCHAR_" + cols.getString(sizeIndex);
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
91 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
92 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
93 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
94
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
95 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
96 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
97 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
98 out.println(" <xsd:restriction base=\"xsd:string\">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
99 out.print(" <xsd:maxLength value=");
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
100 out.print(dq(cols.getString(sizeIndex)));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
101 out.println(" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
102 out.println(" </xsd:restriction>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
103 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
104 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
105 case Types.CLOB:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
106 ident = "CLOB";
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
107 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
108 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
109 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
110
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
111 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
112 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
113 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
114 out.println(" <xsd:restriction base=\"xsd:string\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
115 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
116 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
117 case Types.DECIMAL:
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
118 case Types.NUMERIC:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
119 ident = "DECIMAL_" + cols.getString(sizeIndex) + "_" + cols.getString(digitsIndex);
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
120 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
121 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
122 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
123
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
124 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
125 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
126 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
127 out.println(" <xsd:restriction base=\"xsd:decimal\">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
128 out.print(" <xsd:totalDigits value=");
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
129 out.print(dq(cols.getString(sizeIndex)));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
130 out.println(" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
131 out.print(" <xsd:fractionDigits value=");
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
132 out.print(dq(cols.getString(digitsIndex)));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
133 out.println(" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
134 out.println(" </xsd:restriction>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
135 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
136 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
137 case Types.TINYINT:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
138 ident = "TINYINT";
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
139 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
140 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
141 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
142
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
143 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
144 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
145 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
146 out.println(" <xsd:restriction base=\"xsd:byte\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
147 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
148 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
149 case Types.SMALLINT:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
150 ident = "SMALLINT";
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
151 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
152 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
153 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
154
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
155 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
156 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
157 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
158 out.println(" <xsd:restriction base=\"xsd:short\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
159 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
160 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
161 case Types.INTEGER:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
162 ident = "INTEGER";
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
163 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
164 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
165 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
166
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
167 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
168 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
169 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
170 out.println(" <xsd:restriction base=\"xsd:integer\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
171 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
172 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
173 case Types.BIGINT:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
174 ident = "BIGINT";
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
175 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
176 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
177 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
178
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
179 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
180 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
181 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
182 out.println(" <xsd:restriction base=\"xsd:long\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
183 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
184 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
185 case Types.BIT:
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
186 ident = "BIT";
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
187 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
188 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
189 types.add(ident);
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
190
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
191 out.print(" <xsd:simpleType name=");
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
192 out.print(dq(ident));
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
193 out.println(">");
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
194 out.println(" <xsd:restriction base=\"xsd:bit\" />");
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
195 out.println(" </xsd:simpleType>");
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
196 break;
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
197 case Types.BOOLEAN:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
198 ident = "BOOLEAN";
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
199 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
200 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
201 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
202
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
203 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
204 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
205 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
206 out.println(" <xsd:restriction base=\"xsd:boolean\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
207 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
208 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
209 case Types.DATE:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
210 ident = "DATE";
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
211 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
212 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
213 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
214
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
215 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
216 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
217 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
218 out.println(" <xsd:restriction base=\"xsd:date\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
219 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
220 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
221 case Types.TIME:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
222 if ("timetz".equals(cols.getString(colTypeNmIndex))) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
223 ident = "TIME_WTZ";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
224 } else {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
225 ident = "TIME";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
226 }
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
227 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
228 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
229 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
230
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
231 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
232 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
233 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
234 out.println(" <xsd:restriction base=\"xsd:time\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
235 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
236 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
237 case Types.TIMESTAMP:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
238 if ("timestamptz".equals(cols.getString(colTypeNmIndex))) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
239 ident = "TIMESTAMP_WTZ";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
240 } else {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
241 ident = "TIMESTAMP";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
242 }
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
243 if (types.contains(ident))
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
244 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
245 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
246
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
247 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
248 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
249 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
250 out.println(" <xsd:restriction base=\"xsd:dateTime\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
251 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
252 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
253 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
254 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
255
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
256 // rewind the ResultSet
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
257 cols.beforeFirst();
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
258
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
259 // create the RowType
315
4793f9b80bb3 Removed the catalog parameter from the Exporter.dumpSchema method as it is always null for MonetDB.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 314
diff changeset
260 final String tablenm = schema.replaceAll("\\.", "_x002e_") + "." + name.replaceAll("\\.", "_x002e_");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
261 out.print(" <xsd:complexType name=");
315
4793f9b80bb3 Removed the catalog parameter from the Exporter.dumpSchema method as it is always null for MonetDB.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 314
diff changeset
262 out.print(dq("RowType." + tablenm));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
263 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
264 out.println(" <xsd:sequence>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
265 while (cols.next()) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
266 out.print(" <xsd:element name=");
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
267 out.print(dq(cols.getString(colNmIndex)));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
268 out.print(" type=");
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
269 switch (cols.getInt(datatypeIndex)) {
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
270 case Types.CHAR:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
271 ident = "CHAR_" + cols.getString(sizeIndex);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
272 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
273 case Types.VARCHAR:
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
274 case Types.LONGVARCHAR:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
275 ident = "VARCHAR_" + cols.getString(sizeIndex);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
276 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
277 case Types.CLOB:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
278 ident = "CLOB";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
279 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
280 case Types.DECIMAL:
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
281 case Types.NUMERIC:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
282 ident = "DECIMAL_" + cols.getString(sizeIndex) +
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
283 "_" + cols.getString(digitsIndex);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
284 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
285 case Types.TINYINT:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
286 ident = "TINYINT";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
287 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
288 case Types.SMALLINT:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
289 ident = "SMALLINT";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
290 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
291 case Types.INTEGER:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
292 ident = "INTEGER";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
293 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
294 case Types.BIGINT:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
295 ident = "BIGINT";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
296 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
297 case Types.BIT:
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
298 ident = "BIT";
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
299 break;
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
300 case Types.BOOLEAN:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
301 ident = "BOOLEAN";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
302 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
303 case Types.DATE:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
304 ident = "DATE";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
305 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
306 case Types.TIME:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
307 if ("timetz".equals(cols.getString(colTypeNmIndex))) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
308 ident = "TIME_WTZ";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
309 } else {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
310 ident = "TIME";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
311 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
312 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
313 case Types.TIMESTAMP:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
314 if ("timestamptz".equals(cols.getString(colTypeNmIndex))) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
315 ident = "TIMESTAMP_WTZ";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
316 } else {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
317 ident = "TIMESTAMP";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
318 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
319 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
320 default:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
321 ident = "(unknown)";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
322 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
323 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
324 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
325 out.println(" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
326 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
327 out.println(" </xsd:sequence>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
328 out.println(" </xsd:complexType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
329
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
330 out.print(" <xsd:complexType name=");
315
4793f9b80bb3 Removed the catalog parameter from the Exporter.dumpSchema method as it is always null for MonetDB.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 314
diff changeset
331 out.print(dq("TableType." + tablenm));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
332 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
333 out.println(" <xsd:sequence>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
334 out.print(" <xsd:element name=\"row\" type=");
315
4793f9b80bb3 Removed the catalog parameter from the Exporter.dumpSchema method as it is always null for MonetDB.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 314
diff changeset
335 out.print(dq("RowType." + tablenm));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
336 out.println(" minOccurs=\"0\" maxOccurs=\"unbounded\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
337 out.println(" </xsd:sequence>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
338 out.println(" </xsd:complexType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
339
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
340 out.println("</xsd:schema>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
341 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
342
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
343 private static SimpleDateFormat xsd_ts;
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
344 private static SimpleDateFormat xsd_tstz;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
345
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
346 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
347 * Generates an XML representation of the given ResultSet.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
348 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
349 * @param rs the ResultSet
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
350 */
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
351 public void dumpResultSet(final ResultSet rs) throws SQLException {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
352 // write simple XML serialisation
309
8a96a4a13528 Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 307
diff changeset
353 final java.sql.ResultSetMetaData rsmd = rs.getMetaData();
313
f2750ea9f93d When exporting table/view definition always include the schema name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 312
diff changeset
354 final String schema = rsmd.getSchemaName(1);
f2750ea9f93d When exporting table/view definition always include the schema name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 312
diff changeset
355 final String fqname = (schema != null && !schema.isEmpty() ? schema + "." : "") + rsmd.getTableName(1);
f2750ea9f93d When exporting table/view definition always include the schema name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 312
diff changeset
356 out.println("<" + fqname + ">");
f2750ea9f93d When exporting table/view definition always include the schema name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 312
diff changeset
357
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
358 String data;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
359 while (rs.next()) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
360 out.println(" <row>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
361 for (int i = 1; i <= rsmd.getColumnCount(); i++) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
362 switch (rsmd.getColumnType(i)) {
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
363 case Types.TIMESTAMP:
309
8a96a4a13528 Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 307
diff changeset
364 final Timestamp ts = rs.getTimestamp(i);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
365 if ("timestamptz".equals(rsmd.getColumnTypeName(i))) {
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
366 if (xsd_tstz == null) {
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
367 // first time it is needed, create it
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
368 xsd_tstz = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
369 }
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
370 data = xsd_tstz.format(ts).toString();
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
371 } else {
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
372 if (xsd_ts == null) {
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
373 // first time it is needed, create it
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
374 xsd_ts = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
375 }
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
376 data = xsd_ts.format(ts).toString();
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
377 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
378 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
379 default:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
380 data = rs.getString(i);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
381 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
382 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
383 if (data == null) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
384 if (useNil) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
385 // "nil" method: write <tag xsi:nil="true" />
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
386 out.println(" <" + rsmd.getColumnLabel(i) + " xsi:nil=\"true\" />");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
387 } else {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
388 // This is the "absent" method (of completely
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
389 // hiding the tag if null
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
390 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
391 } else {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
392 if (data.length() == 0) {
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
393 out.println(" <" + rsmd.getColumnLabel(i) + " />");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
394 } else {
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
395 final String colLabel = rsmd.getColumnLabel(i);
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
396 out.println(" <" + colLabel + ">" + escapeSpecialXMLChars(data) + "</" + colLabel + ">");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
397 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
398 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
399 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
400 out.println(" </row>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
401 }
313
f2750ea9f93d When exporting table/view definition always include the schema name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 312
diff changeset
402 out.println("</" + fqname + ">");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
403 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
404
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
405 // https://en.wikipedia.org/wiki/XML#Escaping
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
406 private static final String escapeSpecialXMLChars(final String val) {
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
407 final int len = val.length();
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
408 final StringBuilder sb = new StringBuilder(len + 50);
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
409 // replace each & or < or > or ' or " by special XML escape code
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
410 for (int i = 0; i < len; i++) {
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
411 char c = val.charAt(i);
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
412 switch (c) {
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
413 case '&':
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
414 sb.append("&amp;");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
415 break;
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
416 case '<':
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
417 sb.append("&lt;");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
418 break;
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
419 case '>':
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
420 sb.append("&gt;");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
421 break;
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
422 case '\'':
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
423 sb.append("&apos;");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
424 break;
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
425 case '"':
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
426 sb.append("&quot;");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
427 break;
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
428 default:
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
429 sb.append(c);
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
430 }
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
431 }
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
432 return (sb.length() > len) ? sb.toString() : val;
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
433 }
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
434
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
435 public void setProperty(final int type, final int value) throws Exception {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
436 switch (type) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
437 case TYPE_NIL:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
438 switch (value) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
439 case VALUE_OMIT:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
440 useNil = false;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
441 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
442 case VALUE_XSI:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
443 useNil = true;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
444 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
445 default:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
446 throw new Exception("Illegal value " + value + " for TYPE_NIL");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
447 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
448 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
449 default:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
450 throw new Exception("Illegal type " + type);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
451 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
452 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
453
307
05549bc7ed26 Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
454 public int getProperty(final int type) throws Exception {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
455 switch (type) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
456 case TYPE_NIL:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
457 return useNil ? VALUE_XSI : VALUE_OMIT;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
458 default:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
459 throw new Exception("Illegal type " + type);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
460 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
461 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
462 }