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