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

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

package ru.curs.celesta.syscursors;

import java.lang.reflect.Field;
import java.sql.ResultSet;
import java.sql.SQLException;
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 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;

public final class PermissionsCursor extends Cursor implements Iterable {
    public static final String TABLE_NAME = "permissions";

    private String roleid;

    private String grainid;

    private String tablename;

    private Boolean r;

    private Boolean i;

    private Boolean m;

    private Boolean d;

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

    public PermissionsCursor(CallContext context, Set fields) {
        super(context, fields);
    }

    public String getRoleid() {
        return this.roleid;
    }

    public void setRoleid(String roleid) {
        this.roleid = roleid;
    }

    public String getGrainid() {
        return this.grainid;
    }

    public void setGrainid(String grainid) {
        this.grainid = grainid;
    }

    public String getTablename() {
        return this.tablename;
    }

    public void setTablename(String tablename) {
        this.tablename = tablename;
    }

    public Boolean getR() {
        return this.r;
    }

    public void setR(Boolean r) {
        this.r = r;
    }

    public Boolean getI() {
        return this.i;
    }

    public void setI(Boolean i) {
        this.i = i;
    }

    public Boolean getM() {
        return this.m;
    }

    public void setM(Boolean m) {
        this.m = m;
    }

    public Boolean getD() {
        return this.d;
    }

    public void setD(Boolean d) {
        this.d = d;
    }

    @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[3];
        result[0] = this.roleid;
        result[1] = this.grainid;
        result[2] = this.tablename;
        return result;
    }

    @Override
    protected void _parseResultInternal(ResultSet rs) throws SQLException {
        if (this.inRec("roleid")) {
            this.roleid = rs.getString("roleid");
            if (rs.wasNull()) {
                this.roleid = null;
            }
        }
        if (this.inRec("grainid")) {
            this.grainid = rs.getString("grainid");
            if (rs.wasNull()) {
                this.grainid = null;
            }
        }
        if (this.inRec("tablename")) {
            this.tablename = rs.getString("tablename");
            if (rs.wasNull()) {
                this.tablename = null;
            }
        }
        if (this.inRec("r")) {
            this.r = rs.getBoolean("r");
            if (rs.wasNull()) {
                this.r = null;
            }
        }
        if (this.inRec("i")) {
            this.i = rs.getBoolean("i");
            if (rs.wasNull()) {
                this.i = null;
            }
        }
        if (this.inRec("m")) {
            this.m = rs.getBoolean("m");
            if (rs.wasNull()) {
                this.m = null;
            }
        }
        if (this.inRec("d")) {
            this.d = rs.getBoolean("d");
            if (rs.wasNull()) {
                this.d = null;
            }
        }
        this.setRecversion(rs.getInt("recversion"));
    }

    @Override
    public void _clearBuffer(boolean withKeys) {
        if (withKeys) {
            this.roleid = null;
            this.grainid = null;
            this.tablename = null;
        }
        this.r = null;
        this.i = null;
        this.m = null;
        this.d = null;
    }

    @Override
    public Object[] _currentValues() {
        Object[] result = new Object[7];
        result[0] = this.roleid;
        result[1] = this.grainid;
        result[2] = this.tablename;
        result[3] = this.r;
        result[4] = this.i;
        result[5] = this.m;
        result[6] = this.d;
        return result;
    }

    @Override
    protected void _setAutoIncrement(int val) {
    }

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

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

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

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

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

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

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

    @Override
    public void copyFieldsFrom(BasicCursor c) {
        PermissionsCursor from = (PermissionsCursor)c;
        this.roleid = from.roleid;
        this.grainid = from.grainid;
        this.tablename = from.tablename;
        this.r = from.r;
        this.i = from.i;
        this.m = from.m;
        this.d = from.d;
        this.setRecversion(from.getRecversion());
    }

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

    @Override
    protected String _grainName() {
        return "celesta";
    }

    @Override
    protected String _objectName() {
        return "permissions";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy