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

ru.curs.celesta.syscursors.GrainsCursor Maven / Gradle / Ivy

package ru.curs.celesta.syscursors;

import java.lang.reflect.Field;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import javax.annotation.Generated;
import ru.curs.celesta.CallContext;
import ru.curs.celesta.ICelesta;
import ru.curs.celesta.dbutils.BasicCursor;
import ru.curs.celesta.dbutils.Cursor;
import ru.curs.celesta.dbutils.CursorIterator;
import ru.curs.celesta.event.TriggerType;
import ru.curs.celesta.score.ColumnMeta;
import ru.curs.celesta.score.Table;

@Generated(
        value = "ru.curs.celesta.plugin.maven.CursorGenerator",
        date = "2020-10-05T21:02:19.403"
)
public final class GrainsCursor extends Cursor implements Iterable, ISchemaCursor {
    private static final String GRAIN_NAME = "celesta";

    private static final String OBJECT_NAME = "grains";

    public static final String TABLE_NAME = OBJECT_NAME;

    public final GrainsCursor.Columns COLUMNS;

    private String id;

    private String version;

    private Integer length;

    private String checksum;

    private Integer state;

    private Date lastmodified;

    private String message;

    {
        this.COLUMNS = new GrainsCursor.Columns(callContext().getCelesta());
    }

    public GrainsCursor(CallContext context) {
        super(context);
    }

    public GrainsCursor(CallContext context, ColumnMeta... columns) {
        super(context, columns);
    }

