diff --git a/couchbase/pom.xml b/couchbase/pom.xml index d3d7cd31c46aca855b56d6fc8e7c05b7f6c15aa8..f8e1640fa73aae2b8d4c3b1305d8c9c900284b7f 100644 --- a/couchbase/pom.xml +++ b/couchbase/pom.xml @@ -56,4 +56,28 @@ LICENSE file. <artifactId>slf4j-api</artifactId> </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <version>2.15</version> + <configuration> + <consoleOutput>true</consoleOutput> + <configLocation>../checkstyle.xml</configLocation> + <failOnViolation>true</failOnViolation> + <failsOnError>true</failsOnError> + </configuration> + <executions> + <execution> + <id>validate</id> + <phase>validate</phase> + <goals> + <goal>checkstyle</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> diff --git a/couchbase/src/main/java/com/yahoo/ycsb/db/CouchbaseClient.java b/couchbase/src/main/java/com/yahoo/ycsb/db/CouchbaseClient.java index 1eb3aeb318d06703e740f10562c64baa7fd6ec86..e86999c6b73c91f5adceca54c642ed189dab20d3 100644 --- a/couchbase/src/main/java/com/yahoo/ycsb/db/CouchbaseClient.java +++ b/couchbase/src/main/java/com/yahoo/ycsb/db/CouchbaseClient.java @@ -18,6 +18,20 @@ package com.yahoo.ycsb.db; import com.couchbase.client.protocol.views.*; +import java.io.StringWriter; +import java.io.Writer; +import java.net.URI; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.Vector; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonNode; @@ -33,34 +47,27 @@ import net.spy.memcached.PersistTo; import net.spy.memcached.ReplicateTo; import net.spy.memcached.internal.OperationFuture; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.StringWriter; -import java.io.Writer; -import java.net.URI; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.Vector; - /** - * A class that wraps the CouchbaseClient to allow it to be interfaced with YCSB. - * This class extends {@link DB} and implements the database interface used by YCSB client. + * A class that wraps the CouchbaseClient to allow it to be interfaced with + * YCSB. This class extends {@link DB} and implements the database interface + * used by YCSB client. * - * <p> The following options must be passed when using this database client. + * <p> + * The following options must be passed when using this database client. * * <ul> - * <li><b>couchbase.url=http://127.0.0.1:8091/pools</b> The connection URL from one server.</li> + * <li><b>couchbase.url=http://127.0.0.1:8091/pools</b> The connection URL from + * one server.</li> * <li><b>couchbase.bucket=default</b> The bucket name to use./li> * <li><b>couchbase.password=</b> The password of the bucket.</li> - * <li><b>couchbase.checkFutures=true</b> If the futures should be inspected (makes ops sync).</li> - * <li><b>couchbase.persistTo=0</b> Observe Persistence ("PersistTo" constraint)</li> - * <li><b>couchbase.replicateTo=0</b> Observe Replication ("ReplicateTo" constraint)</li> - * <li><b>couchbase.json=true</b> Use json or java serialization as target format.</li> + * <li><b>couchbase.checkFutures=true</b> If the futures should be inspected + * (makes ops sync).</li> + * <li><b>couchbase.persistTo=0</b> Observe Persistence ("PersistTo" constraint) + * </li> + * <li><b>couchbase.replicateTo=0</b> Observe Replication ("ReplicateTo" + * constraint)</li> + * <li><b>couchbase.json=true</b> Use json or java serialization as target + * format.</li> * </ul> * * @author Michael Nitschinger @@ -116,15 +123,13 @@ public class CouchbaseClient extends DB { Double scanproportion = Double.valueOf(props.getProperty(SCAN_PROPERTY, SCAN_PROPERTY_DEFAULT)); Properties systemProperties = System.getProperties(); - systemProperties.put("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.SLF4JLogger"); + systemProperties.put("net.spy.log.LoggerImpl", + "net.spy.memcached.compat.log.SLF4JLogger"); System.setProperties(systemProperties); try { client = new com.couchbase.client.CouchbaseClient( - Arrays.asList(new URI(url)), - bucket, - password - ); + Arrays.asList(new URI(url)), bucket, password); } catch (Exception e) { throw new DBException("Could not create CouchbaseClient object.", e); } @@ -142,41 +147,55 @@ public class CouchbaseClient extends DB { /** * Parse the replicate property into the correct enum. * - * @param property the stringified property value. - * @throws DBException if parsing the property did fail. + * @param property + * the stringified property value. + * @throws DBException + * if parsing the property did fail. * @return the correct enum. */ - private ReplicateTo parseReplicateTo(final String property) throws DBException { + private ReplicateTo parseReplicateTo(final String property) + throws DBException { int value = Integer.parseInt(property); switch (value) { - case 0: return ReplicateTo.ZERO; - case 1: return ReplicateTo.ONE; - case 2: return ReplicateTo.TWO; - case 3: return ReplicateTo.THREE; - default: - throw new DBException(REPLICATE_PROPERTY + " must be between 0 and 3"); + case 0: + return ReplicateTo.ZERO; + case 1: + return ReplicateTo.ONE; + case 2: + return ReplicateTo.TWO; + case 3: + return ReplicateTo.THREE; + default: + throw new DBException(REPLICATE_PROPERTY + " must be between 0 and 3"); } } /** * Parse the persist property into the correct enum. * - * @param property the stringified property value. - * @throws DBException if parsing the property did fail. + * @param property + * the stringified property value. + * @throws DBException + * if parsing the property did fail. * @return the correct enum. */ private PersistTo parsePersistTo(final String property) throws DBException { int value = Integer.parseInt(property); switch (value) { - case 0: return PersistTo.ZERO; - case 1: return PersistTo.ONE; - case 2: return PersistTo.TWO; - case 3: return PersistTo.THREE; - case 4: return PersistTo.FOUR; - default: - throw new DBException(PERSIST_PROPERTY + " must be between 0 and 4"); + case 0: + return PersistTo.ZERO; + case 1: + return PersistTo.ONE; + case 2: + return PersistTo.TWO; + case 3: + return PersistTo.THREE; + case 4: + return PersistTo.FOUR; + default: + throw new DBException(PERSIST_PROPERTY + " must be between 0 and 4"); } } @@ -189,8 +208,8 @@ public class CouchbaseClient extends DB { } @Override - public Status read(final String table, final String key, final Set<String> fields, - final HashMap<String, ByteIterator> result) { + public Status read(final String table, final String key, + final Set<String> fields, final HashMap<String, ByteIterator> result) { String formattedKey = formatKey(table, key); try { @@ -213,11 +232,17 @@ public class CouchbaseClient extends DB { /** * Scan is currently not implemented. * - * @param table The name of the table - * @param startkey The record key of the first record to read. - * @param recordcount The number of records to read - * @param fields The list of fields to read, or null for all of them - * @param result A Vector of HashMaps, where each HashMap is a set field/value pairs for one record + * @param table + * The name of the table + * @param startkey + * The record key of the first record to read. + * @param recordcount + * The number of records to read + * @param fields + * The list of fields to read, or null for all of them + * @param result + * A Vector of HashMaps, where each HashMap is a set field/value + * pairs for one record * @return Status.ERROR, because not implemented yet. */ @Override @@ -245,16 +270,13 @@ public class CouchbaseClient extends DB { } @Override - public Status update(final String table, final String key, final HashMap<String, ByteIterator> values) { + public Status update(final String table, final String key, + final HashMap<String, ByteIterator> values) { String formattedKey = formatKey(table, key); try { - final OperationFuture<Boolean> future = client.replace( - formattedKey, - encode(values), - persistTo, - replicateTo - ); + final OperationFuture<Boolean> future = + client.replace(formattedKey, encode(values), persistTo, replicateTo); return checkFutureStatus(future); } catch (Exception e) { if (log.isErrorEnabled()) { @@ -265,16 +287,13 @@ public class CouchbaseClient extends DB { } @Override - public Status insert(final String table, final String key, final HashMap<String, ByteIterator> values) { + public Status insert(final String table, final String key, + final HashMap<String, ByteIterator> values) { String formattedKey = formatKey(table, key); try { - final OperationFuture<Boolean> future = client.add( - formattedKey, - encode(values), - persistTo, - replicateTo - ); + final OperationFuture<Boolean> future = + client.add(formattedKey, encode(values), persistTo, replicateTo); return checkFutureStatus(future); } catch (Exception e) { if (log.isErrorEnabled()) { @@ -289,7 +308,8 @@ public class CouchbaseClient extends DB { String formattedKey = formatKey(table, key); try { - final OperationFuture<Boolean> future = client.delete(formattedKey, persistTo, replicateTo); + final OperationFuture<Boolean> future = + client.delete(formattedKey, persistTo, replicateTo); return checkFutureStatus(future); } catch (Exception e) { if (log.isErrorEnabled()) { @@ -302,8 +322,10 @@ public class CouchbaseClient extends DB { /** * Prefix the key with the given prefix, to establish a unique namespace. * - * @param prefix the prefix to use. - * @param key the actual key. + * @param prefix + * the prefix to use. + * @param key + * the actual key. * @return the formatted and prefixed key. */ private String formatKey(final String prefix, final String key) { @@ -313,7 +335,8 @@ public class CouchbaseClient extends DB { /** * Wrapper method that either inspects the future or not. * - * @param future the future to potentially verify. + * @param future + * the future to potentially verify. * @return the status of the future result. */ private Status checkFutureStatus(final OperationFuture<?> future) { @@ -327,12 +350,15 @@ public class CouchbaseClient extends DB { /** * Decode the object from server into the storable result. * - * @param source the loaded object. - * @param fields the fields to check. - * @param dest the result passed back to the ycsb core. + * @param source + * the loaded object. + * @param fields + * the fields to check. + * @param dest + * the result passed back to the ycsb core. */ private void decode(final Object source, final Set<String> fields, - final HashMap<String, ByteIterator> dest) { + final HashMap<String, ByteIterator> dest) { if (useJson) { try { JsonNode json = JSON_MAPPER.readTree((String) source); @@ -362,7 +388,8 @@ public class CouchbaseClient extends DB { /** * Encode the object for couchbase storage. * - * @param source the source value. + * @param source + * the source value. * @return the storable object. */ private Object encode(final HashMap<String, ByteIterator> source) { @@ -386,5 +413,4 @@ public class CouchbaseClient extends DB { return writer.toString(); } - } diff --git a/couchbase/src/main/java/com/yahoo/ycsb/db/package-info.java b/couchbase/src/main/java/com/yahoo/ycsb/db/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..1cbc5b6944dadde668d65872aa408ad716e99f4b --- /dev/null +++ b/couchbase/src/main/java/com/yahoo/ycsb/db/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2014, Yahoo!, Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you + * may not use this file except in compliance with the License. You + * may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. See accompanying + * LICENSE file. + */ + +/** + * The YCSB binding for <a href="http://www.couchbase.com/">Couchbase</a>. + */ +package com.yahoo.ycsb.db; +