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.io.File;
|
|
20 |
import java.util.List;
|
|
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 Unit.
|
|
29 |
* Contains all helpers related to Unit manipulation.
|
|
30 |
*
|
|
31 |
*/
|
|
32 |
public class SysdefUnitDAO extends JpaDAO<SysdefUnit> {
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Get a map of units rows based on the unit name.
|
|
36 |
* @return a map of (unitName, unit).
|
|
37 |
*/
|
|
38 |
public List<SysdefUnit> getUnits() {
|
|
39 |
return this.getEntityManager().createQuery("SELECT c from SysdefUnit c", SysdefUnit.class).getResultList();
|
|
40 |
}
|
|
41 |
|
|
42 |
/**
|
|
43 |
* Get a unit based on its model Id.
|
|
44 |
* @param id
|
|
45 |
* @return the entity representing the unit of null if not found.
|
|
46 |
*/
|
|
47 |
public SysdefUnit getUnitByLocation(File epocroot, File location) {
|
|
48 |
return getUnitByLocation(epocroot.toURI().relativize(location.toURI()).getPath());
|
|
49 |
}
|
|
50 |
|
|
51 |
public SysdefUnit getUnitByLocation(String location) {
|
|
52 |
TypedQuery<SysdefUnit> query = this.getEntityManager().createQuery("SELECT u from SysdefUnit u where u.location=?1", SysdefUnit.class);
|
|
53 |
query.setParameter(1, location);
|
|
54 |
try {
|
|
55 |
return query.getSingleResult();
|
|
56 |
} catch (NoResultException ex) {
|
|
57 |
return null;
|
|
58 |
}
|
|
59 |
}
|
|
60 |
|
|
61 |
}
|