|
2 | 2 |
|
3 | 3 | import com.codingapi.dbstream.proxy.ConnectionProxy; |
4 | 4 | import com.codingapi.dbstream.scanner.DBMetaData; |
| 5 | +import com.codingapi.dbstream.scanner.DBScanner; |
5 | 6 | import com.codingapi.dbstream.scanner.DbColumn; |
6 | 7 | import com.codingapi.dbstream.scanner.DbTable; |
7 | 8 | import lombok.Getter; |
@@ -127,19 +128,6 @@ public void setParam(int index, Object value) { |
127 | 128 | } |
128 | 129 |
|
129 | 130 |
|
130 | | - /** |
131 | | - * 获取表的元数据数据信息 |
132 | | - * |
133 | | - * @param tableName 表名称 不区分大小写 |
134 | | - * @return 表数据 |
135 | | - */ |
136 | | - public DbTable getTable(String tableName) { |
137 | | - if (metaData == null) { |
138 | | - return null; |
139 | | - } |
140 | | - return metaData.getTable(tableName); |
141 | | - } |
142 | | - |
143 | 131 | /** |
144 | 132 | * 元数据中是否存在表 |
145 | 133 | * |
@@ -172,7 +160,7 @@ public List<Map<String, Object>> query(String sql, List<Object> params) throws S |
172 | 160 | PreparedStatement preparedStatement = connection.prepareStatement(sql); |
173 | 161 | for (int i = 0; i < params.size(); i++) { |
174 | 162 | Object param = params.get(i); |
175 | | - preparedStatement.setObject(i + 1,param); |
| 163 | + preparedStatement.setObject(i + 1, param); |
176 | 164 | } |
177 | 165 | ResultSet resultSet = preparedStatement.executeQuery(); |
178 | 166 | ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); |
@@ -216,18 +204,39 @@ public List<Map<String, Object>> getStatementGenerateKeys(DbTable dbTable) { |
216 | 204 | } |
217 | 205 |
|
218 | 206 |
|
219 | | - public Properties getDriverProperties(){ |
| 207 | + /** |
| 208 | + * 获取驱动配置信息 |
| 209 | + * @return Properties |
| 210 | + */ |
| 211 | + public Properties getDriverProperties() { |
220 | 212 | if (metaData == null) { |
221 | 213 | return null; |
222 | 214 | } |
223 | 215 | return this.metaData.getProperties(); |
224 | 216 | } |
225 | 217 |
|
226 | 218 |
|
| 219 | + /** |
| 220 | + * 获取数据库的jdbcUrl |
| 221 | + * @return jdbcUrl |
| 222 | + */ |
227 | 223 | public String getJdbcUrl() { |
228 | 224 | if (metaData == null) { |
229 | 225 | return null; |
230 | 226 | } |
231 | 227 | return metaData.getJdbcUrl(); |
232 | 228 | } |
| 229 | + |
| 230 | + |
| 231 | + /** |
| 232 | + * 更新数据库的元数据信息 |
| 233 | + * @param tableName 表名 |
| 234 | + */ |
| 235 | + public void updateMetaData(String tableName) throws SQLException { |
| 236 | + // 当前表需要更新时,将会连同所有带更新的表一次性全部更新 |
| 237 | + if (this.metaData.isUpdateTableMeta(tableName)) { |
| 238 | + DBScanner dbScanner = new DBScanner(connection, getDriverProperties()); |
| 239 | + dbScanner.updateMetadata(this.metaData); |
| 240 | + } |
| 241 | + } |
233 | 242 | } |
0 commit comments