buildframework/helium/sf/java/metadata/src/com/nokia/helium/metadata/fmpp/QueryTemplateModel.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.fmpp;
       
    18 
       
    19 import javax.persistence.EntityManager;
       
    20 
       
    21 import freemarker.template.TemplateHashModel;
       
    22 import freemarker.template.TemplateModel;
       
    23 
       
    24 /**
       
    25  * Internal class to handle the sql query and returns the data in either
       
    26  * hash or sequence or containers.
       
    27  */
       
    28 class QueryTemplateModel implements TemplateHashModel {
       
    29 
       
    30     private EntityManager entityManager;
       
    31     
       
    32     private String queryMode;
       
    33     
       
    34     private String returnType;
       
    35     
       
    36     private TemplateModel resultObject;
       
    37     
       
    38     public QueryTemplateModel(EntityManager entityManager, String mode, String retType) {
       
    39         this.entityManager = entityManager;
       
    40         queryMode = mode;
       
    41         returnType = retType;
       
    42     }
       
    43 
       
    44     public TemplateModel get(String query) {
       
    45         if (queryMode.equals("jpasingle")) {
       
    46             resultObject = new ORMSequenceModel(entityManager, query);
       
    47         } else {
       
    48             resultObject = new ORMQueryModel(entityManager, query, queryMode, returnType); 
       
    49         }
       
    50         return resultObject;
       
    51     }
       
    52     
       
    53     public boolean isEmpty() {
       
    54         return false;
       
    55     }
       
    56 }