Example usage for org.apache.ibatis.session ResultHandler ResultHandler

List of usage examples for org.apache.ibatis.session ResultHandler ResultHandler

Introduction

In this page you can find the example usage for org.apache.ibatis.session ResultHandler ResultHandler.

Prototype

ResultHandler

Source Link

Usage

From source file:org.sonar.server.db.migrations.v50.PopulateProjectsUuidColumnsMigration.java

License:Open Source License

@Override
public void execute() {
    progress.start();/*from   w w  w.  j  a  va  2s  .  c  om*/

    final DbSession readSession = db.openSession(false);
    final DbSession writeSession = db.openSession(true);
    try {
        readSession.select("org.sonar.core.persistence.migration.v50.Migration50Mapper.selectRootProjects",
                new ResultHandler() {
                    @Override
                    public void handleResult(ResultContext context) {
                        Component project = (Component) context.getResultObject();
                        Map<Long, String> uuidByComponentId = newHashMap();
                        migrateEnabledComponents(readSession, writeSession, project, uuidByComponentId);
                        migrateDisabledComponents(readSession, writeSession, project, uuidByComponentId);
                    }
                });
        writeSession.commit();
        readSession.commit();

        migrateComponentsWithoutUuid(readSession, writeSession);
        writeSession.commit();

        // log the total number of process rows
        progress.log();
    } finally {
        readSession.close();
        writeSession.close();
        progress.stop();
    }
}

From source file:org.sonar.server.db.migrations.v50.PopulateProjectsUuidColumnsMigrationStep.java

License:Open Source License

@Override
public void execute() {
    ProgressLogger progress = ProgressLogger.create(getClass(), counter);
    progress.start();/*from w  ww  .ja va  2s  .  c o m*/

    final DbSession readSession = db.openSession(false);
    final DbSession writeSession = db.openSession(true);
    try {
        readSession.select("org.sonar.core.persistence.migration.v50.Migration50Mapper.selectRootProjects",
                new ResultHandler() {
                    @Override
                    public void handleResult(ResultContext context) {
                        Component project = (Component) context.getResultObject();
                        List<Component> components = readSession.getMapper(Migration50Mapper.class)
                                .selectComponentChildrenForProjects(project.getId());
                        MigrationContext migrationContext = new MigrationContext(readSession, writeSession,
                                project, components);
                        migrateEnabledComponents(migrationContext);
                        migrateDisabledComponents(migrationContext);
                    }
                });
        writeSession.commit(true);
        readSession.commit(true);

        migrateComponentsWithoutUuid(readSession, writeSession);
        writeSession.commit(true);

        // log the total number of process rows
        progress.log();
    } finally {
        readSession.close();
        writeSession.close();
        progress.stop();
    }
}

From source file:org.sonar.server.permission.ws.SearchProjectPermissionsDataLoader.java

License:Open Source License

private Table<Long, String, Integer> userCountByRootComponentIdAndPermission(DbSession dbSession,
        List<Long> rootComponentIds) {
    final Table<Long, String, Integer> userCountByRootComponentIdAndPermission = TreeBasedTable.create();

    dbClient.permissionDao().usersCountByComponentIdAndPermission(dbSession, rootComponentIds,
            new ResultHandler() {
                @Override/* w w  w.  j  a v a2 s  .  c  o m*/
                public void handleResult(ResultContext context) {
                    CountByProjectAndPermissionDto row = (CountByProjectAndPermissionDto) context
                            .getResultObject();
                    userCountByRootComponentIdAndPermission.put(row.getComponentId(), row.getPermission(),
                            row.getCount());
                }
            });

    return userCountByRootComponentIdAndPermission;
}

From source file:org.sonar.server.permission.ws.SearchProjectPermissionsDataLoader.java

License:Open Source License

private Table<Long, String, Integer> groupCountByRootComponentIdAndPermission(DbSession dbSession,
        List<Long> rootComponentIds) {
    final Table<Long, String, Integer> userCountByRootComponentIdAndPermission = TreeBasedTable.create();

    dbClient.permissionDao().groupsCountByComponentIdAndPermission(dbSession, rootComponentIds,
            new ResultHandler() {
                @Override/*from   w w w.j av  a 2s. c  o  m*/
                public void handleResult(ResultContext context) {
                    CountByProjectAndPermissionDto row = (CountByProjectAndPermissionDto) context
                            .getResultObject();
                    userCountByRootComponentIdAndPermission.put(row.getComponentId(), row.getPermission(),
                            row.getCount());
                }
            });

    return userCountByRootComponentIdAndPermission;
}

From source file:org.sonar.server.permission.ws.SearchTemplatesDataLoader.java

License:Open Source License

