Skip to content
Snippets Groups Projects
Commit 66c2b6c5 authored by Stanley Feng's avatar Stanley Feng
Browse files

[core] Fix some coding style issues in DBWrapper.java

Specifically:

1. Remove trailing spaces,
2. Replace TAB with spaces,
3. Break lines > 80 characters
4. Misc code alignment.

No functional code change. use ?w=1 on the URL to view non-whitespace changes.
parent 6373cf9e
No related branches found
No related tags found
No related merge requests found
/** /**
* Copyright (c) 2010 Yahoo! Inc. All rights reserved. * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you * Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You * may not use this file except in compliance with the License. You
* may obtain a copy of the License at * may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing * implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying * permissions and limitations under the License. See accompanying
* LICENSE file. * LICENSE file.
*/ */
package com.yahoo.ycsb; package com.yahoo.ycsb;
...@@ -29,154 +29,165 @@ import com.yahoo.ycsb.measurements.Measurements; ...@@ -29,154 +29,165 @@ import com.yahoo.ycsb.measurements.Measurements;
*/ */
public class DBWrapper extends DB public class DBWrapper extends DB
{ {
DB _db; DB _db;
Measurements _measurements; Measurements _measurements;
public DBWrapper(DB db)
{
_db=db;
_measurements=Measurements.getMeasurements();
}
public DBWrapper(DB db) /**
{ * Set the properties for this DB.
_db=db; */
_measurements=Measurements.getMeasurements(); public void setProperties(Properties p)
} {
_db.setProperties(p);
}
/** /**
* Set the properties for this DB. * Get the set of properties for this DB.
*/ */
public void setProperties(Properties p) public Properties getProperties()
{ {
_db.setProperties(p); return _db.getProperties();
} }
/** /**
* Get the set of properties for this DB. * Initialize any state for this DB.
*/ * Called once per DB instance; there is one DB instance per client thread.
public Properties getProperties() */
{ public void init() throws DBException
return _db.getProperties(); {
} _db.init();
}
/** /**
* Initialize any state for this DB. * Cleanup any state for this DB.
* Called once per DB instance; there is one DB instance per client thread. * Called once per DB instance; there is one DB instance per client thread.
*/ */
public void init() throws DBException public void cleanup() throws DBException
{ {
_db.init(); long ist=_measurements.getIntendedtartTimeNs();
} long st = System.nanoTime();
_db.cleanup();
long en=System.nanoTime();
measure("CLEANUP",ist, st, en);
}
/** /**
* Cleanup any state for this DB. * Read a record from the database. Each field/value pair from the result
* Called once per DB instance; there is one DB instance per client thread. * will be stored in a HashMap.
*/ *
public void cleanup() throws DBException * @param table The name of the table
{ * @param key The record key of the record to read.
long ist=_measurements.getIntendedtartTimeNs(); * @param fields The list of fields to read, or null for all of them
long st = System.nanoTime(); * @param result A HashMap of field/value pairs for the result
_db.cleanup(); * @return The result of the operation.
long en=System.nanoTime(); */
measure("CLEANUP",ist, st, en); public Status read(String table, String key, Set<String> fields,
} HashMap<String,ByteIterator> result)
{
long ist=_measurements.getIntendedtartTimeNs();
long st = System.nanoTime();
Status res=_db.read(table,key,fields,result);
long en=System.nanoTime();
measure("READ",ist, st, en);
_measurements.reportStatus("READ",res);
return res;
}
/** /**
* Read a record from 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 key The record key of the record to read. * @param table The name of the table
* @param fields The list of fields to read, or null for all of them * @param startkey The record key of the first record to read.
* @param result A HashMap of field/value pairs for the result * @param recordcount The number of records to read
* @return The result of the operation. * @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
public Status read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result) * field/value pairs for one record
{ * @return The result of the operation.
long ist=_measurements.getIntendedtartTimeNs(); */
long st = System.nanoTime(); public Status scan(String table, String startkey, int recordcount,
Status res=_db.read(table,key,fields,result); Set<String> fields, Vector<HashMap<String,ByteIterator>> result)
long en=System.nanoTime(); {
measure("READ",ist, st, en); long ist=_measurements.getIntendedtartTimeNs();
_measurements.reportStatus("READ",res); long st = System.nanoTime();
return res; Status res=_db.scan(table,startkey,recordcount,fields,result);
} long en=System.nanoTime();
measure("SCAN",ist, st, en);
_measurements.reportStatus("SCAN",res);
return res;
}
/** private void measure(String op, long intendedStartTimeNanos,
* 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. long startTimeNanos, long endTimeNanos) {
* _measurements.measure(op, (int)((endTimeNanos-startTimeNanos)/1000));
* @param table The name of the table _measurements.measureIntended(op,
* @param startkey The record key of the first record to read. (int)((endTimeNanos-intendedStartTimeNanos)/1000));
* @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 The result of the operation.
*/
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result)
{
long ist=_measurements.getIntendedtartTimeNs();
long st = System.nanoTime();
Status res=_db.scan(table,startkey,recordcount,fields,result);
long en=System.nanoTime();
measure("SCAN",ist, st, en);
_measurements.reportStatus("SCAN",res);
return res;
}
private void measure(String op, long intendedStartTimeNanos, long startTimeNanos, long endTimeNanos) { /**
_measurements.measure(op, (int)((endTimeNanos-startTimeNanos)/1000)); * Update a record in the database. Any field/value pairs in the specified
_measurements.measureIntended(op, (int)((endTimeNanos-intendedStartTimeNanos)/1000)); * 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
* Update a record in the database. Any field/value pairs in the specified values HashMap will be written into the record with the specified * @param key The record key of the record to write.
* record key, overwriting any existing values with the same field name. * @param values A HashMap of field/value pairs to update in the record
* * @return The result of the operation.
* @param table The name of the table */
* @param key The record key of the record to write. public Status update(String table, String key,
* @param values A HashMap of field/value pairs to update in the record HashMap<String,ByteIterator> values)
* @return The result of the operation. {
*/ long ist=_measurements.getIntendedtartTimeNs();
public Status update(String table, String key, HashMap<String,ByteIterator> values) long st = System.nanoTime();
{ Status res=_db.update(table,key,values);
long ist=_measurements.getIntendedtartTimeNs(); long en=System.nanoTime();
long st = System.nanoTime(); measure("UPDATE",ist, st, en);
Status res=_db.update(table,key,values); _measurements.reportStatus("UPDATE",res);
long en=System.nanoTime(); return res;
measure("UPDATE",ist, st, en); }
_measurements.reportStatus("UPDATE",res);
return res;
}
/** /**
* Insert a record in the database. Any field/value pairs in the specified values HashMap will be written into the record with the specified * Insert a record in the database. Any field/value pairs in the specified
* record key. * 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 table The name of the table
* @param values A HashMap of field/value pairs to insert in the record * @param key The record key of the record to insert.
* @return The result of the operation. * @param values A HashMap of field/value pairs to insert in the record
*/ * @return The result of the operation.
public Status insert(String table, String key, HashMap<String,ByteIterator> values) */
{ public Status insert(String table, String key,
long ist=_measurements.getIntendedtartTimeNs(); HashMap<String,ByteIterator> values)
long st = System.nanoTime(); {
Status res=_db.insert(table,key,values); long ist=_measurements.getIntendedtartTimeNs();
long en=System.nanoTime(); long st = System.nanoTime();
measure("INSERT",ist, st, en); Status res=_db.insert(table,key,values);
_measurements.reportStatus("INSERT",res); long en=System.nanoTime();
return res; measure("INSERT",ist, st, en);
} _measurements.reportStatus("INSERT",res);
return res;
}
/** /**
* Delete a record from the database. * Delete a record from the database.
* *
* @param table The name of the table * @param table The name of the table
* @param key The record key of the record to delete. * @param key The record key of the record to delete.
* @return The result of the operation. * @return The result of the operation.
*/ */
public Status delete(String table, String key) public Status delete(String table, String key)
{ {
long ist=_measurements.getIntendedtartTimeNs(); long ist=_measurements.getIntendedtartTimeNs();
long st = System.nanoTime(); long st = System.nanoTime();
Status res=_db.delete(table,key); Status res=_db.delete(table,key);
long en=System.nanoTime(); long en=System.nanoTime();
measure("DELETE",ist, st, en); measure("DELETE",ist, st, en);
_measurements.reportStatus("DELETE",res); _measurements.reportStatus("DELETE",res);
return res; return res;
} }
} }
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