Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
tables = new DatabaseLoader().loadTables(databaseDescription, Connections.getCatalog(connection), Connections.getSchema(connection), null);
return Pipeline.of(tables).map(new Function
() {
@Override
public String apply(Table table) {
return SQLs.getTableFQN(databaseDescription, table.getCatalog(), table.getSchema(), table.getName());
}
}).asList();
} catch (Throwable ex) {
throw Throwables.wrapAsRuntimeException(ex);
} finally {
IOs.close(connection);
}
}
@ShellMethod(key = "show table", value = "Show table detail")
public Table getTable(@ShellOption(help = "the connection configuration name") String connectionName,
@ShellOption(help = "the table name") String table) {
Connection connection = getConnectionByConnectionConfigurationId(connectionName);
try {
DatabaseMetaData dbMetaData = connection.getMetaData();
return new DatabaseLoader().loadTable(new DatabaseDescription(dbMetaData), Connections.getCatalog(connection), Connections.getSchema(connection), table);
} catch (Throwable ex) {
throw Throwables.wrapAsRuntimeException(ex);
} finally {
IOs.close(connection);
}
}
@ShellMethod(key = "show indexes", value = "Show table index")
public List getIndexNames(
@ShellOption(help = "the connection configuration name") String connectionName,
@ShellOption(help = "the table name") String table) {
Connection connection = getConnectionByConnectionConfigurationId(connectionName);
try {
DatabaseMetaData dbMetaData = connection.getMetaData();
DatabaseDescription databaseDescription = new DatabaseDescription(dbMetaData);
List indexes = new DatabaseLoader().findTableIndexes(databaseDescription, Connections.getCatalog(connection), Connections.getSchema(connection), table);
return Pipeline.of(indexes).map(new Function() {
@Override
public String apply(Index index) {
return index.getName() + "\t" + SQLs.getTableFQN(index.getCatalog(), index.getSchema(), index.getTableName());
}
}).asList();
} catch (Throwable ex) {
throw Throwables.wrapAsRuntimeException(ex);
} finally {
IOs.close(connection);
}
}
@ShellMethod(key = "show index", value = "Show index detail")
public Index getIndex(@ShellOption(help = "the connection configuration name") String connectionName,
@ShellOption(help = "the table name") String table,
@ShellOption(help = "the index name") String index) {
Connection connection = getConnectionByConnectionConfigurationId(connectionName);
try {
DatabaseMetaData dbMetaData = connection.getMetaData();
Table t = new DatabaseLoader().loadTable(new DatabaseDescription(dbMetaData), Connections.getCatalog(connection), Connections.getSchema(connection), table);
return t.getIndex(index);
} catch (Throwable ex) {
throw Throwables.wrapAsRuntimeException(ex);
} finally {
IOs.close(connection);
}
}
@ShellMethod(key = "show ddl", value = "Show table DDL")
public String getTableDDL(@ShellOption(help = "the connection configuration name") String connectionName,
@ShellOption(help = "the table name") String table) {
Connection connection = getConnectionByConnectionConfigurationId(connectionName);
try {
DatabaseMetaData dbMetaData = connection.getMetaData();
DatabaseDescription databaseDescription = new DatabaseDescription(dbMetaData);
Table t = new DatabaseLoader().loadTable(databaseDescription, Connections.getCatalog(connection), Connections.getSchema(connection), table);
Preconditions.checkNotNull(t, StringTemplates.formatWithPlaceholder("table {} is not exists", table));
CommonTableGenerator generator = new CommonTableGenerator(databaseDescription);
return generator.generate(t);
} catch (Throwable ex) {
throw Throwables.wrapAsRuntimeException(ex);
} finally {
IOs.close(connection);
}
}
@ShellMethod(key = "dump ddl", value = "Show table DDL")
public String dumpTablesDDL(@ShellOption(help = "the connection configuration name") String connectionName,
@ShellOption(help = "the table name", defaultValue = "") String table,
@ShellOption(help = "the dump directory") String directory,
@ShellOption(help = "the dump filename") String filename,
@ShellOption(help = "postback to you", defaultValue = "false") boolean postback) {
Connection connection = getConnectionByConnectionConfigurationId(connectionName);
BufferedWriter bf = null;
try {
DatabaseMetaData dbMetaData = connection.getMetaData();
DatabaseDescription databaseDescription = new DatabaseDescription(dbMetaData);
table = Strings.getNullIfBlank(table);
List
ts = new DatabaseLoader().loadTables(databaseDescription, Connections.getCatalog(connection), Connections.getSchema(connection), table, true, true, true, true);
Preconditions.checkNotNull(ts, StringTemplates.formatWithPlaceholder("table {} is not exists", table));
if (!Strings.endsWithIgnoreCase(filename, SQL_FILE_SUFFIX)) {
filename = filename + ".sql";
}
Files.makeDirs(directory);
File file = new File(directory, filename);
Files.makeFile(file);
bf = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
final BufferedWriter bufferedWriter = bf;
CommonTableGenerator generator = new CommonTableGenerator(databaseDescription);
StringBuilder builder = new StringBuilder();
Collects.forEach(ts, new Consumer