use of com.varsql.core.db.valueobject.ddl.DDLInfo in project varsql by varsqlinfo.
the class DDLScriptImpl method getTables.
/**
* @Method Name : getTable
* @Method 설명 : table ddl
* @Method override : @see com.varsql.core.db.ddl.script.DDLScript#getTable(com.varsql.core.db.valueobject.DatabaseParamInfo, java.lang.String[])
* @작성자 : ytkim
* @작성일 : 2015. 6. 18.
* @변경이력 :
* @param dataParamInfo
* @param objNm
* @return
* @throws Exception
*/
public List<DDLInfo> getTables(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
List<TableInfo> tableInfoList = dbInstanceFactory.getDBObjectMeta(ObjectType.TABLE.getObjectTypeId(), dataParamInfo, objNmArr);
StringBuilder ddlStrBuf;
List<DDLInfo> reval = new ArrayList<DDLInfo>();
DDLInfo ddlInfo;
for (TableInfo tableInfo : tableInfoList) {
String name = tableInfo.getName();
dataParamInfo.setObjectName(name);
ddlInfo = new DDLInfo();
ddlInfo.setName(name);
ddlStrBuf = new StringBuilder();
if (ddlOption.isAddDropClause()) {
ddlStrBuf.append("/* DROP TABLE " + name + " CASCADE CONSTRAINT; */ ").append(BlankConstants.NEW_LINE_TWO);
}
List<ColumnInfo> columnList = tableInfo.getColList();
ddlStrBuf.append("CREATE TABLE " + name + "(").append(BlankConstants.NEW_LINE);
DataTypeInfo dataTypeInfo;
ColumnInfo columnInfo;
for (int i = 0; i < columnList.size(); i++) {
columnInfo = columnList.get(i);
dataTypeInfo = dbInstanceFactory.getDataTypeImpl().getDataType(columnInfo.getDataType());
ddlStrBuf.append(BlankConstants.TAB);
if (i > 0) {
ddlStrBuf.append(",");
}
ddlStrBuf.append(columnInfo.getName()).append(" ");
ddlStrBuf.append(columnInfo.getTypeAndLength());
ddlStrBuf.append(getDefaultValue(columnInfo.getDefaultVal(), dataTypeInfo));
ddlStrBuf.append(getNotNullValue(columnInfo.getNullable()));
ddlStrBuf.append(BlankConstants.NEW_LINE);
}
List<Map> keyInfo = getTablePrimaryKeyInfo(dataParamInfo, name);
if (keyInfo.size() > 0) {
Map source;
ddlStrBuf.append(BlankConstants.TAB).append(",CONSTRAINT ").append(keyInfo.get(0).get(MetaColumnConstants.PK_NAME)).append(" PRIMARY KEY ( ");
for (int i = 0; i < keyInfo.size(); i++) {
source = keyInfo.get(i);
ddlStrBuf.append(i == 0 ? "" : ", ").append(source.get(MetaColumnConstants.COLUMN_NAME));
}
ddlStrBuf.append(")").append(BlankConstants.NEW_LINE);
}
ddlStrBuf.append(")").append(ddlOption.isAddLastSemicolon() ? ";" : "").append(BlankConstants.NEW_LINE_TWO);
ddlInfo.setCreateScript(ddlStrBuf.toString());
reval.add(ddlInfo);
}
return reval;
}
use of com.varsql.core.db.valueobject.ddl.DDLInfo in project varsql by varsqlinfo.
the class MssqlDDLScript 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();
List srcScriptList = sqlSesseion.selectList("indexScriptSource", dataParamInfo);
Map indexMap;
if (srcScriptList.size() > 0) {
if (ddlOption.isAddDropClause()) {
ddlStr.append("/* DROP INDEX " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
}
for (int i = 0; i < srcScriptList.size(); i++) {
indexMap = (Map) srcScriptList.get(i);
ddlStr.append(indexMap.get("SOURCES"));
}
}
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 getProcedures.
@Override
public List<DDLInfo> getProcedures(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
logger.debug(" Procedure DDL Generation...");
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);
ParamMap source = sqlSesseion.selectOne("procedureScript", dataParamInfo);
ddlStr.append(source.getString("Create Procedure"));
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 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;
for (String name : objNmArr) {
ddlInfo = new DDLInfo();
ddlInfo.setName(name);
dataParamInfo.setObjectName(name);
ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat("", dbType));
reval.add(ddlInfo);
}
return reval;
}
use of com.varsql.core.db.valueobject.ddl.DDLInfo in project varsql by varsqlinfo.
the class MysqlDDLScript method getViews.
@Override
public List<DDLInfo> getViews(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
StringBuilder ddlStr;
SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
List<DDLInfo> reval = new ArrayList<DDLInfo>();
DDLInfo ddlInfo;
for (String name : objNmArr) {
ddlStr = new StringBuilder();
ddlInfo = new DDLInfo();
ddlInfo.setName(name);
dataParamInfo.setObjectName(name);
if (ddlOption.isAddDropClause()) {
ddlStr.append("/* DROP ViEW " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
}
ParamMap source = sqlSesseion.selectOne("viewScript", dataParamInfo);
ddlStr.append(source.getString("Create View"));
ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
reval.add(ddlInfo);
}
return reval;
}
Aggregations