synchronizer jdbc & optimize
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2022, MaxKey and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* Please contact MaxKey, visit www.maxkey.top if you need additional
|
||||
* information or have any questions.
|
||||
*/
|
||||
|
||||
package org.maxkey.entity;
|
||||
|
||||
public class DbTableColumn {
|
||||
String column;
|
||||
String type;
|
||||
int precision;
|
||||
int scale;
|
||||
|
||||
public DbTableColumn(String column, String type, int precision, int scale) {
|
||||
super();
|
||||
this.column = column;
|
||||
this.type = type;
|
||||
this.precision = precision;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public String getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
||||
public void setColumn(String column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getPrecision() {
|
||||
return precision;
|
||||
}
|
||||
|
||||
public void setPrecision(int precision) {
|
||||
this.precision = precision;
|
||||
}
|
||||
|
||||
public int getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public void setScale(int scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2022, MaxKey and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* Please contact MaxKey, visit www.maxkey.top if you need additional
|
||||
* information or have any questions.
|
||||
*/
|
||||
|
||||
package org.maxkey.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DbTableMetaData {
|
||||
String tableName;
|
||||
|
||||
ArrayList<DbTableColumn> columns = new ArrayList<DbTableColumn>();
|
||||
|
||||
HashMap<String,DbTableColumn> columnsMap = new HashMap<String,DbTableColumn>();
|
||||
|
||||
public DbTableMetaData(String tableName) {
|
||||
super();
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public ArrayList<DbTableColumn> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumns(ArrayList<DbTableColumn> columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
public HashMap<String, DbTableColumn> getColumnsMap() {
|
||||
return columnsMap;
|
||||
}
|
||||
|
||||
public void setColumnsMap(HashMap<String, DbTableColumn> columnsMap) {
|
||||
this.columnsMap = columnsMap;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -20,9 +20,14 @@ package org.maxkey.util;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.maxkey.entity.DbTableColumn;
|
||||
import org.maxkey.entity.DbTableMetaData;
|
||||
|
||||
|
||||
public class JdbcUtils {
|
||||
|
||||
public static Connection connect(String url, String user, String pwd, String driverClass) {
|
||||
@@ -106,6 +111,27 @@ public class JdbcUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static DbTableMetaData getMetaData(ResultSet rs) {
|
||||
try {
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
DbTableMetaData meta = new DbTableMetaData(metaData.getTableName(1));
|
||||
int count = metaData.getColumnCount();
|
||||
for (int i = 1; i <= count; i++) {
|
||||
DbTableColumn column = new DbTableColumn(
|
||||
metaData.getColumnName(i).toLowerCase(),
|
||||
metaData.getColumnTypeName(i),
|
||||
metaData.getPrecision(i),
|
||||
metaData.getScale(i)
|
||||
);
|
||||
meta.getColumns().add(column);
|
||||
meta.getColumnsMap().put(column.getColumn(), column);
|
||||
}
|
||||
return meta;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user