use of com.developmentontheedge.be5.metadata.util.ProcessController in project be5 by DevelopmentOnTheEdge.
the class H2SchemaReader method readColumns.
@Override
public Map<String, List<SqlColumnInfo>> readColumns(SqlExecutor sql, String defSchema, ProcessController controller) throws SQLException, ProcessInterruptedException {
DbmsConnector connector = sql.getConnector();
Map<String, List<SqlColumnInfo>> result = new HashMap<>();
ResultSet rs = connector.executeQuery("SELECT " + "c.table_name, " + "c.column_name, " + "c.column_default, " + "c.TYPE_NAME, " + "c.character_maximum_length, " + "c.numeric_precision, " + "c.numeric_scale, " + "c.is_nullable, " + "c.CHECK_CONSTRAINT " + "FROM INFORMATION_SCHEMA.COLUMNS c " + "WHERE c.TABLE_SCHEMA <> 'INFORMATION_SCHEMA'");
try {
while (rs.next()) {
String tableName = rs.getString(1).toLowerCase();
if (!tableName.equals(tableName.toLowerCase()))
continue;
List<SqlColumnInfo> list = result.get(tableName);
if (list == null) {
list = new ArrayList<>();
result.put(tableName, list);
}
SqlColumnInfo info = new SqlColumnInfo();
list.add(info);
info.setName(rs.getString(2));
info.setType(rs.getString(4));
info.setCanBeNull("YES".equals(rs.getString(8)));
String defaultValue = rs.getString(3);
if (defaultValue != null) {
for (String suffix : SUFFICES) {
if (defaultValue.endsWith(suffix))
defaultValue = defaultValue.substring(0, defaultValue.length() - suffix.length());
}
defaultValue = DEFAULT_DATE_PATTERN.matcher(defaultValue).replaceFirst("'$1'");
}
info.setDefaultValue(defaultValue);
info.setSize(rs.getInt(5));
if (rs.wasNull()) {
info.setSize(rs.getInt(6));
}
info.setPrecision(rs.getInt(7));
info.setAutoIncrement(defaultValue != null && defaultValue.startsWith("nextval"));
String check = rs.getString(9);
if (check == null)
continue;
Matcher matcher = ENUM_VALUES_PATTERN.matcher(check);
List<String> vals = new ArrayList<>();
while (matcher.find()) {
vals.add(matcher.group(1));
}
info.setEnumValues(vals.toArray(new String[vals.size()]));
// Just to check for interrupts
controller.setProgress(0);
}
} finally {
connector.close(rs);
}
return result;
}
use of com.developmentontheedge.be5.metadata.util.ProcessController in project be5 by DevelopmentOnTheEdge.
the class MySqlSchemaReader method readIndices.
@Override
public Map<String, List<IndexInfo>> readIndices(SqlExecutor sql, String defSchema, ProcessController controller) throws SQLException, ProcessInterruptedException {
DbmsConnector connector = sql.getConnector();
Map<String, List<IndexInfo>> result = new HashMap<>();
ResultSet rs = connector.executeQuery("SELECT table_name,index_name,column_name,non_unique FROM information_schema.statistics " + "WHERE table_schema='" + defSchema + "' ORDER BY table_name,index_name,seq_in_index");
try {
IndexInfo curIndex = null;
String lastTable = null;
while (rs.next()) {
String tableName = rs.getString(1).toLowerCase();
String indexName = rs.getString(2);
if (!tableName.equals(lastTable) || curIndex == null || !curIndex.getName().equals(indexName)) {
List<IndexInfo> list = result.get(tableName);
if (list == null) {
list = new ArrayList<>();
result.put(tableName, list);
}
curIndex = new IndexInfo();
lastTable = tableName;
list.add(curIndex);
curIndex.setName(indexName);
int nonUnique = rs.getInt(4);
curIndex.setUnique(nonUnique == 0);
}
String column = rs.getString(3);
curIndex.addColumn(column);
}
} finally {
connector.close(rs);
}
return result;
}
use of com.developmentontheedge.be5.metadata.util.ProcessController in project be5 by DevelopmentOnTheEdge.
the class AppSync method readSchema.
private void readSchema() throws ExtendedSqlException, SQLException, ProcessInterruptedException {
getLog().info("Read database scheme ...");
long time = System.currentTimeMillis();
ProcessController controller = new NullLogger();
Rdbms rdbms = DatabaseUtils.getRdbms(connector);
DbmsSchemaReader schemaReader = rdbms.getSchemaReader();
defSchema = schemaReader.getDefaultSchema(sqlExecutor);
tableTypes = schemaReader.readTableNames(sqlExecutor, defSchema, controller);
columns = schemaReader.readColumns(sqlExecutor, defSchema, controller);
indices = schemaReader.readIndices(sqlExecutor, defSchema, controller);
if (debug) {
if (!warnings.isEmpty()) {
System.err.println(warnings.size() + " warning(s) during loading the project from " + sqlExecutor.getConnector().getConnectString());
Collections.sort(warnings);
for (String warning : warnings) {
System.err.println(warning);
}
}
}
getLog().info("comleted, " + (System.currentTimeMillis() - time) + "ms.");
}
use of com.developmentontheedge.be5.metadata.util.ProcessController in project be5 by DevelopmentOnTheEdge.
the class AppTools method execute.
@Override
public void execute() throws MojoFailureException {
init();
BeConnectionProfile prof = be5Project.getConnectionProfile();
if (prof == null) {
throw new MojoFailureException("Connection profile is required for SQL console");
}
try {
getLog().info("Welcome to FTL/SQL console!");
BeSqlExecutor sql = new BeSqlExecutor(connector) {
@Override
public void executeSingle(String statement) throws ExtendedSqlException {
ResultSet rs = null;
try {
rs = connector.executeQuery(statement);
format(rs, System.err, 20);
} catch (SQLException e) {
throw new ExtendedSqlException(connector, statement, e);
} finally {
connector.close(rs);
}
}
};
FreemarkerScript fs = new FreemarkerScript("SQL", be5Project.getApplication().getFreemarkerScripts());
DataElementUtils.save(fs);
ProcessController log = new NullLogger();
while (true) {
getLog().info("Enter FTL/SQL (use 'quit' to exit):");
String line = new BufferedReader(new InputStreamReader(inputStream)).readLine();
if (line == null) {
break;
}
line = line.trim();
if (line.equals("quit")) {
break;
}
fs.setSource(line);
ParseResult result = fs.getResult();
if (result.getResult() != null) {
getLog().info("SQL> " + result.getResult());
} else {
getLog().info("ERROR> " + result.getError());
continue;
}
try {
sql.executeScript(fs, log);
} catch (Exception e) {
getLog().info("ERROR> " + e.getMessage());
}
}
} catch (Exception e) {
throw new MojoFailureException("Console error: " + e.getMessage(), e);
}
}
use of com.developmentontheedge.be5.metadata.util.ProcessController in project be5 by DevelopmentOnTheEdge.
the class ModuleLoader2 method mergeModules.
public static void mergeModules(Project be5Project, ProcessController logger) throws ProjectLoadException {
long startTime = System.nanoTime();
LoadContext loadContext = new LoadContext();
try {
ModuleLoader2.mergeAllModules(be5Project, logger, loadContext);
} catch (ProjectLoadException e) {
throw new ProjectLoadException("Merge modules", e);
}
loadContext.check();
log.info(ModuleLoader2.logLoadedProject(be5Project, startTime));
}
Aggregations