001
014
015 package com.liferay.portal.dao.db;
016
017 import com.liferay.portal.kernel.dao.db.DB;
018 import com.liferay.portal.kernel.io.unsync.UnsyncBufferedReader;
019 import com.liferay.portal.kernel.io.unsync.UnsyncStringReader;
020 import com.liferay.portal.kernel.util.StringBundler;
021 import com.liferay.portal.kernel.util.StringUtil;
022
023 import java.io.IOException;
024
025
030 public class HypersonicDB extends BaseDB {
031
032 public static DB getInstance() {
033 return _instance;
034 }
035
036 public String buildSQL(String template) throws IOException {
037 template = convertTimestamp(template);
038 template = replaceTemplate(template, getTemplate());
039
040 template = reword(template);
041 template = StringUtil.replace(template, "\\'", "''");
042
043 return template;
044 }
045
046 protected HypersonicDB() {
047 super(TYPE_HYPERSONIC);
048 }
049
050 protected String buildCreateFileContent(
051 String sqlDir, String databaseName, int population) {
052
053 return null;
054 }
055
056 protected String getServerName() {
057 return "hypersonic";
058 }
059
060 protected String[] getTemplate() {
061 return _HYPERSONIC;
062 }
063
064 protected String reword(String data) throws IOException {
065 UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(
066 new UnsyncStringReader(data));
067
068 StringBundler sb = new StringBundler();
069
070 String line = null;
071
072 while ((line = unsyncBufferedReader.readLine()) != null) {
073 if (line.startsWith(ALTER_COLUMN_NAME)) {
074 String[] template = buildColumnNameTokens(line);
075
076 line = StringUtil.replace(
077 "alter table @table@ alter column @old-column@ rename to " +
078 "@new-column@;",
079 REWORD_TEMPLATE, template);
080 }
081 else if (line.startsWith(ALTER_COLUMN_TYPE)) {
082 String[] template = buildColumnTypeTokens(line);
083
084 line = StringUtil.replace(
085 "alter table @table@ alter column @old-column@ @type@ " +
086 "@nullable@;",
087 REWORD_TEMPLATE, template);
088 }
089 else if (line.indexOf(DROP_INDEX) != -1) {
090 String[] tokens = StringUtil.split(line, " ");
091
092 line = StringUtil.replace(
093 "drop index @index@;", "@index@", tokens[2]);
094 }
095
096 sb.append(line);
097 sb.append("\n");
098 }
099
100 unsyncBufferedReader.close();
101
102 return sb.toString();
103 }
104
105 private static String[] _HYPERSONIC = {
106 "
107 "'1970-01-01'", "now()",
108 " binary", " bit", " timestamp",
109 " double", " int", " bigint",
110 " longvarchar", " longvarchar", " varchar",
111 "", "commit"
112 };
113
114 private static HypersonicDB _instance = new HypersonicDB();
115
116 }