use of com.varsql.core.db.valueobject.DataTypeInfo in project varsql by varsqlinfo.
the class TableInfoHandler method handleResult.
@Override
public void handleResult(ResultContext<? extends ParamMap> paramResultContext) {
ParamMap rowData = paramResultContext.getResultObject();
String tblName = rowData.getString(MetaColumnConstants.TABLE_NAME);
if (!tblName.equals(beforeTableName)) {
if (useTableIndex) {
currentTableInfo = this.tableInfoList.get(this.tableIndexInfo.get(tblName));
currentTableInfo.setColList(new ArrayList<ColumnInfo>());
currentTableInfo.setRemarks(StringUtils.nullToString(currentTableInfo.getRemarks(), ""));
} else {
currentTableInfo = new TableInfo();
currentTableInfo.setName(tblName);
currentTableInfo.setColList(new ArrayList<ColumnInfo>());
currentTableInfo.setRemarks(rowData.getString(MetaColumnConstants.REMARKS, ""));
tableInfoList.add(currentTableInfo);
}
}
ColumnInfo column = new ColumnInfo();
String cName = rowData.getString(MetaColumnConstants.COLUMN_NAME);
String columnSize = rowData.getString(MetaColumnConstants.COLUMN_SIZE);
String degitsLen = rowData.getString(MetaColumnConstants.DECIMAL_DIGITS);
String dataType = rowData.getString(MetaColumnConstants.DATA_TYPE);
DataTypeInfo dataTypeInfo = dataTypeImpl.getDataType(dataType);
column.setName(cName);
column.setDataType(dataType);
Object lenInfoObj = rowData.get(MetaColumnConstants.COLUMN_SIZE);
if (lenInfoObj != null) {
if (lenInfoObj instanceof Integer) {
column.setLength(Integer.parseInt(lenInfoObj + ""));
} else {
column.setLength(new BigDecimal(lenInfoObj + ""));
}
}
column.setDefaultVal(rowData.getString(MetaColumnConstants.COLUMN_DEF));
column.setNullable(rowData.getString(MetaColumnConstants.IS_NULLABLE));
column.setTypeName(dataTypeInfo.getDataTypeName());
String typeAndLength = rowData.getString(MetaColumnConstants.TYPE_NAME_SIZE, "");
if ("".equals(typeAndLength)) {
column.setTypeAndLength(DbMetaUtils.getTypeName(dataTypeInfo, column, dataTypeInfo.getDataTypeName(), columnSize, degitsLen));
} else {
column.setTypeAndLength(typeAndLength);
}
column.setComment(rowData.getString(MetaColumnConstants.COMMENT, ""));
column.setConstraints(rowData.getString(MetaColumnConstants.CONSTRAINTS, ""));
currentTableInfo.addColInfo(column);
beforeTableName = tblName;
}
use of com.varsql.core.db.valueobject.DataTypeInfo in project varsql by varsqlinfo.
the class DBMetaHandlerImpl 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 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.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(), 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 MssqlDDLScript 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((String) 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 TiberoDBMetaHandler 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 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;
}
Aggregations