]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
d47d2bc1a46a8fccc18a37020c7ed8a1441aa2ef
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2  *  Copyright 2010 Sun Microsystems, Inc.
3  *  All rights reserved. Use is subject to license terms.
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; version 2 of the License.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
17  */
18
19 package com.mysql.clusterj.bindings;
20
21 import com.mysql.cluster.ndbj.NdbApiException;
22 import com.mysql.cluster.ndbj.NdbScanFilter;
23
24 import com.mysql.clusterj.ClusterJDatastoreException;
25
26 import com.mysql.clusterj.ClusterJFatalInternalException;
27 import com.mysql.clusterj.core.store.Column;
28 import com.mysql.clusterj.core.store.ScanFilter;
29
30 import com.mysql.clusterj.core.util.I18NHelper;
31 import com.mysql.clusterj.core.util.Logger;
32 import com.mysql.clusterj.core.util.LoggerFactoryService;
33
34 import java.sql.Date;
35 import java.sql.Time;
36 import java.sql.Timestamp;
37
38 /**
39  *
40  */
41 class ScanFilterImpl implements ScanFilter {
42
43     /** My message translator */
44     static final I18NHelper local = I18NHelper
45             .getInstance(ScanFilterImpl.class);
46
47     /** My logger */
48     static final Logger logger = LoggerFactoryService.getFactory()
49             .getInstance(ScanFilterImpl.class);
50
51     private NdbScanFilter scanFilter;
52
53     public ScanFilterImpl(NdbScanFilter scanFilter) {
54         this.scanFilter = scanFilter;
55     }
56
57     public void begin() {
58         try {
59             scanFilter.begin();
60         } catch (NdbApiException ndbApiException) {
61             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
62                     ndbApiException);
63         }
64     }
65
66     public void begin(Group group) {
67         try {
68             scanFilter.begin(convertGroup(group));
69         } catch (NdbApiException ndbApiException) {
70             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
71                     ndbApiException);
72         }
73     }
74
75     public void cmpBoolean(BinaryCondition condition, Column storeColumn, boolean booleanValue) {
76         throw new UnsupportedOperationException(local.message("ERR_NotImplemented"));
77     }
78
79     public void cmpBytes(BinaryCondition condition, Column storeColumn, byte[] value) {
80         try {
81             scanFilter.cmp(convertCondition(condition), storeColumn.getName(), value);
82         } catch (NdbApiException ndbApiException) {
83             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
84                     ndbApiException);
85         }
86     }
87
88     public void cmpDouble(BinaryCondition condition, Column storeColumn, double value) {
89         try {
90             scanFilter.cmp(convertCondition(condition), storeColumn.getName(), value);
91         } catch (NdbApiException ndbApiException) {
92             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
93                     ndbApiException);
94         }
95     }
96
97     public void cmpFloat(BinaryCondition condition, Column storeColumn, float value) {
98         try {
99             scanFilter.cmp(convertCondition(condition), storeColumn.getName(), value);
100         } catch (NdbApiException ndbApiException) {
101             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
102                     ndbApiException);
103         }
104     }
105
106     public void cmpInt(BinaryCondition condition, Column storeColumn, int value) {
107         try {
108             scanFilter.cmp(convertCondition(condition), storeColumn.getName(), value);
109         } catch (NdbApiException ndbApiException) {
110             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
111                     ndbApiException);
112         }
113     }
114
115     public void cmpLong(BinaryCondition condition, Column storeColumn, long value) {
116         try {
117             scanFilter.cmp(convertCondition(condition), storeColumn.getName(), value);
118         } catch (NdbApiException ndbApiException) {
119             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
120                     ndbApiException);
121         }
122     }
123
124     public void cmpString(BinaryCondition condition, Column storeColumn, String value) {
125         try {
126             scanFilter.cmpString(convertCondition(condition), storeColumn.getName(), value);
127         } catch (NdbApiException ndbApiException) {
128             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
129                     ndbApiException);
130         }
131     }
132
133     public void cmpTimestamp(BinaryCondition condition, Column storeColumn, Timestamp value) {
134         try {
135             scanFilter.cmpTimestamp(convertCondition(condition), storeColumn.getName(), value);
136         } catch (NdbApiException ndbApiException) {
137             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
138                     ndbApiException);
139         }
140     }
141
142     public void cmpDatetime(BinaryCondition condition, Column storeColumn, Timestamp value) {
143         try {
144             scanFilter.cmp(convertCondition(condition), storeColumn.getName(), value);
145         } catch (NdbApiException ndbApiException) {
146             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
147                     ndbApiException);
148         }
149     }
150
151     public void cmpDate(BinaryCondition condition, Column storeColumn, Date value) {
152         try {
153             Timestamp timestamp = new Timestamp(value.getTime());
154             scanFilter.cmp(convertCondition(condition), storeColumn.getName(), timestamp);
155         } catch (NdbApiException ndbApiException) {
156             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
157                     ndbApiException);
158         }
159     }
160
161     public void cmpTime(BinaryCondition condition, Column storeColumn, Time value) {
162         try {
163             Timestamp timestamp = new Timestamp(value.getTime());
164             scanFilter.cmp(convertCondition(condition), storeColumn.getName(), timestamp);
165         } catch (NdbApiException ndbApiException) {
166             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
167                     ndbApiException);
168         }
169     }
170
171     public void end() {
172         try {
173             scanFilter.end();
174         } catch (NdbApiException ndbApiException) {
175             throw new ClusterJDatastoreException(local.message("ERR_Datastore"),
176                     ndbApiException);
177         }
178     }
179
180     private NdbScanFilter.BinaryCondition convertCondition(BinaryCondition condition) {
181         switch (condition) {
182             case COND_EQ:
183                 return NdbScanFilter.BinaryCondition.COND_EQ;
184             case COND_LE:
185                 return NdbScanFilter.BinaryCondition.COND_LE;
186             case COND_LT:
187                 return NdbScanFilter.BinaryCondition.COND_LT;
188             case COND_GE:
189                 return NdbScanFilter.BinaryCondition.COND_GE;
190             case COND_GT:
191                 return NdbScanFilter.BinaryCondition.COND_GT;
192             default:
193                 throw new ClusterJFatalInternalException(
194                         local.message("ERR_Implementation_Should_Not_Occur"));
195         }
196     }
197
198     private NdbScanFilter.Group convertGroup(Group group) {
199         switch(group) {
200             case GROUP_AND:
201                 return NdbScanFilter.Group.AND;
202             default:
203                 throw new ClusterJFatalInternalException(
204                         local.message("ERR_Implementation_Should_Not_Occur"));
205         }
206     }
207
208 }