Skip to content
Snippets Groups Projects
Commit 942c46a2 authored by Andy Kruth's avatar Andy Kruth
Browse files

Merge pull request #585 from kruthar/orientdb-checkstyle

Orientdb checkstyle
parents a02649b7 759f6e1d
No related branches found
No related tags found
No related merge requests found
......@@ -17,41 +17,65 @@ LICENSE file.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>binding-parent</artifactId>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../binding-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>binding-parent</artifactId>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../binding-parent</relativePath>
</parent>
<artifactId>orientdb-binding</artifactId>
<name>OrientDB Binding</name>
<packaging>jar</packaging>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-client</artifactId>
<version>${orientdb.version}</version>
</dependency>
<artifactId>orientdb-binding</artifactId>
<name>OrientDB Binding</name>
<packaging>jar</packaging>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-client</artifactId>
<version>${orientdb.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</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>
......@@ -47,8 +47,8 @@ import java.util.Vector;
*/
public class OrientDBClient extends DB {
private static final String CLASS = "usertable";
protected ODatabaseDocumentTx db;
private static final String CLASS = "usertable";
private ODatabaseDocumentTx db;
private ODictionary<ORecord> dictionary;
private boolean isRemote = false;
......@@ -70,9 +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();
......@@ -81,7 +79,8 @@ public class OrientDBClient extends DB {
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));
......@@ -93,7 +92,8 @@ public class OrientDBClient extends DB {
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 {
......@@ -136,10 +136,10 @@ public class OrientDBClient extends DB {
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,20 +155,12 @@ public class OrientDBClient extends DB {
}
@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.
*
* @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<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();
dictionary.put(key, document);
......@@ -180,13 +172,6 @@ public class OrientDBClient extends DB {
}
@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.
*/
public Status delete(String table, String key) {
try {
dictionary.remove(key);
......@@ -198,25 +183,19 @@ public class OrientDBClient extends DB {
}
@Override
/**
* 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".
*/
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)
if (fields != null) {
for (String field : fields) {
result.put(field, new StringByteIterator((String) document.field(field)));
else
for (String field : document.fieldNames())
}
} else {
for (String field : document.fieldNames()) {
result.put(field, new StringByteIterator((String) document.field(field)));
}
}
return Status.OK;
}
} catch (Exception e) {
......@@ -226,21 +205,13 @@ public class OrientDBClient extends DB {
}
@Override
/**
* 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.
*/
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();
return Status.OK;
}
......@@ -251,17 +222,8 @@ public class OrientDBClient extends DB {
}
@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.
*
* @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.
*/
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;
......@@ -275,7 +237,8 @@ public class OrientDBClient extends DB {
final Entry<Object, OIdentifiable> entry = entries.nextEntry();
final ODocument document = entry.getValue().getRecord();
final HashMap<String, ByteIterator> map = new HashMap<String, ByteIterator>();
final HashMap<String, ByteIterator> map =
new HashMap<String, ByteIterator>();
result.add(map);
for (String field : fields) {
......@@ -291,4 +254,11 @@ public class OrientDBClient extends DB {
}
return Status.ERROR;
}
/**
* Access method to db variable for unit testing.
**/
ODatabaseDocumentTx getDB() {
return db;
}
}
/*
* 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
* 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://orientdb.com/orientdb/">OrientDB</a>.
*/
package com.yahoo.ycsb.db;
......@@ -54,7 +54,7 @@ public class OrientDBClientTest {
orientDBClient.setProperties(p);
orientDBClient.init();
orientDBDictionary = orientDBClient.db.getDictionary();
orientDBDictionary = orientDBClient.getDB().getDictionary();
}
@After
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment