Java Code Examples for com.jfinal.plugin.activerecord.Db#save()

The following examples show how to use com.jfinal.plugin.activerecord.Db#save() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean updateUserAmount(Object userId, BigDecimal oldAmount, BigDecimal updateAmount) {
    BigDecimal value = JbootDb.queryBigDecimal("select amount from user_amount where user_id = ?", userId);
    if (value == null) {
        Record record = new Record();
        record.set("user_id", userId);
        record.set("amount", updateAmount);
        record.set("modified", new Date());
        record.set("created", new Date());
        return Db.save("user_amount", record);
    } else {
        return Db.update("update user_amount set amount = ? , modified = ? where user_id = ? and amount = ?",
                value.add(updateAmount), new Date(), userId, oldAmount) > 0;
    }
}
 
Example 2
Source File: RoleServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
@CacheEvict(name = "user_permission", key = "*")
public boolean addPermission(long roleId, long permissionId) {
    Record rolePermission = new Record().set("role_id", roleId).set("permission_id", permissionId);
    return Db.save("role_permission_mapping", rolePermission);
}