annotate src/main/java/org/monetdb/util/XMLExporter.java @ 424:709300b32284

Added entries for new Java 8 java.sql.Types: Types.TIME_WITH_TIMEZONE and Types.TIMESTAMP_WITH_TIMEZONE
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Wed, 03 Feb 2021 16:23:39 +0100 (2021-02-03)
parents bf9f6b6ecf40
children 6aa38e8c0f2d
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 *
406
bf9f6b6ecf40 Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 391
diff changeset
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2021 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:
424
709300b32284 Added entries for new Java 8 java.sql.Types: Types.TIME_WITH_TIMEZONE and Types.TIMESTAMP_WITH_TIMEZONE
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 406
diff changeset
222 case Types.TIME_WITH_TIMEZONE:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
223 if ("timetz".equals(cols.getString(colTypeNmIndex))) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
224 ident = "TIME_WTZ";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
225 } else {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
226 ident = "TIME";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
227 }
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
228 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
229 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
230 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
231
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
232 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
233 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
234 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
235 out.println(" <xsd:restriction base=\"xsd:time\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
236 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
237 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
238 case Types.TIMESTAMP:
424
709300b32284 Added entries for new Java 8 java.sql.Types: Types.TIME_WITH_TIMEZONE and Types.TIMESTAMP_WITH_TIMEZONE
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 406
diff changeset
239 case Types.TIMESTAMP_WITH_TIMEZONE:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
240 if ("timestamptz".equals(cols.getString(colTypeNmIndex))) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
241 ident = "TIMESTAMP_WTZ";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
242 } else {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
243 ident = "TIMESTAMP";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
244 }
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
245 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
246 break;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
247 types.add(ident);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
248
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
249 out.print(" <xsd:simpleType name=");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
250 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
251 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
252 out.println(" <xsd:restriction base=\"xsd:dateTime\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
253 out.println(" </xsd:simpleType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
254 break;
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 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
257
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
258 // rewind the ResultSet
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
259 cols.beforeFirst();
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
260
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
261 // 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
262 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
263 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
264 out.print(dq("RowType." + tablenm));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
265 out.println(">");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
266 out.println(" <xsd:sequence>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
267 while (cols.next()) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
268 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
269 out.print(dq(cols.getString(colNmIndex)));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
270 out.print(" type=");
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
271 switch (cols.getInt(datatypeIndex)) {
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
272 case Types.CHAR:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
273 ident = "CHAR_" + cols.getString(sizeIndex);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
274 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
275 case Types.VARCHAR:
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
276 case Types.LONGVARCHAR:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
277 ident = "VARCHAR_" + cols.getString(sizeIndex);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
278 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
279 case Types.CLOB:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
280 ident = "CLOB";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
281 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
282 case Types.DECIMAL:
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
283 case Types.NUMERIC:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
284 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
285 "_" + cols.getString(digitsIndex);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
286 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
287 case Types.TINYINT:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
288 ident = "TINYINT";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
289 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
290 case Types.SMALLINT:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
291 ident = "SMALLINT";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
292 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
293 case Types.INTEGER:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
294 ident = "INTEGER";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
295 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
296 case Types.BIGINT:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
297 ident = "BIGINT";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
298 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
299 case Types.BIT:
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
300 ident = "BIT";
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
301 break;
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
302 case Types.BOOLEAN:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
303 ident = "BOOLEAN";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
304 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
305 case Types.DATE:
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
306 ident = "DATE";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
307 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
308 case Types.TIME:
424
709300b32284 Added entries for new Java 8 java.sql.Types: Types.TIME_WITH_TIMEZONE and Types.TIMESTAMP_WITH_TIMEZONE
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 406
diff changeset
309 case Types.TIME_WITH_TIMEZONE:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
310 if ("timetz".equals(cols.getString(colTypeNmIndex))) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
311 ident = "TIME_WTZ";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
312 } else {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
313 ident = "TIME";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
314 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
315 break;
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
316 case Types.TIMESTAMP:
424
709300b32284 Added entries for new Java 8 java.sql.Types: Types.TIME_WITH_TIMEZONE and Types.TIMESTAMP_WITH_TIMEZONE
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 406
diff changeset
317 case Types.TIMESTAMP_WITH_TIMEZONE:
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
318 if ("timestamptz".equals(cols.getString(colTypeNmIndex))) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
319 ident = "TIMESTAMP_WTZ";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
320 } else {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
321 ident = "TIMESTAMP";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
322 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
323 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
324 default:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
325 ident = "(unknown)";
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
326 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
327 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
328 out.print(dq(ident));
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
329 out.println(" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
330 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
331 out.println(" </xsd:sequence>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
332 out.println(" </xsd:complexType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
333
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
334 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
335 out.print(dq("TableType." + tablenm));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
336 out.println(">");
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.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
339 out.print(dq("RowType." + tablenm));
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
340 out.println(" minOccurs=\"0\" maxOccurs=\"unbounded\" />");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
341 out.println(" </xsd:sequence>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
342 out.println(" </xsd:complexType>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
343
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
344 out.println("</xsd:schema>");
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
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
347 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
348 private static SimpleDateFormat xsd_tstz;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
349
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
350 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
351 * Generates an XML representation of the given ResultSet.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
352 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
353 * @param rs the ResultSet
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
354 */
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
355 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
356 // 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
357 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
358 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
359 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
360 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
361
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
362 String data;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
363 while (rs.next()) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
364 out.println(" <row>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
365 for (int i = 1; i <= rsmd.getColumnCount(); i++) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
366 switch (rsmd.getColumnType(i)) {
70
17fbaf2635bb Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
367 case Types.TIMESTAMP:
424
709300b32284 Added entries for new Java 8 java.sql.Types: Types.TIME_WITH_TIMEZONE and Types.TIMESTAMP_WITH_TIMEZONE
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 406
diff changeset
368 case Types.TIMESTAMP_WITH_TIMEZONE:
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
369 final Timestamp ts = rs.getTimestamp(i);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
370 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
371 if (xsd_tstz == null) {
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
372 // 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
373 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
374 }
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
375 data = xsd_tstz.format(ts).toString();
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
376 } else {
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
377 if (xsd_ts == null) {
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
378 // 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
379 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
380 }
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
381 data = xsd_ts.format(ts).toString();
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 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
384 default:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
385 data = rs.getString(i);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
386 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
387 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
388 if (data == null) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
389 if (useNil) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
390 // "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
391 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
392 } else {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
393 // This is the "absent" method (of completely
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
394 // hiding the tag if null
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
395 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
396 } else {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
397 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
398 out.println(" <" + rsmd.getColumnLabel(i) + " />");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
399 } else {
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
400 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
401 out.println(" <" + colLabel + ">" + escapeSpecialXMLChars(data) + "</" + colLabel + ">");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
402 }
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 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
405 out.println(" </row>");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
406 }
313
f2750ea9f93d When exporting table/view definition always include the schema name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 312
diff changeset
407 out.println("</" + fqname + ">");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
408 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
409
314
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
410 // 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
411 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
412 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
413 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
414 // 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
415 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
416 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
417 switch (c) {
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
418 case '&':
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
419 sb.append("&amp;");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
420 break;
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
421 case '<':
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
422 sb.append("&lt;");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
423 break;
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
424 case '>':
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
425 sb.append("&gt;");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
426 break;
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
427 case '\'':
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
428 sb.append("&apos;");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
429 break;
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
430 case '"':
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
431 sb.append("&quot;");
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
432 break;
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
433 default:
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
434 sb.append(c);
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
435 }
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
436 }
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
437 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
438 }
6d98a1d3af00 Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 313
diff changeset
439
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
440 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
441 switch (type) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
442 case TYPE_NIL:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
443 switch (value) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
444 case VALUE_OMIT:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
445 useNil = false;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
446 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
447 case VALUE_XSI:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
448 useNil = true;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
449 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
450 default:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
451 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
452 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
453 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
454 default:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
455 throw new Exception("Illegal type " + type);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
456 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
457 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
458
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
459 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
460 switch (type) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
461 case TYPE_NIL:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
462 return useNil ? VALUE_XSI : VALUE_OMIT;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
463 default:
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
464 throw new Exception("Illegal type " + type);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
465 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
466 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
467 }