use of com.varsql.core.db.meta.datatype.DataTypeImpl 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.meta.datatype.DataTypeImpl in project varsql by varsqlinfo.
the class DBMetaDataUtil method tableAndColumnsInfo.
protected List<TableInfo> tableAndColumnsInfo(DatabaseParamInfo dataParamInfo, Connection conn, MetaControlBean dbInstanceFactory, String type, List<TableInfo> tableList) throws SQLException {
List<TableInfo> reLst = new ArrayList<TableInfo>();
ResultSet colRs = null;
String schema = dataParamInfo.getSchema();
try {
DatabaseMetaData dbmd = conn.getMetaData();
DataTypeImpl dataTypeImpl = dbInstanceFactory.getDataTypeImpl();
DBMetaHandlerImpl dbMetaHandlerImpl = dbInstanceFactory.getDBMetaHandlerImpl();
List<ColumnInfo> columnList = null;
String tableNm = "";
Map<String, HashSet<String>> pkMap = new HashMap<String, HashSet<String>>();
Map<String, TableInfo> tableInfoMap = new HashMap<String, TableInfo>();
for (TableInfo tableInfo : tableList) {
columnList = new ArrayList<ColumnInfo>();
tableNm = tableInfo.getName();
colRs = dbmd.getPrimaryKeys(null, schema, tableNm);
HashSet<String> keyColumn = new HashSet<String>();
while (colRs.next()) {
keyColumn.add(colRs.getString(MetaColumnConstants.COLUMN_NAME));
}
colRs.close();
pkMap.put(tableNm, keyColumn);
tableInfoMap.put(tableNm, tableInfo);
tableInfo.setColList(columnList);
reLst.add(tableInfo);
}
colRs = dbmd.getColumns(null, schema, null, null);
while (colRs.next()) {
tableNm = colRs.getString(MetaColumnConstants.TABLE_NAME);
if (tableInfoMap.containsKey(tableNm)) {
tableInfoMap.get(tableNm).getColList().add(dbMetaHandlerImpl.getColumnInfo(colRs, dataTypeImpl, pkMap.get(tableNm)));
}
}
colRs.close();
} finally {
JdbcUtils.close(colRs);
}
return reLst;
}
use of com.varsql.core.db.meta.datatype.DataTypeImpl 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.meta.datatype.DataTypeImpl 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.meta.datatype.DataTypeImpl 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