use of com.varsql.core.db.valueobject.TableInfo 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.TableInfo in project varsql by varsqlinfo.
the class TableReportImpl method columnsInfo.
@Override
public ExcelReport columnsInfo(DatabaseParamInfo dataParamInfo, List<Map> columnInfoList, boolean addTableDefinitionFlag, boolean multiSheetFlag, String... tableNmArr) throws Exception {
ExcelReport report;
List<TableInfo> tableList = MetaControlFactory.getDbInstanceFactory(dataParamInfo.getDbType()).getDBObjectMeta(ObjectType.TABLE.getObjectTypeId(), dataParamInfo, tableNmArr);
List<String> tableNames = Arrays.asList(tableNmArr);
Collections.sort(tableList, new Comparator<TableInfo>() {
@Override
public int compare(TableInfo o1, TableInfo o2) {
return tableNames.indexOf(o1.getName()) > tableNames.indexOf(o2.getName()) ? 1 : -1;
}
});
// 테이블 요약 정보 추가 여부.
if (addTableDefinitionFlag) {
List<ExcelReportVO> tableLabelInfo = new ArrayList<ExcelReportVO>();
for (VarsqlReportConfig.TABLE tableInfo : VarsqlReportConfig.TABLE.values()) {
tableLabelInfo.add(ExcelReportVO.builder().key(tableInfo.getKey()).name(tableInfo.getLabel()).width(tableInfo.getWidth()).cellStyle(ExcelCellStyle.builder().align(ExcelConstants.ALIGN.CENTER).build()).headerCellStyle(ExcelCellStyle.builder().align(ExcelConstants.ALIGN.CENTER).bgColor(ExcelConstants.DEFAULT_LABEL_BG_COLOR).bold(true).build()).build());
}
ExcelReportVO[] labelInfoArr = tableLabelInfo.toArray(new ExcelReportVO[tableLabelInfo.size()]);
report = new ExcelReport("Table Info", labelInfoArr);
Map<String, String> tableInfoMap = new HashMap<String, String>();
report.createSheet();
report.addLabelRow();
tableInfoMap.put(VarsqlReportConfig.TABLE.DATABASE.getKey(), dataParamInfo.getSchema());
for (TableInfo tableInfo : tableList) {
tableInfoMap.put(VarsqlReportConfig.TABLE.NAME.getKey(), tableInfo.getName());
tableInfoMap.put(VarsqlReportConfig.TABLE.COMMENT.getKey(), tableInfo.getRemarks());
report.addRow(tableInfoMap);
}
} else {
report = new ExcelReport();
}
Map<String, String> headerInfo = new HashMap<String, String>();
headerInfo.put("{databaseName}", dataParamInfo.getSchema());
List<ExcelReportVO> columnList = new ArrayList<ExcelReportVO>();
for (Map colInfo : columnInfoList) {
String colName = String.valueOf(colInfo.get(VarsqlReportConfig.MapperKey.code.getKey()));
VarsqlReportConfig.TABLE_COLUMN tableInfo = VarsqlReportConfig.TABLE_COLUMN.valueOf(colName.toUpperCase());
String title = tableInfo.colName();
if (colInfo.containsKey(VarsqlReportConfig.MapperKey.title.getKey())) {
title = String.valueOf(colInfo.get(VarsqlReportConfig.MapperKey.title.getKey()));
}
int width = tableInfo.colWidth();
if (colInfo.containsKey(VarsqlReportConfig.MapperKey.width.getKey())) {
try {
width = Integer.parseInt(String.valueOf(colInfo.get(VarsqlReportConfig.MapperKey.width.getKey())));
} catch (NumberFormatException e) {
e.getMessage();
}
}
// columnList.add(new ExcelReportVO(tableInfo.getKey(), title, width, tableInfo.getAlign()));
columnList.add(ExcelReportVO.builder().key(tableInfo.getKey()).name(title).width(width).cellStyle(ExcelCellStyle.builder().align(tableInfo.getAlign()).build()).headerCellStyle(ExcelCellStyle.builder().align(ExcelConstants.ALIGN.CENTER).bgColor(ExcelConstants.DEFAULT_LABEL_BG_COLOR).bold(true).build()).build());
}
report.setColumnArr(columnList.toArray(new ExcelReportVO[columnList.size()]));
report.setHaderInfoList(getHeaderInfoList());
if (multiSheetFlag) {
report.createSheet(tableList.get(0).getName());
} else {
report.createSheet("Table Column Info");
}
boolean firstFlag = true;
List<ColumnInfo> colList;
ColumnInfo columnInfo = null;
String tableNm = "";
for (TableInfo tableInfo : tableList) {
tableNm = tableInfo.getName();
if (multiSheetFlag && !firstFlag) {
report.createSheet(tableNm);
}
headerInfo.put("{tableName}", tableNm);
headerInfo.put("{tableSpace}", "");
headerInfo.put("{entity}", "");
headerInfo.put("{comment}", tableInfo.getRemarks());
report.setHeaderInfo(headerInfo);
report.addHeaderInfo(true);
report.addLabelRow();
colList = tableInfo.getColList();
for (int j = 0; j < colList.size(); j++) {
columnInfo = colList.get(j);
columnInfo.setNo(j + 1);
report.addRow(columnInfo);
}
report.addSpaceRow();
firstFlag = false;
}
return report;
}
use of com.varsql.core.db.valueobject.TableInfo in project varsql by varsqlinfo.
the class DBMetaImpl method getTableMetadata.
public List<TableInfo> getTableMetadata(DatabaseParamInfo dataParamInfo, String... tableNames) throws Exception {
logger.debug("DBMetaImpl getTableMetadata {} tableArr :: {}", VartechReflectionUtils.reflectionToString(dataParamInfo), tableNames);
SqlSession session = SQLManager.getInstance().openSession(dataParamInfo.getVconnid());
try {
Connection conn = session.getConnection();
List<TableInfo> tableList = null;
if (tableNames != null && tableNames.length > 0) {
tableList = new ArrayList<TableInfo>();
TableInfo tableInfo = null;
for (String nm : tableNames) {
tableInfo = new TableInfo();
tableInfo.setName(nm);
tableInfo.setRemarks("");
tableList.add(tableInfo);
}
} else {
tableList = dBMetaDataUtil.tableInfo(dataParamInfo, conn, "TABLE");
}
return dBMetaDataUtil.tableAndColumnsInfo(dataParamInfo, conn, dbInstanceFactory, "TABLE", tableList);
} finally {
sessionClose(dataParamInfo.getVconnid(), session);
}
}
use of com.varsql.core.db.valueobject.TableInfo 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.TableInfo in project varsql by varsqlinfo.
the class DBMetaDataUtil method tableInfo.
protected List<TableInfo> tableInfo(DatabaseParamInfo dataParamInfo, Connection conn, String type) throws SQLException {
List<TableInfo> reLst = new ArrayList<TableInfo>();
ResultSet rs = null;
try {
DatabaseMetaData dbmd = conn.getMetaData();
String[] types = { type };
rs = dbmd.getTables(null, dataParamInfo.getSchema(), "%", types);
TableInfo tableInfo = null;
while (rs.next()) {
tableInfo = new TableInfo();
tableInfo.setName(rs.getString(MetaColumnConstants.TABLE_NAME));
tableInfo.setRemarks(StringUtils.nullToString(rs.getString(MetaColumnConstants.REMARKS)));
reLst.add(tableInfo);
}
} finally {
JdbcUtils.close(rs);
}
return reLst;
}
Aggregations