1
19
20 package com.liferay.portal.tools.sql;
21
22 import com.liferay.portal.kernel.util.StringUtil;
23
24 import java.io.BufferedReader;
25 import java.io.IOException;
26 import java.io.StringReader;
27
28
36 public class HypersonicUtil extends DBUtil {
37
38 public static DBUtil getInstance() {
39 return _instance;
40 }
41
42 public String buildSQL(String template) throws IOException {
43 template = convertTimestamp(template);
44 template = replaceTemplate(template, getTemplate());
45
46 template = reword(template);
47 template = StringUtil.replace(template, "\\'", "''");
48
49 return template;
50 }
51
52 protected HypersonicUtil() {
53 super(DB_TYPE_HYPERSONIC);
54 }
55
56 protected void buildCreateFile(String databaseName, boolean minimal) {
57 }
58
59 protected String getServerName() {
60 return "hypersonic";
61 }
62
63 protected String[] getTemplate() {
64 return _HYPERSONIC;
65 }
66
67 protected String reword(String data) throws IOException {
68 BufferedReader br = new BufferedReader(new StringReader(data));
69
70 StringBuilder sb = new StringBuilder();
71
72 String line = null;
73
74 while ((line = br.readLine()) != null) {
75 if (line.startsWith(ALTER_COLUMN_TYPE)) {
76 String[] template = buildColumnTypeTokens(line);
77
78 line = StringUtil.replace(
79 "alter table @table@ alter column @type@ @nullable@;",
80 REWORD_TEMPLATE, template);
81 }
82 else if (line.startsWith(ALTER_COLUMN_NAME)) {
83 String[] template = buildColumnNameTokens(line);
84
85 line = StringUtil.replace(
86 "alter table @table@ alter column @old-column@ rename to " +
87 "@new-column@;",
88 REWORD_TEMPLATE, template);
89 }
90
91 sb.append(line);
92 sb.append("\n");
93 }
94
95 br.close();
96
97 return sb.toString();
98 }
99
100 private static String[] _HYPERSONIC = {
101 "//", "true", "false",
102 "'1970-01-01'", "now()",
103 " binary", " bit", " timestamp",
104 " double", " int", " bigint",
105 " longvarchar", " longvarchar", " varchar",
106 "", "commit"
107 };
108
109 private static HypersonicUtil _instance = new HypersonicUtil();
110
111 }