package kfs.kfsWfl;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;
import kfs.kfsDbi.*;

/**
 *
 * @author pavedrim
 */
public class wflTask extends kfsDbObject {

    private final kfsIntAutoInc id;
    private final kfsInt idTemplate;
    private final kfsString name;
    private final kfsString ownerLogin;
    private final kfsInt firstNodeId;
    private final kfsDate lastChange;
    private final kfsDate archivedDate;

    public wflTask(final kfsDbServerType serverType) {
        super(serverType, "T_WFL_TASK");
        int pos = 0;
        id = new kfsIntAutoInc("ID", "Id", pos++);
        idTemplate = new kfsInt("ID_TEMPLATE", "Template ID", kfsIntAutoInc.idMaxLen, pos++, true);
        name = new kfsString("NAME", "Name", 48, pos++);
        ownerLogin = new kfsString("OWNER_LOGIN", "Owner Login", wflUser.loginLen, pos++);
        firstNodeId = new kfsInt("FIRST_NODE_ID", "First Node Id", kfsIntAutoInc.idMaxLen, pos++, true);
        lastChange = new kfsDate("LAST_CHNG", "Last Change", pos++);
        archivedDate = new kfsDate("ARCHIVED_DATE", "Archived Date", pos++);

        super.setColumns(new kfsDbiColumn[]{id, idTemplate, ownerLogin, name, firstNodeId, lastChange, archivedDate});
        super.setUpdateColumns(new kfsDbiColumn[]{ownerLogin, name, firstNodeId, lastChange, archivedDate});
        super.setIdsColumns(new kfsDbiColumn[]{id});
    }

    public kfsRowData create(int templId, String ownerLogin) {
        kfsRowData ret = new kfsRowData(this);
        this.idTemplate.setInt(templId, ret);
        this.ownerLogin.setString(ownerLogin, ret);
        return ret;
    }

    public kfsRowData create() {
        return new kfsRowData(this);
    }

    public int getId(kfsRowData r) {
        return id.getInt(r);
    }

    public Integer getTemplateId(kfsRowData r) {
        return idTemplate.getInt(r);
    }

    public String getName(kfsRowData r) {
        return name.getString(r);
    }

    public void setName(kfsRowData r, String newName) {
        name.setString(newName, r);
    }

    public int getFirstNodeId(kfsRowData r) {
        return firstNodeId.getInt(r);
    }

    public void setFirstNodeId(kfsRowData r, int fist) {
        firstNodeId.setInt(fist, r);
    }

    public Date getLastChange(kfsRowData r) {
        return lastChange.getDate(r);
    }

    public void setLastChange(kfsRowData r, Date lch) {
        lastChange.setDate(lch, r);
    }

    public Date getArchivedDate(kfsRowData r) {
        return archivedDate.getDate(r);
    }

    public void setArchivedDate(kfsRowData r, Date lch) {
        archivedDate.setDate(lch, r);
    }

    public String sqlGetTaskById() {
        return getSelect(getName(), getColumns(), new kfsDbiColumn[]{id});
    }

    public void psGetTaskById(PreparedStatement ps, int taskId) throws SQLException {
        ps.setInt(1, taskId);
    }
    public String sqlGetTaskByName() {
        return getSelect(getName(), getColumns(), new kfsDbiColumn[]{name});
    }

    public void psGetTaskByName(PreparedStatement ps, String taskName) throws SQLException {
        ps.setString(1, taskName);
    }

    public String getOwnerLogin(kfsRowData r) {
        return this.ownerLogin.getString(r);
    }

    public void setOwnerLogin(kfsRowData r, String ownerLogin) {
        this.ownerLogin.setString(ownerLogin, r);
    }

    @Override
    public pojo getPojo(kfsRowData row) {
        return new pojo(row);
    }

    
    public class pojo extends kfsPojoObj<wflTask> {

        public pojo(kfsRowData rd) {
            super(wflTask.this, rd);
        }

        public int getId() {
            return id.getInt(rd);
        }

        public Integer getTemplateId() {
            return idTemplate.getInt(rd);
        }

        public String getName() {
            return name.getString(rd);
        }

        public void setName(String newName) {
            name.setString(newName, rd);
        }

        public int getFirstNodeId() {
            return firstNodeId.getInt(rd);
        }

        public void setFirstNodeId(int fist) {
            firstNodeId.setInt(fist, rd);
        }

        public Date getLastChange() {
            return lastChange.getDate(rd);
        }

        public void setLastChange( Date lch) {
            lastChange.setDate(lch, rd);
        }

        public Date getArchivedDate() {
            return archivedDate.getDate(rd);
        }

        public void setArchivedDate(Date lch) {
            archivedDate.setDate(lch, rd);
        }


        public String getOwnerLogin() {
            return ownerLogin.getString(rd);
        }

        public void setOwnerLogin(String owner) {
            ownerLogin.setString(owner, rd);
        }
    }
}

@@ -3150,32 +3150,303 @@
 skName);%0A    %7D%0A%0A
+    public String sqlGetAllTemplates() %7B%0A        return getSelect(getName(), getColumns(), new kfsDbiColumn%5B%5D%7BidTemplate%7D);%0A    %7D%0A    %0A    public void psGetAllTemplates(PreparedStatement ps) throws SQLException %7B%0A        ps.setNull(1, java.sql.Types.INTEGER);%0A    %7D%0A    %0A
     public Strin

add support for "get all templates"