com.liferay.portal.dao.db.SAPDB Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of portal-impl Show documentation
Show all versions of portal-impl Show documentation
Contains implementation for the portal services.
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.dao.db;
import com.liferay.portal.kernel.dao.db.DB;
import com.liferay.portal.kernel.io.unsync.UnsyncBufferedReader;
import com.liferay.portal.kernel.io.unsync.UnsyncStringReader;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringUtil;
import java.io.IOException;
/**
* @author Alexander Chow
* @author Sandeep Soni
* @author Ganesh Ram
*/
public class SAPDB extends BaseDB {
public static DB getInstance() {
return _instance;
}
@Override
public String buildSQL(String template) throws IOException {
template = convertTimestamp(template);
template = replaceTemplate(template, getTemplate());
template = reword(template);
return template;
}
protected SAPDB() {
super(TYPE_SAP);
}
@Override
protected String buildCreateFileContent(
String sqlDir, String databaseName, int population) {
return null;
}
@Override
protected String getServerName() {
return "sap";
}
@Override
protected String[] getTemplate() {
return _SAP;
}
@Override
protected String reword(String data) throws IOException {
UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(
new UnsyncStringReader(data));
StringBundler sb = new StringBundler();
String line = null;
while ((line = unsyncBufferedReader.readLine()) != null) {
if (line.startsWith(ALTER_COLUMN_NAME)) {
String[] template = buildColumnNameTokens(line);
line = StringUtil.replace(
"rename column @table@.@old-column@ to @new-column@;",
REWORD_TEMPLATE, template);
}
else if (line.startsWith(ALTER_COLUMN_TYPE)) {
String[] template = buildColumnTypeTokens(line);
line = StringUtil.replace(
"alter table @table@ modify @old-column@ @type@;",
REWORD_TEMPLATE, template);
}
else if (line.startsWith(ALTER_TABLE_NAME)) {
String[] template = buildTableNameTokens(line);
line = StringUtil.replace(
"alter table @old-table@ to @new-table@;",
RENAME_TABLE_TEMPLATE, template);
}
sb.append(line);
sb.append("\n");
}
unsyncBufferedReader.close();
return sb.toString();
}
private static final String[] _SAP = {
"##", "TRUE", "FALSE", "'1970-01-01 00:00:00.000000'", "timestamp",
" blob", " blob", " boolean", " timestamp", " float", " int", " bigint",
" varchar", " varchar", " varchar", "", "commit"
};
private static SAPDB _instance = new SAPDB();
}