From 3064c13d8af996a322ec56e23367cdb45dacd706 Mon Sep 17 00:00:00 2001 From: "Robert J. Moore" Date: Sun, 8 Nov 2015 19:05:04 -0500 Subject: [PATCH 1/2] [orientdb] Checkstyle updates for the OrientDB binding. --- orientdb/pom.xml | 84 +++++++---- .../com/yahoo/ycsb/db/OrientDBClient.java | 134 ++++++++++++------ .../java/com/yahoo/ycsb/db/package-info.java | 22 +++ 3 files changed, 163 insertions(+), 77 deletions(-) create mode 100644 orientdb/src/main/java/com/yahoo/ycsb/db/package-info.java diff --git a/orientdb/pom.xml b/orientdb/pom.xml index b3c82f235a..8a6b1d5d2d 100644 --- a/orientdb/pom.xml +++ b/orientdb/pom.xml @@ -17,41 +17,65 @@ LICENSE file. --> - 4.0.0 - - com.yahoo.ycsb - binding-parent - 0.7.0-SNAPSHOT - ../binding-parent - + 4.0.0 + + com.yahoo.ycsb + binding-parent + 0.7.0-SNAPSHOT + ../binding-parent + - orientdb-binding - OrientDB Binding - jar - - - sonatype-nexus-snapshots - Sonatype Nexus Snapshots - https://oss.sonatype.org/content/repositories/snapshots - - - - - com.yahoo.ycsb - core - ${project.version} - provided - - - com.orientechnologies - orientdb-client - ${orientdb.version} - + orientdb-binding + OrientDB Binding + jar + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots + + + + + com.yahoo.ycsb + core + ${project.version} + provided + + + com.orientechnologies + orientdb-client + ${orientdb.version} + junit junit 4.12 test - + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.15 + + true + ../checkstyle.xml + true + true + + + + validate + validate + + checkstyle + + + + + + diff --git a/orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java b/orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java index 4ef72fe901..4e47fbf1be 100644 --- a/orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java +++ b/orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java @@ -47,8 +47,8 @@ */ public class OrientDBClient extends DB { - private static final String CLASS = "usertable"; - protected ODatabaseDocumentTx db; + private static final String CLASS = "usertable"; + protected ODatabaseDocumentTx db; private ODictionary dictionary; private boolean isRemote = false; @@ -71,7 +71,8 @@ public class OrientDBClient extends DB { private static final String ORIENTDB_DOCUMENT_TYPE = "document"; /** - * Initialize any state for this DB. Called once per DB instance; there is one DB instance per client thread. + * Initialize any state for this DB. Called once per DB instance; there is one + * DB instance per client thread. */ public void init() throws DBException { Properties props = getProperties(); @@ -154,21 +155,29 @@ public void cleanup() throws DBException { } } - @Override /** - * Insert a record in the database. Any field/value pairs in the specified values HashMap will be written into the record with the specified - * record key. + * Insert a record in the database. Any field/value pairs in the specified + * values HashMap will be written into the record with the specified record + * key. * - * @param table The name of the table - * @param key The record key of the record to insert. - * @param values A HashMap of field/value pairs to insert in the record - * @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. + * @param table + * The name of the table + * @param key + * The record key of the record to insert. + * @param values + * A HashMap of field/value pairs to insert in the record + * @return Zero on success, a non-zero error code on error. See this class's + * description for a discussion of error codes. */ - public Status insert(String table, String key, HashMap values) { + @Override + public Status insert(String table, String key, + HashMap values) { try { final ODocument document = new ODocument(CLASS); - for (Entry entry : StringByteIterator.getStringMap(values).entrySet()) + for (Entry entry : StringByteIterator.getStringMap(values) + .entrySet()) { document.field(entry.getKey(), entry.getValue()); + } document.save(); dictionary.put(key, document); @@ -179,14 +188,17 @@ public Status insert(String table, String key, HashMap val return Status.ERROR; } - @Override /** * Delete a record from the database. * - * @param table The name of the table - * @param key The record key of the record to delete. - * @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. + * @param table + * The name of the table + * @param key + * The record key of the record to delete. + * @return Zero on success, a non-zero error code on error. See this class's + * description for a discussion of error codes. */ + @Override public Status delete(String table, String key) { try { dictionary.remove(key); @@ -197,26 +209,37 @@ public Status delete(String table, String key) { return Status.ERROR; } - @Override /** - * Read a record from the database. Each field/value pair from the result will be stored in a HashMap. + * Read a record from the database. Each field/value pair from the result will + * be stored in a HashMap. * - * @param table The name of the table - * @param key The record key of the record to read. - * @param fields The list of fields to read, or null for all of them - * @param result A HashMap of field/value pairs for the result + * @param table + * The name of the table + * @param key + * The record key of the record to read. + * @param fields + * The list of fields to read, or null for all of them + * @param result + * A HashMap of field/value pairs for the result * @return Zero on success, a non-zero error code on error or "not found". */ - public Status read(String table, String key, Set fields, HashMap result) { + @Override + public Status read(String table, String key, Set fields, + HashMap result) { try { final ODocument document = dictionary.get(key); if (document != null) { - if (fields != null) - for (String field : fields) - result.put(field, new StringByteIterator((String) document.field(field))); - else - for (String field : document.fieldNames()) - result.put(field, new StringByteIterator((String) document.field(field))); + if (fields != null) { + for (String field : fields) { + result.put(field, + new StringByteIterator((String) document.field(field))); + } + } else { + for (String field : document.fieldNames()) { + result.put(field, + new StringByteIterator((String) document.field(field))); + } + } return Status.OK; } } catch (Exception e) { @@ -225,22 +248,30 @@ public Status read(String table, String key, Set fields, HashMap values) { + @Override + public Status update(String table, String key, + HashMap values) { try { final ODocument document = dictionary.get(key); if (document != null) { - for (Entry entry : StringByteIterator.getStringMap(values).entrySet()) + for (Entry entry : StringByteIterator + .getStringMap(values).entrySet()) { document.field(entry.getKey(), entry.getValue()); + } document.save(); return Status.OK; } @@ -250,17 +281,25 @@ public Status update(String table, String key, HashMap val return Status.ERROR; } - @Override /** - * Perform a range scan for a set of records in the database. Each field/value pair from the result will be stored in a HashMap. + * Perform a range scan for a set of records in the database. Each field/value + * pair from the result will be stored in a HashMap. * - * @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 Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes. + * @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 Zero on success, a non-zero error code on error. See this class's + * description for a discussion of error codes. */ + @Override public Status scan(String table, String startkey, int recordcount, Set fields, Vector> result) { if (isRemote) { // Iterator methods needed for scanning are Unsupported for remote database connections. @@ -275,7 +314,8 @@ public Status scan(String table, String startkey, int recordcount, Set f final Entry entry = entries.nextEntry(); final ODocument document = entry.getValue().getRecord(); - final HashMap map = new HashMap(); + final HashMap map = + new HashMap(); result.add(map); for (String field : fields) { diff --git a/orientdb/src/main/java/com/yahoo/ycsb/db/package-info.java b/orientdb/src/main/java/com/yahoo/ycsb/db/package-info.java new file mode 100644 index 0000000000..df5a3732cd --- /dev/null +++ b/orientdb/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 OrientDB. + */ +package com.yahoo.ycsb.db; + From 759f6e1d458d71ba18de9ee91eb29abc00d302cb Mon Sep 17 00:00:00 2001 From: Andy Kruth Date: Mon, 18 Jan 2016 08:15:03 -0600 Subject: [PATCH 2/2] [orientdb] additional checkstyle cleanup * Rabased pull/489/head (@allanbank) to master * Backed out unnecessary line breaks for 120 char limit * Enforced checkstyle on new code * Was required to make db variable private, updated in tests * Removed TODO Closes #489 --- .../com/yahoo/ycsb/db/OrientDBClient.java | 118 ++++-------------- .../java/com/yahoo/ycsb/db/package-info.java | 2 +- .../com/yahoo/ycsb/db/OrientDBClientTest.java | 2 +- 3 files changed, 26 insertions(+), 96 deletions(-) diff --git a/orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java b/orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java index 4e47fbf1be..853f9ab328 100644 --- a/orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java +++ b/orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java @@ -48,7 +48,7 @@ public class OrientDBClient extends DB { private static final String CLASS = "usertable"; - protected ODatabaseDocumentTx db; + private ODatabaseDocumentTx db; private ODictionary dictionary; private boolean isRemote = false; @@ -70,10 +70,7 @@ public class OrientDBClient extends DB { private static final String ORIENTDB_DOCUMENT_TYPE = "document"; - /** - * Initialize any state for this DB. Called once per DB instance; there is one - * DB instance per client thread. - */ + @Override public void init() throws DBException { Properties props = getProperties(); @@ -82,7 +79,8 @@ public void init() throws DBException { String password = props.getProperty(PASSWORD_PROPERTY, PASSWORD_PROPERTY_DEFAULT); Boolean newdb = Boolean.parseBoolean(props.getProperty(NEWDB_PROPERTY, NEWDB_PROPERTY_DEFAULT)); String remoteStorageType = props.getProperty(STORAGE_TYPE_PROPERTY); - Boolean dotransactions = Boolean.parseBoolean(props.getProperty(DO_TRANSACTIONS_PROPERTY, DO_TRANSACTIONS_PROPERTY_DEFAULT)); + Boolean dotransactions = Boolean.parseBoolean( + props.getProperty(DO_TRANSACTIONS_PROPERTY, DO_TRANSACTIONS_PROPERTY_DEFAULT)); if (url == null) { throw new DBException(String.format("Required property \"%s\" missing for OrientDBClient", URL_PROPERTY)); @@ -94,7 +92,8 @@ public void init() throws DBException { if (url.startsWith(OEngineRemote.NAME)) { isRemote = true; if (remoteStorageType == null) { - throw new DBException("When connecting to a remote OrientDB instance, specify a database storage type (plocal or memory) with " + STORAGE_TYPE_PROPERTY); + throw new DBException("When connecting to a remote OrientDB instance, " + + "specify a database storage type (plocal or memory) with " + STORAGE_TYPE_PROPERTY); } try { @@ -137,10 +136,10 @@ public void init() throws DBException { System.err.println("OrientDB connection created with " + url); dictionary = db.getMetadata().getIndexManager().getDictionary(); - if (!db.getMetadata().getSchema().existsClass(CLASS)) + if (!db.getMetadata().getSchema().existsClass(CLASS)) { db.getMetadata().getSchema().createClass(CLASS); + } - // TODO: This is a transparent optimization that should be openned up to the user. db.declareIntent(new OIntentMassiveInsert()); } @@ -155,27 +154,11 @@ public void cleanup() throws DBException { } } - /** - * Insert a record in the database. Any field/value pairs in the specified - * values HashMap will be written into the record with the specified record - * key. - * - * @param table - * The name of the table - * @param key - * The record key of the record to insert. - * @param values - * A HashMap of field/value pairs to insert in the record - * @return Zero on success, a non-zero error code on error. See this class's - * description for a discussion of error codes. - */ @Override - public Status insert(String table, String key, - HashMap values) { + public Status insert(String table, String key, HashMap values) { try { final ODocument document = new ODocument(CLASS); - for (Entry entry : StringByteIterator.getStringMap(values) - .entrySet()) { + for (Entry entry : StringByteIterator.getStringMap(values).entrySet()) { document.field(entry.getKey(), entry.getValue()); } document.save(); @@ -188,16 +171,6 @@ public Status insert(String table, String key, return Status.ERROR; } - /** - * Delete a record from the database. - * - * @param table - * The name of the table - * @param key - * The record key of the record to delete. - * @return Zero on success, a non-zero error code on error. See this class's - * description for a discussion of error codes. - */ @Override public Status delete(String table, String key) { try { @@ -209,35 +182,18 @@ public Status delete(String table, String key) { return Status.ERROR; } - /** - * Read a record from the database. Each field/value pair from the result will - * be stored in a HashMap. - * - * @param table - * The name of the table - * @param key - * The record key of the record to read. - * @param fields - * The list of fields to read, or null for all of them - * @param result - * A HashMap of field/value pairs for the result - * @return Zero on success, a non-zero error code on error or "not found". - */ @Override - public Status read(String table, String key, Set fields, - HashMap result) { + public Status read(String table, String key, Set fields, HashMap result) { try { final ODocument document = dictionary.get(key); if (document != null) { if (fields != null) { for (String field : fields) { - result.put(field, - new StringByteIterator((String) document.field(field))); + result.put(field, new StringByteIterator((String) document.field(field))); } } else { for (String field : document.fieldNames()) { - result.put(field, - new StringByteIterator((String) document.field(field))); + result.put(field, new StringByteIterator((String) document.field(field))); } } return Status.OK; @@ -248,28 +204,12 @@ public Status read(String table, String key, Set fields, return Status.ERROR; } - /** - * Update a record in the database. Any field/value pairs in the specified - * values HashMap will be written into the record with the specified record - * key, overwriting any existing values with the same field name. - * - * @param table - * The name of the table - * @param key - * The record key of the record to write. - * @param values - * A HashMap of field/value pairs to update in the record - * @return Zero on success, a non-zero error code on error. See this class's - * description for a discussion of error codes. - */ @Override - public Status update(String table, String key, - HashMap values) { + public Status update(String table, String key, HashMap values) { try { final ODocument document = dictionary.get(key); if (document != null) { - for (Entry entry : StringByteIterator - .getStringMap(values).entrySet()) { + for (Entry entry : StringByteIterator.getStringMap(values).entrySet()) { document.field(entry.getKey(), entry.getValue()); } document.save(); @@ -281,26 +221,9 @@ public Status update(String table, String key, return Status.ERROR; } - /** - * Perform a range scan for a set of records in the database. Each field/value - * pair from the result will be stored in a HashMap. - * - * @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 Zero on success, a non-zero error code on error. See this class's - * description for a discussion of error codes. - */ @Override - public Status scan(String table, String startkey, int recordcount, Set fields, Vector> result) { + public Status scan(String table, String startkey, int recordcount, Set fields, + Vector> result) { if (isRemote) { // Iterator methods needed for scanning are Unsupported for remote database connections. return Status.NOT_IMPLEMENTED; @@ -331,4 +254,11 @@ public Status scan(String table, String startkey, int recordcount, Set f } return Status.ERROR; } + + /** + * Access method to db variable for unit testing. + **/ + ODatabaseDocumentTx getDB() { + return db; + } } diff --git a/orientdb/src/main/java/com/yahoo/ycsb/db/package-info.java b/orientdb/src/main/java/com/yahoo/ycsb/db/package-info.java index df5a3732cd..d4568271c4 100644 --- a/orientdb/src/main/java/com/yahoo/ycsb/db/package-info.java +++ b/orientdb/src/main/java/com/yahoo/ycsb/db/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Yahoo!, Inc. All rights reserved. + * Copyright (c) 2015 - 2016, 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 diff --git a/orientdb/src/test/java/com/yahoo/ycsb/db/OrientDBClientTest.java b/orientdb/src/test/java/com/yahoo/ycsb/db/OrientDBClientTest.java index e9f3a58f7a..717637d0c3 100644 --- a/orientdb/src/test/java/com/yahoo/ycsb/db/OrientDBClientTest.java +++ b/orientdb/src/test/java/com/yahoo/ycsb/db/OrientDBClientTest.java @@ -54,7 +54,7 @@ public void setup() throws DBException { orientDBClient.setProperties(p); orientDBClient.init(); - orientDBDictionary = orientDBClient.db.getDictionary(); + orientDBDictionary = orientDBClient.getDB().getDictionary(); } @After