use of com.varsql.core.db.valueobject.ddl.DDLInfo in project varsql by varsqlinfo.
the class ExportServiceImpl method ddlExport.
/**
* @Method Name : tableDDLExport
* @Method 설명 : 테이블 ddl 내보내기
* @작성자 : ytkim
* @작성일 : 2017. 8. 24.
* @변경이력 :
* @param preferencesInfo
* @param req
* @param res
* @throws Exception
*/
public void ddlExport(PreferencesRequestDTO preferencesInfo, HttpServletRequest req, HttpServletResponse res) throws Exception {
String jsonString = preferencesInfo.getPrefVal();
logger.debug("ddlExport PreferencesInfo :{}", VartechUtils.reflectionToString(preferencesInfo));
logger.debug("settingInfo :{}", jsonString);
DataCommonVO settingInfo = VartechUtils.jsonStringToObject(jsonString, DataCommonVO.class);
Map<String, List<Map>> exportInfo = (Map<String, List<Map>>) settingInfo.get("exportInfo");
Iterator<String> iter = exportInfo.keySet().iterator();
MetaControlBean dbMetaEnum = MetaControlFactory.getDbInstanceFactory(preferencesInfo.getDbType());
StringBuilder allDDLScript = new StringBuilder();
DDLCreateOption ddlOption = new DDLCreateOption();
while (iter.hasNext()) {
String objectName = iter.next();
allDDLScript.append("--------- " + objectName + " start----------").append(BlankConstants.NEW_LINE_TWO);
List<Map> objList = exportInfo.get(objectName);
String[] objNmArr = Arrays.stream(objList.toArray(new HashMap[objList.size()])).map(tmp -> tmp.get("name")).toArray(String[]::new);
preferencesInfo.setObjectType(ObjectType.getDBObjectType(objectName).name());
List<DDLInfo> ddlList = dbMetaEnum.getDDLScript(ObjectType.getDBObjectType(objectName).getObjectTypeId(), preferencesInfo, ddlOption, objNmArr);
for (DDLInfo ddlInfo : ddlList) {
allDDLScript.append(ddlInfo.getCreateScript()).append(BlankConstants.NEW_LINE_TWO);
}
allDDLScript.append(BlankConstants.NEW_LINE).append("--------- // " + objectName + " end----------").append(BlankConstants.NEW_LINE_THREE);
}
String exportFileName = settingInfo.getString("exportName", "export-ddl");
exportFileName += exportFileName.endsWith(".sql") ? "" : ".sql";
VarsqlUtils.setResponseDownAttr(res, req, exportFileName);
VarsqlUtils.textDownload(res.getOutputStream(), allDDLScript.toString());
}
use of com.varsql.core.db.valueobject.ddl.DDLInfo in project varsql by varsqlinfo.
the class DDLScriptImpl method getIndexs.
/**
* @Method Name : getIndex
* @Method 설명 : index ddl
* @Method override : @see com.varsql.core.db.ddl.script.DDLScript#getIndex(com.varsql.core.db.valueobject.DatabaseParamInfo, java.lang.String[])
* @작성자 : ytkim
* @작성일 : 2015. 6. 18.
* @변경이력 :
* @param dataParamInfo
* @param objNm
* @return
* @throws Exception
*/
@Override
public List<DDLInfo> getIndexs(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
StringBuilder ddlStrBuf;
List<DDLInfo> reval = new ArrayList<DDLInfo>();
DDLInfo ddlInfo;
SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
for (String viewNm : objNmArr) {
ddlInfo = new DDLInfo();
ddlInfo.setName(viewNm);
ddlStrBuf = new StringBuilder();
dataParamInfo.setObjectName(viewNm);
if (ddlOption.isAddDropClause()) {
ddlStrBuf.append("/* DROP INDEX " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
}
List<String> srcProcList = sqlSesseion.selectList("indexScript", dataParamInfo);
for (int j = 0; j < srcProcList.size(); j++) {
ddlStrBuf.append(srcProcList.get(j));
}
ddlStrBuf.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 DDLScriptImpl method getFunctions.
/**
* @Method Name : getFunction
* @Method 설명 : function ddl
* @Method override : @see com.varsql.core.db.ddl.script.DDLScript#getFunction(com.varsql.core.db.valueobject.DatabaseParamInfo, java.lang.String[])
* @작성자 : ytkim
* @작성일 : 2015. 6. 18.
* @변경이력 :
* @param dataParamInfo
* @param objNm
* @return
* @throws Exception
*/
@Override
public List<DDLInfo> getFunctions(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
StringBuilder ddlStrBuf;
List<DDLInfo> reval = new ArrayList<DDLInfo>();
DDLInfo ddlInfo;
SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
for (String objNm : objNmArr) {
ddlInfo = new DDLInfo();
ddlInfo.setName(objNm);
ddlStrBuf = new StringBuilder();
dataParamInfo.setObjectName(objNm);
if (ddlOption.isAddDropClause()) {
ddlStrBuf.append("/* DROP FUNCTION " + objNm + "; */").append(BlankConstants.NEW_LINE_TWO);
}
List<String> srcProcList = sqlSesseion.selectList("functionScript", dataParamInfo);
for (int j = 0; j < srcProcList.size(); j++) {
ddlStrBuf.append(srcProcList.get(j));
}
ddlStrBuf.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 DDLScriptImpl method getSequences.
/**
* @Method Name : getSequence
* @Method 설명 : sequence ddl
* @Method override : @see com.varsql.core.db.ddl.script.DDLScript#getSequence(com.varsql.core.db.valueobject.DatabaseParamInfo, java.lang.String[])
* @작성자 : ytkim
* @작성일 : 2015. 6. 18.
* @변경이력 :
* @param dataParamInfo
* @param objNm
* @return
* @throws Exception
*/
@Override
public List<DDLInfo> getSequences(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
StringBuilder ddlStrBuf;
List<DDLInfo> reval = new ArrayList<DDLInfo>();
DDLInfo ddlInfo;
SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
for (String objNm : objNmArr) {
ddlInfo = new DDLInfo();
ddlInfo.setName(objNm);
ddlStrBuf = new StringBuilder();
dataParamInfo.setObjectName(objNm);
if (ddlOption.isAddDropClause()) {
ddlStrBuf.append("/* DROP SEQUENCE " + objNm + "; */").append(BlankConstants.NEW_LINE_TWO);
}
Map param = sqlSesseion.selectOne("sequenceScript", dataParamInfo);
param.put("schema", dataParamInfo.getSchema());
param.put("ddlOption", ddlOption);
ddlStrBuf.append(SQLTemplateFactory.getInstance().sqlRender(DBType.OTHER, SQLTemplateCode.SEQUENCE.create, param));
ddlStrBuf.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 DDLScriptImpl method getTriggers.
/**
* @Method Name : getTrigger
* @Method 설명 : trigger ddl
* @Method override : @see com.varsql.core.db.ddl.script.DDLScript#getTrigger(com.varsql.core.db.valueobject.DatabaseParamInfo, java.lang.String[])
* @작성자 : ytkim
* @작성일 : 2015. 6. 18.
* @변경이력 :
* @param dataParamInfo
* @param objNm
* @return
* @throws Exception
*/
@Override
public List<DDLInfo> getTriggers(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
StringBuilder ddlStrBuf;
List<DDLInfo> reval = new ArrayList<DDLInfo>();
DDLInfo ddlInfo;
SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
for (String objNm : objNmArr) {
ddlInfo = new DDLInfo();
ddlInfo.setName(objNm);
ddlStrBuf = new StringBuilder();
dataParamInfo.setObjectName(objNm);
if (ddlOption.isAddDropClause()) {
ddlStrBuf.append("/* DROP TRIGGER " + objNm + "; */").append(BlankConstants.NEW_LINE_TWO);
}
List<String> srcProcList = sqlSesseion.selectList("triggerScript", dataParamInfo);
for (int j = 0; j < srcProcList.size(); j++) {
ddlStrBuf.append(srcProcList.get(j));
}
ddlStrBuf.append(ddlOption.isAddLastSemicolon() ? ";" : "").append(BlankConstants.NEW_LINE_TWO);
ddlInfo.setCreateScript(ddlStrBuf.toString());
reval.add(ddlInfo);
}
return reval;
}
Aggregations