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

ru.curs.celesta.syscursors.TablesCursor 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 TablesCursor extends Cursor implements Iterable {
    public static final String TABLE_NAME = "tables";

    private String grainid;

    private String tablename;

    private String tabletype;

    private Boolean orphaned;

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

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

    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 String getTabletype() {
        return this.tabletype;
    }

    public void setTabletype(String tabletype) {
        this.tabletype = tabletype;
    }

    public Boolean getOrphaned() {
        return this.orphaned;
    }

    public void setOrphaned(Boolean orphaned) {
        this.orphaned = orphaned;
    }

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

    @Override
    protected void _parseResultInternal(ResultSet rs) throws SQLException {
        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("tabletype")) {
            this.tabletype = rs.getString("tabletype");
            if (rs.wasNull()) {
                this.tabletype = null;
            }
        }
        if (this.inRec("orphaned")) {
            this.orphaned = rs.getBoolean("orphaned");
            if (rs.wasNull()) {
                this.orphaned = null;
            }
        }
    }

    @Override
    public void _clearBuffer(boolean withKeys) {
        if (withKeys) {
            this.grainid = null;
            this.tablename = null;
        }
        this.tabletype = null;
        this.orphaned = null;
    }

    @Override
    public Object[] _currentValues() {
        Object[] result = new Object[4];
        result[0] = this.grainid;
        result[1] = this.tablename;
        result[2] = this.tabletype;
        result[3] = this.orphaned;
        return result;
    }

    @Override
    protected void _setAutoIncrement(int val) {
    }

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

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

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

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

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

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

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

    @Override
    public void copyFieldsFrom(BasicCursor c) {
        TablesCursor from = (TablesCursor)c;
        this.grainid = from.grainid;
        this.tablename = from.tablename;
        this.tabletype = from.tabletype;
        this.orphaned = from.orphaned;
    }

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

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

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy