public boolean updateComment(final Context ctx, final Comment comment) { final ShardResult commentSR = comment.getMessage() != null ? shardComment() : null; final ShardResult commentTargetSR = comment.getTarget().id != null ? shardCommentTarget() : null; String[] dbs = ShardResult.getDbs(commentSR, commentTargetSR); if (dbs[0] != null || dbs[1] != null) { return sqlExecutor.openConnections( dbs, new ConnectionsHandler<Boolean>() { @Override public Boolean handle(Connection[] conns) { Connection commentConn = conns[0]; Connection commentTargetConn = conns[1]; long isUpdate = 0; if (commentConn != null) { String updateCommentSql = CommentSql.updateComment(commentSR.table, comment); isUpdate = SqlExecutor.executeUpdate(ctx, commentConn, updateCommentSql); } if (commentTargetConn != null && isUpdate != 0) { String updateTargetSqls = CommentSql.updateCommentTarget(commentTargetSR.table, comment); SqlExecutor.executeUpdate(ctx, commentTargetConn, updateTargetSqls); } return true; } }); } else { return false; } }
public static String updateCommentTarget(String table, Comment comment) { return new Sql() .update(table) .setValues( valueIf("target_id", comment.getTarget().id, comment.getTarget().id != null), valueIf("target_type", comment.getTarget().type, comment.getTarget().type > 0)) .where("comment_id=:comment_id", "comment_id", comment.getCommentId()) .toString(); }
public static String saveCommentTarget(String table, Comment comment) { return new Sql() .insertInto(table) .values( value("comment_id", comment.getCommentId()), value("target_id", comment.getTarget().id), value("target_type", comment.getTarget().type)) .toString(); }
public static String saveComment(String table, Comment comment) { return new Sql() .insertInto(table) .values( value("comment_id", comment.getCommentId()), value("can_like", comment.getCanLike()), value("commenter", comment.getCommenterId()), value("created_time", comment.getCreatedTime()), value("destroyed_time", 0), value("device", comment.getDevice()), value("message", comment.getMessage()), value("target_id", comment.getTarget().id), value("target_type", comment.getTarget().type), value( "add_to", comment.getAddTo() != null ? StringHelper.join(comment.getAddTo().getIds(PeopleId.USER), ",") : "")) .toString(); }
public static String updateComment(String table, Comment comment) { return new Sql() .update(table) .setValues( valueIf("target_id", comment.getTarget().id, comment.getTarget().id != null), valueIf("target_type", comment.getTarget().type, comment.getTarget().type > 0), valueIf("destroyed_time", comment.getDestroyedTime(), comment.getDestroyedTime() > 0), valueIf("commenter", comment.getCommenterId(), comment.getCommenterId() > 0), valueIf("message", comment.getMessage(), comment.getMessage() != null), valueIf("can_like", comment.getCanLike(), true)) .where("comment_id=:comment_id AND destroyed_time=0", "comment_id", comment.getCommentId()) .and(" commenter=:commenter", "commenter", comment.getCommenterId()) .toString(); }