1
22
23 package com.liferay.portal.dao.db;
24
25 import com.liferay.portal.kernel.dao.db.DB;
26 import com.liferay.portal.kernel.io.unsync.UnsyncBufferedReader;
27 import com.liferay.portal.kernel.io.unsync.UnsyncStringReader;
28 import com.liferay.portal.kernel.util.StringUtil;
29
30 import java.io.IOException;
31
32
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 UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(
74 new UnsyncStringReader(data));
75
76 StringBuilder sb = new StringBuilder();
77
78 String line = null;
79
80 while ((line = unsyncBufferedReader.readLine()) != null) {
81 if (line.startsWith(ALTER_COLUMN_NAME)) {
82 String[] template = buildColumnNameTokens(line);
83
84 line = StringUtil.replace(
85 "rename column @table@.@old-column@ to @new-column@;",
86 REWORD_TEMPLATE, template);
87 }
88 else if (line.startsWith(ALTER_COLUMN_TYPE)) {
89 String[] template = buildColumnTypeTokens(line);
90
91 line = StringUtil.replace(
92 "alter table @table@ modify @old-column@ @type@;",
93 REWORD_TEMPLATE, template);
94 }
95
96 sb.append(line);
97 sb.append("\n");
98 }
99
100 unsyncBufferedReader.close();
101
102 return sb.toString();
103 }
104
105 private static String[] _SAP = {
106 "##", "TRUE", "FALSE",
107 "'1970-01-01 00:00:00.000000'", "timestamp",
108 " long byte", " boolean", " timestamp",
109 " float", " int", " bigint",
110 " varchar", " varchar", " varchar",
111 "", "commit"
112 };
113
114 private static SAPDB _instance = new SAPDB();
115
116 }