Created
March 1, 2018 01:57
-
-
Save sualeh/97ae60a0d8f7a0a8d47bc1f42669421d to your computer and use it in GitHub Desktop.
SchemaCrawler Issue #167
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static us.fatehi.commandlineparser.CommandLineUtility.applyApplicationLogLevel; | |
import static us.fatehi.commandlineparser.CommandLineUtility.logSystemProperties; | |
import java.sql.Connection; | |
import java.sql.SQLException; | |
import java.util.Collection; | |
import java.util.Iterator; | |
import java.util.logging.Level; | |
import javax.sql.DataSource; | |
import schemacrawler.schema.Catalog; | |
import schemacrawler.schema.Column; | |
import schemacrawler.schema.JavaSqlType; | |
import schemacrawler.schema.Schema; | |
import schemacrawler.schema.Table; | |
import schemacrawler.schemacrawler.DatabaseConnectionOptions; | |
import schemacrawler.schemacrawler.ExcludeAll; | |
import schemacrawler.schemacrawler.RegularExpressionInclusionRule; | |
import schemacrawler.schemacrawler.SchemaCrawlerException; | |
import schemacrawler.schemacrawler.SchemaCrawlerOptions; | |
import schemacrawler.tools.options.InfoLevel; | |
import schemacrawler.utility.SchemaCrawlerUtility; | |
public final class Issue167 | |
{ | |
public static void main(final String[] args) | |
throws Exception | |
{ | |
// Turn application logging on by applying the correct log level | |
applyApplicationLogLevel(Level.OFF); | |
// Log system properties and classpath | |
logSystemProperties(); | |
final Connection connection = getConnection(); | |
final SchemaCrawlerOptions sco = new SchemaCrawlerOptions(); | |
sco.setSchemaInfoLevel(InfoLevel.standard.buildSchemaInfoLevel()); | |
sco.setRoutineInclusionRule(new ExcludeAll()); | |
sco | |
.setSchemaInclusionRule(new RegularExpressionInclusionRule("SVIL")); | |
sco.setTableNamePattern("XGPI_DDL_ORACLE%"); | |
final Catalog catalog = SchemaCrawlerUtility.getCatalog(connection, sco); | |
final Schema schema = catalog.getSchemas().iterator().next(); | |
if (catalog != null) | |
{ | |
final Collection<Table> tablesList = catalog.getTables(schema); | |
final Iterator<Table> i = tablesList.iterator(); | |
Table tbl; | |
while (i.hasNext()) | |
{ | |
tbl = i.next(); | |
System.out.println(tbl); | |
for (final Column col: tbl.getColumns()) | |
{ | |
final JavaSqlType sqlType = col.getColumnDataType().getJavaSqlType(); | |
System.out | |
.println("o--> " + col.getName() + " -data-type- " + sqlType); | |
} | |
} | |
} | |
} | |
private static Connection getConnection() | |
throws SchemaCrawlerException, SQLException | |
{ | |
final DataSource dataSource = new DatabaseConnectionOptions("jdbc:oracle:thin:@srvsvil:1521:orcl"); | |
return dataSource.getConnection("username", "password"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment