Mercurial > hg > monetdb-java
comparison src/main/java/nl/cwi/monetdb/util/Exporter.java @ 0:a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Wed, 21 Sep 2016 09:34:48 +0200 (2016-09-21) |
parents | |
children | 57978db4ee57 17fbaf2635bb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a5a898f6886c |
---|---|
1 /* | |
2 * This Source Code Form is subject to the terms of the Mozilla Public | |
3 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
5 * | |
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V. | |
7 */ | |
8 | |
9 package nl.cwi.monetdb.util; | |
10 | |
11 import java.io.*; | |
12 import java.sql.*; | |
13 import java.util.Arrays; | |
14 | |
15 | |
16 public abstract class Exporter { | |
17 protected PrintWriter out; | |
18 protected boolean useSchema; | |
19 | |
20 protected Exporter(PrintWriter out) { | |
21 this.out = out; | |
22 } | |
23 | |
24 public abstract void dumpSchema( | |
25 DatabaseMetaData dbmd, | |
26 String type, | |
27 String catalog, | |
28 String schema, | |
29 String name) throws SQLException; | |
30 | |
31 public abstract void dumpResultSet(ResultSet rs) throws SQLException; | |
32 | |
33 public abstract void setProperty(int type, int value) throws Exception; | |
34 public abstract int getProperty(int type) throws Exception; | |
35 | |
36 //=== shared utilities | |
37 | |
38 public void useSchemas(boolean use) { | |
39 useSchema = use; | |
40 } | |
41 | |
42 /** | |
43 * returns the given string between two double quotes for usage as | |
44 * identifier such as column or table name in SQL queries. | |
45 * | |
46 * @param in the string to quote | |
47 * @return the quoted string | |
48 */ | |
49 protected static String dq(String in) { | |
50 return "\"" + in.replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"") + "\""; | |
51 } | |
52 | |
53 /** | |
54 * returns the given string between two single quotes for usage as | |
55 * string literal in SQL queries. | |
56 * | |
57 * @param in the string to quote | |
58 * @return the quoted string | |
59 */ | |
60 protected static String q(String in) { | |
61 return "'" + in.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'") + "'"; | |
62 } | |
63 | |
64 /** | |
65 * Simple helper function to repeat a given character a number of | |
66 * times. | |
67 * | |
68 * @param chr the character to repeat | |
69 * @param cnt the number of times to repeat chr | |
70 * @return a String holding cnt times chr | |
71 */ | |
72 protected static String repeat(char chr, int cnt) { | |
73 char[] buf = new char[cnt]; | |
74 Arrays.fill(buf, chr); | |
75 return new String(buf); | |
76 } | |
77 } |