Search in sources :

Example 21 with SqlResultSet

use of com.bedatadriven.rebar.sql.client.SqlResultSet in project activityinfo by bedatadriven.

the class GetSiteAttachmentsHandler method execute.

@Override
public void execute(GetSiteAttachments command, ExecutionContext context, final AsyncCallback<SiteAttachmentResult> callback) {
    dtos = new ArrayList<SiteAttachmentDTO>();
    SqlQuery.selectAll().from(Tables.SITE_ATTACHMENT, "s").where("s.siteid").equalTo(command.getSiteId()).execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            for (SqlResultSetRow row : results.getRows()) {
                SiteAttachmentDTO dto = new SiteAttachmentDTO();
                dto.setSiteId(row.getInt("siteid"));
                dto.setBlobId(row.getString("blobid"));
                dto.setFileName(row.getString("filename"));
                dto.setUploadedBy(row.getInt("uploadedby"));
                dto.setBlobSize(row.getInt("blobsize"));
                dto.setContentType(row.getString("contenttype"));
                dtos.add(dto);
            }
            callback.onSuccess(new SiteAttachmentResult(dtos));
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SiteAttachmentDTO(org.activityinfo.legacy.shared.model.SiteAttachmentDTO) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) SiteAttachmentResult(org.activityinfo.legacy.shared.command.result.SiteAttachmentResult)

Example 22 with SqlResultSet

use of com.bedatadriven.rebar.sql.client.SqlResultSet in project activityinfo by bedatadriven.

the class UpdateMonthlyReportsAsync method queryPeriodMap.

private Promise<Map<Month, Integer>> queryPeriodMap(UpdateMonthlyReports command, ExecutionContext context) {
    final Promise<Map<Month, Integer>> promise = new Promise<>();
    SqlQuery.select("reportingPeriodId", "Date2").from(Tables.REPORTING_PERIOD, "rp").where("siteId").equalTo(command.getSiteId()).execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            Map<Month, Integer> periodMap = Maps.newHashMap();
            for (SqlResultSetRow row : results.getRows()) {
                Date endDate = row.getDate("Date2");
                Month month = Month.of(endDate);
                periodMap.put(month, row.getInt("reportingPeriodId"));
            }
            promise.resolve(periodMap);
        }
    });
    return promise;
}
Also used : Promise(org.activityinfo.promise.Promise) Month(org.activityinfo.model.type.time.Month) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) Map(java.util.Map) Date(java.util.Date)

Example 23 with SqlResultSet

use of com.bedatadriven.rebar.sql.client.SqlResultSet in project activityinfo by bedatadriven.

the class UpdateMonthlyReportsAsync method executeUpdate.

private Promise<Void> executeUpdate(SqlTransaction tx, SqlUpdate update) {
    final Promise<Void> promise = new Promise<>();
    update.execute(tx, new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            promise.resolve(null);
        }
    });
    return promise;
}
Also used : Promise(org.activityinfo.promise.Promise) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction)

Example 24 with SqlResultSet

use of com.bedatadriven.rebar.sql.client.SqlResultSet in project activityinfo by bedatadriven.

the class HibernateExecutor method execute.

