628
|
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 Collection.
|
|
29 |
* Contains all helpers related to Collection manipulation.
|
|
30 |
*
|
|
31 |
*/
|
|
32 |
public class SysdefCollectionDAO extends JpaDAO<SysdefCollection> {
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Get a map of collections rows based on the collection name.
|
|
36 |
* @return a map of (collectionName, collection).
|
|
37 |
*/
|
|
38 |
public Map<String, SysdefCollection> getCollections() {
|
|
39 |
Map<String, SysdefCollection> result = new Hashtable<String, SysdefCollection>();
|
|
40 |
for (SysdefCollection collection : this.getEntityManager().createQuery("SELECT c from SysdefCollection c", SysdefCollection.class).getResultList()) {
|
|
41 |
result.put(collection.getCollectionId(), collection);
|
|
42 |
}
|
|
43 |
return result;
|
|
44 |
}
|
|
45 |
|
|
46 |
/**
|
|
47 |
* Get a collection based on its model Id.
|
|
48 |
* @param id
|
|
49 |
* @return the entity representing the collection of null if not found.
|
|
50 |
*/
|
|
51 |
public SysdefCollection getCollectionById(String id) {
|
|
52 |
TypedQuery<SysdefCollection> query = this.getEntityManager().createQuery("SELECT c from SysdefCollection c where c.collectionId=?1", SysdefCollection.class);
|
|
53 |
query.setParameter(1, id);
|
|
54 |
try {
|
|
55 |
return query.getSingleResult();
|
|
56 |
} catch (NoResultException ex) {
|
|
57 |
return null;
|
|
58 |
}
|
|
59 |
}
|
|
60 |
}
|