buildframework/helium/sf/java/metadata/src/com/nokia/helium/metadata/model/metadata/LogFileDAO.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.io.File;
       
    20 import java.util.List;
       
    21 
       
    22 import javax.persistence.NoResultException;
       
    23 
       
    24 import com.nokia.helium.metadata.JpaDAO;
       
    25 
       
    26 /**
       
    27  * Implements DAO for the LogFile.
       
    28  * Contains all helpers related to LogFile manipulation.
       
    29  *
       
    30  */
       
    31 public class LogFileDAO extends JpaDAO<LogFile> {
       
    32     
       
    33     /**
       
    34      * Get a logfile instance by file name.
       
    35      * @param logfile
       
    36      * @return
       
    37      */
       
    38     public LogFile findByLogName(File logfile) {
       
    39         LogFile result = null;
       
    40         try {
       
    41             List<LogFile> resultList = this.getEntityManager().createQuery("select l from LogFile l where l.path='" +
       
    42                 logfile.getAbsolutePath().replace('\\', '/') + "'", LogFile.class).getResultList();
       
    43             if (resultList.size() > 0) {
       
    44                 result = resultList.get(0);
       
    45             }
       
    46         } catch (NoResultException ex) {
       
    47             result = null;
       
    48         }
       
    49         return result;
       
    50     }
       
    51     
       
    52 }