    @Deprecated
    public GrainsCursor(CallContext context, Set fields) {
        super(context, fields);
    }

    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getVersion() {
        return this.version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public Integer getLength() {
        return this.length;
    }

    public void setLength(Integer length) {
        this.length = length;
    }

    public String getChecksum() {
        return this.checksum;
    }

    public void setChecksum(String checksum) {
        this.checksum = checksum;
    }

    public Integer getState() {
        return this.state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Date getLastmodified() {
        return this.lastmodified;
    }

    public void setLastmodified(Date lastmodified) {
        this.lastmodified = lastmodified;
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    protected Object _getFieldValue(String name) {
        try {
            Field f = getClass().getDeclaredField(name);
            f.setAccessible(true);
            return f.get(this);
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void _setFieldValue(String name, Object value) {
        try {
            Field f = getClass().getDeclaredField(name);
            f.setAccessible(true);
            f.set(this, value);
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected Object[] _currentKeyValues() {
        Object[] result = new Object[1];
        result[0] = this.id;
        return result;
    }

    @Override
    protected void _parseResultInternal(ResultSet rs) throws SQLException {
        if (this.inRec("id")) {
            this.id = rs.getString("id");
            if (rs.wasNull()) {
                this.id = null;
            }
        }
        if (this.inRec("version")) {
            this.version = rs.getString("version");
            if (rs.wasNull()) {
                this.version = null;
            }
        }
        if (this.inRec("length")) {
            this.length = rs.getInt("length");
            if (rs.wasNull()) {
                this.length = null;
            }
        }
        if (this.inRec("checksum")) {
            this.checksum = rs.getString("checksum");
            if (rs.wasNull()) {
                this.checksum = null;
            }
        }
        if (this.inRec("state")) {
            this.state = rs.getInt("state");
            if (rs.wasNull()) {
                this.state = null;
            }
        }
        if (this.inRec("lastmodified")) {
            this.lastmodified = rs.getTimestamp("lastmodified");
            if (rs.wasNull()) {
                this.lastmodified = null;
            }
        }
        if (this.inRec("message")) {
            this.message = rs.getString("message");
            if (rs.wasNull()) {
                this.message = null;
            }
        }
    }

    @Override
    public void _clearBuffer(boolean withKeys) {
        if (withKeys) {
            this.id = null;
        }
        this.version = null;
        this.length = null;
        this.checksum = null;
        this.state = null;
        this.lastmodified = null;
        this.message = null;
    }

    @Override
    public Object[] _currentValues() {
        Object[] result = new Object[7];
        result[0] = this.id;
        result[1] = this.version;
        result[2] = this.length;
        result[3] = this.checksum;
        result[4] = this.state;
        result[5] = this.lastmodified;
        result[6] = this.message;
        return result;
    }

    @Override
    protected void _setAutoIncrement(int val) {
    }

    public static void onPreDelete(ICelesta celesta,
            Consumer cursorConsumer) {
        celesta.getTriggerDispatcher().registerTrigger(TriggerType.PRE_DELETE, GrainsCursor.class, cursorConsumer);
    }

    public static void onPostDelete(ICelesta celesta,
            Consumer cursorConsumer) {
        celesta.getTriggerDispatcher().registerTrigger(TriggerType.POST_DELETE, GrainsCursor.class, cursorConsumer);
    }

    public static void onPreInsert(ICelesta celesta,
            Consumer cursorConsumer) {
        celesta.getTriggerDispatcher().registerTrigger(TriggerType.PRE_INSERT, GrainsCursor.class, cursorConsumer);
    }

    public static void onPostInsert(ICelesta celesta,
            Consumer cursorConsumer) {
        celesta.getTriggerDispatcher().registerTrigger(TriggerType.POST_INSERT, GrainsCursor.class, cursorConsumer);
    }

    public static void onPreUpdate(ICelesta celesta,
            Consumer cursorConsumer) {
        celesta.getTriggerDispatcher().registerTrigger(TriggerType.PRE_UPDATE, GrainsCursor.class, cursorConsumer);
    }

    public static void onPostUpdate(ICelesta celesta,
            Consumer cursorConsumer) {
        celesta.getTriggerDispatcher().registerTrigger(TriggerType.POST_UPDATE, GrainsCursor.class, cursorConsumer);
    }

    @Override
    public GrainsCursor _getBufferCopy(CallContext context, List fields) {
        final GrainsCursor result;
        if (Objects.isNull(fields)) {
            result = new GrainsCursor(context);
        }
        else {
            result = new GrainsCursor(context, new LinkedHashSet<>(fields));
        }
        result.copyFieldsFrom(this);
        return result;
    }

    @Override
    public void copyFieldsFrom(BasicCursor c) {
        GrainsCursor from = (GrainsCursor)c;
        this.id = from.id;
        this.version = from.version;
        this.length = from.length;
        this.checksum = from.checksum;
        this.state = from.state;
        this.lastmodified = from.lastmodified;
        this.message = from.message;
    }

    @Override
    public Iterator iterator() {
        return new CursorIterator(this);
    }

    @Override
    protected String _grainName() {
        return GRAIN_NAME;
    }

    @Override
    protected String _objectName() {
        return OBJECT_NAME;
    }

    @SuppressWarnings("unchecked")
    @Generated(
            value = "ru.curs.celesta.plugin.maven.CursorGenerator",
            date = "2020-10-05T21:02:19.405"
    )
    public static final class Columns {
        private final Table element;

        public Columns(ICelesta celesta) {
            this.element = celesta.getScore().getGrains().get(GRAIN_NAME).getElements(Table.class).get(OBJECT_NAME);
        }

        public ColumnMeta id() {
            return (ColumnMeta) this.element.getColumns().get("id");
        }

        public ColumnMeta version() {
            return (ColumnMeta) this.element.getColumns().get("version");
        }

        public ColumnMeta length() {
            return (ColumnMeta) this.element.getColumns().get("length");
        }

        public ColumnMeta checksum() {
            return (ColumnMeta) this.element.getColumns().get("checksum");
        }

        public ColumnMeta state() {
            return (ColumnMeta) this.element.getColumns().get("state");
        }

        public ColumnMeta lastmodified() {
            return (ColumnMeta) this.element.getColumns().get("lastmodified");
        }

        public ColumnMeta message() {
            return (ColumnMeta) this.element.getColumns().get("message");
        }
    }

    @Generated(
            value = "ru.curs.celesta.plugin.maven.CursorGenerator",
            date = "2020-10-05T21:02:19.406"
    )
    public static final class State {
        public static final Integer ready = 0;

        public static final Integer upgrading = 1;

        public static final Integer error = 2;

        public static final Integer recover = 3;

        public static final Integer lock = 4;

        private State() {
            throw new AssertionError();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy