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