All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.redkalex.source.mysql.MyReqUpdate Maven / Gradle / Ivy

There is a newer version: 2.7.7
Show newest version
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.redkalex.source.mysql;

import static org.redkalex.source.mysql.Mysqls.COM_QUERY;

import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import org.redkale.convert.json.JsonConvert;
import org.redkale.net.client.ClientConnection;
import org.redkale.util.*;

/** @author zhangjx */
public class MyReqUpdate extends MyClientRequest {

    protected int fetchSize;

    protected Attribute[] attrs;

    protected String sql;

    protected Object[][] parameters;

    public  MyReqUpdate prepare(String sql) {
        prepare(sql, 0, null);
        return this;
    }

    public  MyReqUpdate prepare(
            String sql, int fetchSize, final Attribute[] attrs, final Object[]... parameters) {
        super.prepare();
        this.sql = sql;
        this.fetchSize = fetchSize;
        this.attrs = attrs;
        this.parameters = parameters;
        return this;
    }

    @Override
    public int getType() {
        return REQ_TYPE_UPDATE;
    }

    @Override
    public String toString() {
        return "MyReqUpdate_" + Objects.hashCode(this) + "{sql=" + sql + ", parameters="
                + JsonConvert.root().convertTo(parameters) + "}";
    }

    @Override
    public void writeTo(ClientConnection conn, ByteArray array) {
        byte[] sqlbytes = sql.getBytes(StandardCharsets.UTF_8);
        Mysqls.writeUB3(array, 1 + sqlbytes.length);
        array.put(packetIndex);
        array.put(COM_QUERY);
        array.put(sqlbytes);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy