Search in sources :

Example 1 with SqlResultSetRowList

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

the class GetUserProfileHandler method execute.

@Override
public void execute(final GetUserProfile command, ExecutionContext context, final AsyncCallback<UserProfileDTO> callback) {
    final int userId = command.getUserId();
    SqlQuery.select().appendColumn("u.name", "name").appendColumn("u.email", "email").appendColumn("u.organization", "organization").appendColumn("u.jobtitle", "jobtitle").appendColumn("u.locale", "locale").appendColumn("u.emailNotification", "emailNotification").from("userlogin", "u").where("u.userid").equalTo(userId).execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            SqlResultSetRowList list = results.getRows();
            if (list.isEmpty()) {
                callback.onFailure(new IllegalArgumentException("user " + userId + " not found"));
            }
            SqlResultSetRow row = list.get(0);
            UserProfileDTO dto = new UserProfileDTO(userId);
            dto.setName(row.getString("name"));
            dto.setEmail(row.getString("email"));
            dto.setOrganization(row.getString("organization"));
            dto.setJobtitle(row.getString("jobtitle"));
            dto.setLocale(row.getString("locale"));
            dto.setEmailNotification(row.getBoolean("emailNotification"));
            callback.onSuccess(dto);
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) UserProfileDTO(org.activityinfo.shared.dto.UserProfileDTO) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) SqlResultSetRowList(com.bedatadriven.rebar.sql.client.SqlResultSetRowList)

Aggregations

SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlResultSetRowList (com.bedatadriven.rebar.sql.client.SqlResultSetRowList)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 UserProfileDTO (org.activityinfo.shared.dto.UserProfileDTO)1