d12895c257cb5a04fbc8157a743f57150ed205dc
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2    Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; version 2 of the License.
7
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
16 */
17
18 package com.mysql.clusterj.core.query;
19
20
21 import com.mysql.clusterj.Results;
22 import com.mysql.clusterj.core.*;
23 import com.mysql.clusterj.Query;
24 import com.mysql.clusterj.core.util.I18NHelper;
25 import com.mysql.clusterj.core.util.Logger;
26 import com.mysql.clusterj.core.util.LoggerFactoryService;
27
28 import java.util.List;
29 import java.util.Map;
30
31 public class QueryImpl<E> implements Query<E> {
32
33     /** My message translator */
34     static final I18NHelper local = I18NHelper.getInstance(BetweenPredicateImpl.class);
35
36     /** My logger */
37     static final Logger logger = LoggerFactoryService.getFactory().getInstance(BetweenPredicateImpl.class);
38
39     /** My session. */
40     protected SessionImpl session;
41
42     /** My DomainObject */
43     protected QueryDomainTypeImpl<E> dobj;
44
45     /** My query execution context. */
46     protected QueryExecutionContextImpl context = null;
47
48     public QueryImpl(SessionImpl session, QueryDomainTypeImpl<E> dobj) {
49         this.session = session;
50         context = new QueryExecutionContextImpl(session);
51         this.dobj = dobj;
52     }
53
54     public Results<E> execute(Object arg0) {
55             throw new UnsupportedOperationException(
56                     local.message("ERR_NotImplemented"));
57     }
58
59     public Results<E> execute(Object... arg0) {
60             throw new UnsupportedOperationException(
61                     local.message("ERR_NotImplemented"));
62     }
63
64     public Results<E> execute(Map<String, ?> arg0) {
65             throw new UnsupportedOperationException(
66                     local.message("ERR_NotImplemented"));
67     }
68
69     public void setParameter(String parameterName, Object parameterValue) {
70         context.bindParameterValue(parameterName, parameterValue);
71     }
72
73     public List<E> getResultList() {
74         List<E> results = dobj.getResultList(context);
75         // create new context, copying the parameters, for another execution
76         context = new QueryExecutionContextImpl(context);
77         return results;
78     }
79
80     /** Delete the instances that satisfy the query criteria.
81      * @return the number of instances deleted
82      */
83     public int deletePersistentAll() {
84         int result = dobj.deletePersistentAll(context);
85         return result;
86     }
87
88     /**
89      * Explain this query.
90      * @return the data about the execution of this query
91      */
92     public Map<String, Object> explain() {
93         Map<String, Object> result = context.getExplain();
94         if (result == null) {
95             dobj.explain(context);
96             return context.getExplain();
97         }
98         return result;
99     }
100
101 }