@Override
public SqlResultSet execute(final String statement, final Object[] params) throws Exception {
    final List<SqlResultSet> result = Lists.newArrayList();
    entityManager.getSession().doWork(new Work() {

        @Override
        public void execute(Connection connection) throws SQLException {
            try {
                result.add(doExecute(connection, statement, params));
            } catch (Throwable e) {
                LOGGER.log(Level.SEVERE, "Exception thrown while executing query: " + statement, e);
                throw new SQLException(e);
            }
        }
    });
    if (result.size() != 1) {
        throw new AssertionError();
    }
    return result.get(0);
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SQLException(java.sql.SQLException) Work(org.hibernate.jdbc.Work) Connection(java.sql.Connection)

Example 25 with SqlResultSet

use of com.bedatadriven.rebar.sql.client.SqlResultSet in project activityinfo by bedatadriven.

the class GetReportModelHandler method loadMetadataAndCallback.

private void loadMetadataAndCallback(final GetReportModel cmd, final ExecutionContext context, final ReportDTO reportDTO, final AsyncCallback<ReportDTO> callback) {
    final int userId = context.getUser().getId();
    SqlQuery mySubscriptions = SqlQuery.selectAll().from("reportsubscription").where("userId").equalTo(userId);
    SqlQuery myDatabases = SqlQuery.selectSingle("d.databaseid").from("userdatabase", "d").leftJoin(SqlQuery.selectAll().from(Tables.USER_PERMISSION, "UserPermission").where("UserPermission.UserId").equalTo(userId), "p").on("p.DatabaseId = d.DatabaseId").where("d.ownerUserId").equalTo(userId).or("p.AllowView").equalTo(1);
    SqlQuery.select().appendColumn("r.reportTemplateId", "reportId").appendColumn("r.title", "title").appendColumn("r.ownerUserId", "ownerUserId").appendColumn("o.name", "ownerName").appendColumn("s.dashboard", "dashboard").appendColumn("s.emaildelivery", "emaildelivery").appendColumn("s.emailday", "emailday").appendColumn(SqlQuery.selectSingle("max(defaultDashboard)").from("reportvisibility", "v").where("v.databaseId").in(myDatabases).whereTrue("v.reportid = r.reportTemplateId"), "defaultDashboard").from("reporttemplate", "r").leftJoin("userlogin o").on("o.userid = r.ownerUserId").leftJoin(mySubscriptions, "s").on("r.reportTemplateId = s.reportId").where("r.ownerUserId").equalTo(userId).where("r.reportTemplateId").equalTo(cmd.getReportId()).execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(final SqlTransaction tx, final SqlResultSet results) {
            List<ReportMetadataDTO> dtos = Lists.newArrayList();
            for (SqlResultSetRow row : results.getRows()) {
                ReportMetadataDTO dto = new ReportMetadataDTO();
                dto.setId(row.getInt("reportId"));
                dto.setAmOwner(row.getInt("ownerUserId") == userId);
                dto.setOwnerName(row.getString("ownerName"));
                dto.setTitle(row.getString("title"));
                dto.setEditAllowed(dto.getAmOwner());
                if (!row.isNull("emaildelivery")) {
                    dto.setEmailDelivery(EmailDelivery.valueOf(row.getString("emaildelivery")));
                }
                if (row.isNull("emailday")) {
                    dto.setDay(1);
                } else {
                    dto.setDay(row.getInt("emailday"));
                }
                if (row.isNull("dashboard")) {
                    // inherited from database-wide visibility
                    dto.setDashboard(!row.isNull("defaultDashboard") && row.getBoolean("defaultDashboard"));
                } else {
                    dto.setDashboard(row.getBoolean("dashboard"));
                }
                dtos.add(dto);
            }
            if (dtos.size() == 0) {
                ReportMetadataDTO dummy = new ReportMetadataDTO();
                dummy.setId(cmd.getReportId());
                dtos.add(dummy);
            }
            // there should be only one result
            reportDTO.setReportMetadataDTO(dtos.get(0));
            // exit handler with both the report and metadata objects
            // filled
            memcache(cmd, reportDTO);
            callback.onSuccess(reportDTO);
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) List(java.util.List) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) ReportMetadataDTO(org.activityinfo.legacy.shared.model.ReportMetadataDTO)

Aggregations

SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)25 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)23 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)23 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)19 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)13 Promise (org.activityinfo.promise.Promise)10 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Date (java.util.Date)3 Map (java.util.Map)3 Function (com.google.common.base.Function)2 HashMap (java.util.HashMap)2 Nullable (javax.annotation.Nullable)2 Filter (org.activityinfo.legacy.shared.command.Filter)2 LocationResult (org.activityinfo.legacy.shared.command.result.LocationResult)2 AdminEntityDTO (org.activityinfo.legacy.shared.model.AdminEntityDTO)2 LocationDTO (org.activityinfo.legacy.shared.model.LocationDTO)2 EntityCategory (org.activityinfo.legacy.shared.reports.content.EntityCategory)2 AdminDimension (org.activityinfo.legacy.shared.reports.model.AdminDimension)2 AttributeGroupDimension (org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)2