Package easyJ.database.dao.command

Examples of easyJ.database.dao.command.UpdateCommand


        }
        return list.get(0);
    }

    public Object update(Object o, Connection conn) throws EasyJException {
        UpdateCommand ucmd = DAOFactory.getUpdateCommand(o);
        /* 将updateTime,buildTime设为当前时间。所有的表都应该有这两个字段。useState设为Y */
        try {
            BeanUtil.setFieldValue(o, "updateTime", new java.sql.Date(System
                    .currentTimeMillis()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            BeanUtil.setFieldValue(o, "useState", "Y");
        } catch (Exception e) {
            e.printStackTrace();
        }

        // 在返回之前是不是需要对从数据库中读取o,这里简略了,应该是从数据库按照主键再读一次的。
        ucmd.execute(conn);
        return o;
    }
View Full Code Here


    /* 多主键的删除 */
    public void delete(Object primaryKeys[], Class clazz) throws EasyJException {
        Session session = null;
        try {
            session = SessionFactory.openSession();
            UpdateCommand ucmd = session.getUpdateCommand(clazz);
            UpdateItem ui = new UpdateItem("useState", "N");
            ucmd.addUpdateItem(ui);
            for (int i = 0; i < primaryKeys.length; i++) {
                String primaryKey = (String) BeanUtil.getPubStaticFieldValue(
                        clazz, easyJ.common.Const.PRIMARY_KEY);
                Filter filter = DAOFactory.getFilter(primaryKey,
                        SQLOperator.EQUAL, primaryKeys[i]);
                ucmd.setFilter(filter);
                // EasyJLog.debug(ucmd.getExecutableSQL());
                session.update(ucmd);
            }
        } finally {
            if (session != null)
View Full Code Here

        dao.update(ucmd, conn);
    }

    /* 在这里删除只是改变状态,并不是真正的删除,所以调用的是update */
    public void delete(Object o) throws easyJ.common.EasyJException {
        UpdateCommand ucmd = DAOFactory.getUpdateCommand(o.getClass());
        UpdateItem ui = new UpdateItem("useState", "N");
        ucmd.addUpdateItem(ui);
        String primaryKey = (String) BeanUtil.getPubFieldValue(o,
                easyJ.common.Const.PRIMARY_KEY);
        Filter filter = DAOFactory.getFilter(primaryKey, SQLOperator.EQUAL,
                BeanUtil.getFieldValue(o, primaryKey));
        ucmd.setFilter(filter);
        EasyJLog.debug(ucmd.getExecutableSQL());
        dao.update(ucmd, conn);
    }
View Full Code Here

    }

    /* 根据主键批量删除 */
    public void deleteBatch(Class clazz, Object[] primaryKeys)
            throws easyJ.common.EasyJException {
        UpdateCommand ucmd = DAOFactory.getUpdateCommand(clazz);
        UpdateItem ui = new UpdateItem("useState", "N");
        ucmd.addUpdateItem(ui);
        Long[] primaryKeysLong = new Long[primaryKeys.length];
        for (int i = 0; i < primaryKeys.length; i++)
            primaryKeysLong[i] = new Long(primaryKeys[i].toString());
        String primaryKey = (String) BeanUtil.getPubStaticFieldValue(clazz,
                easyJ.common.Const.PRIMARY_KEY);
        Filter filter = DAOFactory.getFilter(primaryKey, SQLOperator.IN,
                primaryKeysLong);
        ucmd.setFilter(filter);
        EasyJLog.debug(ucmd.getExecutableSQL());
        dao.update(ucmd, conn);
    }
View Full Code Here

TOP

Related Classes of easyJ.database.dao.command.UpdateCommand

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.