Skip to content

Commit

Permalink
Allow table row count to be greater than Integer.MAX_VALUE (2^31-1) b…
Browse files Browse the repository at this point in the history
…y refactoring numRows from int to long
  • Loading branch information
sturton committed Jan 8, 2014
1 parent e5d01db commit c6a38d5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/main/java/net/sourceforge/schemaspy/model/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private class BasicTableMeta
final String type;
final String remarks;
final String viewSql;
final int numRows; // -1 if not determined
final long numRows; // -1 if not determined

/**
* @param schema
Expand All @@ -320,7 +320,7 @@ private class BasicTableMeta
* @param text optional textual SQL used to create the view
* @param numRows number of rows, or -1 if not determined
*/
BasicTableMeta(String schema, String name, String type, String remarks, String text, int numRows)
BasicTableMeta(String schema, String name, String type, String remarks, String text, long numRows)
{
this.schema = schema;
this.name = name;
Expand Down Expand Up @@ -365,7 +365,7 @@ private List<BasicTableMeta> getBasicTableMeta(DatabaseMetaData metadata,
String remarks = getOptionalString(rs, clazz + "_comment");
String text = forTables ? null : getOptionalString(rs, "view_definition");
String rows = forTables ? getOptionalString(rs, "table_rows") : null;
int numRows = rows == null ? -1 : Integer.parseInt(rows);
long numRows = rows == null ? -1 : Long.parseLong(rows);

basics.add(new BasicTableMeta(sch, name, clazz, remarks, text, numRows));
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/net/sourceforge/schemaspy/model/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class Table implements Comparable<Table> {
private final CaseInsensitiveMap<TableIndex> indexes = new CaseInsensitiveMap<TableIndex>();
private Object id;
private final Map<String, String> checkConstraints = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
private Integer numRows;
private Long numRows;
protected final Database db;
protected final Properties properties;
private String comments;
Expand Down Expand Up @@ -895,7 +895,7 @@ public String getViewSql() {
*
* @return
*/
public int getNumRows() {
public long getNumRows() {
if (numRows == null) {
numRows = Config.getInstance().isNumRowsEnabled() ? fetchNumRows() : -1;
}
Expand All @@ -908,7 +908,7 @@ public int getNumRows() {
*
* @param numRows
*/
public void setNumRows(int numRows) {
public void setNumRows(long numRows) {
this.numRows = numRows;
}

Expand All @@ -918,10 +918,10 @@ public void setNumRows(int numRows) {
* returns -1 if unable to successfully fetch the row count
*
* @param db Database
* @return int
* @return long
* @throws SQLException
*/
protected int fetchNumRows() {
protected long fetchNumRows() {
if (properties == null) // some "meta" tables don't have associated properties
return 0;

Expand All @@ -937,7 +937,7 @@ protected int fetchNumRows() {
rs = stmt.executeQuery();

while (rs.next()) {
return rs.getInt("row_count");
return rs.getLong("row_count");
}
} catch (SQLException sqlException) {
// don't die just because this failed
Expand Down Expand Up @@ -975,7 +975,7 @@ protected int fetchNumRows() {
}
}

protected int fetchNumRows(String clause, boolean forceQuotes) throws SQLException {
protected long fetchNumRows(String clause, boolean forceQuotes) throws SQLException {
PreparedStatement stmt = null;
ResultSet rs = null;
StringBuilder sql = new StringBuilder("select ");
Expand All @@ -996,7 +996,7 @@ protected int fetchNumRows(String clause, boolean forceQuotes) throws SQLExcepti
stmt = db.getConnection().prepareStatement(sql.toString());
rs = stmt.executeQuery();
while (rs.next()) {
return rs.getInt(1);
return rs.getLong(1);
}
return -1;
} catch (SQLException exc) {
Expand Down Expand Up @@ -1150,4 +1150,4 @@ public int compare(TableColumn column1, TableColumn column2) {
return column1.getId().toString().compareToIgnoreCase(column2.getId().toString());
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/sourceforge/schemaspy/model/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public String getViewSql() {
}

@Override
protected int fetchNumRows() {
protected long fetchNumRows() {
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sourceforge/schemaspy/view/DotNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ else if (indexColumns.contains(column))
if (table.isView())
buf.append("view");
else {
final int numRows = table.getNumRows();
final long numRows = table.getNumRows();
if (displayNumRows && numRows != -1) {
buf.append(NumberFormat.getInstance().format(numRows));
buf.append(" row");
Expand Down Expand Up @@ -222,4 +222,4 @@ public DotNodeConfig(boolean showTrivialColumns, boolean showColumnDetails) {
this.showColumnDetails = showColumnDetails;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public int compare(Table table1, Table table2) {

int numTableCols = 0;
int numViewCols = 0;
int numRows = 0;
long numRows = 0;
for (Table table : byName) {
writeLineItem(table, showIds, html);

Expand Down Expand Up @@ -244,7 +244,7 @@ private void writeLineItem(Table table, boolean showIds, LineWriter html) throws
html.writeln(" </tr>");
}

protected void writeFooter(int numTables, int numTableCols, int numViews, int numViewCols, int numRows, LineWriter html) throws IOException {
protected void writeFooter(int numTables, int numTableCols, int numViews, int numViewCols, long numRows, LineWriter html) throws IOException {
html.writeln(" <tr>");
html.writeln(" <td class='detail'>&nbsp;</td>");
html.writeln(" <td class='detail'>&nbsp;</td>");
Expand Down

0 comments on commit c6a38d5

Please sign in to comment.