import oracle.kv.Value; //导入方法依赖的package包/类
/**
* Displays information about a movie
* @param movieName
*/
public void showMovieValue(String movieName) {
KeyValueVersion keyValue = null;
Value value = null;
String movieIdStr = null;
Key movieIdKey = null;
MovieTO movieTO = null;
// The DB has an index on Movie Name. You will use this index to
// retrieve the ID for the Movie Name. Note, there may be multiple
// movies with the same name
Key movieNameKey = getMovieKey(movieName, KeyConstant.MOVIE_NAME_TABLE);
// Find movie id's for this movie name
Iterator keyIter = kvstore.multiGetIterator(
Direction.FORWARD, 0,
movieNameKey, null, null);
// Are there any movies available?
if (!keyIter.hasNext()) {
System.out.println("Movie \"" + movieName + "\" not found.");
System.out.println("");
return;
}
String snippet="";
System.out.println("Movie Information");
System.out.println("--------------------");
System.out.println("(Note: there may be multiple movies w/the same name.)");
System.out.println("");
System.out.println("Movie Name Key : " + movieNameKey.toString());
// Will loop over all movies with the same name
while (keyIter.hasNext()) {
keyValue = keyIter.next();
// the value is the movie id
value = keyValue.getValue();
movieIdStr = new String(value.getValue());
// get the movieid key for this movieid value
movieIdKey = getMovieKey(movieIdStr, KeyConstant.MOVIE_TABLE);
long start = Calendar.getInstance().getTimeInMillis();
ValueVersion vv = kvstore.get(movieIdKey);
long elapsed = Calendar.getInstance().getTimeInMillis() - start;
// Get the information about the movie
movieTO = movieDAO.getMovieTO(vv.getValue());
System.out.println("Movie Name Value : " + movieIdStr);
System.out.println("");
System.out.println("Movie ID Key : " + movieIdKey.toString());
System.out.println("Movie ID Value : " + movieTO.getMovieJsonTxt());
System.out.println();
System.out.println("elapsed: " + elapsed + "ms");
System.out.println("");
snippet = snippet + " movieIdKey = Key.fromString(\"" + movieIdKey.toString() + "\");\n";
snippet = snippet + " movieIdValue = kvstore.get(movieIdKey);\n";
} //EOF while
System.out.println("snippet:");
System.out.println(" movieNameKey = Key.fromString(\"" + movieNameKey.toString() + "\");");
System.out.println(" movieNameVal = kvstore.get(movieNameKey);");
System.out.println();
System.out.println(snippet);
}