private Table<Long, String, Integer> userCountByTemplateIdAndPermission(DbSession dbSession,
        List<Long> templateIds) {
    final Table<Long, String, Integer> userCountByTemplateIdAndPermission = TreeBasedTable.create();

    dbClient.permissionTemplateDao().usersCountByTemplateIdAndPermission(dbSession, templateIds,
            new ResultHandler() {
                @Override//  www .jav  a  2 s . c  o m
                public void handleResult(ResultContext context) {
                    CountByTemplateAndPermissionDto row = (CountByTemplateAndPermissionDto) context
                            .getResultObject();
                    userCountByTemplateIdAndPermission.put(row.getTemplateId(), row.getPermission(),
                            row.getCount());
                }
            });

    return userCountByTemplateIdAndPermission;
}

From source file:org.sonar.server.permission.ws.SearchTemplatesDataLoader.java

License:Open Source License

private Table<Long, String, Integer> groupCountByTemplateIdAndPermission(DbSession dbSession,
        List<Long> templateIds) {
    final Table<Long, String, Integer> userCountByTemplateIdAndPermission = TreeBasedTable.create();

    dbClient.permissionTemplateDao().groupsCountByTemplateIdAndPermission(dbSession, templateIds,
            new ResultHandler() {
                @Override/*from w w w.j  a  v a  2 s.  c o  m*/
                public void handleResult(ResultContext context) {
                    CountByTemplateAndPermissionDto row = (CountByTemplateAndPermissionDto) context
                            .getResultObject();
                    userCountByTemplateIdAndPermission.put(row.getTemplateId(), row.getPermission(),
                            row.getCount());
                }
            });

    return userCountByTemplateIdAndPermission;
}

From source file:org.sonar.server.qualityprofile.db.ActiveRuleDao.java

License:Open Source License

@Override
public void synchronizeAfter(final DbSession session, Date date) {
    session.select("selectAllKeysAfterTimestamp", new Timestamp(date.getTime()), new ResultHandler() {
        @Override//from www .ja  va2  s  .co  m
        public void handleResult(ResultContext context) {
            Map<String, Object> fields = (Map<String, Object>) context.getResultObject();
            // "rule" is a reserved keyword in SQLServer, so "rulefield" is used
            ActiveRuleKey key = ActiveRuleKey.of((String) fields.get("profileKey"),
                    RuleKey.of((String) fields.get("repository"), (String) fields.get("rulefield")));
            session.enqueue(new KeyIndexAction<ActiveRuleKey>(getIndexType(), IndexAction.Method.UPSERT, key));
        }
    });
    session.commit();
}

From source file:org.sonar.server.rule.db.RuleDao.java

License:Open Source License

@Override
public void synchronizeAfter(final DbSession session, Date date) {
    session.select("selectKeysOfRulesUpdatedSince", new Timestamp(date.getTime()), new ResultHandler() {
        @Override//from   w w w .  j a v  a2s. com
        public void handleResult(ResultContext context) {
            Map<String, String> map = (Map) context.getResultObject();
            session.enqueue(new KeyIndexAction<RuleKey>(getIndexType(), IndexAction.Method.UPSERT,
                    RuleKey.of(map.get("repoField"), map.get("ruleField"))));
        }
    });
    session.commit();
}

From source file:org.sonar.server.rule.ws.ListAction.java

License:Open Source License

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    DbSession dbSession = dbClient.openSession(false);
    final ListResponse.Builder listResponseBuilder = ListResponse.newBuilder();
    final ListResponse.Rule.Builder ruleBuilder = ListResponse.Rule.newBuilder();
    try {//from w w w.  j  a v a 2 s.  c  om
        dbClient.ruleDao().selectEnabledAndNonManual(dbSession, new ResultHandler() {
            @Override
            public void handleResult(ResultContext resultContext) {
                RuleDto dto = (RuleDto) resultContext.getResultObject();
                ruleBuilder.clear().setRepository(dto.getRepositoryKey()).setKey(dto.getRuleKey())
                        .setName(nullToEmpty(dto.getName())).setInternalKey(nullToEmpty(dto.getConfigKey()));
                listResponseBuilder.addRules(ruleBuilder.build());
            }
        });
    } finally {
        dbClient.closeSession(dbSession);
    }

    // JSON response is voluntarily not supported. This WS is for internal use.
    wsResponse.stream().setMediaType(MediaTypes.PROTOBUF);
    listResponseBuilder.build().writeTo(wsResponse.stream().output());
}

From source file:org.sonar.server.rule2.RuleDao.java

License:Open Source License

@Override
public Collection<RuleKey> keysOfRowsUpdatedAfter(long timestamp, DbSession session) {
    final List<RuleKey> keys = Lists.newArrayList();
    session.select("selectKeysOfRulesUpdatedSince", new Timestamp(timestamp), new ResultHandler() {
        @Override/*  w  ww .  j ava 2s .  c o  m*/
        public void handleResult(ResultContext context) {
            Map<String, String> map = (Map) context.getResultObject();
            keys.add(RuleKey.of(map.get("repo"), map.get("rule")));
        }
    });
    return keys;
}