use of com.varsql.core.db.valueobject.ddl.DDLInfo in project varsql by varsqlinfo.
the class MysqlDDLScript method getFunctions.
@Override
public List<DDLInfo> getFunctions(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
logger.debug(" Function DDL Generation...");
SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
List<DDLInfo> reval = new ArrayList<DDLInfo>();
DDLInfo ddlInfo;
StringBuilder ddlStr;
for (String name : objNmArr) {
ddlInfo = new DDLInfo();
ddlInfo.setName(name);
ddlStr = new StringBuilder();
dataParamInfo.setObjectName(name);
if (ddlOption.isAddDropClause()) {
ddlStr.append("/* DROP FUNCTION " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
}
ParamMap source = sqlSesseion.selectOne("functionScript", dataParamInfo);
ddlStr.append(source.getString("Create Function"));
ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
reval.add(ddlInfo);
}
return reval;
}
use of com.varsql.core.db.valueobject.ddl.DDLInfo in project varsql by varsqlinfo.
the class MysqlDDLScript method getTables.
@Override
public List<DDLInfo> getTables(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
SqlSession client = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
List<DDLInfo> reval = new ArrayList<DDLInfo>();
DDLInfo ddlInfo;
StringBuilder ddlStr;
for (String name : objNmArr) {
ddlStr = new StringBuilder();
ddlInfo = new DDLInfo();
ddlInfo.setName(name);
dataParamInfo.setObjectName(name);
if (ddlOption.isAddDropClause()) {
ddlStr.append("/* DROP TABLE " + name + "; */").append(BlankConstants.NEW_LINE_TWO);
}
ParamMap source = client.selectOne("tableScript", dataParamInfo);
ddlStr.append(source.getString("Create Table"));
ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
reval.add(ddlInfo);
}
return reval;
}
use of com.varsql.core.db.valueobject.ddl.DDLInfo in project varsql by varsqlinfo.
the class OracleDDLScript method getTables.
@Override
public List<DDLInfo> getTables(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
SqlSession client = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
List<DDLInfo> reval = new ArrayList<DDLInfo>();
DDLInfo ddlInfo;
StringBuilder ddlStr;
for (String name : objNmArr) {
ddlStr = new StringBuilder();
ddlInfo = new DDLInfo();
ddlInfo.setName(name);
dataParamInfo.setObjectName(name);
if (ddlOption.isAddDropClause()) {
ddlStr.append("/* DROP TABLE " + name + "; */").append(BlankConstants.NEW_LINE_TWO);
}
List<ParamMap> srcList = client.selectList("tableScript", dataParamInfo);
ddlStr.append("CREATE TABLE " + name + "(\n");
String dataType = "";
dataParamInfo.setObjectName(name);
DataTypeImpl dataTypeImpl = dbInstanceFactory.getDataTypeImpl();
ParamMap source;
for (int i = 0; i < srcList.size(); i++) {
source = srcList.get(i);
dataType = String.valueOf(source.get("DATA_TYPE"));
DataTypeInfo dataTypeInfo = dataTypeImpl.getDataType(dataType);
ddlStr.append("\t");
if (i > 0) {
ddlStr.append(",");
}
ddlStr.append(source.get(MetaColumnConstants.COLUMN_NAME)).append(" ");
ddlStr.append(DbMetaUtils.getTypeName(dataTypeInfo, null, dataTypeInfo.getDataTypeName(), source.getString(MetaColumnConstants.COLUMN_SIZE), source.getString(MetaColumnConstants.DECIMAL_DIGITS)));
ddlStr.append(getDefaultValue(source.getString("DATA_DEFAULT"), dataTypeInfo, true));
ddlStr.append(getNotNullValue(source.getString(MetaColumnConstants.NULLABLE)));
ddlStr.append(BlankConstants.NEW_LINE);
}
List srcPkList = client.selectList("tableScriptPk", dataParamInfo);
Map pkMap;
for (int i = 0; i < srcPkList.size(); i++) {
pkMap = (HashMap) srcPkList.get(i);
if (i == 0)
ddlStr.append(BlankConstants.TAB).append(",CONSTRAINT ").append(pkMap.get("CONSTRAINT_NAME")).append(" PRIMARY KEY ( ").append(pkMap.get("COLUMN_NAME"));
else {
ddlStr.append(", " + pkMap.get("COLUMN_NAME"));
}
if (i == srcPkList.size() - 1) {
ddlStr.append(")").append(BlankConstants.NEW_LINE);
}
}
ddlStr.append(");").append(BlankConstants.NEW_LINE_TWO);
List srcCommentList = client.selectList("tableScriptComments", dataParamInfo);
for (int i = 0; i < srcCommentList.size(); i++) {
ddlStr.append(srcCommentList.get(i)).append(BlankConstants.NEW_LINE);
}
if (srcCommentList.size() > 0) {
ddlStr.append(BlankConstants.NEW_LINE);
}
ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(ddlStr.toString(), dbType));
reval.add(ddlInfo);
}
return reval;
}
use of com.varsql.core.db.valueobject.ddl.DDLInfo in project varsql by varsqlinfo.
the class OracleDDLScript method getIndexs.
@Override
public List<DDLInfo> getIndexs(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
List<DDLInfo> reval = new ArrayList<DDLInfo>();
DDLInfo ddlInfo;
StringBuilder ddlStr;
for (String name : objNmArr) {
ddlInfo = new DDLInfo();
ddlInfo.setName(name);
dataParamInfo.setObjectName(name);
ddlStr = new StringBuilder();
if (ddlOption.isAddDropClause()) {
ddlStr.append("/* DROP INDEX " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
}
List srcScriptList = sqlSesseion.selectList("indexScriptSource", dataParamInfo);
ddlStr.append("CREATE ");
Map indexMap;
if (srcScriptList.size() > 0) {
indexMap = (Map) srcScriptList.get(0);
if ("UNIQUE".equals(indexMap.get("UNIQUENESS")))
ddlStr.append(" UNIQUE INDEX ");
else {
ddlStr.append(" INDEX ");
}
ddlStr.append(indexMap.get("TABLE_OWNER") + ".");
ddlStr.append(indexMap.get("INDEX_NAME") + " ON ");
ddlStr.append(indexMap.get("TABLE_OWNER") + ".");
ddlStr.append(indexMap.get("TABLE_NAME") + "\n ( ");
for (int i = 0; i < srcScriptList.size(); i++) {
indexMap = (Map) srcScriptList.get(i);
if (("NORMAL".equals(indexMap.get("INDEX_TYPE"))) && (indexMap.get("COLUMN_EXPRESSION") == null)) {
if (i > 0)
ddlStr.append(",");
ddlStr.append(indexMap.get("COLUMN_NAME"));
} else {
if (i > 0)
ddlStr.append(",");
ddlStr.append(indexMap.get("COLUMN_EXPRESSION"));
}
}
ddlStr.append(" ) ").append(BlankConstants.NEW_LINE);
;
if ("YES".equals(indexMap.get("LOGGING")))
ddlStr.append(" LOGGING ").append(BlankConstants.NEW_LINE);
else {
ddlStr.append(" NO LOGGING ").append(BlankConstants.NEW_LINE);
}
ddlStr.append(" TABLESPACE " + indexMap.get("TABLESPACE_NAME") + BlankConstants.NEW_LINE);
ddlStr.append(" PCTFREE " + String.valueOf(indexMap.get("PCT_FREE")) + BlankConstants.NEW_LINE);
ddlStr.append(" INITRANS " + String.valueOf(indexMap.get("INI_TRANS")) + BlankConstants.NEW_LINE);
ddlStr.append(" MAXTRANS " + String.valueOf(indexMap.get("MAX_TRANS")) + BlankConstants.NEW_LINE);
ddlStr.append(" STORAGE ( \n ");
ddlStr.append(BlankConstants.TAB + " INITIAL " + String.valueOf(indexMap.get("INITIAL_EXTENT")) + BlankConstants.NEW_LINE);
ddlStr.append(BlankConstants.TAB + " MINEXTENTS " + String.valueOf(indexMap.get("MIN_EXTENTS")) + BlankConstants.NEW_LINE);
ddlStr.append(BlankConstants.TAB + " MAXEXTENTS " + String.valueOf(indexMap.get("MAX_EXTENTS")) + BlankConstants.NEW_LINE);
ddlStr.append(BlankConstants.TAB + " PCTINCREASE " + String.valueOf(indexMap.get("PCT_INCREASE")) + BlankConstants.NEW_LINE);
ddlStr.append(BlankConstants.TAB + " BUFFER_POOL " + String.valueOf(indexMap.get("BUFFER_POOL")) + BlankConstants.NEW_LINE);
ddlStr.append("\t ) \n ");
}
ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
reval.add(ddlInfo);
}
return reval;
}
use of com.varsql.core.db.valueobject.ddl.DDLInfo in project varsql by varsqlinfo.
the class OracleDDLScript method getFunctions.
@Override
public List<DDLInfo> getFunctions(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
logger.debug(" Function DDL Generation info {}", VartechUtils.reflectionToString(dataParamInfo));
SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
List<DDLInfo> reval = new ArrayList<DDLInfo>();
DDLInfo ddlInfo;
StringBuilder ddlStr;
dataParamInfo.setObjectType(ObjectType.FUNCTION.name());
for (String name : objNmArr) {
ddlInfo = new DDLInfo();
ddlInfo.setName(name);
ddlStr = new StringBuilder();
dataParamInfo.setObjectName(name);
if (ddlOption.isAddDropClause()) {
ddlStr.append("/* DROP FUNCTION " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
}
ddlStr.append("CREATE OR REPLACE ");
List srcList = sqlSesseion.selectList("objectScriptSource", dataParamInfo);
for (int i = 0; i < srcList.size(); i++) {
ddlStr.append(srcList.get(i));
}
ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
reval.add(ddlInfo);
}
return reval;
}
Aggregations