1
14
15 package com.liferay.portal.dao.db;
16
17 import com.liferay.portal.kernel.dao.db.DB;
18 import com.liferay.portal.kernel.io.unsync.UnsyncBufferedReader;
19 import com.liferay.portal.kernel.io.unsync.UnsyncStringReader;
20 import com.liferay.portal.kernel.util.StringBundler;
21 import com.liferay.portal.kernel.util.StringUtil;
22
23 import java.io.IOException;
24
25
32 public class HypersonicDB extends BaseDB {
33
34 public static DB getInstance() {
35 return _instance;
36 }
37
38 public String buildSQL(String template) throws IOException {
39 template = convertTimestamp(template);
40 template = replaceTemplate(template, getTemplate());
41
42 template = reword(template);
43 template = StringUtil.replace(template, "\\'", "''");
44
45 return template;
46 }
47
48 protected HypersonicDB() {
49 super(TYPE_HYPERSONIC);
50 }
51
52 protected String buildCreateFileContent(
53 String sqlDir, String databaseName, int population) {
54
55 return null;
56 }
57
58 protected String getServerName() {
59 return "hypersonic";
60 }
61
62 protected String[] getTemplate() {
63 return _HYPERSONIC;
64 }
65
66 protected String reword(String data) throws IOException {
67 UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(
68 new UnsyncStringReader(data));
69
70 StringBundler sb = new StringBundler();
71
72 String line = null;
73
74 while ((line = unsyncBufferedReader.readLine()) != null) {
75 if (line.startsWith(ALTER_COLUMN_NAME)) {
76 String[] template = buildColumnNameTokens(line);
77
78 line = StringUtil.replace(
79 "alter table @table@ alter column @old-column@ rename to " +
80 "@new-column@;",
81 REWORD_TEMPLATE, template);
82 }
83 else if (line.startsWith(ALTER_COLUMN_TYPE)) {
84 String[] template = buildColumnTypeTokens(line);
85
86 line = StringUtil.replace(
87 "alter table @table@ alter column @old-column@ @type@ " +
88 "@nullable@;",
89 REWORD_TEMPLATE, template);
90 }
91 else if (line.indexOf(DROP_INDEX) != -1) {
92 String[] tokens = StringUtil.split(line, " ");
93
94 line = StringUtil.replace(
95 "drop index @index@;", "@index@", tokens[2]);
96 }
97
98 sb.append(line);
99 sb.append("\n");
100 }
101
102 unsyncBufferedReader.close();
103
104 return sb.toString();
105 }
106
107 private static String[] _HYPERSONIC = {
108 "//", "true", "false",
109 "'1970-01-01'", "now()",
110 " binary", " bit", " timestamp",
111 " double", " int", " bigint",
112 " longvarchar", " longvarchar", " varchar",
113 "", "commit"
114 };
115
116 private static HypersonicDB _instance = new HypersonicDB();
117
118 }