001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.tools.sql;
022:
023: import com.liferay.portal.kernel.util.StringMaker;
024: import com.liferay.portal.kernel.util.StringUtil;
025:
026: import java.io.BufferedReader;
027: import java.io.IOException;
028: import java.io.StringReader;
029:
030: /**
031: * <a href="HypersonicUtil.java.html"><b><i>View Source</i></b></a>
032: *
033: * @author Alexander Chow
034: *
035: */
036: public class HypersonicUtil extends DBUtil {
037:
038: public static DBUtil getInstance() {
039: return _instance;
040: }
041:
042: public String buildSQL(String template) throws IOException {
043: template = convertTimestamp(template);
044: template = StringUtil
045: .replace(template, TEMPLATE, getTemplate());
046:
047: template = reword(template);
048: template = StringUtil.replace(template, "\\'", "''");
049:
050: return template;
051: }
052:
053: protected HypersonicUtil() {
054: }
055:
056: protected void buildCreateFile(String databaseName, boolean minimal)
057: throws IOException {
058: }
059:
060: protected String getServerName() {
061: return "hypersonic";
062: }
063:
064: protected String[] getTemplate() {
065: return _HYPERSONIC;
066: }
067:
068: protected String reword(String data) throws IOException {
069: BufferedReader br = new BufferedReader(new StringReader(data));
070:
071: StringMaker sm = new StringMaker();
072:
073: String line = null;
074:
075: while ((line = br.readLine()) != null) {
076: if (line.startsWith(ALTER_COLUMN_TYPE)) {
077: String[] template = buildColumnTypeTokens(line);
078:
079: line = StringUtil
080: .replace(
081: "alter table @table@ alter column @type@ @nullable@;",
082: REWORD_TEMPLATE, template);
083: } else if (line.startsWith(ALTER_COLUMN_NAME)) {
084: String[] template = buildColumnNameTokens(line);
085:
086: line = StringUtil.replace(
087: "alter table @table@ alter column @old-column@ rename to "
088: + "@new-column@;", REWORD_TEMPLATE,
089: template);
090: }
091:
092: sm.append(line);
093: sm.append("\n");
094: }
095:
096: br.close();
097:
098: return sm.toString();
099: }
100:
101: private static String[] _HYPERSONIC = { "//", "true", "false",
102: "'1970-01-01'", "now()", " bit", " timestamp", " double",
103: " int", " bigint", " longvarchar", " longvarchar",
104: " varchar", "", "commit" };
105:
106: private static HypersonicUtil _instance = new HypersonicUtil();
107:
108: }
|