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="SAPUtil.java.html"><b><i>View Source</i></b></a>
032: *
033: * @author Alexander Chow
034: *
035: */
036: public class SAPUtil 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:
049: return template;
050: }
051:
052: protected SAPUtil() {
053: }
054:
055: protected void buildCreateFile(String databaseName, boolean minimal)
056: throws IOException {
057: }
058:
059: protected String getServerName() {
060: return "sap";
061: }
062:
063: protected String[] getTemplate() {
064: return _SAP;
065: }
066:
067: protected String reword(String data) throws IOException {
068: BufferedReader br = new BufferedReader(new StringReader(data));
069:
070: StringMaker sm = new StringMaker();
071:
072: String line = null;
073:
074: while ((line = br.readLine()) != null) {
075: if (line.startsWith(ALTER_COLUMN_TYPE)) {
076: String[] template = buildColumnTypeTokens(line);
077:
078: line = StringUtil
079: .replace(
080: "alter table @table@ modify @old-column@ @type@;",
081: REWORD_TEMPLATE, template);
082: } else if (line.startsWith(ALTER_COLUMN_NAME)) {
083: String[] template = buildColumnNameTokens(line);
084:
085: line = StringUtil
086: .replace(
087: "rename column @table@.@old-column@ to @new-column@;",
088: REWORD_TEMPLATE, template);
089: }
090:
091: sm.append(line);
092: sm.append("\n");
093: }
094:
095: br.close();
096:
097: return sm.toString();
098: }
099:
100: private static String[] _SAP = { "##", "TRUE", "FALSE",
101: "'1970-01-01 00:00:00.000000'", "timestamp", " boolean",
102: " timestamp", " float", " int", " bigint", " varchar",
103: " varchar", " varchar", "", "commit" };
104:
105: private static SAPUtil _instance = new SAPUtil();
106:
107: }
|