Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
usfalami committed Sep 25, 2024
1 parent 50b251d commit be19e6b
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions src/main/java/org/usf/jquery/web/ViewMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,37 @@ final ViewMetadata fetch(DatabaseMetaData metadata, String schema) throws SQLExc
}

void fetchView(DatabaseMetaData metadata, TableView view, String schema) throws SQLException {
try(var rs = metadata.getColumns(null, view.getSchemaOrElse(schema), view.getName(), null)){
if(rs.next()) {
var db = reverseMapKeys(); //reverse key
do {
var cm = db.remove(rs.getString("COLUMN_NAME"));
if(nonNull(cm)) {
cm.update(
rs.getInt("DATA_TYPE"),
rs.getInt("COLUMN_SIZE"),
rs.getInt("DECIMAL_DIGITS"));
} // else undeclared column
} while(rs.next());
if(!db.isEmpty()) { //no such columns
throw columnsNotFoundException(db.keySet());
schema = view.getSchemaOrElse(schema);
try(var tm = metadata.getTables(null, schema, view.getName(), null)) {
if(tm.next()) {
if("TABLE".equals(tm.getString("TABLE_TYPE"))) {
try(var rs = metadata.getColumns(null, schema, view.getName(), null)){
if(rs.next()) {
var db = reverseMapKeys(); //reverse key
do {
var cm = db.remove(rs.getString("COLUMN_NAME"));
if(nonNull(cm)) {
cm.update(
rs.getInt("DATA_TYPE"),
rs.getInt("COLUMN_SIZE"),
rs.getInt("DECIMAL_DIGITS"));
} // else undeclared column
} while(rs.next());
if(!db.isEmpty()) { //no such columns
throw columnsNotFoundException(db.keySet());
}
}
else {
throw new IllegalArgumentException("no columns");
}
}
}
else {
fetch(metadata, view, schema);
}
}
else {
throw new NoSuchElementException(quote(view.toString()) + " table not found");
throw new NoSuchElementException(quote(view.toString()) + " table or view not found");
}
}
}
Expand Down

0 comments on commit be19e6b

Please sign in to comment.