Skip to content

Commit

Permalink
[orientdb] additional checkstyle cleanup
Browse files Browse the repository at this point in the history
* 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 brianfrankcooper#489
  • Loading branch information
kruthar committed Jan 18, 2016
1 parent 3064c13 commit 759f6e1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 96 deletions.
118 changes: 24 additions & 94 deletions orientdb/src/main/java/com/yahoo/ycsb/db/OrientDBClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public class OrientDBClient extends DB {

private static final String CLASS = "usertable";
protected ODatabaseDocumentTx db;
private ODatabaseDocumentTx db;
private ODictionary<ORecord> dictionary;
private boolean isRemote = false;

Expand All @@ -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();

Expand All @@ -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));
Expand All @@ -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 {
Expand Down Expand Up @@ -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());
}

Expand All @@ -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<String, ByteIterator> values) {
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
try {
final ODocument document = new ODocument(CLASS);
for (Entry<String, String> entry : StringByteIterator.getStringMap(values)
.entrySet()) {
for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {
document.field(entry.getKey(), entry.getValue());
}
document.save();
Expand All @@ -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 {
Expand All @@ -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<String> fields,
HashMap<String, ByteIterator> result) {
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> 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;
Expand All @@ -248,28 +204,12 @@ public Status read(String table, String key, Set<String> 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<String, ByteIterator> values) {
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
try {
final ODocument document = dictionary.get(key);
if (document != null) {
for (Entry<String, String> entry : StringByteIterator
.getStringMap(values).entrySet()) {
for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {
document.field(entry.getKey(), entry.getValue());
}
document.save();
Expand All @@ -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<String> fields, Vector<HashMap<String, ByteIterator>> result) {
public Status scan(String table, String startkey, int recordcount, Set<String> fields,
Vector<HashMap<String, ByteIterator>> result) {
if (isRemote) {
// Iterator methods needed for scanning are Unsupported for remote database connections.
return Status.NOT_IMPLEMENTED;
Expand Down Expand Up @@ -331,4 +254,11 @@ public Status scan(String table, String startkey, int recordcount, Set<String> f
}
return Status.ERROR;
}

/**
* Access method to db variable for unit testing.
**/
ODatabaseDocumentTx getDB() {
return db;
}
}
2 changes: 1 addition & 1 deletion orientdb/src/main/java/com/yahoo/ycsb/db/package-info.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void setup() throws DBException {

orientDBClient.setProperties(p);
orientDBClient.init();
orientDBDictionary = orientDBClient.db.getDictionary();
orientDBDictionary = orientDBClient.getDB().getDictionary();
}

@After
Expand Down

0 comments on commit 759f6e1

Please sign in to comment.