Merge "BUG 2509 : Removing all journal entries from a Followers in-memory journal...
[controller.git] / opendaylight / adsal / northbound / commons / src / main / java / org / opendaylight / controller / northbound / commons / query / QueryContextImpl.java
1 /**
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.northbound.commons.query;
9
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12
13 /*package*/ class QueryContextImpl implements QueryContext {
14
15     private static final Logger LOGGER = LoggerFactory.getLogger(QueryContext.class);
16
17     @Override
18     public <T> Query<T> createQuery(String queryString, Class<T> type) throws QueryException {
19         if (queryString == null || queryString.trim().length() == 0) {
20             return null;
21         }
22         try {
23             if (LOGGER.isDebugEnabled()) {
24                 LOGGER.debug("Processing query: {}", queryString);
25             }
26             // FiqlParser is a parser generated by javacc
27             Expression expression = FiqlParser.parse(queryString);
28             if (LOGGER.isDebugEnabled()) {
29                 LOGGER.debug("Query expression: {}", expression);
30             }
31             // create Query and return;
32             return new QueryImpl<T>(type, expression);
33         } catch (Exception ex) {
34             if (LOGGER.isDebugEnabled()) {
35                 LOGGER.error("Query processing failed = {}",
36                     queryString, ex);
37             }
38             throw new QueryException("Unable to parse query.", ex);
39         }
40     }
41 }