use of java.sql.Timestamp in project binnavi by google.
the class PostgreSQLDatabaseFunctions method loadProjects.
/**
* Loads the projects of a database.
*
* @param provider The SQL provider that provides the connection.
* @param debuggerManager Debugger manager object that belongs to the given database.
*
* @return A list of projects that contains the projects stored in the database.
*
* @throws CouldntLoadDataException Thrown if the projects could not be loaded from the database.
*/
public static List<INaviProject> loadProjects(final AbstractSQLProvider provider, final DebuggerTemplateManager debuggerManager) throws CouldntLoadDataException {
PostgreSQLDatabaseFunctions.checkArguments(provider, debuggerManager);
final CConnection connection = provider.getConnection();
final List<INaviProject> projects = new ArrayList<>();
if (!PostgreSQLHelpers.hasTable(connection, CTableNames.PROJECTS_TABLE)) {
return projects;
}
String query = "SELECT id, name, description, creation_date, modification_date, " + " (SELECT count(*) FROM " + CTableNames.ADDRESS_SPACES_TABLE + " WHERE project_id = " + CTableNames.PROJECTS_TABLE + ".id) " + " AS addressspace_count FROM " + CTableNames.PROJECTS_TABLE;
try (ResultSet resultSet = connection.executeQuery(query, true)) {
while (resultSet.next()) {
final int projectId = resultSet.getInt("id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final int addressSpaceCount = resultSet.getInt("addressspace_count");
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final List<DebuggerTemplate> debuggers = PostgreSQLDatabaseFunctions.getAssignedDebuggers(connection, projectId, debuggerManager);
projects.add(new CProject(projectId, name, description == null ? "" : description, creationDate, modificationDate, addressSpaceCount, debuggers, provider));
}
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
return new ArrayList<INaviProject>(projects);
}
use of java.sql.Timestamp in project binnavi by google.
the class PostgreSQLDatabaseFunctions method loadModules.
/**
* Loads the modules of a database.
*
* @param provider The SQL provider that provides the connection.
* @param rawModules Previously loaded raw module objects.
* @param debuggerManager Debugger manager object that belongs to the given database.
*
* @return A list of modules that contains the modules stored in the database.
*
* @throws CouldntLoadDataException Thrown if the modules could not be loaded from the database.
*/
public static List<INaviModule> loadModules(final AbstractSQLProvider provider, final List<INaviRawModule> rawModules, final DebuggerTemplateManager debuggerManager) throws CouldntLoadDataException {
Preconditions.checkNotNull(rawModules, "IE02043: rawModules argument can not be null");
PostgreSQLDatabaseFunctions.checkArguments(provider, debuggerManager);
final List<CModule> modules = new ArrayList<>();
final CConnection connection = provider.getConnection();
if (!PostgreSQLHelpers.hasTable(connection, CTableNames.MODULES_TABLE)) {
return new ArrayList<INaviModule>(modules);
}
final String query = "SELECT id, raw_module_id, " + CTableNames.MODULES_TABLE + ".name, " + " md5, sha1, description, import_time, modification_date, file_base, image_base, stared, " + " initialization_state, debugger_id, " + " (SELECT count(*) FROM " + CTableNames.FUNCTIONS_TABLE + " " + " WHERE id = " + CTableNames.FUNCTIONS_TABLE + ".module_id) " + " AS function_count, " + " (SELECT count(*) FROM " + CTableNames.MODULE_VIEWS_TABLE + " JOIN " + CTableNames.VIEWS_TABLE + " ON view_id = id " + " WHERE type = 'non-native' and module_id = " + CTableNames.MODULES_TABLE + ".id) " + " AS view_count FROM " + CTableNames.MODULES_TABLE + " " + " WHERE raw_module_id IS NOT NULL ORDER BY id";
try (ResultSet resultSet = connection.executeQuery(query, true)) {
while (resultSet.next()) {
final int moduleId = resultSet.getInt("id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String md5 = PostgreSQLHelpers.readString(resultSet, "md5");
final String sha1 = PostgreSQLHelpers.readString(resultSet, "sha1");
final String comment = PostgreSQLHelpers.readString(resultSet, "description");
final Timestamp timestamp = resultSet.getTimestamp("import_time");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
int functionCount = resultSet.getInt("function_count");
final int viewCount = resultSet.getInt("view_count");
final IAddress imageBase = PostgreSQLHelpers.loadAddress(resultSet, "image_base");
final IAddress fileBase = PostgreSQLHelpers.loadAddress(resultSet, "file_base");
final int debuggerId = resultSet.getInt("debugger_id");
final boolean isStared = resultSet.getBoolean("stared");
final int initializationState = resultSet.getInt("initialization_state");
final DebuggerTemplate description = debuggerManager.findDebugger(debuggerId);
final int rawModuleId = resultSet.getInt("raw_module_id");
final INaviRawModule rawModule = PostgreSQLDatabaseFunctions.findRawModule(rawModuleId, rawModules);
if ((functionCount == 0) && (rawModule != null)) {
functionCount = rawModule.getFunctionCount();
}
modules.add(new CModule(moduleId, name, comment, timestamp, modificationDate, md5, sha1, functionCount, viewCount, fileBase, imageBase, description, rawModule, initializationState, isStared, provider));
}
} catch (final SQLException e) {
throw new CouldntLoadDataException(e);
}
return new ArrayList<INaviModule>(modules);
}
use of java.sql.Timestamp in project binnavi by google.
the class PostgreSQLProjectFlowgraphsLoader method loadFlowGraphInformation.
public static ImmutableNaviViewConfiguration loadFlowGraphInformation(final SQLProvider provider, final INaviProject project, final Integer viewId) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "IE02618: provider argument can not be null");
Preconditions.checkNotNull(project, "IE02619: project argument can not be null");
Preconditions.checkNotNull(viewId, "IE02620: viewId argument can not be null");
final CConnection connection = provider.getConnection();
final String query = " SELECT * FROM load_project_flowGraph(?,?) ";
try {
final PreparedStatement statement = connection.getConnection().prepareStatement(query);
statement.setInt(1, project.getConfiguration().getId());
statement.setInt(2, viewId);
final ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
final int databaseViewId = resultSet.getInt("view_id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final ViewType viewType = resultSet.getString("type").equalsIgnoreCase("native") ? ViewType.Native : ViewType.NonNative;
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final boolean isStared = resultSet.getBoolean("stared");
final int nodeCount = resultSet.getInt("bbcount");
final int edgeCount = resultSet.getInt("edgecount");
final ImmutableNaviViewConfiguration viewConfiguration = new ImmutableNaviViewConfiguration(databaseViewId, name, description, viewType, creationDate, modificationDate, isStared, nodeCount, edgeCount);
return viewConfiguration;
}
return null;
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of java.sql.Timestamp in project binnavi by google.
the class PostgreSQLViewsLoader method processQueryResults.
/**
* Processes the results of a view loading query.
*
* @param resultSet Contains the results of the SQL query.
* @param module The module the views were loaded for.
* @param tags Map that contains the tags the views are tagged with.
* @param nodeTagManager Provides the node tags.
* @param provider The connection to the database.
* @param views The loaded views are stored in this list.
* @param viewType View type of the loaded views.
* @param graphType Graph type of the loaded views.
*
* @return The loaded views.
*
* @throws SQLException Thrown if the views could not be loaded.
*/
protected static final List<CView> processQueryResults(final ResultSet resultSet, final INaviModule module, final Map<Integer, Set<CTag>> tags, final ITagManager nodeTagManager, final SQLProvider provider, final List<CView> views, final ViewType viewType, final GraphType graphType) throws SQLException {
final Map<Integer, Set<CTag>> nodeTagMap = getNodeTags(provider.getConnection(), module, nodeTagManager);
try {
while (resultSet.next()) {
final int viewId = resultSet.getInt("view_id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final boolean starState = resultSet.getBoolean("stared");
final int nodeCount = resultSet.getInt("bbcount");
final int edgeCount = resultSet.getInt("edgecount");
final Set<CTag> viewTags = tags.containsKey(viewId) ? tags.get(viewId) : new HashSet<CTag>();
final Set<CTag> nodeTags = nodeTagMap.containsKey(viewId) ? nodeTagMap.get(viewId) : new HashSet<CTag>();
final CModuleViewGenerator generator = new CModuleViewGenerator(provider, module);
views.add(generator.generate(viewId, name, description, viewType, graphType, creationDate, modificationDate, nodeCount, edgeCount, viewTags, nodeTags, starState));
}
return views;
} finally {
resultSet.close();
}
}
use of java.sql.Timestamp in project binnavi by google.
the class PostgreSQLViewsLoader method processQueryResults.
/**
* Processes the results of a view loading query.
*
* @param resultSet Contains the results of the SQL query.
* @param project The project the views were loaded for.
* @param tags Map that contains the tags the views are tagged with.
* @param nodeTagManager Provides the node tags.
* @param provider The connection to the database.
* @param views The loaded views are stored in this list.
* @param viewType View type of the loaded views.
* @param graphType Graph type of the loaded views.
*
* @return The loaded views.
*
* @throws SQLException Thrown if the views could not be loaded.
*/
protected static final List<CView> processQueryResults(final ResultSet resultSet, final INaviProject project, final Map<Integer, Set<CTag>> tags, final ITagManager nodeTagManager, final SQLProvider provider, final List<CView> views, final ViewType viewType, final GraphType graphType) throws SQLException {
final Map<Integer, Set<CTag>> nodeTagMap = getNodeTags(provider.getConnection(), project, nodeTagManager);
try {
while (resultSet.next()) {
final int viewId = resultSet.getInt("view_id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final boolean starState = resultSet.getBoolean("stared");
final int nodeCount = resultSet.getInt("bbcount");
final int edgeCount = resultSet.getInt("edgecount");
final Set<CTag> viewTags = tags.containsKey(viewId) ? tags.get(viewId) : new HashSet<CTag>();
final Set<CTag> nodeTags = nodeTagMap.containsKey(viewId) ? nodeTagMap.get(viewId) : new HashSet<CTag>();
final CProjectViewGenerator generator = new CProjectViewGenerator(provider, project);
views.add(generator.generate(viewId, name, description, viewType, graphType, creationDate, modificationDate, nodeCount, edgeCount, viewTags, nodeTags, starState));
}
return views;
} finally {
resultSet.close();
}
}
Aggregations