org.kuali.mobility.xsl.dao.XslDaoImpl.java Source code

Java tutorial

Introduction

Here is the source code for org.kuali.mobility.xsl.dao.XslDaoImpl.java

Source

/**
 * Copyright 2011 The Kuali Foundation Licensed under the
 * Educational Community License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may
 * obtain a copy of the License at
 *
 * http://www.osedu.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package org.kuali.mobility.xsl.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.kuali.mobility.xsl.entity.Xsl;
import org.springframework.stereotype.Repository;

@Repository
public class XslDaoImpl implements XslDao {

    @PersistenceContext
    private EntityManager entityManager;

    public void deleteXslById(Long id) {
        Query query = entityManager.createQuery("delete from Xsl x where x.xslId = :id");
        query.setParameter("id", id);
        query.executeUpdate();
    }

    @SuppressWarnings("unchecked")
    public List<Xsl> findAllXsl() {
        Query query = entityManager.createQuery("select x from Xsl x order by x.id");
        return query.getResultList();
    }

    public Xsl findXslById(Long id) {
        Query query = entityManager.createQuery("select x from Xsl x where x.xslId = :id");
        query.setParameter("id", id);
        return (Xsl) query.getSingleResult();
    }

    public Xsl findXslByCode(String code) {
        Query query = entityManager.createQuery("select x from Xsl x where x.code = :code");
        query.setParameter("code", code);
        return (Xsl) query.getSingleResult();
    }

    public void saveXsl(Xsl xsl) {
        if (xsl == null) {
            return;
        }
        if (xsl.getValue() != null) {
            xsl.setValue(xsl.getValue().trim());
        }
        if (xsl.getXslId() == null) {
            entityManager.persist(xsl);
        } else {
            entityManager.merge(xsl);
        }
    }

    public EntityManager getEntityManager() {
        return entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

}