001
014
015 package com.liferay.portal.dao.db;
016
017 import com.liferay.portal.kernel.dao.db.DBType;
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 HypersonicDB(int majorVersion, int minorVersion) {
033 super(DBType.HYPERSONIC, majorVersion, minorVersion);
034 }
035
036 @Override
037 public String buildSQL(String template) throws IOException {
038 template = convertTimestamp(template);
039 template = replaceTemplate(template, getTemplate());
040
041 template = reword(template);
042 template = StringUtil.replace(template, "\\'", "''");
043
044 return template;
045 }
046
047 @Override
048 protected String buildCreateFileContent(
049 String sqlDir, String databaseName, int population) {
050
051 return null;
052 }
053
054 @Override
055 protected String getServerName() {
056 return "hypersonic";
057 }
058
059 @Override
060 protected String[] getTemplate() {
061 return _HYPERSONIC;
062 }
063
064 @Override
065 protected String reword(String data) throws IOException {
066 try (UnsyncBufferedReader unsyncBufferedReader =
067 new UnsyncBufferedReader(new UnsyncStringReader(data))) {
068
069 StringBundler sb = new StringBundler();
070
071 String line = null;
072
073 while ((line = unsyncBufferedReader.readLine()) != null) {
074 if (line.startsWith(ALTER_COLUMN_NAME)) {
075 String[] template = buildColumnNameTokens(line);
076
077 line = StringUtil.replace(
078 "alter table @table@ alter column @old-column@ rename" +
079 " to @new-column@;",
080 REWORD_TEMPLATE, template);
081 }
082 else if (line.startsWith(ALTER_COLUMN_TYPE)) {
083 String[] template = buildColumnTypeTokens(line);
084
085 line = StringUtil.replace(
086 "alter table @table@ alter column @old-column@ " +
087 "@type@ @nullable@;",
088 REWORD_TEMPLATE, template);
089 }
090 else if (line.startsWith(ALTER_TABLE_NAME)) {
091 String[] template = buildTableNameTokens(line);
092
093 line = StringUtil.replace(
094 "alter table @old-table@ rename to @new-table@;",
095 RENAME_TABLE_TEMPLATE, template);
096 }
097 else if (line.contains(DROP_INDEX)) {
098 String[] tokens = StringUtil.split(line, ' ');
099
100 line = StringUtil.replace(
101 "drop index @index@;", "@index@", tokens[2]);
102 }
103
104 sb.append(line);
105 sb.append("\n");
106 }
107
108 return sb.toString();
109 }
110 }
111
112 private static final String[] _HYPERSONIC = {
113 "
114 " blob", " bit", " timestamp", " double", " int", " bigint",
115 " longvarchar", " longvarchar", " varchar", "", "commit"
116 };
117
118 }