| SAPDB.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.liferay.portal.dao.db;
24
25 import com.liferay.portal.kernel.dao.db.DB;
26 import com.liferay.portal.kernel.util.StringUtil;
27
28 import java.io.BufferedReader;
29 import java.io.IOException;
30 import java.io.StringReader;
31
32 /**
33 * <a href="SAPDB.java.html"><b><i>View Source</i></b></a>
34 *
35 * @author Alexander Chow
36 * @author Sandeep Soni
37 * @author Ganesh Ram
38 */
39 public class SAPDB 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
51 return template;
52 }
53
54 protected SAPDB() {
55 super(TYPE_SAP);
56 }
57
58 protected String buildCreateFileContent(
59 String databaseName, int population) {
60
61 return null;
62 }
63
64 protected String getServerName() {
65 return "sap";
66 }
67
68 protected String[] getTemplate() {
69 return _SAP;
70 }
71
72 protected String reword(String data) throws IOException {
73 BufferedReader br = new BufferedReader(new StringReader(data));
74
75 StringBuilder sb = new StringBuilder();
76
77 String line = null;
78
79 while ((line = br.readLine()) != null) {
80 if (line.startsWith(ALTER_COLUMN_NAME)) {
81 String[] template = buildColumnNameTokens(line);
82
83 line = StringUtil.replace(
84 "rename column @table@.@old-column@ to @new-column@;",
85 REWORD_TEMPLATE, template);
86 }
87 else if (line.startsWith(ALTER_COLUMN_TYPE)) {
88 String[] template = buildColumnTypeTokens(line);
89
90 line = StringUtil.replace(
91 "alter table @table@ modify @old-column@ @type@;",
92 REWORD_TEMPLATE, template);
93 }
94
95 sb.append(line);
96 sb.append("\n");
97 }
98
99 br.close();
100
101 return sb.toString();
102 }
103
104 private static String[] _SAP = {
105 "##", "TRUE", "FALSE",
106 "'1970-01-01 00:00:00.000000'", "timestamp",
107 " long byte", " boolean", " timestamp",
108 " float", " int", " bigint",
109 " varchar", " varchar", " varchar",
110 "", "commit"
111 };
112
113 private static SAPDB _instance = new SAPDB();
114
115 }