| 
 | 1 | +package io.izzel.netzach.data.entity;  | 
 | 2 | + | 
 | 3 | +import com.google.common.io.ByteStreams;  | 
 | 4 | + | 
 | 5 | +import java.io.ByteArrayInputStream;  | 
 | 6 | +import java.io.IOException;  | 
 | 7 | +import java.sql.PreparedStatement;  | 
 | 8 | +import java.sql.ResultSet;  | 
 | 9 | +import java.sql.SQLException;  | 
 | 10 | +import java.util.UUID;  | 
 | 11 | + | 
 | 12 | +public class ItemRecord {  | 
 | 13 | + | 
 | 14 | +    public static final String CREATE_TABLE =  | 
 | 15 | +        "CREATE TABLE IF NOT EXISTS %s\n" +  | 
 | 16 | +            "(\n" +  | 
 | 17 | +            "    id          INT PRIMARY KEY AUTO_INCREMENT,\n" +  | 
 | 18 | +            "    shop        VARCHAR(32) NOT NULL,\n" +  | 
 | 19 | +            "    item        MEDIUMBLOB  NOT NULL,\n" +  | 
 | 20 | +            "    stock       INT         NOT NULL,\n" +  | 
 | 21 | +            "    owner       VARCHAR(36) NOT NULL,\n" +  | 
 | 22 | +            "    create_time BIGINT(19)  NOT NULL,\n" +  | 
 | 23 | +            "    stock_time  BIGINT(19)  NOT NULL,\n" +  | 
 | 24 | +            "    expire      BIGINT(19)  NOT NULL,\n" +  | 
 | 25 | +            "    info        TEXT        NOT NULL,\n" +  | 
 | 26 | +            "    INDEX (shop)\n" +  | 
 | 27 | +            ");";  | 
 | 28 | + | 
 | 29 | +    private int id;  | 
 | 30 | +    private String shop;  | 
 | 31 | +    private byte[] item;  | 
 | 32 | +    private int stock;  | 
 | 33 | +    private UUID owner;  | 
 | 34 | +    private long createTime;  | 
 | 35 | +    private long stockTime;  | 
 | 36 | +    private long expire;  | 
 | 37 | +    private String info;  | 
 | 38 | + | 
 | 39 | +    public int id() {  | 
 | 40 | +        return id;  | 
 | 41 | +    }  | 
 | 42 | + | 
 | 43 | +    public void setId(int id) {  | 
 | 44 | +        this.id = id;  | 
 | 45 | +    }  | 
 | 46 | + | 
 | 47 | +    public String shop() {  | 
 | 48 | +        return shop;  | 
 | 49 | +    }  | 
 | 50 | + | 
 | 51 | +    public void setShop(String shop) {  | 
 | 52 | +        this.shop = shop;  | 
 | 53 | +    }  | 
 | 54 | + | 
 | 55 | +    public byte[] item() {  | 
 | 56 | +        return item;  | 
 | 57 | +    }  | 
 | 58 | + | 
 | 59 | +    public void setItem(byte[] item) {  | 
 | 60 | +        this.item = item;  | 
 | 61 | +    }  | 
 | 62 | + | 
 | 63 | +    public int stock() {  | 
 | 64 | +        return stock;  | 
 | 65 | +    }  | 
 | 66 | + | 
 | 67 | +    public void setStock(int stock) {  | 
 | 68 | +        this.stock = stock;  | 
 | 69 | +    }  | 
 | 70 | + | 
 | 71 | +    public UUID owner() {  | 
 | 72 | +        return owner;  | 
 | 73 | +    }  | 
 | 74 | + | 
 | 75 | +    public void setOwner(UUID owner) {  | 
 | 76 | +        this.owner = owner;  | 
 | 77 | +    }  | 
 | 78 | + | 
 | 79 | +    public long createTime() {  | 
 | 80 | +        return createTime;  | 
 | 81 | +    }  | 
 | 82 | + | 
 | 83 | +    public void setCreateTime(long createTime) {  | 
 | 84 | +        this.createTime = createTime;  | 
 | 85 | +    }  | 
 | 86 | + | 
 | 87 | +    public long stockTime() {  | 
 | 88 | +        return stockTime;  | 
 | 89 | +    }  | 
 | 90 | + | 
 | 91 | +    public void setStockTime(long stockTime) {  | 
 | 92 | +        this.stockTime = stockTime;  | 
 | 93 | +    }  | 
 | 94 | + | 
 | 95 | +    public long expire() {  | 
 | 96 | +        return expire;  | 
 | 97 | +    }  | 
 | 98 | + | 
 | 99 | +    public void setExpire(long expire) {  | 
 | 100 | +        this.expire = expire;  | 
 | 101 | +    }  | 
 | 102 | + | 
 | 103 | +    public String info() {  | 
 | 104 | +        return info;  | 
 | 105 | +    }  | 
 | 106 | + | 
 | 107 | +    public void setInfo(String info) {  | 
 | 108 | +        this.info = info;  | 
 | 109 | +    }  | 
 | 110 | + | 
 | 111 | +    public void read(ResultSet resultSet, int i) throws SQLException, IOException {  | 
 | 112 | +        this.id = resultSet.getInt(i++);  | 
 | 113 | +        this.shop = resultSet.getString(i++);  | 
 | 114 | +        this.item = ByteStreams.toByteArray(resultSet.getBlob(i++).getBinaryStream());  | 
 | 115 | +        this.stock = resultSet.getInt(i++);  | 
 | 116 | +        this.owner = UUID.fromString(resultSet.getString(i++));  | 
 | 117 | +        this.createTime = resultSet.getLong(i++);  | 
 | 118 | +        this.stockTime = resultSet.getLong(i++);  | 
 | 119 | +        this.expire = resultSet.getLong(i++);  | 
 | 120 | +        this.info = resultSet.getString(i);  | 
 | 121 | +    }  | 
 | 122 | + | 
 | 123 | +    public void write(PreparedStatement statement, int i) throws SQLException {  | 
 | 124 | +        statement.setInt(i++, this.id);  | 
 | 125 | +        statement.setString(i++, this.shop);  | 
 | 126 | +        statement.setBlob(i++, new ByteArrayInputStream(this.item));  | 
 | 127 | +        statement.setInt(i++, this.stock);  | 
 | 128 | +        statement.setString(i++, this.owner.toString());  | 
 | 129 | +        statement.setLong(i++, this.createTime);  | 
 | 130 | +        statement.setLong(i++, this.stockTime);  | 
 | 131 | +        statement.setLong(i++, this.expire);  | 
 | 132 | +        statement.setString(i, this.info);  | 
 | 133 | +    }  | 
 | 134 | +}  | 
0 commit comments