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