* @throws java.io.IOException If any IO error occurs
*/
public void doShutdown () throws SQLException, IOException;
+
+ /**
+ * Some getter for total rows
+ *
+ * @return Total rows
+ * @throws java.io.IOException If an IO error occurs
+ * @throws java.sql.SQLException If any SQL error occurs
+ */
+ public Long getTotalRows () throws IOException, SQLException;
}
// Full output string
StringBuilder output = new StringBuilder(dataset.size() * 20);
+ // Add index column
+ output.append(String.format("key=%s,value=\"%s\";", this.getFrontend().getIdName(), this.getTotalRows() + 1));
+
// "Walk" over all entries
while (iterator.hasNext()) {
// Get next entry
String str = (String) value;
// Does it contain a " ?
- if (str.contains("")) {
+ if (str.contains("\"")) {
// Don't accept here
throw new IllegalArgumentException("value " + value + " with double-quote not supported yet.");
}
// Generate key=value pair
String pair = String.format("key=%s,value=\"%s\";", entry.getKey(), String.valueOf(value));
+ // Debug message
+ this.getLogger().debug("pair=" + pair);
+
// Append to output
output.append(pair);
}
// Return finished map
return map;
}
+
+ @Override
+ public final Long getTotalRows () throws IOException {
+ // Trace message
+ this.getLogger().trace("CALLED!");
+
+ // Init count
+ Long count = 0L;
+
+ // First rewind
+ this.rewind();
+
+ // Walk through all rows
+ while (!this.isEndOfFile()) {
+ // Get next line
+ String line = this.readLine();
+
+ // Count one up
+ count++;
+ }
+
+ // Trace message
+ this.getLogger().trace("count=" + count + " - EXIT!");
+
+ // Return it
+ return count;
+ }
}
*/
private static Connection connection;
+ /**
+ * Prepared statement for total row count
+ */
+ private PreparedStatement totalRows;
+
/**
* Constructor with table name
*
throw new SQLException("Connection is closed."); //NOI18N
}
- // Already connected
+ // Already connected
this.getLogger().debug("Connection is already established."); //NOI18N
// No need to connect
// Debug message
this.getLogger().debug("Connection is up, preparing some statements ..."); //NOI18N
+ // Set prepared statement
+ this.totalRows = connection.prepareStatement("SELECT COUNT(`?`) AS `cnt` FROM `?` LIMIT 1");
+
+ // Set values in prepared statement
+ this.totalRows.setObject(1, this.getFrontend().getIdName());
+ this.totalRows.setObject(2, this.getTableName());
+
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
}
// Return it
return statement;
}
+
+ @Override
+ public Long getTotalRows () throws IOException, SQLException {
+ // Trace message
+ this.getLogger().trace("CALLED!");
+
+ // Execute query
+ ResultSet set = this.totalRows.executeQuery();
+
+ // Rewind to beginning
+ set.beforeFirst();
+
+ // Get long
+ Long count = set.getLong("cnt");
+
+ // Trace message
+ this.getLogger().trace("count=" + count + " - EXIT!");
+
+ // Return it
+ return count;
+ }
}
* @throws java.lang.reflect.InvocationTargetException Any other problems?
*/
public Storeable toStoreable (final Map<String, String> map) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException;
+
+ /**
+ * Some getter for name of id column
+ *
+ * @return Name of id column
+ */
+ public String getIdName ();
}