Skip to content

Commit

Permalink
Creates a parameter to specify if the empty ranges of incremental rowid
Browse files Browse the repository at this point in the history
should be indentified.
  • Loading branch information
patrickdalla committed Jan 5, 2024
1 parent 8a056a1 commit 56df412
Showing 1 changed file with 41 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Set;

import org.apache.tika.config.Field;
import org.apache.tika.exception.TikaException;
import org.apache.tika.extractor.EmbeddedDocumentExtractor;
import org.apache.tika.extractor.ParsingEmbeddedDocumentExtractor;
Expand Down Expand Up @@ -63,11 +64,19 @@ public abstract class AbstractDBParser extends AbstractParser {
protected Connection connection;
int tableRowsPerItem = 100;

private boolean parseEmptyIncrementalRanges;

@Override
public Set<MediaType> getSupportedTypes(ParseContext context) {
return null;
}

@Field
public void setParseEmptyIncrementalRanges(boolean value) {
this.parseEmptyIncrementalRanges = value;
}

@Field
public void setTableRowsPerItem(int value) {
this.tableRowsPerItem = value;
}
Expand Down Expand Up @@ -172,36 +181,39 @@ public void parse(InputStream stream, ContentHandler handler, Metadata metadata,

xHandler.endElement("tr");

try {
StringBuffer sb = new StringBuffer();
DatabaseMetaData dbmd = connection.getMetaData();
ResultSet rs = dbmd.getColumns(null, null, tableName, "");
while(rs.next()) {
String isAutoIncrement = rs.getString("IS_AUTOINCREMENT");
if(isAutoIncrement!=null && isAutoIncrement.equals("YES")) {
String columnName = rs.getString("COLUMN_NAME");
ResultSet rsGaps = reader.getSequentialGaps(columnName);
if(rs.next()) {
if(first) {
first=false;
sb.append("<h1>Tabelas com vãos em campos autoincrementais</h1>");
}
sb.append("<table>");
sb.append("<tr><th colspan=\"2\">Tabela:"+tableName+"</th></tr>");
sb.append("<tr><th colspan=\"2\">Coluna:"+columnName+"</th></tr>");
sb.append("<tr><th>Inicio</th><th>Fim</th></tr>");
do {
sb.append("<tr><td>"+rs.getString("start")+"</td><td>"+rs.getString("end")+"</td></tr>");

}while(rs.next());
sb.append("</table>");
}
}
if (parseEmptyIncrementalRanges) {
try {
StringBuffer sb = new StringBuffer();
DatabaseMetaData dbmd = connection.getMetaData();
ResultSet rs = dbmd.getColumns(null, null, tableName, "");
while (rs.next()) {
String isAutoIncrement = rs.getString("IS_AUTOINCREMENT");
if (isAutoIncrement != null && isAutoIncrement.equals("YES")) {
String columnName = rs.getString("COLUMN_NAME");
ResultSet rsGaps = reader.getSequentialGaps(columnName);
if (rs.next()) {
if (first) {
first = false;
sb.append("<h1>Tabelas com vãos em campos autoincrementais</h1>");
}
sb.append("<table>");
sb.append("<tr><th colspan=\"2\">Tabela:" + tableName + "</th></tr>");
sb.append("<tr><th colspan=\"2\">Coluna:" + columnName + "</th></tr>");
sb.append("<tr><th>Inicio</th><th>Fim</th></tr>");
do {
sb.append("<tr><td>" + rs.getString("start") + "</td><td>" + rs.getString("end")
+ "</td></tr>");

} while (rs.next());
sb.append("</table>");
}
}
}
sbfim.append(sb.toString());
} catch (Exception e) {
// ignores
}
sbfim.append(sb.toString());
}catch (Exception e) {
// ignores
}
}


reader.closeReader();
Expand Down

0 comments on commit 56df412

Please sign in to comment.