import org.opendaylight.ovsdb.lib.notation.Column;
import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.lib.notation.Version;
import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
return false;
}
+ public static Version getFromVersion (Method method) {
+ TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
+ if (typedColumn != null) {
+ return Version.fromString(typedColumn.fromVersion());
+ }
+ TypedTable typedTable = method.getAnnotation(TypedTable.class);
+ if (typedTable != null) {
+ return Version.fromString(typedTable.fromVersion());
+ }
+ return Version.NULL;
+ }
+
+ public static Version getUntilVersion(Method method) {
+ TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
+ if (typedColumn != null) {
+ return Version.fromString(typedColumn.untilVersion());
+ }
+ TypedTable typedTable = method.getAnnotation(TypedTable.class);
+ if (typedTable != null) {
+ return Version.fromString(typedTable.untilVersion());
+ }
+ return Version.NULL;
+ }
+
/**
* Method that checks validity of the parameter passed to getTypedRowWrapper.
* This method checks for a valid Database Schema matching the expected Database for a given table
return true;
}
+ private static void checkSchemaVersion(DatabaseSchema dbSchema, Method method) {
+ Version fromVersion = getFromVersion(method);
+ Version untilVersion = getUntilVersion(method);
+ if (!fromVersion.equals(Version.NULL)) {
+ if (dbSchema.getVersion().compareTo(fromVersion) < 0) {
+ throw new RuntimeException("This row is not supported until version "
+ + fromVersion + "of the Schema");
+ }
+ }
+ if (!untilVersion.equals(Version.NULL)) {
+ if (dbSchema.getVersion().compareTo(untilVersion) > 0) {
+ throw new RuntimeException("This row was deprecated in "
+ + untilVersion + "of the Schema");
+ }
+ }
+ }
+
/**
* 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.
return Reflection.newProxy(klazz, new InvocationHandler() {
private Object processGetData(Method method) throws Throwable {
String columnName = getColumnName(method);
+ checkSchemaVersion(dbSchema, method);
if (columnName == null) {
throw new RuntimeException("Error processing Getter : "+ method.getName());
}
private Object processGetColumn(Method method) throws Throwable {
String columnName = getColumnName(method);
+ checkSchemaVersion(dbSchema, method);
if (columnName == null) {
throw new RuntimeException("Error processing GetColumn : "+ method.getName());
}
if (args == null || args.length != 1) {
throw new RuntimeException("Setter method : "+method.getName() + " requires 1 argument");
}
+ checkSchemaVersion(dbSchema, method);
String columnName = getColumnName(method);
if (columnName == null) {
throw new RuntimeException("Unable to locate Column Name for "+method.getName());