use of com.varsql.core.db.valueobject.DataTypeInfo in project varsql by varsqlinfo.
the class MysqlDBMetaHandler method getColumnInfo.
/**
* @Method Name : getColumnInfo
* @Method 설명 : 컬럼 정보 얻기.
* @작성자 : ytkim
* @작성일 : 2017. 11. 20.
* @변경이력 :
* @param rs
* @param dataTypeImpl
* @param keyColumn
* @return
* @throws SQLException
*/
@Override
public ColumnInfo getColumnInfo(ResultSet rs, DataTypeImpl dataTypeImpl, Set keyColumn, Map colComment) throws SQLException {
ColumnInfo column = new ColumnInfo();
String cName = rs.getString(MetaColumnConstants.COLUMN_NAME);
String dataType = rs.getString(MetaColumnConstants.DATA_TYPE);
String degitsLen = StringUtils.nullToString(rs.getString(MetaColumnConstants.DECIMAL_DIGITS));
String columnSize = rs.getString(MetaColumnConstants.COLUMN_SIZE);
DataTypeInfo dataTypeInfo = dataTypeImpl.getDataType(dataType);
column.setName(cName);
column.setDataType(dataType);
column.setLength(rs.getBigDecimal(MetaColumnConstants.COLUMN_SIZE));
column.setDefaultVal(StringUtils.nullToString(rs.getString(MetaColumnConstants.COLUMN_DEF)));
column.setNullable(StringUtils.nullToString(rs.getString(MetaColumnConstants.IS_NULLABLE)));
column.setAutoincrement("");
column.setTypeName(dataTypeInfo.getDataTypeName());
column.setTypeAndLength(DbMetaUtils.getTypeName(dataTypeInfo, column, dataTypeInfo.getDataTypeName(), columnSize, degitsLen));
if (colComment != null) {
column.setComment(StringUtils.nullToString(colComment.get(cName) != null ? (String) colComment.get(cName) : rs.getString(MetaColumnConstants.REMARKS)));
}
if (keyColumn != null) {
column.setConstraints(keyColumn.contains(cName) ? "PK" : "");
}
return column;
}
use of com.varsql.core.db.valueobject.DataTypeInfo in project varsql by varsqlinfo.
the class OracleDBMetaHandler method getColumnInfo.
@Override
public ColumnInfo getColumnInfo(ResultSet rs, DataTypeImpl dataTypeImpl, Set keyColumn, Map colComment) throws SQLException {
ColumnInfo column = new ColumnInfo();
String cName = rs.getString(MetaColumnConstants.COLUMN_NAME);
String degitsLen = StringUtils.nullToString(rs.getString(MetaColumnConstants.DECIMAL_DIGITS));
String dataType = rs.getString(MetaColumnConstants.DATA_TYPE);
DataTypeInfo dataTypeInfo = dataTypeImpl.getDataType(dataType);
column.setName(cName);
column.setDataType(dataType);
column.setLength(rs.getInt(MetaColumnConstants.COLUMN_SIZE));
column.setDefaultVal(StringUtils.nullToString(rs.getString(MetaColumnConstants.COLUMN_DEF)));
column.setNullable(StringUtils.nullToString(rs.getString(MetaColumnConstants.IS_NULLABLE)));
column.setAutoincrement("");
column.setTypeName(dataTypeInfo.getDataTypeName());
column.setTypeAndLength(DbMetaUtils.getTypeName(dataTypeInfo, column, dataTypeInfo.getDataTypeName(), degitsLen));
if (colComment != null) {
column.setComment(StringUtils.nullToString(colComment.get(cName) != null ? (String) colComment.get(cName) : rs.getString(MetaColumnConstants.REMARKS)));
}
column.setConstraints(keyColumn.contains(cName) ? "PK" : "");
return column;
}
use of com.varsql.core.db.valueobject.DataTypeInfo 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.DataTypeInfo in project varsql by varsqlinfo.
the class TiberoDDLScript 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("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;
}
Aggregations