use of com.varsql.core.db.valueobject.ddl.DDLInfo in project varsql by varsqlinfo.
the class PostgresqlDDLScript 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("CREATE OR REPLACE VIEW ").append(name).append(" AS ").append(BlankConstants.NEW_LINE_TWO);
ddlStr.append(source.getString("VIEW_SOURCE"));
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 PostgresqlDDLScript 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);
}
Map indexInfo = sqlSesseion.selectOne("indexScript", dataParamInfo);
ddlStr.append(indexInfo.get(MetaColumnConstants.CREATE_SOURCE));
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 PostgresqlDDLScript 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");
dataParamInfo.setObjectName(name);
DataTypeImpl dataTypeImpl = dbInstanceFactory.getDataTypeImpl();
ParamMap source;
for (int i = 0; i < srcList.size(); i++) {
source = srcList.get(i);
ddlStr.append(BlankConstants.TAB);
if (i > 0) {
ddlStr.append(",");
}
ddlStr.append(source.get(MetaColumnConstants.COLUMN_NAME)).append(" ");
ddlStr.append(source.get(MetaColumnConstants.DATA_TYPE)).append(" ");
ddlStr.append(source.getString(MetaColumnConstants.COLUMN_DEF)).append(" ");
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);
ddlStr.append(BlankConstants.TAB).append(",CONSTRAINT ").append(pkMap.get("CONSTRAINT_NAME")).append(" ").append(pkMap.get("CONSTRAINDDEF"));
}
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 SybaseDDLScript method getSequences.
/**
* @Method Name : getSequence
* @Method 설명 : Sequence 구하기.
* @Method override : @see com.varsql.core.db.ddl.script.DDLScriptImpl#getSequence(com.varsql.core.db.valueobject.DatabaseParamInfo, java.lang.String[])
* @작성자 : ytkim
* @작성일 : 2018. 9. 19.
* @변경이력 :
* @param dataParamInfo
* @param objNmArr
* @return
* @throws Exception
*/
@Override
public List<DDLInfo> getSequences(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
logger.debug("Sequence 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);
Map param = sqlSesseion.selectOne("sequenceScript", dataParamInfo);
param.put("schema", dataParamInfo.getSchema());
param.put("ddlOption", ddlOption);
ddlStr.append(SQLTemplateFactory.getInstance().sqlRender(dbType, SQLTemplateCode.SEQUENCE.create, param));
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 SybaseDDLScript method getProcedures.
@Override
public List<DDLInfo> getProcedures(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
logger.debug(" Procedure 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);
Map param = getDefaultTemplateParam(ddlOption, dataParamInfo, sqlSesseion.selectList("objectScriptSource", dataParamInfo));
ddlStr.append(SQLTemplateFactory.getInstance().sqlRender(dbType, SQLTemplateCode.PROCEDURE.create, param));
ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
reval.add(ddlInfo);
}
return reval;
}
Aggregations