void update(TableUpdates result, DatabaseSchema dbSchema);
- void exception(Throwable t);
+ void exception(Throwable throwable);
}
import java.io.Serializable;
-public class MonitorHandle implements Serializable{
- String id;
+public class MonitorHandle implements Serializable {
+ String id;
public MonitorHandle(String id) {
this.id = id;
* handle is used to later cancel ({@link #cancelMonitor(MonitorHandle)}) the monitor.
* @param callback receives the monitor response
*/
- public <E extends TableSchema<E>> TableUpdates monitor(DatabaseSchema schema, List<MonitorRequest<E>> monitorRequests,
- MonitorCallBack callback);
+ public <E extends TableSchema<E>> TableUpdates monitor(DatabaseSchema schema,
+ List<MonitorRequest<E>> monitorRequests,
+ MonitorCallBack callback);
/**
* Cancels an existing monitor method.
public void disconnect();
- public DatabaseSchema getDatabaseSchema (String dbName);
+ public DatabaseSchema getDatabaseSchema(String dbName);
/**
* User friendly convenient methods that make use of TyperUtils.getTypedRowWrapper to create a Typed Row Proxy
* User friendly convenient method to get a Typed Row Proxy given a Typed Table Class and the Row to be wrapped.
*
* @param klazz Typed Interface
- * @param row The actual Row that the wrapper is operating on. It can be null if the caller is just interested in getting ColumnSchema.
+ * @param row The actual Row that the wrapper is operating on. It can be null if the caller
+ * is just interested in getting ColumnSchema.
* @return Proxy wrapper for the actual raw Row class.
*/
- public <T extends TypedBaseTable<?>> T getTypedRowWrapper(final Class<T> klazz, final Row<GenericTableSchema> row);
+ public <T extends TypedBaseTable<?>> T getTypedRowWrapper(final Class<T> klazz,
+ final Row<GenericTableSchema> row);
}
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
-@XmlRootElement(name="Connection")
+@XmlRootElement(name = "Connection")
public class OvsdbConnectionInfo {
public enum ConnectionType {
ACTIVE, PASSIVE
this.type = type;
}
- @XmlElement(name="remoteAddress")
+ @XmlElement(name = "remoteAddress")
public InetAddress getRemoteAddress() {
return ((InetSocketAddress)channel.remoteAddress()).getAddress();
}
- @XmlElement(name="remotePort")
+ @XmlElement(name = "remotePort")
public int getRemotePort() {
return ((InetSocketAddress)channel.remoteAddress()).getPort();
}
- @XmlElement(name="localAddress")
+ @XmlElement(name = "localAddress")
public InetAddress getLocalAddress() {
return ((InetSocketAddress)channel.localAddress()).getAddress();
}
- @XmlElement(name="localPort")
+ @XmlElement(name = "localPort")
public int getLocalPort() {
return ((InetSocketAddress)channel.localAddress()).getPort();
}
- @XmlElement(name="connectionType")
+ @XmlElement(name = "connectionType")
public ConnectionType getType() {
return type;
}
- @XmlElement(name="clientCertificate")
+ @XmlElement(name = "clientCertificate")
public Certificate getCertificate() throws SSLPeerUnverifiedException {
SslHandler sslHandler = (SslHandler) channel.pipeline().get("ssl");
if (sslHandler != null) {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
OvsdbConnectionInfo other = (OvsdbConnectionInfo) obj;
if (channel == null) {
- if (other.channel != null)
+ if (other.channel != null) {
return false;
+ }
} else if (!getRemoteAddress().equals(other.getRemoteAddress())) {
return false;
} else if (!getLocalAddress().equals(other.getLocalAddress())) {
} else if (getLocalPort() != other.getLocalPort()) {
return false;
}
- if (type != other.type)
+ if (type != other.type) {
return false;
+ }
return true;
}
@Override
public String toString() {
- return "ConnectionInfo [Remote-address=" + this.getRemoteAddress().getHostAddress() +
- ", Remote-port=" + this.getRemotePort() +
- ", Local-address" + this.getLocalAddress().getHostAddress() +
- ", Local-port=" + this.getLocalPort() +
- ", type=" + type + "]";
+ return "ConnectionInfo [Remote-address=" + this.getRemoteAddress().getHostAddress()
+ + ", Remote-port=" + this.getRemotePort()
+ + ", Local-address" + this.getLocalAddress().getHostAddress()
+ + ", Local-port=" + this.getLocalPort()
+ + ", type=" + type + "]";
}
}
* BadSchema exception is thrown when the received schema is invalid
*/
public class BadSchemaException extends RuntimeException {
- public BadSchemaException(String message){
+ public BadSchemaException(String message) {
super(message);
}
- public BadSchemaException(String message, Throwable cause){
+ public BadSchemaException(String message, Throwable cause) {
super(message, cause);
}
*/
public class ColumnSchemaNotFoundException extends RuntimeException {
- public ColumnSchemaNotFoundException(String message){
+ public ColumnSchemaNotFoundException(String message) {
super(message);
}
super(message, cause);
}
- public static String createMessage(String columnName, String tableName){
- String message = "Unable to locate ColumnSchema for "+ columnName + " in "+ tableName;
+ public static String createMessage(String columnName, String tableName) {
+ String message = "Unable to locate ColumnSchema for " + columnName + " in " + tableName;
return message;
}
private final String actual;
public InvalidEncodingException(String actual, String message) {
- super(message);
- this.actual = actual;
- }
+ super(message);
+ this.actual = actual;
+ }
public String getActual() {
return actual;
super(message);
}
- public SchemaVersionMismatchException(String message, Throwable cause){
+ public SchemaVersionMismatchException(String message, Throwable cause) {
super(message, cause);
}
public static String createMessage(Version currentVersion, Version requiredVersion) {
- String message = "The schema version used to access this Table/Column does not match the required version.\n" +
- "Current Version: " + currentVersion.toString() + "\n";
+ String message =
+ "The schema version used to access this Table/Column does not match the required version.\n"
+ + "Current Version: " + currentVersion.toString() + "\n";
if (currentVersion.compareTo(requiredVersion) > 1) {
message += "Removed in Version: " + requiredVersion.toString();
*/
public class TableSchemaNotFoundException extends RuntimeException {
- public TableSchemaNotFoundException(String message){
+ public TableSchemaNotFoundException(String message) {
super(message);
}
super(message, cause);
}
- public static String createMessage(String tableName, String schemaName){
- String message = "Unable to locate TableSchema for "+ tableName + " in "+ schemaName;
+ public static String createMessage(String tableName, String schemaName) {
+ String message = "Unable to locate TableSchema for " + tableName + " in " + schemaName;
return message;
}
*/
public class TyperException extends RuntimeException {
- public TyperException(String message){
+ public TyperException(String message) {
super(message);
}
* This exception is thrown when a result does not meet any of the known formats in RFC7047
*/
public class UnexpectedResultException extends RuntimeException {
- public UnexpectedResultException(String message){
+ public UnexpectedResultException(String message) {
super(message);
}
public class UnsupportedArgumentException extends RuntimeException {
- public UnsupportedArgumentException(String message){
+ public UnsupportedArgumentException(String message) {
super(message);
}
- public UnsupportedArgumentException(String message, Throwable cause){
- super(message, cause);
- }
+ public UnsupportedArgumentException(String message, Throwable cause) {
+ super(message, cause);
+ }
}
public class ChannelConnectionHandler implements ChannelFutureListener {
OvsdbClient client;
- public ChannelConnectionHandler (OvsdbClient client) {
+ public ChannelConnectionHandler(OvsdbClient client) {
this.client = client;
}
@Override
public class FutureTransformUtils {
private static final ObjectMapper objectMapper = new ObjectMapper();
- public final static ListenableFuture<List<OperationResult>> transformTransactResponse
- (ListenableFuture<List<JsonNode>> transactResponseFuture, final List<Operation> operations) {
+ public static final ListenableFuture<List<OperationResult>> transformTransactResponse(
+ ListenableFuture<List<JsonNode>> transactResponseFuture, final List<Operation> operations) {
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return Futures.transform(transactResponseFuture, new Function<List<JsonNode>, List<OperationResult>>() {
@Override
public List<OperationResult> apply(List<JsonNode> jsonNodes) {
final List<OperationResult> operationResults = new ArrayList<>();
- for (int i = 0; i < jsonNodes.size(); i++) {
- JsonNode jsonNode = jsonNodes.get(i);
+ for (int index = 0; index < jsonNodes.size(); index++) {
+ JsonNode jsonNode = jsonNodes.get(index);
OperationResult or;
if (jsonNode != null && jsonNode.size() > 0) {
/*
* json elements than the transaction operation request.
* Also handle that case by checking for i < operations.size().
*/
- if (i < operations.size()) {
- Operation op = operations.get(i);
+ if (index < operations.size()) {
+ Operation op = operations.get(index);
switch (op.getOp()) {
- case "select":
- or = new OperationResult();
- or.setRows(op.getTableSchema().createRows(jsonNode));
- break;
+ case "select":
+ or = new OperationResult();
+ or.setRows(op.getTableSchema().createRows(jsonNode));
+ break;
- default:
- or = objectMapper.convertValue(jsonNode, OperationResult.class);
+ default:
+ or = objectMapper.convertValue(jsonNode, OperationResult.class);
- break;
+ break;
}
} else {
or = objectMapper.convertValue(jsonNode, OperationResult.class);
logger.info("callback received with context {}, but no known handler. Ignoring!", key);
return;
}
- TableUpdates updates = _transformingCallback(updateNotification.getUpdates(), callbackContext.schema);
+ TableUpdates updates = transformingCallback(updateNotification.getUpdates(),
+ callbackContext.schema);
monitorCallBack.update(updates, callbackContext.schema);
}
}
- protected TableUpdates _transformingCallback(JsonNode tableUpdatesJson, DatabaseSchema dbSchema) {
+ protected TableUpdates transformingCallback(JsonNode tableUpdatesJson, DatabaseSchema dbSchema) {
//todo(ashwin): we should move all the JSON parsing logic to a utility class
if (tableUpdatesJson instanceof ObjectNode) {
Map<String, TableUpdate> tableUpdateMap = Maps.newHashMap();
ObjectNode updatesJson = (ObjectNode) tableUpdatesJson;
- for (Iterator<Map.Entry<String,JsonNode>> itr = updatesJson.fields(); itr.hasNext();){
+ for (Iterator<Map.Entry<String,JsonNode>> itr = updatesJson.fields(); itr.hasNext();) {
Map.Entry<String, JsonNode> entry = itr.next();
DatabaseSchema databaseSchema = this.schema.get(dbSchema.getName());
//todo, we may not need transactionbuilder if we can have JSON objects
TransactBuilder builder = new TransactBuilder(dbSchema);
- for (Operation o : operations) {
- builder.addOperation(o);
+ for (Operation operation : operations) {
+ builder.addOperation(operation);
}
return FutureTransformUtils.transformTransactResponse(rpc.transact(builder), operations);
} catch (InterruptedException | ExecutionException e) {
return null;
}
- TableUpdates updates = _transformingCallback(result, dbSchema);
+ TableUpdates updates = transformingCallback(result, dbSchema);
return updates;
}
@Override
public DatabaseSchema apply(Map<String, DatabaseSchema> result) {
if (result.containsKey(database)) {
- DatabaseSchema s = result.get(database);
- s.populateInternallyGeneratedColumns();
- OvsdbClientImpl.this.schema.put(database, s);
- return s;
+ DatabaseSchema dbSchema = result.get(database);
+ dbSchema.populateInternallyGeneratedColumns();
+ OvsdbClientImpl.this.schema.put(database, dbSchema);
+ return dbSchema;
} else {
return null;
}
private ListenableFuture<Map<String, DatabaseSchema>> getSchemaFromDevice(final List<String> dbNames) {
Map<String, DatabaseSchema> schema = Maps.newHashMap();
SettableFuture<Map<String, DatabaseSchema>> future = SettableFuture.create();
- _populateSchema(dbNames, schema, future);
+ populateSchema(dbNames, schema, future);
return future;
}
- private void _populateSchema(final List<String> dbNames,
+ private void populateSchema(final List<String> dbNames,
final Map<String, DatabaseSchema> schema,
final SettableFuture<Map<String, DatabaseSchema>> sfuture) {
try {
schema.put(dbNames.get(0), DatabaseSchema.fromJson(dbNames.get(0), jsonNode));
if (schema.size() > 1 && !sfuture.isCancelled()) {
- _populateSchema(dbNames.subList(1, dbNames.size()), schema, sfuture);
+ populateSchema(dbNames.subList(1, dbNames.size()), schema, sfuture);
} else if (schema.size() == 1) {
sfuture.set(schema);
}
}
@Override
- public DatabaseSchema getDatabaseSchema (String dbName) {
+ public DatabaseSchema getDatabaseSchema(String dbName) {
return schema.get(dbName);
}
* @param klazz Typed Class that represents a Table
* @return DatabaseSchema that matches a Typed Table Class
*/
- private <T> DatabaseSchema getDatabaseSchemaForTypedTable (Class <T> klazz) {
+ private <T> DatabaseSchema getDatabaseSchemaForTypedTable(Class<T> klazz) {
TypedTable typedTable = klazz.getAnnotation(TypedTable.class);
if (typedTable != null) {
return this.getDatabaseSchema(typedTable.database());
* User friendly convenient method to get a Typed Row Proxy given a Typed Table Class and the Row to be wrapped.
*
* @param klazz Typed Interface
- * @param row The actual Row that the wrapper is operating on. It can be null if the caller is just interested in getting ColumnSchema.
+ * @param row The actual Row that the wrapper is operating on.
+ * It can be null if the caller is just interested in getting ColumnSchema.
* @return Proxy wrapper for the actual raw Row class.
*/
@Override
*/
public class OvsdbConnectionService implements OvsdbConnection {
private static final Logger logger = LoggerFactory.getLogger(OvsdbConnectionService.class);
- private final static int NUM_THREADS = 3;
+ private static final int NUM_THREADS = 3;
// Singleton Service object that can be used in Non-OSGi environment
private static Set<OvsdbConnectionListener> connectionListeners = Sets.newHashSet();
private static Map<OvsdbClient, Channel> connections = Maps.newHashMap();
private static OvsdbConnection connectionService;
- private volatile static boolean singletonCreated = false;
+ private static volatile boolean singletonCreated = false;
public static OvsdbConnection getService() {
if (connectionService == null) {
if (sslContext != null) {
/* First add ssl handler if ssl context is given */
SSLEngine engine =
- sslContext.createSSLEngine(address.toString(), port);
+ sslContext.createSSLEngine(address.toString(), port);
engine.setUseClientMode(true);
channel.pipeline().addLast("ssl", new SslHandler(engine));
}
ChannelFuture future = bootstrap.connect(address, port).sync();
Channel channel = future.channel();
- OvsdbClient client = getChannelClient(channel, ConnectionType.ACTIVE, Executors.newFixedThreadPool(NUM_THREADS));
+ OvsdbClient client = getChannelClient(channel, ConnectionType.ACTIVE,
+ Executors.newFixedThreadPool(NUM_THREADS));
return client;
} catch (InterruptedException e) {
System.out.println("Thread was interrupted during connect");
@Override
public void disconnect(OvsdbClient client) {
- if (client == null) return;
+ if (client == null) {
+ return;
+ }
Channel channel = connections.get(client);
if (channel != null) {
channel.disconnect();
* be overridden using the ovsdb.listenPort system property.
*/
@Override
- synchronized
- public boolean startOvsdbManager(final int ovsdbListenPort) {
+ public synchronized boolean startOvsdbManager(final int ovsdbListenPort) {
if (!singletonCreated) {
new Thread() {
@Override
* 6640 which can be overridden using the ovsdb.listenPort system property.
*/
@Override
- synchronized
- public boolean startOvsdbManagerWithSsl(final int ovsdbListenPort,
+ public synchronized boolean startOvsdbManagerWithSsl(final int ovsdbListenPort,
final SSLContext sslContext) {
if (!singletonCreated) {
new Thread() {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
- ServerBootstrap b = new ServerBootstrap();
- b.group(bossGroup, workerGroup)
- .channel(NioServerSocketChannel.class)
- .option(ChannelOption.SO_BACKLOG, 100)
- .handler(new LoggingHandler(LogLevel.INFO))
- .childHandler(new ChannelInitializer<SocketChannel>() {
- @Override
- public void initChannel(SocketChannel channel) throws Exception {
- logger.debug("New Passive channel created : "+ channel.toString());
- if (sslContext != null) {
- /* Add SSL handler first if SSL context is provided */
- SSLEngine engine = sslContext.createSSLEngine();
- engine.setUseClientMode(false); // work in a server mode
- engine.setNeedClientAuth(true); // need client authentication
- channel.pipeline().addLast("ssl", new SslHandler(engine));
- }
+ ServerBootstrap serverBootstrap = new ServerBootstrap();
+ serverBootstrap.group(bossGroup, workerGroup)
+ .channel(NioServerSocketChannel.class)
+ .option(ChannelOption.SO_BACKLOG, 100)
+ .handler(new LoggingHandler(LogLevel.INFO))
+ .childHandler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ public void initChannel(SocketChannel channel) throws Exception {
+ logger.debug("New Passive channel created : {}", channel);
+ if (sslContext != null) {
+ /* Add SSL handler first if SSL context is provided */
+ SSLEngine engine = sslContext.createSSLEngine();
+ engine.setUseClientMode(false); // work in a server mode
+ engine.setNeedClientAuth(true); // need client authentication
+ channel.pipeline().addLast("ssl", new SslHandler(engine));
+ }
- channel.pipeline().addLast(
- new JsonRpcDecoder(100000),
- new StringEncoder(CharsetUtil.UTF_8),
- new ExceptionHandler());
+ channel.pipeline().addLast(
+ new JsonRpcDecoder(100000),
+ new StringEncoder(CharsetUtil.UTF_8),
+ new ExceptionHandler());
- handleNewPassiveConnection(channel);
- }
- });
- b.option(ChannelOption.TCP_NODELAY, true);
- b.option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(65535, 65535, 65535));
+ handleNewPassiveConnection(channel);
+ }
+ });
+ serverBootstrap.option(ChannelOption.TCP_NODELAY, true);
+ serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR,
+ new AdaptiveRecvByteBufAllocator(65535, 65535, 65535));
// Start the server.
- ChannelFuture f = b.bind(port).sync();
- Channel serverListenChannel = f.channel();
+ ChannelFuture channelFuture = serverBootstrap.bind(port).sync();
+ Channel serverListenChannel = channelFuture.channel();
// Wait until the server socket is closed.
serverListenChannel.closeFuture().sync();
} catch (InterruptedException e) {
executorService.execute(new Runnable() {
@Override
public void run() {
- OvsdbClient client = getChannelClient(channel, ConnectionType.PASSIVE, Executors.newFixedThreadPool(NUM_THREADS));
+ OvsdbClient client = getChannelClient(channel, ConnectionType.PASSIVE,
+ Executors.newFixedThreadPool(NUM_THREADS));
SslHandler sslHandler = (SslHandler) channel.pipeline().get("ssl");
if (sslHandler != null) {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if ((cause instanceof InvalidEncodingException)
- || (cause instanceof TooLongFrameException)){
+ || (cause instanceof TooLongFrameException)) {
ctx.channel().disconnect();
}
/* In cases where a connection is quickly established and the closed
Catch the IOException and close the channel
*/
- if (cause instanceof IOException){
+ if (cause instanceof IOException) {
ctx.channel().close();
}
}
}
}
- int i = lastRecordBytes + buf.readerIndex();
+ int index = lastRecordBytes + buf.readerIndex();
- for (; i < buf.writerIndex(); i++) {
- switch (buf.getByte(i)) {
+ for (; index < buf.writerIndex(); index++) {
+ switch (buf.getByte(index)) {
case '{':
- if (!inS) leftCurlies++;
+ if (!inS) {
+ leftCurlies++;
+ }
break;
case '}':
- if (!inS) rightCurlies++;
+ if (!inS) {
+ rightCurlies++;
+ }
break;
- case '"': {
- if (buf.getByte(i - 1) != '\\') inS = !inS;
+ case '"':
+ if (buf.getByte(index - 1) != '\\') {
+ inS = !inS;
+ }
+ break;
+ default:
break;
- }
}
if (leftCurlies != 0 && leftCurlies == rightCurlies && !inS) {
- ByteBuf slice = buf.readSlice(1 + i - buf.readerIndex());
+ ByteBuf slice = buf.readSlice(1 + index - buf.readerIndex());
JsonParser jp = jacksonJsonFactory.createParser(new ByteBufInputStream(slice));
JsonNode root = jp.readValueAsTree();
out.add(root);
break;
}
- if (i - buf.readerIndex() >= maxFrameLength) {
- fail(ctx, i - buf.readerIndex());
+ if (index - buf.readerIndex() >= maxFrameLength) {
+ fail(ctx, index - buf.readerIndex());
}
}
// end of stream, save the incomplete record index to avoid reexamining the whole on next run
- if (i >= buf.writerIndex()) {
+ if (index >= buf.writerIndex()) {
lastRecordBytes = buf.readableBytes();
return;
}
return recordsRead;
}
- private static void skipSpaces(ByteBuf b) throws IOException {
- while (b.isReadable()) {
- int ch = b.getByte(b.readerIndex()) & 0xFF;
+ private static void skipSpaces(ByteBuf byteBuf) throws IOException {
+ while (byteBuf.isReadable()) {
+ int ch = byteBuf.getByte(byteBuf.readerIndex()) & 0xFF;
if (!(ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t')) {
return;
} else {
- b.readByte(); //move the read index
+ byteBuf.readByte(); //move the read index
}
}
}
}
private void print(ByteBuf buf, int startPos, int chars, String message) {
- if (null == message) message = "";
+ if (null == message) {
+ message = "";
+ }
if (startPos > buf.writerIndex()) {
logger.trace("startPos out of bounds");
}
- byte[] b = new byte[startPos + chars <= buf.writerIndex() ? chars : buf.writerIndex() - startPos];
- buf.getBytes(startPos, b);
- logger.trace("{} ={}", message, new String(b));
+ byte[] bytes = new byte[startPos + chars <= buf.writerIndex() ? chars : buf.writerIndex() - startPos];
+ buf.getBytes(startPos, bytes);
+ logger.trace("{} ={}", message, new String(bytes));
}
// copied from Netty decoder
if (frameLength > 0) {
ctx.fireExceptionCaught(
new TooLongFrameException(
- "frame length exceeds " + maxFrameLength +
- ": " + frameLength + " - discarded"));
+ "frame length exceeds " + maxFrameLength + ": " + frameLength + " - discarded"));
} else {
ctx.fireExceptionCaught(
new TooLongFrameException(
- "frame length exceeds " + maxFrameLength +
- " - discarding"));
+ "frame length exceeds " + maxFrameLength + " - discarding"));
}
}
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getName().equals(OvsdbRPC.REGISTER_CALLBACK_METHOD)) {
- if ((args == null) || args.length != 1 || !(args[0] instanceof OvsdbRPC.Callback)) return false;
+ if ((args == null) || args.length != 1 || !(args[0] instanceof OvsdbRPC.Callback)) {
+ return false;
+ }
requestCallbacks.put(context, (OvsdbRPC.Callback)args[0]);
return true;
}
}
}
- String s = objectMapper.writeValueAsString(request);
- logger.trace("getClient Request : {}", s);
+ String requestString = objectMapper.writeValueAsString(request);
+ logger.trace("getClient Request : {}", requestString);
SettableFuture<Object> sf = SettableFuture.create();
methodContext.put(request.getId(), new CallContext(request, method, sf));
- nettyChannel.writeAndFlush(s);
+ nettyChannel.writeAndFlush(requestString);
return sf;
}
logger.trace("Response : {}", response.toString());
CallContext returnCtxt = methodContext.get(response.get("id").asText());
- if (returnCtxt == null) return;
+ if (returnCtxt == null) {
+ return;
+ }
if (ListenableFuture.class == returnCtxt.getMethod().getReturnType()) {
TypeToken<?> retType = TypeToken.of(
returnCtxt.getMethod().getGenericReturnType())
.resolveType(ListenableFuture.class.getMethod("get").getGenericReturnType());
- JavaType javaType = TypeFactory.defaultInstance().constructType (retType.getType());
+ JavaType javaType = TypeFactory.defaultInstance().constructType(retType.getType());
JsonNode result = response.get("result");
Object result1 = objectMapper.convertValue(result, javaType);
OvsdbRPC.Callback callback = requestCallbacks.get(context);
if (callback != null) {
Method[] methods = callback.getClass().getDeclaredMethods();
- for (Method m : methods) {
- if (m.getName().equals(request.getMethod())) {
- Class<?>[] parameters = m.getParameterTypes();
+ for (Method method : methods) {
+ if (method.getName().equals(request.getMethod())) {
+ Class<?>[] parameters = method.getParameterTypes();
JsonNode params = requestJson.get("params");
Object param = objectMapper.convertValue(params, parameters[1]);
try {
- Invokable from = Invokable.from(m);
+ Invokable from = Invokable.from(method);
from.setAccessible(true);
from.invoke(callback, context, param);
} catch (IllegalAccessException | InvocationTargetException e) {
- logger.error("Unable to invoke callback " + m.getName(), e);
+ logger.error("Unable to invoke callback " + method.getName(), e);
}
return;
}
if (request.getMethod().equals("echo")) {
JsonRpc10Response response = new JsonRpc10Response(request.getId());
response.setError(null);
- String s = null;
+ String jsonString = null;
try {
- s = objectMapper.writeValueAsString(response);
- nettyChannel.writeAndFlush(s);
+ jsonString = objectMapper.writeValueAsString(response);
+ nettyChannel.writeAndFlush(jsonString);
} catch (JsonProcessingException e) {
- logger.error("Exception while processing JSON string " + s, e );
+ logger.error("Exception while processing JSON string " + jsonString, e );
}
return;
}
ChannelRead is a method invoked during Netty message receive event.
The only sane thing we can do is to print a meaningful error message.
*/
- logger.error("NoSuchMethodException when handling "+msg.toString(), e);
+ logger.error("NoSuchMethodException when handling {}", msg, e);
}
} else if (jsonNode.hasNonNull("method")) {
if (jsonNode.has("id") && !Strings.isNullOrEmpty(jsonNode.get("id").asText())) {
static ObjectWriter prettyWriter = mapper.writerWithDefaultPrettyPrinter();
- public static String prettyString(Object jsonNode){
+ public static String prettyString(Object jsonNode) {
try {
return prettyWriter.writeValueAsString(jsonNode);
} catch (JsonProcessingException e) {
import java.util.List;
public interface Params {
- List<Object> params();
+ List<Object> params();
}
/*
- * Copyright (C) 2013 EBay Software Foundation
+ * Copyright (C) 2013 EBay Software Foundation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Authors : Ashwin Raveendran, Madhu Venugopal
*/
package org.opendaylight.ovsdb.lib.message;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.common.collect.Sets;
+/**
+ * @author Ashwin Raveendran
+ * @author Madhu Venugopal
+ * @param <E> monitor
+ */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MonitorRequest<E extends TableSchema<E>> {
@JsonIgnore String tableName;
}
public MonitorRequestBuilder<E> addColumns(List<ColumnSchema<E, ?>> columns) {
- for(ColumnSchema<E, ?> schema : columns) {
+ for (ColumnSchema<E, ?> schema : columns) {
this.addColumn(schema);
}
return this;
public static final String REGISTER_CALLBACK_METHOD = "registerCallback";
//public ListenableFuture<DatabaseSchema> get_schema(List<String> db_names);
- public ListenableFuture<JsonNode> get_schema(List<String> db_names);
+ public ListenableFuture<JsonNode> get_schema(List<String> dbNames);
public ListenableFuture<List<String>> echo();
public ListenableFuture<Response> cancel(String id);
- public ListenableFuture<Object> monitor_cancel(Object json_value);
+ public ListenableFuture<Object> monitor_cancel(Object jsonValue);
public ListenableFuture<Object> lock(List<String> id);
return rows;
}
- public class RowUpdate <E extends TableSchema<E>> {
+ public class RowUpdate<E extends TableSchema<E>> {
private UUID uuid;
- private Row<E> old;
- private Row<E> new_;
+ private Row<E> oldRow;
+ private Row<E> newRow;
- public RowUpdate (UUID uuid, Row<E> old, Row<E> new_) {
+ public RowUpdate(UUID uuid, Row<E> oldRow, Row<E> newRow) {
this.uuid = uuid;
- this.old = old;
- this.new_ = new_;
+ this.oldRow = oldRow;
+ this.newRow = newRow;
}
public UUID getUuid() {
}
public Row<E> getOld() {
- return old;
+ return oldRow;
}
- public void setOld(Row<E> old) {
- this.old = old;
+ public void setOld(Row<E> oldRow) {
+ this.oldRow = oldRow;
}
public Row<E> getNew() {
- return new_;
+ return newRow;
}
- public void setNew(Row<E> new_) {
- this.new_ = new_;
+ public void setNew(Row<E> newRow) {
+ this.newRow = newRow;
}
@Override
public String toString() {
- return "RowUpdate [uuid=" + uuid + ", old=" + old + ", new_=" + new_
+ return "RowUpdate [uuid=" + uuid + ", oldRow=" + oldRow + ", newRow=" + newRow
+ "]";
}
}
rows = Maps.newHashMap();
}
- public void addRow(UUID uuid, Row<E> old, Row<E> new_) {
- rows.put(uuid, new RowUpdate<E>(uuid, old, new_));
+ public void addRow(UUID uuid, Row<E> oldRow, Row<E> newRow) {
+ rows.put(uuid, new RowUpdate<E>(uuid, oldRow, newRow));
}
public Row<E> getOld(UUID uuid) {
RowUpdate<E> rowUpdate = rows.get(uuid);
- if (rowUpdate == null) return null;
+ if (rowUpdate == null) {
+ return null;
+ }
return rowUpdate.getOld();
}
public Row<E> getNew(UUID uuid) {
RowUpdate<E> rowUpdate = rows.get(uuid);
- if (rowUpdate == null) return null;
+ if (rowUpdate == null) {
+ return null;
+ }
return rowUpdate.getNew();
}
List<Operation> requests = Lists.newArrayList();
DatabaseSchema dbSchema;
- public TransactBuilder (DatabaseSchema dbSchema) {
+ public TransactBuilder(DatabaseSchema dbSchema) {
this.dbSchema = dbSchema;
}
return lists;
}
- public void addOperations (List<Operation> o) {
- requests.addAll(o);
+ public void addOperations(List<Operation> operation) {
+ requests.addAll(operation);
}
- public void addOperation (Operation o) {
- requests.add(o);
+ public void addOperation(Operation operation) {
+ requests.add(operation);
}
}
private ColumnSchema<E, D> schema;
private D data;
- public Column(ColumnSchema<E, D> schema, D d) {
+ public Column(ColumnSchema<E, D> schema, D data) {
this.schema = schema;
- this.data = d;
+ this.data = data;
}
public <E extends TableSchema<E>, T> T getData(ColumnSchema<E, T> schema) {
@Override
public String toString() {
- return "["+schema.getName() + "=" + data + "]";
+ return "[" + schema.getName() + "=" + data + "]";
}
@Override
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Column other = (Column) obj;
if (data == null) {
- if (other.data != null)
+ if (other.data != null) {
return false;
- } else if (!data.equals(other.data))
+ }
+ } else if (!data.equals(other.data)) {
return false;
+ }
if (schema == null) {
- if (other.schema != null)
+ if (other.schema != null) {
return false;
- } else if (!schema.equals(other.schema))
+ }
+ } else if (!schema.equals(other.schema)) {
return false;
+ }
return true;
}
}
return target;
}
- public static<K,V> OvsdbMap<K,V> fromMap(Map<K, V> value) {
+ public static <K,V> OvsdbMap<K,V> fromMap(Map<K, V> value) {
return new OvsdbMap<K,V>(value);
}
}
}
public OvsdbSet(Set<T> backing) {
- this.target = backing;
+ this.target = backing;
}
@Override
return target;
}
- public static<D> OvsdbSet<D> fromSet(Set<D> value) {
+ public static <D> OvsdbSet<D> fromSet(Set<D> value) {
return new OvsdbSet<>(value);
}
}
*/
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Row other = (Row) obj;
if (columns == null) {
- if (other.columns != null)
+ if (other.columns != null) {
return false;
- } else if (!columns.equals(other.columns))
+ }
+ } else if (!columns.equals(other.columns)) {
return false;
+ }
return true;
}
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
UUID other = (UUID) obj;
if (val == null) {
- if (other.val != null)
+ if (other.val != null) {
return false;
- } else if (!val.equals(other.val))
+ }
+ } else if (!val.equals(other.val)) {
return false;
+ }
return true;
}
}
public static final Version NULL = new Version(0,0,0);
public static final String NULL_VERSION_STRING = "0.0.0";
- public static Version fromString(String version){
+ public static Version fromString(String version) {
final Matcher matcher = Version.PATTERN.matcher(version);
if (!matcher.find()) {
- throw new IllegalArgumentException("<"+version+"> does not match format "+Version.FORMAT);
+ throw new IllegalArgumentException("<" + version + "> does not match format " + Version.FORMAT);
}
int major = Integer.valueOf(matcher.group(1));
int minor = Integer.valueOf(matcher.group(2));
return new Version(major, minor, patch);
}
- public String toString(){
+ public String toString() {
return "" + major + "." + minor + "." + patch;
}
// ToDo: While format is X.X.X semantics are schema dependent.
// Therefore we should allow equals to be overridden by the schema
@Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ public boolean equals(Object object) {
+ if (this == object) {
+ return true;
+ }
+ if (object == null || getClass() != object.getClass()) {
+ return false;
+ }
- Version version = (Version) o;
+ Version version = (Version) object;
- if (major != version.major) return false;
- if (minor != version.minor) return false;
- if (patch != version.patch) return false;
+ if (major != version.major) {
+ return false;
+ }
+ if (minor != version.minor) {
+ return false;
+ }
+ if (patch != version.patch) {
+ return false;
+ }
return true;
}
// ToDo: While format is X.X.X semantics are schema dependent
// Therefore we should allow compareTo to be overridden by the schema
@Override
- public int compareTo(Version o) {
- if (this.equals(o)) return 0;
- if (this.major > o.major) return 1;
- if (this.major < o.major) return -1;
+ public int compareTo(Version version) {
+ if (this.equals(version)) {
+ return 0;
+ }
+ if (this.major > version.major) {
+ return 1;
+ }
+ if (this.major < version.major) {
+ return -1;
+ }
// major is equal
- if (this.minor > o.minor) return 1;
- if (this.minor < o.minor) return -1;
+ if (this.minor > version.minor) {
+ return 1;
+ }
+ if (this.minor < version.minor) {
+ return -1;
+ }
// minor is equal
- if (this.patch > o.patch) return 1;
+ if (this.patch > version.patch) {
+ return 1;
+ }
// must be less than
return -1;
}
}
case STRING:
return node.asText();
+ default:
+ break;
}
}
generator.writeString("map");
generator.writeStartArray();
Map<?,?> javaMap = map.delegate();
- for (Object t : javaMap.keySet()) {
+ for (Object set : javaMap.keySet()) {
generator.writeStartArray();
- generator.writeObject(t);
- generator.writeObject(javaMap.get(t));
+ generator.writeObject(set);
+ generator.writeObject(javaMap.get(set));
generator.writeEndArray();
}
generator.writeEndArray();
generator.writeString("set");
generator.writeStartArray();
Set<?> javaSet = set.delegate();
- for (Object t : javaSet) {
- generator.writeObject(t);
+ for (Object setObject : javaSet) {
+ generator.writeObject(setObject);
}
generator.writeEndArray();
generator.writeEndArray();
public class OvsdbTypesIdResolver implements TypeIdResolver {
- private JavaType baseType;
-
- @Override
- public void init(JavaType bt) {
- this.baseType = bt;
- }
-
- @Override
- public String idFromValue(Object value) {
- throw new UnsupportedOperationException("not yet done");
- }
-
- @Override
- public String idFromValueAndType(Object value, Class<?> suggestedType) {
- throw new UnsupportedOperationException("not yet done");
- }
-
- @Override
- public String idFromBaseType() {
- throw new UnsupportedOperationException("not yet done");
- }
-
- @Override
- public JavaType typeFromId(String id) {
- if ("set".equals(id)) {
- return TypeFactory.defaultInstance().constructCollectionType(OvsdbSet.class, Object.class);
- } else if ("uuid".equals(id) || "named-uuid".equals(id)) {
- return TypeFactory.defaultInstance().constructType(UUID.class);
- }
- return null;
- }
-
- @Override
- public JsonTypeInfo.Id getMechanism() {
- throw new UnsupportedOperationException("not yet done");
+ private JavaType baseType;
+
+ @Override
+ public void init(JavaType bt) {
+ this.baseType = bt;
+ }
+
+ @Override
+ public String idFromValue(Object value) {
+ throw new UnsupportedOperationException("not yet done");
+ }
+
+ @Override
+ public String idFromValueAndType(Object value, Class<?> suggestedType) {
+ throw new UnsupportedOperationException("not yet done");
+ }
+
+ @Override
+ public String idFromBaseType() {
+ throw new UnsupportedOperationException("not yet done");
+ }
+
+ @Override
+ public JavaType typeFromId(String id) {
+ if ("set".equals(id)) {
+ return TypeFactory.defaultInstance().constructCollectionType(OvsdbSet.class, Object.class);
+ } else if ("uuid".equals(id) || "named-uuid".equals(id)) {
+ return TypeFactory.defaultInstance().constructType(UUID.class);
}
- }
\ No newline at end of file
+ return null;
+ }
+
+ @Override
+ public JsonTypeInfo.Id getMechanism() {
+ throw new UnsupportedOperationException("not yet done");
+ }
+}
\ No newline at end of file
super(schema, DELETE);
}
- public Delete<E> on(TableSchema schema){
+ public Delete<E> on(TableSchema schema) {
return this;
}
private Map<String, Object> row = Maps.newHashMap();
- public Insert<E> on(TableSchema<E> schema){
+ public Insert<E> on(TableSchema<E> schema) {
this.setTableSchema(schema);
return this;
}
List<Condition> where = Lists.newArrayList();
private List<Mutation> mutations = Lists.newArrayList();
- public Mutate on(TableSchema schema){
+ public Mutate on(TableSchema schema) {
this.setTableSchema(schema);
return this;
}
super(schema, MUTATE);
}
- public <T extends TableSchema<T>, D> Mutate<E> addMutation(ColumnSchema<T, D> columnSchema, Mutator mutator, D value) {
+ public <T extends TableSchema<T>, D> Mutate<E> addMutation(ColumnSchema<T, D> columnSchema,
+ Mutator mutator, D value) {
columnSchema.validate(value);
Object untypedValue = columnSchema.getNormalizeData(value);
mutations.add(new Mutation(columnSchema.getName(), mutator, untypedValue));
List<Condition> where = Lists.newArrayList();
private List<String> columns = Lists.newArrayList();
- public Select on(TableSchema schema){
+ public Select on(TableSchema schema) {
this.setTableSchema(schema);
return this;
}
public class TransactionBuilder {
- private DatabaseSchema eDatabaseSchema;
+ private DatabaseSchema databaseSchema;
OvsdbClient ovs;
ArrayList<Operation> operations = Lists.newArrayList();
public TransactionBuilder(OvsdbClient ovs, DatabaseSchema schema) {
this.ovs = ovs;
- eDatabaseSchema = schema;
+ databaseSchema = schema;
}
public ArrayList<Operation> getOperations() {
}
public ListenableFuture<List<OperationResult>> execute() {
- return ovs.transact(eDatabaseSchema, operations);
+ return ovs.transact(databaseSchema, operations);
}
public DatabaseSchema getDatabaseSchema() {
- return eDatabaseSchema;
+ return databaseSchema;
}
}
super(schema, UPDATE);
}
- public Update<E> on(TableSchema schema){
+ public Update<E> on(TableSchema schema) {
return this;
}
.setInterface(OvsdbConnection.class.getName(), null)
.setImplementation(OvsdbConnectionService.class)
.add(createServiceDependency()
- .setService(OvsdbConnectionListener.class)
- .setCallbacks("registerConnectionListener", "unregisterConnectionListener")
- .setRequired(false)
+ .setService(OvsdbConnectionListener.class)
+ .setCallbacks("registerConnectionListener", "unregisterConnectionListener")
+ .setRequired(false)
)
);
}
public abstract class BaseType<E extends BaseType<E>> {
- private static BaseType[] types = new BaseType[]{
- new StringBaseType(),
- new IntegerBaseType(),
- new RealBaseType(),
- new BooleanBaseType(),
- new UuidBaseType(),
+ private static BaseType[] types = new BaseType[] {
+ new StringBaseType(),
+ new IntegerBaseType(),
+ new RealBaseType(),
+ new BooleanBaseType(),
+ new UuidBaseType(),
};
public static BaseType fromJson(JsonNode json, String keyorval) {
private void populateEnum(JsonNode node) {
if (node.has("enum")) {
- Set<Long> s = Sets.newHashSet();
+ Set<Long> enums = Sets.newHashSet();
JsonNode anEnum = node.get("enum").get(1);
- for (JsonNode n : anEnum) {
- s.add(n.asLong());
+ for (JsonNode enm : anEnum) {
+ enums.add(enm.asLong());
}
}
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
IntegerBaseType other = (IntegerBaseType) obj;
if (enums == null) {
- if (other.enums != null)
+ if (other.enums != null) {
return false;
- } else if (!enums.equals(other.enums))
+ }
+ } else if (!enums.equals(other.enums)) {
return false;
- if (max != other.max)
+ }
+ if (max != other.max) {
return false;
- if (min != other.min)
+ }
+ if (min != other.min) {
return false;
+ }
return true;
}
}
private void populateEnum(JsonNode node) {
if (node.has("enum")) {
- Set<Double> s = Sets.newHashSet();
+ Set<Double> enums = Sets.newHashSet();
JsonNode anEnum = node.get("enum").get(1);
- for (JsonNode n : anEnum) {
- s.add(n.asDouble());
+ for (JsonNode enm : anEnum) {
+ enums.add(enm.asDouble());
}
}
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
RealBaseType other = (RealBaseType) obj;
if (enums == null) {
- if (other.enums != null)
+ if (other.enums != null) {
return false;
- } else if (!enums.equals(other.enums))
+ }
+ } else if (!enums.equals(other.enums)) {
return false;
- if (Double.doubleToLongBits(max) != Double
- .doubleToLongBits(other.max))
+ }
+ if (Double.doubleToLongBits(max) != Double.doubleToLongBits(other.max)) {
return false;
- if (Double.doubleToLongBits(min) != Double
- .doubleToLongBits(other.min))
+ }
+ if (Double.doubleToLongBits(min) != Double.doubleToLongBits(other.min)) {
return false;
+ }
return true;
}
}
private void populateEnum(StringBaseType baseType, JsonNode node) {
if (node.has("enum")) {
- Set<String> s = Sets.newHashSet();
+ Set<String> enums = Sets.newHashSet();
JsonNode enumVal = node.get("enum");
if (enumVal.isArray()) {
JsonNode anEnum = enumVal.get(1);
- for (JsonNode n : anEnum) {
- s.add(n.asText());
+ for (JsonNode enm : anEnum) {
+ enums.add(enm.asText());
}
} else if (enumVal.isTextual()) {
- s.add(enumVal.asText());
+ enums.add(enumVal.asText());
}
- baseType.setEnums(s);
+ baseType.setEnums(enums);
}
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
StringBaseType other = (StringBaseType) obj;
if (enums == null) {
- if (other.enums != null)
+ if (other.enums != null) {
return false;
- } else if (!enums.equals(other.enums))
+ }
+ } else if (!enums.equals(other.enums)) {
return false;
- if (maxLength != other.maxLength)
+ }
+ if (maxLength != other.maxLength) {
return false;
- if (minLength != other.minLength)
+ }
+ if (minLength != other.minLength) {
return false;
+ }
return true;
}
public static class UuidBaseType extends BaseType<UuidBaseType> {
- public static enum RefType {strong, weak}
+ public static enum RefType { strong, weak }
String refTable;
RefType refType;
@Override
public Object toValue(JsonNode value) {
- if(value.isArray()) {
+ if (value.isArray()) {
if (value.size() == 2) {
if (value.get(0).isTextual() && "uuid".equals(value.get(0).asText())) {
return new UUID(value.get(1).asText());
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
UuidBaseType other = (UuidBaseType) obj;
if (refTable == null) {
- if (other.refTable != null)
+ if (other.refTable != null) {
return false;
- } else if (!refTable.equals(other.refTable))
+ }
+ } else if (!refTable.equals(other.refTable)) {
return false;
- if (refType != other.refType)
+ }
+ if (refType != other.refType) {
return false;
+ }
return true;
}
}
return name;
}
- public ColumnType getType() { return type; }
+ public ColumnType getType() {
+ return type;
+ }
// --- Operations on the column ----------//
@Override
public String toString() {
- return "ColumnSchema{" +
- "name='" + name + '\'' +
- ", type=" + type +
- '}';
+ return "ColumnSchema{"
+ + "name='" + name + '\''
+ + ", type=" + type
+ + '}';
}
@Override
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
ColumnSchema other = (ColumnSchema) obj;
if (name == null) {
- if (other.name != null)
+ if (other.name != null) {
return false;
- } else if (!name.equals(other.name))
+ }
+ } else if (!name.equals(other.name)) {
return false;
+ }
if (type == null) {
- if (other.type != null)
+ if (other.type != null) {
return false;
- } else if (!type.equals(other.type))
+ }
+ } else if (!type.equals(other.type)) {
return false;
+ }
return true;
}
}
public D valueFromJson(JsonNode value) {
- return (D) this.getType().valueFromJson(value);
+ return (D) this.getType().valueFromJson(value);
}
public Object getNormalizeData(D value) {
this.max = max;
}
- private static ColumnType columns[] = new ColumnType[]{
- new AtomicColumnType(),
- new KeyValuedColumnType()
+ private static ColumnType[] columns = new ColumnType[] {
+ new AtomicColumnType(),
+ new KeyValuedColumnType()
};
/*
* Per RFC 7047, Section 3.2 <type> :
- * If "min" or "max" is not specified, each defaults to 1. If "max" is specified as "unlimited", then there is no specified maximum
- * number of elements, although the implementation will enforce some limit. After considering defaults, "min" must be exactly 0 or
+ * If "min" or "max" is not specified, each defaults to 1. If "max" is specified as "unlimited",
+ * then there is no specified maximum number of elements, although the implementation will
+ * enforce some limit. After considering defaults, "min" must be exactly 0 or
* exactly 1, "max" must be at least 1, and "max" must be greater than or equal to "min".
*
* If "min" and "max" are both 1 and "value" is not specified, the
@Override
public String toString() {
- return "ColumnType{" +
- "baseType=" + baseType +
- ", min=" + min +
- ", max=" + max +
- '}';
+ return "ColumnType{"
+ + "baseType=" + baseType
+ + ", min=" + min
+ + ", max=" + max
+ + '}';
}
@Override
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
ColumnType other = (ColumnType) obj;
if (baseType == null) {
- if (other.baseType != null)
+ if (other.baseType != null) {
return false;
- } else if (!baseType.equals(other.baseType))
+ }
+ } else if (!baseType.equals(other.baseType)) {
return false;
- if (max != other.max)
+ }
+ if (max != other.max) {
return false;
- if (min != other.min)
+ }
+ if (min != other.min) {
return false;
+ }
return true;
}
}
if ((node = json.get("max")) != null) {
- if (node.isNumber()){
+ if (node.isNumber()) {
atomicColumnType.setMax(node.asLong());
} else if ("unlimited".equals(node.asText())) {
atomicColumnType.setMax(Long.MAX_VALUE);
public Object valueFromJson(JsonNode value) {
if (isMultiValued()) {
OvsdbSet<Object> result = new OvsdbSet<Object>();
- if(value.isArray()) {
+ if (value.isArray()) {
if (value.size() == 2) {
if (value.get(0).isTextual() && "set".equals(value.get(0).asText())) {
- for(JsonNode node: value.get(1)) {
+ for (JsonNode node: value.get(1)) {
result.add(getBaseType().toValue(node));
}
} else {
}
if ((node = json.get("max")) != null) {
- if (node.isLong()){
+ if (node.isLong()) {
keyValueColumnType.setMax(node.asLong());
} else if (node.isTextual() && "unlimited".equals(node.asText())) {
keyValueColumnType.setMax(Long.MAX_VALUE);
@Override
public String toString() {
- return "KeyValuedColumnType [keyType=" + keyType + " "+ super.toString() +"]";
+ return "KeyValuedColumnType [keyType=" + keyType + " " + super.toString() + "]";
}
@Override
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
KeyValuedColumnType other = (KeyValuedColumnType) obj;
if (keyType == null) {
- if (other.keyType != null)
+ if (other.keyType != null) {
return false;
- } else if (!keyType.equals(other.keyType))
+ }
+ } else if (!keyType.equals(other.keyType)) {
return false;
+ }
return true;
}
}
try {
return invokable.invoke(null, table);
} catch (Exception e) {
- String message = String.format("Not able to create instance of class %s using public constructor " +
- "that accepts TableSchema object", clazz);
+ String message = String.format("Not able to create instance of class %s using public constructor "
+ + "that accepts TableSchema object", clazz);
throw new IllegalArgumentException(message, e);
}
}
this.name = name;
}
- public Version getVersion() { return version; }
+ public Version getVersion() {
+ return version;
+ }
- public void setVersion(Version version) { this.version = version; }
+ public void setVersion(Version version) {
+ this.version = version;
+ }
public void populateInternallyGeneratedColumns() {
for (TableSchema tableSchema : tables.values()) {
super(tableName);
}
- public GenericTableSchema (TableSchema tableSchema) {
+ public GenericTableSchema(TableSchema tableSchema) {
super(tableSchema.getName(), tableSchema.getColumnSchemas());
}
public <E extends TableSchema<E>> E as(Class<E> clazz) {
try {
- Constructor<E> e = clazz.getConstructor(TableSchema.class);
- return e.newInstance(this);
+ Constructor<E> instance = clazz.getConstructor(TableSchema.class);
+ return instance.newInstance(this);
} catch (Exception e) {
throw new RuntimeException("exception constructing instance of clazz " + clazz, e);
}
Map.Entry<String, JsonNode> idOldNew = fields.next();
String uuid = idOldNew.getKey();
- ObjectNode new_ = (ObjectNode) idOldNew.getValue().get("new");
- ObjectNode old = (ObjectNode) idOldNew.getValue().get("old");
+ ObjectNode newObjectNode = (ObjectNode) idOldNew.getValue().get("new");
+ ObjectNode oldObjectNode = (ObjectNode) idOldNew.getValue().get("old");
- Row<E> newRow = new_ != null ? createRow(new_) : null;
- Row<E> oldRow = old != null ? createRow(old) : null;
+ Row<E> newRow = newObjectNode != null ? createRow(newObjectNode) : null;
+ Row<E> oldRow = oldObjectNode != null ? createRow(oldObjectNode) : null;
tableUpdate.addRow(new UUID(uuid), oldRow, newRow);
}
* Hence adding some safety checks around that.
*/
if (schema != null) {
- Object o = schema.valueFromJson(next.getValue());
- columns.add(new Column<>(schema, o));
+ Object value = schema.valueFromJson(next.getValue());
+ columns.add(new Column<>(schema, value));
}
}
return new Row<>(this, columns);
import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.schema.TableSchema;
-public interface TypedBaseTable <E extends TableSchema<E>> {
- @TypedColumn(name="", method=MethodType.GETTABLESCHEMA)
+public interface TypedBaseTable<E extends TableSchema<E>> {
+ @TypedColumn(name = "", method = MethodType.GETTABLESCHEMA)
E getSchema();
- @TypedColumn(name="", method=MethodType.GETROW)
+ @TypedColumn(name = "", method = MethodType.GETROW)
Row<E> getRow();
- @TypedColumn(name="_uuid", method=MethodType.GETDATA)
+ @TypedColumn(name = "_uuid", method = MethodType.GETDATA)
public UUID getUuid();
- @TypedColumn(name="_uuid", method=MethodType.GETCOLUMN)
+ @TypedColumn(name = "_uuid", method = MethodType.GETCOLUMN)
public Column<E, UUID> getUuidColumn();
- @TypedColumn(name="_version", method=MethodType.GETDATA)
+ @TypedColumn(name = "_version", method = MethodType.GETDATA)
public UUID getVersion();
- @TypedColumn(name="_version", method=MethodType.GETCOLUMN)
+ @TypedColumn(name = "_version", method = MethodType.GETCOLUMN)
public Column<E, UUID> getVersionColumn();
}
import com.google.common.reflect.Reflection;
public class TyperUtils {
- private static final String GET_STARTS_WITH="get";
- private static final String SET_STARTS_WITH="set";
- private static final String GETCOLUMN_ENDS_WITH="Column";
- private static final String GETROW_ENDS_WITH="Row";
+ private static final String GET_STARTS_WITH = "get";
+ private static final String SET_STARTS_WITH = "set";
+ private static final String GETCOLUMN_ENDS_WITH = "Column";
+ private static final String GETROW_ENDS_WITH = "Row";
- private static <T> String getTableName (Class<T> klazz) {
+ private static <T> String getTableName(Class<T> klazz) {
TypedTable typedTable = klazz.getAnnotation(TypedTable.class);
if (typedTable != null) {
return typedTable.name();
return dbSchema.table(tableName, GenericTableSchema.class);
}
- public static ColumnSchema<GenericTableSchema, Object> getColumnSchema(GenericTableSchema tableSchema, String columnName, Class<Object> metaClass) {
+ public static ColumnSchema<GenericTableSchema, Object>
+ getColumnSchema(GenericTableSchema tableSchema, String columnName, Class<Object> metaClass) {
return tableSchema.column(columnName, metaClass);
}
- private static String getColumnName (Method method) {
+ private static String getColumnName(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
return typedColumn.name();
if (isGetData(method) || isSetData(method)) {
return method.getName().substring(index, method.getName().length()).toLowerCase();
} else if (isGetColumn(method)) {
- return method.getName().substring(index, method.getName().indexOf(GETCOLUMN_ENDS_WITH, index)).toLowerCase();
+ return method.getName().substring(index, method.getName().indexOf(GETCOLUMN_ENDS_WITH,
+ index)).toLowerCase();
}
return null;
}
- private static boolean isGetTableSchema (Method method) {
+ private static boolean isGetTableSchema(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
return typedColumn.method().equals(MethodType.GETTABLESCHEMA) ? true : false;
return false;
}
- private static boolean isGetRow (Method method) {
+ private static boolean isGetRow(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
return typedColumn.method().equals(MethodType.GETROW) ? true : false;
return false;
}
- private static boolean isGetColumn (Method method) {
+ private static boolean isGetColumn(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
return typedColumn.method().equals(MethodType.GETCOLUMN) ? true : false;
return false;
}
- private static boolean isGetData (Method method) {
+ private static boolean isGetData(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
return typedColumn.method().equals(MethodType.GETDATA) ? true : false;
return false;
}
- private static boolean isSetData (Method method) {
+ private static boolean isSetData(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
return typedColumn.method().equals(MethodType.SETDATA) ? true : false;
* @param klazz Typed Class that represents a Table
* @return true if valid, false otherwise
*/
- private static <T> boolean isValid (DatabaseSchema dbSchema, final Class<T> klazz) {
+ private static <T> boolean isValid(DatabaseSchema dbSchema, final Class<T> klazz) {
if (dbSchema == null) {
return false;
}
checkVersion(schemaVersion, fromVersion, untilVersion);
}
- private static void checkVersion(Version schemaVersion, Version fromVersion, Version untilVersion){
+ private static void checkVersion(Version schemaVersion, Version fromVersion, Version untilVersion) {
if (!fromVersion.equals(Version.NULL)) {
if (schemaVersion.compareTo(fromVersion) < 0) {
String message = SchemaVersionMismatchException.createMessage(schemaVersion, fromVersion);
/**
* This method returns a Typed Proxy implementation for the klazz passed as a parameter.
- * Per design choice, the Typed Proxy implementation is just a Wrapper on top of the actual Row which is untyped.
- * Being just a wrapper, it is state-less and more of a convenience functionality to provide a type-safe infrastructure
- * for the applications to built on top of. And this Typed infra is completely optional.
+ * Per design choice, the Typed Proxy implementation is just a Wrapper on top of the actual
+ * Row which is untyped.
+ * Being just a wrapper, it is state-less and more of a convenience functionality to
+ * provide a type-safe infrastructure for the applications to built on top of.
+ * And this Typed infra is completely optional.
*
- * It is the applications responsibilty to pass on the raw Row parameter & this method will return the appropriate
- * Proxy wrapper for the passed klazz Type. The raw Row parameter may be null if the caller is interested in just the
- * ColumnSchema. But that is not a very common use-case.
+ * It is the applications responsibility to pass on the raw Row parameter & this method will
+ * return the appropriate Proxy wrapper for the passed klazz Type.
+ * The raw Row parameter may be null if the caller is interested in just the ColumnSchema.
+ * But that is not a very common use-case.
*
* @param dbSchema DatabaseSchema as learnt from a OVSDB connection
* @param klazz Typed Class that represents a Table
/**
* This method returns a Typed Proxy implementation for the klazz passed as a parameter.
- * Per design choice, the Typed Proxy implementation is just a Wrapper on top of the actual Row which is untyped.
- * Being just a wrapper, it is state-less and more of a convenience functionality to provide a type-safe infrastructure
- * for the applications to built on top of. And this Typed infra is completely optional.
+ * Per design choice, the Typed Proxy implementation is just a Wrapper on top of the actual
+ * Row which is untyped.
+ * Being just a wrapper, it is state-less and more of a convenience functionality
+ * to provide a type-safe infrastructure for the applications to built on top of.
+ * And this Typed infra is completely optional.
*
- * It is the applications responsibilty to pass on the raw Row parameter & this method will return the appropriate
- * Proxy wrapper for the passed klazz Type. The raw Row parameter may be null if the caller is interested in just the
+ * It is the applications responsibility to pass on the raw Row parameter & this method
+ * will return the appropriate Proxy wrapper for the passed klazz Type.
+ * The raw Row parameter may be null if the caller is interested in just the
* ColumnSchema. But that is not a very common use-case.
*
* @param dbSchema DatabaseSchema as learnt from a OVSDB connection
* @param klazz Typed Class that represents a Table
- * @param row The actual Row that the wrapper is operating on. It can be null if the caller is just interested in getting ColumnSchema.
+ * @param row The actual Row that the wrapper is operating on. It can be null if the caller
+ * is just interested in getting ColumnSchema.
* @return
*/
- public static <T> T getTypedRowWrapper(final DatabaseSchema dbSchema, final Class<T> klazz, final Row<GenericTableSchema> row) {
+ public static <T> T getTypedRowWrapper(final DatabaseSchema dbSchema, final Class<T> klazz,
+ final Row<GenericTableSchema> row) {
if (!isValid(dbSchema, klazz)) {
return null;
}
- if (row != null) row.setTableSchema(getTableSchema(dbSchema, klazz));
+ if (row != null) {
+ row.setTableSchema(getTableSchema(dbSchema, klazz));
+ }
return Reflection.newProxy(klazz, new InvocationHandler() {
private Object processGetData(Method method) throws Throwable {
String columnName = getColumnName(method);
checkColumnSchemaVersion(dbSchema, method);
if (columnName == null) {
- throw new TyperException("Error processing Getter : "+ method.getName());
+ throw new TyperException("Error processing Getter : " + method.getName());
}
GenericTableSchema tableSchema = getTableSchema(dbSchema, klazz);
if (tableSchema == null) {
- String message = TableSchemaNotFoundException.createMessage(getTableName(klazz), dbSchema.getName());
+ String message =
+ TableSchemaNotFoundException.createMessage(getTableName(klazz), dbSchema.getName());
throw new TableSchemaNotFoundException(message);
}
- ColumnSchema<GenericTableSchema, Object> columnSchema = getColumnSchema(tableSchema, columnName, (Class<Object>) method.getReturnType());
+ ColumnSchema<GenericTableSchema, Object> columnSchema =
+ getColumnSchema(tableSchema, columnName, (Class<Object>) method.getReturnType());
if (columnSchema == null) {
String message = ColumnSchemaNotFoundException.createMessage(columnName, tableSchema.getName());
throw new ColumnSchemaNotFoundException(message);
String columnName = getColumnName(method);
checkColumnSchemaVersion(dbSchema, method);
if (columnName == null) {
- throw new TyperException("Error processing GetColumn : "+ method.getName());
+ throw new TyperException("Error processing GetColumn : " + method.getName());
}
GenericTableSchema tableSchema = getTableSchema(dbSchema, klazz);
if (tableSchema == null) {
- String message = TableSchemaNotFoundException.createMessage(getTableName(klazz), dbSchema.getName());
+ String message =
+ TableSchemaNotFoundException.createMessage(getTableName(klazz), dbSchema.getName());
throw new TableSchemaNotFoundException(message);
}
- ColumnSchema<GenericTableSchema, Object> columnSchema = getColumnSchema(tableSchema, columnName, (Class<Object>) method.getReturnType());
+ ColumnSchema<GenericTableSchema, Object> columnSchema =
+ getColumnSchema(tableSchema, columnName, (Class<Object>) method.getReturnType());
if (columnSchema == null) {
String message = ColumnSchemaNotFoundException.createMessage(columnName, tableSchema.getName());
throw new ColumnSchemaNotFoundException(message);
}
- // When the row is null, that might indicate that the user maybe interested only in the ColumnSchema and not on the Data.
+ // When the row is null, that might indicate that the user maybe interested
+ // only in the ColumnSchema and not on the Data.
if (row == null) {
return new Column<GenericTableSchema, Object>(columnSchema, null);
}
private Object processSetData(Object proxy, Method method, Object[] args) throws Throwable {
if (args == null || args.length != 1) {
- throw new TyperException("Setter method : "+method.getName() + " requires 1 argument");
+ throw new TyperException("Setter method : " + method.getName() + " requires 1 argument");
}
checkColumnSchemaVersion(dbSchema, method);
String columnName = getColumnName(method);
if (columnName == null) {
- throw new TyperException("Unable to locate Column Name for "+method.getName());
+ throw new TyperException("Unable to locate Column Name for " + method.getName());
}
GenericTableSchema tableSchema = getTableSchema(dbSchema, klazz);
- ColumnSchema<GenericTableSchema, Object> columnSchema = getColumnSchema(tableSchema, columnName,
- (Class<Object>) args[0].getClass());
- Column<GenericTableSchema, Object> column = new Column<GenericTableSchema, Object>(columnSchema, args[0]);
+ ColumnSchema<GenericTableSchema, Object> columnSchema =
+ getColumnSchema(tableSchema, columnName, (Class<Object>) args[0].getClass());
+ Column<GenericTableSchema, Object> column =
+ new Column<GenericTableSchema, Object>(columnSchema, args[0]);
row.addColumn(columnName, column);
return proxy;
}
private Object processGetTableSchema() {
- if (dbSchema == null) return null;
+ if (dbSchema == null) {
+ return null;
+ }
return getTableSchema(dbSchema, klazz);
}
return processGetRow();
} else if (isSetData(method)) {
return processSetData(proxy, method, args);
- } else if(isGetData(method)) {
+ } else if (isGetData(method)) {
return processGetData(method);
- } else if(isGetColumn(method)) {
+ } else if (isGetColumn(method)) {
return processGetColumn(method);
} else if (isHashCodeMethod(method, args)) {
return hashCode();
} else if (isToStringMethod(method, args)) {
return this.toString();
}
- throw new UnsupportedMethodException("Method not supported "+method.toString());
+ throw new UnsupportedMethodException("Method not supported " + method.toString());
}
@Override
public boolean equals(Object obj) {
- if (obj == null) return false;
+ if (obj == null) {
+ return false;
+ }
TypedBaseTable<?> typedRowObj = (TypedBaseTable<?>)obj;
- if (row == null && typedRowObj.getRow() == null) return true;
- if (row.equals(typedRowObj.getRow())) return true;
+ if (row == null && typedRowObj.getRow() == null) {
+ return true;
+ }
+ if (row.equals(typedRowObj.getRow())) {
+ return true;
+ }
return false;
}
@Override public int hashCode() {
- if (row == null) return 0;
+ if (row == null) {
+ return 0;
+ }
return row.hashCode();
}
} catch (Exception e) {
tableName = "";
}
- if (row == null) return tableName;
- return tableName+" : "+row.toString();
+ if (row == null) {
+ return tableName;
+ }
+ return tableName + " : " + row.toString();
}
}
);
Preconditions.checkNotNull(updates);
Preconditions.checkNotNull(dbSchema);
Map<UUID,T> result = new HashMap<UUID,T>();
-
- Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates = extractRowUpdates(klazz,updates,dbSchema);
+ @SuppressWarnings("checkstyle:genericwhitespace")
+ Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates =
+ extractRowUpdates(klazz,updates,dbSchema);
for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
- if(rowUpdate != null) {
- if(rowUpdate.getNew() != null) {
+ if (rowUpdate != null) {
+ if (rowUpdate.getNew() != null) {
Row<GenericTableSchema> row = rowUpdate.getNew();
result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
}
Preconditions.checkNotNull(updates);
Preconditions.checkNotNull(dbSchema);
Map<UUID,T> result = new HashMap<UUID,T>();
-
- Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates = extractRowUpdates(klazz,updates,dbSchema);
+ @SuppressWarnings("checkstyle:genericwhitespace")
+ Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates =
+ extractRowUpdates(klazz,updates,dbSchema);
for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
- if(rowUpdate != null) {
- if(rowUpdate.getNew() == null && rowUpdate.getOld() != null) {
+ if (rowUpdate != null) {
+ if (rowUpdate.getNew() == null && rowUpdate.getOld() != null) {
Row<GenericTableSchema> row = rowUpdate.getOld();
result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
}
* that correspond to rows of type klazz.
* Example:
* <code>
- * Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> updatedBridges = extractRowsUpdates(Bridge.class,updates,dbSchema)
+ * Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> updatedBridges =
+ * extractRowsUpdates(Bridge.class,updates,dbSchema)
* </code>
*
* @param klazz Class for row type to be extracted
* @param updates TableUpdates from which to extract rowUpdates
* @param dbSchema Dbschema for the TableUpdates
- * @return Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> for the type of things being sought
+ * @return Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>>
+ * for the type of things being sought
*/
- public static Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> extractRowUpdates(Class<?> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
+ @SuppressWarnings("checkstyle:genericwhitespace")
+ public static Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>>
+ extractRowUpdates(Class<?> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
Preconditions.checkNotNull(klazz);
Preconditions.checkNotNull(updates);
Preconditions.checkNotNull(dbSchema);
- Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> result = new HashMap<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>>();
+ Map<UUID, TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> result =
+ new HashMap<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>>();
TableUpdate<GenericTableSchema> update = updates.getUpdate(TyperUtils.getTableSchema(dbSchema, klazz));
- if(update != null) {
+ if (update != null) {
Map<UUID, TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rows = update.getRows();
- if(rows != null) {
+ if (rows != null) {
result = rows;
}
}