1
19
20 package com.liferay.portal.tools.sql;
21
22 import com.liferay.portal.kernel.util.StringUtil;
23
24 import java.io.BufferedReader;
25 import java.io.IOException;
26 import java.io.StringReader;
27
28
36 public class SAPUtil extends DBUtil {
37
38 public static DBUtil getInstance() {
39 return _instance;
40 }
41
42 public String buildSQL(String template) throws IOException {
43 template = convertTimestamp(template);
44 template = replaceTemplate(template, getTemplate());
45
46 template = reword(template);
47
48 return template;
49 }
50
51 protected SAPUtil() {
52 super(TYPE_SAP);
53 }
54
55 protected void buildCreateFile(String databaseName, boolean minimal) {
56 }
57
58 protected String getServerName() {
59 return "sap";
60 }
61
62 protected String[] getTemplate() {
63 return _SAP;
64 }
65
66 protected String reword(String data) throws IOException {
67 BufferedReader br = new BufferedReader(new StringReader(data));
68
69 StringBuilder sb = new StringBuilder();
70
71 String line = null;
72
73 while ((line = br.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 br.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 SAPUtil _instance = new SAPUtil();
108
109 }