Package de.danet.an.workflow.util

Source Code of de.danet.an.workflow.util.HibernateUtil

/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* $Id: $
*
* $Log: $
*/
package de.danet.an.workflow.util;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;

import de.danet.an.workflow.api.query.AndOperation;
import de.danet.an.workflow.api.query.ContextVariableEquality;
import de.danet.an.workflow.api.query.NotOperation;
import de.danet.an.workflow.api.query.OrOperation;
import de.danet.an.workflow.api.query.PropertyEquality;
import de.danet.an.workflow.api.query.FilterCriterion;
import de.danet.an.workflow.ejbs.core.ProcessDataStore;

/**
* This class provides utility methods for using Hibernate.
*
* @author mnl
*
*/
public class HibernateUtil {

    public static Criterion convertFilterCriterion
        (FilterCriterion criterion) {
        if (criterion instanceof PropertyEquality) {
            if (((PropertyEquality) criterion).getProperty().equals("key")) {
                return Expression.idEq
                    (new Long
                     ((String)((PropertyEquality) criterion).getValue()));
            }
            if (((PropertyEquality) criterion).getValue() == null) {
                return Expression.isNull
                    (((PropertyEquality)criterion).getProperty());
            }
            return Expression.eq
                (((PropertyEquality) criterion).getProperty(),
                 ((PropertyEquality) criterion).getValue());
        }
        if (criterion instanceof NotOperation) {
            return Expression.not
                (convertFilterCriterion
                 (((NotOperation) criterion).getOperand()));
        }
        if (criterion instanceof AndOperation) {
            return Expression.and
                (convertFilterCriterion
                 (((AndOperation) criterion).getOperand1()),
                 convertFilterCriterion
                 (((AndOperation) criterion).getOperand2()));
        }
        if (criterion instanceof OrOperation) {
            return Expression.or
                (convertFilterCriterion
                 (((OrOperation) criterion).getOperand1()),
                 convertFilterCriterion
                 (((OrOperation) criterion).getOperand2()));
        }
        if (criterion instanceof ContextVariableEquality) {
            DetachedCriteria sub
                = DetachedCriteria.forClass(ProcessDataStore.DAO.class);
            sub.setProjection(Projections.property("mapId"));
            Criterion valueCond = null;
            if (((ContextVariableEquality) criterion).getValue() == null) {
                valueCond = Expression.and
                    (Expression.isNull("svalue"), Expression.isNull("bvalue"));
            } else {
                valueCond = Expression.eq
                    ("svalue", ((ContextVariableEquality)criterion).getValue());
            }
            sub.add
                (Expression.and
                    (Expression.eq("item", ((ContextVariableEquality)criterion)
                                   .getContextVariable()),
                     valueCond));
            return Property.forName("dbId").in(sub);
        }
        return null;
    }
   
}
TOP

Related Classes of de.danet.an.workflow.util.HibernateUtil

TOP
Copyright © 2018 www.massapi.com. 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.