1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.dao.db;
16  
17  import com.liferay.portal.kernel.dao.db.DB;
18  import com.liferay.portal.kernel.io.unsync.UnsyncBufferedReader;
19  import com.liferay.portal.kernel.io.unsync.UnsyncStringReader;
20  import com.liferay.portal.kernel.util.StringBundler;
21  import com.liferay.portal.kernel.util.StringUtil;
22  
23  import java.io.IOException;
24  
25  /**
26   * <a href="SAPDB.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Alexander Chow
29   * @author Sandeep Soni
30   * @author Ganesh Ram
31   */
32  public class SAPDB extends BaseDB {
33  
34      public static DB getInstance() {
35          return _instance;
36      }
37  
38      public String buildSQL(String template) throws IOException {
39          template = convertTimestamp(template);
40          template = replaceTemplate(template, getTemplate());
41  
42          template = reword(template);
43  
44          return template;
45      }
46  
47      protected SAPDB() {
48          super(TYPE_SAP);
49      }
50  
51      protected String buildCreateFileContent(
52          String sqlDir, String databaseName, int population) {
53  
54          return null;
55      }
56  
57      protected String getServerName() {
58          return "sap";
59      }
60  
61      protected String[] getTemplate() {
62          return _SAP;
63      }
64  
65      protected String reword(String data) throws IOException {
66          UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(
67              new UnsyncStringReader(data));
68  
69          StringBundler sb = new StringBundler();
70  
71          String line = null;
72  
73          while ((line = unsyncBufferedReader.readLine()) != null) {
74              if (line.startsWith(ALTER_COLUMN_NAME)) {
75                  String[] template = buildColumnNameTokens(line);
76  
77                  line = StringUtil.replace(
78                      "rename column @table@.@old-column@ to @new-column@;",
79                      REWORD_TEMPLATE, template);
80              }
81              else if (line.startsWith(ALTER_COLUMN_TYPE)) {
82                  String[] template = buildColumnTypeTokens(line);
83  
84                  line = StringUtil.replace(
85                      "alter table @table@ modify @old-column@ @type@;",
86                      REWORD_TEMPLATE, template);
87              }
88  
89              sb.append(line);
90              sb.append("\n");
91          }
92  
93          unsyncBufferedReader.close();
94  
95          return sb.toString();
96      }
97  
98      private static String[] _SAP = {
99          "##", "TRUE", "FALSE",
100         "'1970-01-01 00:00:00.000000'", "timestamp",
101         " long byte", " boolean", " timestamp",
102         " float", " int", " bigint",
103         " varchar", " varchar", " varchar",
104         "", "commit"
105     };
106 
107     private static SAPDB _instance = new SAPDB();
108 
109 }