buildframework/helium/sf/java/metadata/src/com/nokia/helium/metadata/model/metadata/SysdefPackageDAO.java
changeset 628 7c4a911dc066
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
       
     1 /*
       
     2  * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  
       
    15  *
       
    16  */
       
    17 package com.nokia.helium.metadata.model.metadata;
       
    18 
       
    19 import java.util.Hashtable;
       
    20 import java.util.Map;
       
    21 
       
    22 import javax.persistence.NoResultException;
       
    23 import javax.persistence.TypedQuery;
       
    24 
       
    25 import com.nokia.helium.metadata.JpaDAO;
       
    26 
       
    27 /**
       
    28  * Implements DAO for the Package.
       
    29  * Contains all helpers related to Package manipulation.
       
    30  *
       
    31  */
       
    32 public class SysdefPackageDAO extends JpaDAO<SysdefPackage> {
       
    33 
       
    34     /**
       
    35      * Get a map of packages rows based on the package name.
       
    36      * @return a map of (pkgname, Package).
       
    37      */
       
    38     public Map<String, SysdefPackage> getPackages() {
       
    39         Map<String, SysdefPackage> result = new Hashtable<String, SysdefPackage>();
       
    40         for (SysdefPackage pkg : this.getEntityManager().createQuery("SELECT p from SysdefPackage p", SysdefPackage.class).getResultList()) {
       
    41             result.put(pkg.getPackageId(), pkg);
       
    42         }
       
    43         return result;
       
    44     }
       
    45 
       
    46     /**
       
    47      * Get an package based on its model Id.
       
    48      * @param id
       
    49      * @return the entity representing the package of null if not found.
       
    50      */
       
    51     public SysdefPackage getPackageById(String id) {
       
    52         TypedQuery<SysdefPackage> query = this.getEntityManager().createQuery("SELECT p from SysdefPackage p where p.packageId=?1", SysdefPackage.class);
       
    53         query.setParameter(1, id);
       
    54         try {
       
    55             return query.getSingleResult();
       
    56         } catch (NoResultException ex) {
       
    57             return null;
       
    58         }
       
    59     }
       
    60 }