diff --git a/smart-contract/hyperledger-fabric/v2/java/Dockerfile b/smart-contract/hyperledger-fabric/v2/java/Dockerfile index f792562..e7dc040 100644 --- a/smart-contract/hyperledger-fabric/v2/java/Dockerfile +++ b/smart-contract/hyperledger-fabric/v2/java/Dockerfile @@ -6,6 +6,7 @@ COPY buildSrc/ buildSrc/ COPY build.gradle.kts ./ COPY gradle.properties ./ COPY specs/ ./specs/ +COPY libs/ ./libs/ RUN gradle --no-daemon shadowJar diff --git a/smart-contract/hyperledger-fabric/v2/java/build.gradle.kts b/smart-contract/hyperledger-fabric/v2/java/build.gradle.kts index 7467de7..635d103 100644 --- a/smart-contract/hyperledger-fabric/v2/java/build.gradle.kts +++ b/smart-contract/hyperledger-fabric/v2/java/build.gradle.kts @@ -3,7 +3,6 @@ import com.diffplug.gradle.spotless.SpotlessExtension import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import hu.bme.mit.ftsrg.openjmlhelper.* -import java.io.File val openJMLDir = layout.projectDirectory.dir(".openjml") val openJMLJavaHomeDir = openJMLDir.dir("jdk") @@ -21,7 +20,7 @@ plugins { id("com.diffplug.spotless") version "6.19.0" } -group = "hu.bme.mit.ftsrg.tpcc" +group = "hu.bme.mit.ftsrg.chaincode.tpcc" version = "0.1.0" @@ -31,7 +30,9 @@ repositories { } dependencies { - implementation("ch.qos.logback:logback-classic:1.4.8") + implementation("ch.qos.logback:logback-core:1.5.6") + implementation("ch.qos.logback:logback-classic:1.5.6") + implementation("org.slf4j:slf4j-api:2.0.13") implementation("com.google.code.gson:gson:2.10.1") implementation("com.jcabi:jcabi-aspects:0.25.1") implementation("org.aspectj:aspectjrt:1.9.19") @@ -40,6 +41,7 @@ dependencies { implementation("org.hyperledger.fabric:fabric-protos:0.3.0") implementation("org.json:json:20230227") implementation("org.projectlombok:lombok:1.18.28") + implementation(files("libs/hypernate-0.1.0.jar")) // Included also as implementation dependency so shadow will package it implementation(files("$openJMLDir/jmlruntime.jar")) @@ -60,9 +62,7 @@ tasks.named("shadowJar") { tasks.named("test") { useJUnitPlatform() } if (!noOpenJML) { - tasks.named("shadowJar") { - dependsOn(tasks.named("initOpenJML")) - } + tasks.named("shadowJar") { dependsOn(tasks.named("initOpenJML")) } tasks.test { java { @@ -76,14 +76,20 @@ if (!noOpenJML) { // Only when not compiling because of Spotless if (!gradle.startParameter.taskNames.any { it.contains("spotlessApply") }) { val mode = - when (System.getenv("JML_MODE")) { - "esc" -> "esc" - else -> "rac" - } + when (System.getenv("JML_MODE")) { + "esc" -> "esc" + else -> "rac" + } options.isFork = true options.compilerArgs.addAll( - listOf( - "-jml", "-$mode", "-timeout", "30", "--nullable-by-default", "--specs-path", "specs/")) + listOf( + "-jml", + "-$mode", + "-timeout", + "30", + "--nullable-by-default", + "--specs-path", + "specs/")) options.forkOptions.javaHome = openJMLJavaHomeDir.asFile } } @@ -120,4 +126,3 @@ if (!noOpenJML) { logger.lifecycle("✅ OpenJML successfully initialized in $openJMLDir") } } - diff --git a/smart-contract/hyperledger-fabric/v2/java/gradle.properties b/smart-contract/hyperledger-fabric/v2/java/gradle.properties index 11e657e..a07d4e8 100644 --- a/smart-contract/hyperledger-fabric/v2/java/gradle.properties +++ b/smart-contract/hyperledger-fabric/v2/java/gradle.properties @@ -1 +1,2 @@ openJMLVersion = 0.17.0-alpha-15 +withoutOpenJML = false \ No newline at end of file diff --git a/smart-contract/hyperledger-fabric/v2/java/libs/hypernate-0.1.0.jar b/smart-contract/hyperledger-fabric/v2/java/libs/hypernate-0.1.0.jar new file mode 100644 index 0000000..a817129 Binary files /dev/null and b/smart-contract/hyperledger-fabric/v2/java/libs/hypernate-0.1.0.jar differ diff --git a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.jml b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.jml index 7f62c44..021888f 100644 --- a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.jml +++ b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.jml @@ -2,8 +2,8 @@ package hu.bme.mit.ftsrg.chaincode.tpcc; -import hu.bme.mit.ftsrg.chaincode.dataaccess.exception.EntityExistsException; -import hu.bme.mit.ftsrg.chaincode.dataaccess.exception.EntityNotFoundException; +import hu.bme.mit.ftsrg.hypernate.entity.EntityExistsException; +import hu.bme.mit.ftsrg.hypernate.entity.EntityNotFoundException; import hu.bme.mit.ftsrg.chaincode.tpcc.data.input.*; import hu.bme.mit.ftsrg.chaincode.tpcc.data.output.*; import hu.bme.mit.ftsrg.chaincode.tpcc.middleware.TPCCContext; diff --git a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Customer.jml b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Customer.jml index 201bddd..fa4229e 100644 --- a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Customer.jml +++ b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Customer.jml @@ -2,9 +2,9 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; -public class Customer extends SerializableEntityBase { +public class Customer implements Entity { public /*@ pure @*/ int getC_id(); diff --git a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/District.jml b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/District.jml index 42aeab7..49de7f4 100644 --- a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/District.jml +++ b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/District.jml @@ -2,9 +2,9 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; -public final class District extends SerializableEntityBase { +public final class District implements Entity { public /*@ pure @*/ int getD_id(); diff --git a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/History.jml b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/History.jml index 9feddb3..8c872c0 100644 --- a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/History.jml +++ b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/History.jml @@ -2,9 +2,9 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; -public final class History extends SerializableEntityBase { +public final class History implements Entity { public /*@ pure @*/ int getH_c_id(); diff --git a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Item.jml b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Item.jml index 471e37d..f7e3718 100644 --- a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Item.jml +++ b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Item.jml @@ -2,9 +2,9 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; -public final class Item extends SerializableEntityBase { +public final class Item implements Entity { public /*@ pure @*/ int getI_id(); diff --git a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/NewOrder.jml b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/NewOrder.jml index a90b8c9..3dedf03 100644 --- a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/NewOrder.jml +++ b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/NewOrder.jml @@ -2,9 +2,9 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; -public final class NewOrder extends SerializableEntityBase { +public final class NewOrder implements Entity { public /*@ pure @*/ int getNo_o_id(); diff --git a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Order.jml b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Order.jml index 17eb5ee..3136a5a 100644 --- a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Order.jml +++ b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Order.jml @@ -2,9 +2,9 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; -public final class Order extends SerializableEntityBase { +public final class Order implements Entity { public /*@ pure @*/ int getO_id(); diff --git a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/OrderLine.jml b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/OrderLine.jml index 74ff6ef..31cc573 100644 --- a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/OrderLine.jml +++ b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/OrderLine.jml @@ -2,9 +2,9 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; -public final class OrderLine extends SerializableEntityBase { +public final class OrderLine implements Entity { public /*@ pure @*/ int getOl_o_id(); diff --git a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Stock.jml b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Stock.jml index aea077f..38f4643 100644 --- a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Stock.jml +++ b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Stock.jml @@ -2,9 +2,9 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; -public final class Stock extends SerializableEntityBase { +public final class Stock implements Entity { public /*@ pure @*/ int getS_i_id(); diff --git a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Warehouse.jml b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Warehouse.jml index 0b4f00b..7ec63a6 100644 --- a/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Warehouse.jml +++ b/smart-contract/hyperledger-fabric/v2/java/specs/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Warehouse.jml @@ -2,9 +2,9 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; -public class Warehouse extends SerializableEntityBase { +public class Warehouse implements Entity { public /*@ pure @*/ int getW_id(); diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/MethodLogger.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/MethodLogger.java index a2f07e3..ee992a1 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/MethodLogger.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/MethodLogger.java @@ -1,6 +1,6 @@ package hu.bme.mit.ftsrg.chaincode; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntity; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; import java.util.ArrayList; import java.util.List; import org.hyperledger.fabric.contract.Context; @@ -40,7 +40,7 @@ public String generateParamsString(final Context ctx, final int... params) { return "%s,%s".formatted(ctx.toString(), generateParamsString(params)); } - public > String generateParamsString( + public > String generateParamsString( final Context ctx, final Type obj) { return "%s,%s".formatted(ctx.toString(), obj.toString()); } diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/ChaincodeStubMiddlewareBase.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/ChaincodeStubMiddlewareBase.java deleted file mode 100644 index 596595c..0000000 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/ChaincodeStubMiddlewareBase.java +++ /dev/null @@ -1,262 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ - -package hu.bme.mit.ftsrg.chaincode.dataaccess; - -import java.time.Instant; -import java.util.List; -import java.util.Map; -import org.hyperledger.fabric.protos.peer.ChaincodeEvent; -import org.hyperledger.fabric.protos.peer.SignedProposal; -import org.hyperledger.fabric.shim.Chaincode.Response; -import org.hyperledger.fabric.shim.ChaincodeStub; -import org.hyperledger.fabric.shim.ledger.CompositeKey; -import org.hyperledger.fabric.shim.ledger.KeyModification; -import org.hyperledger.fabric.shim.ledger.KeyValue; -import org.hyperledger.fabric.shim.ledger.QueryResultsIterator; -import org.hyperledger.fabric.shim.ledger.QueryResultsIteratorWithMetadata; - -/** - * Base class for {@link ChaincodeStub} middlewares. - * - *

This class provides the same interface as {@link ChaincodeStub}, but under the hood it - * maintains a reference to another {@link ChaincodeStub} and delegates all calls to that. You can - * override any method in this class to inject your custom behaviour, such as logging, access - * control, caching, etc. - */ -public abstract class ChaincodeStubMiddlewareBase implements ChaincodeStub { - - public ChaincodeStubMiddlewareBase(final ChaincodeStub nextLayer) { - this.nextLayer = nextLayer; - } - - protected final ChaincodeStub nextLayer; - - @Override - public List getArgs() { - return this.nextLayer.getArgs(); - } - - @Override - public List getStringArgs() { - return this.nextLayer.getStringArgs(); - } - - @Override - public String getFunction() { - return this.nextLayer.getFunction(); - } - - @Override - public List getParameters() { - return this.nextLayer.getParameters(); - } - - @Override - public String getTxId() { - return this.nextLayer.getTxId(); - } - - @Override - public String getChannelId() { - return this.nextLayer.getChannelId(); - } - - @Override - public Response invokeChaincode( - final String chaincodeName, final List args, final String channel) { - return this.nextLayer.invokeChaincode(chaincodeName, args, channel); - } - - @Override - public byte[] getState(final String key) { - return this.nextLayer.getState(key); - } - - @Override - public byte[] getStateValidationParameter(final String key) { - return this.nextLayer.getStateValidationParameter(key); - } - - @Override - public void putState(final String key, final byte[] value) { - this.nextLayer.putState(key, value); - } - - @Override - public void setStateValidationParameter(final String key, final byte[] value) { - this.nextLayer.setStateValidationParameter(key, value); - } - - @Override - public void delState(final String key) { - this.nextLayer.delState(key); - } - - @Override - public QueryResultsIterator getStateByRange( - final String startKey, final String endKey) { - return this.nextLayer.getStateByRange(startKey, endKey); - } - - @Override - public QueryResultsIteratorWithMetadata getStateByRangeWithPagination( - final String startKey, final String endKey, final int pageSize, final String bookmark) { - return this.nextLayer.getStateByRangeWithPagination(startKey, endKey, pageSize, bookmark); - } - - @Override - public QueryResultsIterator getStateByPartialCompositeKey(final String compositeKey) { - return this.nextLayer.getStateByPartialCompositeKey(compositeKey); - } - - @Override - public QueryResultsIterator getStateByPartialCompositeKey( - final String objectType, final String... attributes) { - return this.nextLayer.getStateByPartialCompositeKey(objectType, attributes); - } - - @Override - public QueryResultsIterator getStateByPartialCompositeKey( - final CompositeKey compositeKey) { - return this.nextLayer.getStateByPartialCompositeKey(compositeKey); - } - - @Override - public QueryResultsIteratorWithMetadata getStateByPartialCompositeKeyWithPagination( - final CompositeKey compositeKey, final int pageSize, final String bookmark) { - return this.nextLayer.getStateByPartialCompositeKeyWithPagination( - compositeKey, pageSize, bookmark); - } - - @Override - public CompositeKey createCompositeKey(final String objectType, final String... attributes) { - return this.nextLayer.createCompositeKey(objectType, attributes); - } - - @Override - public CompositeKey splitCompositeKey(final String compositeKey) { - return this.nextLayer.splitCompositeKey(compositeKey); - } - - @Override - public QueryResultsIterator getQueryResult(final String query) { - return this.nextLayer.getQueryResult(query); - } - - @Override - public QueryResultsIteratorWithMetadata getQueryResultWithPagination( - final String query, final int pageSize, final String bookmark) { - return this.nextLayer.getQueryResultWithPagination(query, pageSize, bookmark); - } - - @Override - public QueryResultsIterator getHistoryForKey(final String key) { - return this.nextLayer.getHistoryForKey(key); - } - - @Override - public byte[] getPrivateData(final String collection, final String key) { - return this.nextLayer.getPrivateData(collection, key); - } - - @Override - public byte[] getPrivateDataHash(final String collection, final String key) { - return this.nextLayer.getPrivateDataHash(collection, key); - } - - @Override - public byte[] getPrivateDataValidationParameter(final String collection, final String key) { - return this.nextLayer.getPrivateDataValidationParameter(collection, key); - } - - @Override - public void putPrivateData(final String collection, final String key, final byte[] value) { - this.nextLayer.putPrivateData(collection, key, value); - } - - @Override - public void setPrivateDataValidationParameter( - final String collection, final String key, final byte[] value) { - this.nextLayer.setPrivateDataValidationParameter(collection, key, value); - } - - @Override - public void delPrivateData(final String collection, final String key) { - this.nextLayer.delPrivateData(collection, key); - } - - @Override - public void purgePrivateData(final String collection, final String key) { - this.nextLayer.purgePrivateData(collection, key); - } - - @Override - public QueryResultsIterator getPrivateDataByRange( - final String collection, final String startKey, final String endKey) { - return this.nextLayer.getPrivateDataByRange(collection, startKey, endKey); - } - - @Override - public QueryResultsIterator getPrivateDataByPartialCompositeKey( - final String collection, final String compositeKey) { - return this.nextLayer.getPrivateDataByPartialCompositeKey(collection, compositeKey); - } - - @Override - public QueryResultsIterator getPrivateDataByPartialCompositeKey( - final String collection, final CompositeKey compositeKey) { - return this.nextLayer.getPrivateDataByPartialCompositeKey(collection, compositeKey); - } - - @Override - public QueryResultsIterator getPrivateDataByPartialCompositeKey( - final String collection, final String objectType, final String... attributes) { - return this.nextLayer.getPrivateDataByPartialCompositeKey(collection, objectType, attributes); - } - - @Override - public QueryResultsIterator getPrivateDataQueryResult( - final String collection, final String query) { - return this.nextLayer.getPrivateDataQueryResult(collection, query); - } - - @Override - public void setEvent(final String name, final byte[] payload) { - this.nextLayer.setEvent(name, payload); - } - - @Override - public ChaincodeEvent getEvent() { - return this.nextLayer.getEvent(); - } - - @Override - public SignedProposal getSignedProposal() { - return this.nextLayer.getSignedProposal(); - } - - @Override - public Instant getTxTimestamp() { - return this.nextLayer.getTxTimestamp(); - } - - @Override - public byte[] getCreator() { - return this.nextLayer.getCreator(); - } - - @Override - public Map getTransient() { - return this.nextLayer.getTransient(); - } - - @Override - public byte[] getBinding() { - return this.nextLayer.getBinding(); - } - - @Override - public String getMspId() { - return this.nextLayer.getMspId(); - } -} diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/ContextWithRegistry.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/ContextWithRegistry.java deleted file mode 100644 index ee3f81d..0000000 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/ContextWithRegistry.java +++ /dev/null @@ -1,22 +0,0 @@ -package hu.bme.mit.ftsrg.chaincode.dataaccess; - -import org.hyperledger.fabric.contract.Context; -import org.hyperledger.fabric.shim.ChaincodeStub; - -/** - * Fabric's original context extended with a {@link Registry}. - * - *

The registry can be used to manage entities. - */ -public class ContextWithRegistry extends Context { - - private final Registry registry = new RegistryImpl(); - - public ContextWithRegistry(final ChaincodeStub stub) { - super(stub); - } - - public Registry getRegistry() { - return registry; - } -} diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/EntityFactory.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/EntityFactory.java deleted file mode 100644 index 2fb5676..0000000 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/EntityFactory.java +++ /dev/null @@ -1,15 +0,0 @@ -package hu.bme.mit.ftsrg.chaincode.dataaccess; - -/** - * Minimal interface to allow entities to return factories that produce them. - * - * @param the entity's type - */ -public interface EntityFactory> { - /** - * Simply gives a new, empty instance of the entity of type Type. - * - * @return a new, empty entity instance - */ - Type create(); -} diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/KeyPart.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/KeyPart.java deleted file mode 100644 index bd75bfe..0000000 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/KeyPart.java +++ /dev/null @@ -1,19 +0,0 @@ -package hu.bme.mit.ftsrg.chaincode.dataaccess; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Marks a field of a {@link SerializableEntity} as a primary key part. - * - *

Add this annotation to all fields you wish to have as primary keys. {@link - * SerializableEntityBase#getKeyParts()} returns an array constructed of these, with additional - * padding. - * - * @see SerializableEntity - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface KeyPart {} diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/Registry.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/Registry.java deleted file mode 100644 index 1456e38..0000000 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/Registry.java +++ /dev/null @@ -1,47 +0,0 @@ -package hu.bme.mit.ftsrg.chaincode.dataaccess; - -import hu.bme.mit.ftsrg.chaincode.dataaccess.exception.EntityExistsException; -import hu.bme.mit.ftsrg.chaincode.dataaccess.exception.EntityNotFoundException; -import java.util.Comparator; -import java.util.List; -import org.hyperledger.fabric.contract.Context; - -public interface Registry { - - > void create(Context ctx, Type entity) - throws EntityExistsException; - - > void update(Context ctx, Type entity) - throws EntityNotFoundException; - - > void delete(Context ctx, Type entity) - throws EntityNotFoundException; - - > Type read(Context ctx, Type target) - throws EntityNotFoundException; - - > List readAll(Context ctx, Type template); - - > SelectionBuilder select(Context ctx, Type template); - - interface SelectionBuilder> { - SelectionBuilder matching(Matcher matcher); - - SelectionBuilder sortedBy(Comparator comparator); - - SelectionBuilder descending(); - - List get(); - - Type getFirst(); - } - - interface Matcher> { - boolean match(Type entity); - } - - enum Order { - ASCENDING, - DESCENDING - } -} diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/RegistryImpl.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/RegistryImpl.java deleted file mode 100644 index 325efb2..0000000 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/RegistryImpl.java +++ /dev/null @@ -1,210 +0,0 @@ -package hu.bme.mit.ftsrg.chaincode.dataaccess; - -import com.jcabi.aspects.Loggable; -import hu.bme.mit.ftsrg.chaincode.MethodLogger; -import hu.bme.mit.ftsrg.chaincode.dataaccess.exception.EntityExistsException; -import hu.bme.mit.ftsrg.chaincode.dataaccess.exception.EntityNotFoundException; -import java.util.*; -import org.hyperledger.fabric.contract.Context; -import org.hyperledger.fabric.shim.ledger.CompositeKey; -import org.hyperledger.fabric.shim.ledger.KeyValue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Loggable(Loggable.DEBUG) // FIXME how to configure AspectJ with OpenJML and Gradle? -public class RegistryImpl implements Registry { - - private static final Logger logger = LoggerFactory.getLogger(RegistryImpl.class); - - private static final MethodLogger methodLogger = new MethodLogger(logger, "RegistryImpl"); - - public RegistryImpl() {} - - private > String getKey(final Context ctx, final Type obj) { - final String paramsString = methodLogger.generateParamsString(ctx, obj); - methodLogger.logStart("getKey", paramsString); - - final CompositeKey compositeKey = - ctx.getStub().createCompositeKey(obj.getType(), obj.getKeyParts()); - - methodLogger.logEnd("getKey", paramsString, compositeKey.toString()); - return compositeKey.toString(); - } - - @Override - public > void create(final Context ctx, final Type entity) - throws EntityExistsException { - final String paramsString = methodLogger.generateParamsString(ctx, entity); - methodLogger.logStart("create", paramsString); - - assertNotExists(ctx, entity); - - final String key = getKey(ctx, entity); - final byte[] buffer = entity.toBuffer(); - logger.debug("Calling stub#putState with key={} and value={}", key, Arrays.toString(buffer)); - ctx.getStub().putState(key, buffer); - - methodLogger.logEnd("create", paramsString, ""); - } - - @Override - public > void update(final Context ctx, final Type entity) - throws EntityNotFoundException { - final String paramsString = methodLogger.generateParamsString(ctx, entity); - methodLogger.logStart("update", paramsString); - - assertExists(ctx, entity); - - final String key = getKey(ctx, entity); - final byte[] buffer = entity.toBuffer(); - logger.debug("Calling stub#putState with key={} and value={}", key, Arrays.toString(buffer)); - ctx.getStub().putState(key, buffer); - - methodLogger.logEnd("update", paramsString, ""); - } - - @Override - public > void delete(final Context ctx, final Type entity) - throws EntityNotFoundException { - final String paramsString = methodLogger.generateParamsString(ctx, entity); - methodLogger.logStart("delete", paramsString); - - assertExists(ctx, entity); - - final String key = getKey(ctx, entity); - logger.debug("Calling stub#delState with key={}", key); - ctx.getStub().delState(key); - - methodLogger.logEnd("delete", paramsString, ""); - } - - @Override - public > Type read(final Context ctx, final Type target) - throws EntityNotFoundException { - final String paramsString = methodLogger.generateParamsString(ctx, target); - methodLogger.logStart("read", paramsString); - - final String key = getKey(ctx, target); - logger.debug("Calling stub#getState with key={}", key); - final byte[] data = ctx.getStub().getState(key); - logger.debug("Got data from stub#getState for key={}: {}", key, Arrays.toString(data)); - - if (data == null || data.length == 0) throw new EntityNotFoundException(key); - - target.fromBuffer(data); - logger.debug("Deserialized entity from data; JSON representation={}", target.toJson()); - - methodLogger.logEnd("read", paramsString, target.toJson()); - return target; - } - - @Override - public > List readAll( - final Context ctx, final Type template) { - final String paramsString = methodLogger.generateParamsString(ctx, template); - methodLogger.logStart("readAll", paramsString); - - final List entities = new ArrayList<>(); - final String compositeKey = ctx.getStub().createCompositeKey(template.getType()).toString(); - logger.debug("Calling stub#getStateByPartialCompositeKey with partial key={}", compositeKey); - for (KeyValue keyValue : ctx.getStub().getStateByPartialCompositeKey(compositeKey)) { - final byte[] value = keyValue.getValue(); - logger.debug("Found value at partial key={}: {}", compositeKey, Arrays.toString(value)); - final EntityFactory factory = template.getFactory(); - final Type entity = factory.create(); - entity.fromBuffer(value); - logger.debug("Deserialized entity from data; JSON representation={}", entity.toJson()); - entities.add(entity); - } - logger.debug("Found {} entities in total for partial key={}", entities.size(), compositeKey); - - methodLogger.logEnd("readAll", paramsString, entities.toString()); - return entities; - } - - @Override - public > SelectionBuilder select( - final Context ctx, final Type template) { - final String paramsString = methodLogger.generateParamsString(ctx, template); - methodLogger.logStart("select", paramsString); - - final SelectionBuilder builder = new SelectionBuilderImpl<>(this.readAll(ctx, template)); - methodLogger.logEnd("select", paramsString, builder.toString()); - return builder; - } - - private boolean keyExists(final Context ctx, final String key) { - final byte[] valueOnLedger = ctx.getStub().getState(key); - return valueOnLedger != null && valueOnLedger.length > 0; - } - - public > boolean exists(final Context ctx, final Type obj) { - return keyExists(ctx, getKey(ctx, obj)); - } - - public > void assertNotExists( - final Context ctx, final Type obj) throws EntityExistsException { - if (exists(ctx, obj)) throw new EntityExistsException(getKey(ctx, obj)); - } - - public > void assertExists( - final Context ctx, final Type obj) throws EntityNotFoundException { - if (!exists(ctx, obj)) throw new EntityNotFoundException(getKey(ctx, obj)); - } - - private static final class SelectionBuilderImpl> - implements SelectionBuilder { - - private List selection; - - SelectionBuilderImpl(final List entities) { - this.selection = entities; - } - - @Override - public SelectionBuilder matching(final Matcher matcher) { - final List newSelection = new ArrayList<>(); - for (Type entity : this.selection) { - logger.debug("Testing matcher on entity (JSON): {}", entity.toJson()); - if (matcher.match(entity)) { - logger.debug("Entity matches"); - newSelection.add(entity); - } else logger.debug("Entity does not match"); - } - logger.debug("Matched {} entities in total with matcher", newSelection.size()); - this.selection = newSelection; - return this; - } - - @Override - public SelectionBuilder sortedBy(final Comparator comparator) { - this.selection.sort(comparator); - logger.debug("Sorted entities"); - return this; - } - - @Override - public SelectionBuilder descending() { - Collections.reverse(this.selection); - logger.debug("Reversed entity order"); - return this; - } - - @Override - public List get() { - return this.selection; - } - - @Override - public Type getFirst() { - if (this.selection.isEmpty()) { - logger.debug("No entites in this selection; returning null"); - return null; - } - - final Type first = this.selection.get(0); - logger.debug("Returning the first entity in selection (JSON): {}", first.toJson()); - return first; - } - } -} diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/SerializableEntity.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/SerializableEntity.java deleted file mode 100644 index ba90160..0000000 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/SerializableEntity.java +++ /dev/null @@ -1,85 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ - -package hu.bme.mit.ftsrg.chaincode.dataaccess; - -/** - * A generic database entity that can be serialized to JSON and to byte arrays. - * - * @param the type of the entity (required because of {@link - * SerializableEntity#getFactory()}) - * @see SerializableEntityBase - */ -public interface SerializableEntity> { - - /** - * Get the type of this entity; essentially a table name. - * - *

Usually this is an all-caps string, such as CUSTOMER. - * - * @return the arbitrary identifier of this entity type - * @see SerializableEntityBase#getType() - */ - String getType(); - - /** - * Get the composite key for this entity. - * - *

The composite key is an array of strings comprising the primary key fields of the entity (ie - * those annotated with {@link KeyPart}). - * - * @return the composite key of this entity - * @see SerializableEntityBase#getKeyParts() - */ - String[] getKeyParts(); - - /** - * Serialize this entity into a byte array. - * - *

The implementation is up to the developer, but it is recommended to simply return the - * encoded version of {@link SerializableEntity#toJson()}. - * - * @return this entity serialized into a byte array - * @see SerializableEntity#fromBuffer(byte[]) - * @see SerializableEntityBase#toBuffer() - */ - byte[] toBuffer(); - - /** - * Deserialize this entity from a byte array. - * - *

Naturally, this should do the inverse of {@link SerializableEntity#toBuffer()} - * - * @param buffer the buffer to parse - * @see SerializableEntity#toBuffer() - * @see SerializableEntityBase#fromBuffer(byte[]) - */ - void fromBuffer(byte[] buffer); - - /** - * Serialize this entity into a JSON string. - * - * @return this entity serialized into a JSON string - * @see SerializableEntity#fromJson(String) - * @see SerializableEntityBase#toJson() - */ - String toJson(); - - /** - * Deserialize this entity from a JSON string. - * - *

Naturally, this should do the inverse of {@link SerializableEntity#toJson()} - * - * @param json the JSON string to parse - * @see SerializableEntity#toJson() - * @see SerializableEntityBase#fromJson(String) - */ - void fromJson(String json); - - /** - * Get a factory for this entity type. - * - * @return A factory that can be used to create empty instances of this entity - * @see SerializableEntityBase#getFactory() - */ - EntityFactory getFactory(); -} diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/SerializableEntityBase.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/SerializableEntityBase.java deleted file mode 100644 index 905e781..0000000 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/SerializableEntityBase.java +++ /dev/null @@ -1,197 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ - -package hu.bme.mit.ftsrg.chaincode.dataaccess; - -import hu.bme.mit.ftsrg.chaincode.tpcc.util.JSON; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.nio.charset.StandardCharsets; -import java.util.*; -import lombok.EqualsAndHashCode; -import org.hyperledger.fabric.contract.annotation.DataType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Base class for {@link SerializableEntity} entities. - * - *

This class provides some reflection-based implementations of the {@link SerializableEntity} - * methods, so that you do not have to implement all the boilerplate yourself in the final entity - * classes. - * - * @param the type of the entity - */ -@EqualsAndHashCode -@DataType -public abstract class SerializableEntityBase> - implements SerializableEntity { - - private static final Logger logger = LoggerFactory.getLogger(SerializableEntityBase.class); - - /** - * Returns the entity type name, which is its class's name in all-uppercase. - * - * @return The name of the class of this entity, in all-uppercase - * @see SerializableEntity#getType() - */ - @Override - public String getType() { - final String type = this.getClass().getName().toUpperCase(); - logger.debug("Returning type name: {}", type); - return type; - } - - /** - * Serializes this entity to a JSON and then to a byte array. - * - * @return This entity, serialized into a JSON string and then converted to a UTF-8 byte array. - * @see SerializableEntity#toBuffer() - */ - @Override - public byte[] toBuffer() { - final String json = this.toJson(); - final byte[] buffer = json.getBytes(StandardCharsets.UTF_8); - logger.debug("Returning buffer (size={}) from JSON: {}", buffer.length, json); - return buffer; - } - - /** - * Deserializes this entity from a byte array. - * - * @param buffer the buffer to parse - * @see SerializableEntityBase#toBuffer() - */ - @Override - public void fromBuffer(final byte[] buffer) { - final String json = new String(buffer, StandardCharsets.UTF_8); - logger.debug("Parsing entity from JSON: {}", json); - this.fromJson(json); - } - - /** - * Serializes this entity into a JSON. - * - * @return this entity as a JSON string - * @see SerializableEntity#toJson() - */ - @Override - public String toJson() { - final String json = JSON.serialize(this); - logger.debug("Returning JSON string from entity: {}", json); - return json; - } - - /** - * Deserializes this entity from a JSON. - * - *

This reflection-based implementation sets all fields with matching names from the JSON. - * Fields that are not found in the JSON remain unset. Conversely, extraneous keys in the JSON are - * ignored. - * - * @param json the JSON string to parse - * @see SerializableEntityBase#toJson() - */ - @Override - public void fromJson(final String json) { - logger.debug("Deserializing from JSON string: {}...", json); - final Object obj = JSON.deserialize(json, this.getClass()); - final Field[] ourFields = this.getClass().getDeclaredFields(); - /* - * Try to get values for our known fields from the deserialized - * object. This process is forgiving: if one of our fields does not - * exist inside the deserialized object, we leave it as is; if the - * deserialized object contains fields we do not recognize, we - * silently ignore them. - */ - for (final Field ourField : ourFields) { - logger.debug("Attempting to set field {}", ourField.getName()); - ourField.setAccessible(true); - try { - final Field theirField = obj.getClass().getDeclaredField(ourField.getName()); - theirField.setAccessible(true); - try { - ourField.set(this, theirField.get(obj)); - } catch (IllegalArgumentException | IllegalAccessException e) { - logger.error("Got exception while trying to access/set a field", e); - e.printStackTrace(); - } - } catch (NoSuchFieldException e) { - logger.error("Got exception while trying to access/set a field", e); - e.printStackTrace(); - } - } - } - - /** - * Get the composite key for this entity. - * - *

This reference implementation takes all fields annotated with {@link KeyPart} in the entity - * class, pads them to {@link SerializableEntityBase#padLength} and creates an array from those. - * - *

WARNING: the order of keys might matter; this implementation has not been tested. - * - * @return the composite key of this entity - */ - @Override - public String[] getKeyParts() { - // Stream-based implementation replaced with code below to accommodate OpenJML... - final List keyParts = new ArrayList<>(); - for (final Field field : this.getClass().getDeclaredFields()) { - logger.debug("Checking if field {} is a key part...", field.getName()); - field.setAccessible(true); - if (field.isAnnotationPresent(KeyPart.class)) { - logger.debug("Field {} seems to be a key part; getting its value", field.getName()); - try { - keyParts.add(pad(field.getInt(this))); - } catch (IllegalAccessException e) { - logger.error("Failed to get the value of a key part", e); - throw new RuntimeException(e); - } - } - } - - logger.debug("Returning key parts for entity: {}", keyParts); - return keyParts.toArray(new String[0]); - } - - /** - * Get a factory that can instantiate this entity. - * - *

WARNING: this is a rather lousy reflection-based implementation that has not been - * tested - * - * @return a {@link EntityFactory} for this entity type - */ - @Override - public EntityFactory getFactory() { - final Class ourClass = this.getClass(); - // Lambda-based implementation replaced with code below to accommodate OpenJML... - return new EntityFactory<>() { - @Override - public Type create() { - logger.debug("Was asked to create a new entity instance of {}...", ourClass.getName()); - try { - return (Type) ourClass.getDeclaredConstructor().newInstance(); - } catch (InstantiationException - | IllegalAccessException - | InvocationTargetException - | NoSuchMethodException e) { - logger.error("Failed to create new entity instance using factory", e); - throw new RuntimeException(e); - } - } - }; - } - - private static final int padLength = Integer.toString(Integer.MAX_VALUE).length(); - - /** - * Converts the number to text and pads it to a fix length. - * - * @param num The number to pad. - * @return The padded number text. - */ - private static String pad(final int num) { - return String.format("%0" + padLength + "d", num); - } -} diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/exception/DataAccessException.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/exception/DataAccessException.java deleted file mode 100644 index 7623311..0000000 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/exception/DataAccessException.java +++ /dev/null @@ -1,12 +0,0 @@ -package hu.bme.mit.ftsrg.chaincode.dataaccess.exception; - -public abstract class DataAccessException extends Exception { - - public DataAccessException(final String message) { - super(message); - } - - public DataAccessException(final String message, final Throwable cause) { - super(message, cause); - } -} diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/exception/EntityExistsException.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/exception/EntityExistsException.java deleted file mode 100644 index 8670f5f..0000000 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/exception/EntityExistsException.java +++ /dev/null @@ -1,8 +0,0 @@ -package hu.bme.mit.ftsrg.chaincode.dataaccess.exception; - -public class EntityExistsException extends DataAccessException { - - public EntityExistsException(final String key) { - super("Entity with key '%s' already exists".formatted(key)); - } -} diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/exception/EntityNotFoundException.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/exception/EntityNotFoundException.java deleted file mode 100644 index f80cdf2..0000000 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/dataaccess/exception/EntityNotFoundException.java +++ /dev/null @@ -1,8 +0,0 @@ -package hu.bme.mit.ftsrg.chaincode.dataaccess.exception; - -public class EntityNotFoundException extends DataAccessException { - - public EntityNotFoundException(final String key) { - super("Entity with key '%s' could not be found".formatted(key)); - } -} diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.java index dc0391a..dda624e 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/TPCC.java @@ -4,10 +4,6 @@ import com.jcabi.aspects.Loggable; import hu.bme.mit.ftsrg.chaincode.MethodLogger; -import hu.bme.mit.ftsrg.chaincode.dataaccess.ContextWithRegistry; -import hu.bme.mit.ftsrg.chaincode.dataaccess.Registry; -import hu.bme.mit.ftsrg.chaincode.dataaccess.exception.EntityExistsException; -import hu.bme.mit.ftsrg.chaincode.dataaccess.exception.EntityNotFoundException; import hu.bme.mit.ftsrg.chaincode.tpcc.data.entity.*; import hu.bme.mit.ftsrg.chaincode.tpcc.data.extra.DeliveredOrder; import hu.bme.mit.ftsrg.chaincode.tpcc.data.extra.ItemsData; @@ -16,6 +12,11 @@ import hu.bme.mit.ftsrg.chaincode.tpcc.data.output.*; import hu.bme.mit.ftsrg.chaincode.tpcc.middleware.TPCCContext; import hu.bme.mit.ftsrg.chaincode.tpcc.util.JSON; +import hu.bme.mit.ftsrg.hypernate.Registry; +import hu.bme.mit.ftsrg.hypernate.context.ContextWithRegistry; +import hu.bme.mit.ftsrg.hypernate.entity.EntityExistsException; +import hu.bme.mit.ftsrg.hypernate.entity.EntityNotFoundException; +import hu.bme.mit.ftsrg.hypernate.entity.SerializationException; import java.util.*; import org.hyperledger.fabric.contract.Context; import org.hyperledger.fabric.contract.ContractInterface; @@ -69,7 +70,7 @@ public Context createContext(final ChaincodeStub stub) { */ @Transaction(intent = Transaction.TYPE.SUBMIT) public String delivery(final TPCCContext ctx, final String parameters) - throws EntityNotFoundException { + throws EntityNotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx, parameters); methodLogger.logStart("delivery", paramString); final String json = @@ -89,7 +90,7 @@ public String delivery(final TPCCContext ctx, final String parameters) */ @Transaction(intent = Transaction.TYPE.SUBMIT) public String newOrder(final TPCCContext ctx, final String parameters) - throws EntityNotFoundException, EntityExistsException { + throws EntityNotFoundException, EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx, parameters); methodLogger.logStart("newOrder", paramString); final String json = @@ -107,7 +108,7 @@ public String newOrder(final TPCCContext ctx, final String parameters) */ @Transaction(intent = Transaction.TYPE.EVALUATE) public String orderStatus(final TPCCContext ctx, final String parameters) - throws NotFoundException, EntityNotFoundException { + throws NotFoundException, EntityNotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx, parameters); methodLogger.logStart("orderStatus", paramString); final String json = @@ -128,7 +129,10 @@ public String orderStatus(final TPCCContext ctx, final String parameters) */ @Transaction(intent = Transaction.TYPE.SUBMIT) public String payment(final TPCCContext ctx, final String parameters) - throws EntityNotFoundException, EntityExistsException, NotFoundException { + throws EntityNotFoundException, + EntityExistsException, + NotFoundException, + SerializationException { final String paramString = methodLogger.generateParamsString(ctx, parameters); methodLogger.logStart("payment", paramString); final String json = @@ -148,7 +152,7 @@ public String payment(final TPCCContext ctx, final String parameters) */ @Transaction(intent = Transaction.TYPE.EVALUATE) public String stockLevel(final TPCCContext ctx, final String parameters) - throws EntityNotFoundException, NotFoundException { + throws EntityNotFoundException, NotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx, parameters); methodLogger.logStart("stockLevel", paramString); final String json = @@ -163,7 +167,7 @@ public String stockLevel(final TPCCContext ctx, final String parameters) * @param ctx The transaction context */ @Transaction(intent = Transaction.TYPE.SUBMIT) - public void init(final TPCCContext ctx) throws EntityExistsException { + public void init(final TPCCContext ctx) throws EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx.toString()); methodLogger.logStart("init", paramString); @@ -186,12 +190,12 @@ public void init(final TPCCContext ctx) throws EntityExistsException { */ @Transaction(intent = Transaction.TYPE.EVALUATE) public String readWarehouse(final TPCCContext ctx, final int w_id) - throws EntityNotFoundException { + throws EntityNotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx, w_id); methodLogger.logStart("readWarehouse", paramString); final Warehouse warehouse = Warehouse.builder().id(w_id).build(); - ctx.getRegistry().read(ctx, warehouse); + ctx.getRegistry().read(warehouse); ctx.commit(); final String json = JSON.serialize(warehouse); @@ -210,12 +214,12 @@ public String readWarehouse(final TPCCContext ctx, final int w_id) */ @Transaction(intent = Transaction.TYPE.EVALUATE) public String readOrder(final TPCCContext ctx, final int w_id, final int d_id, final int o_id) - throws EntityNotFoundException { + throws EntityNotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx, w_id, d_id, o_id); methodLogger.logStart("readOrder", paramString); final Order order = Order.builder().w_id(w_id).d_id(d_id).id(o_id).build(); - ctx.getRegistry().read(ctx, order); + ctx.getRegistry().read(order); ctx.commit(); final String json = JSON.serialize(order); @@ -231,12 +235,13 @@ public String readOrder(final TPCCContext ctx, final int w_id, final int d_id, f * @return The item with matchign I_ID */ @Transaction(intent = Transaction.TYPE.EVALUATE) - public String readItem(final TPCCContext ctx, final int i_id) throws EntityNotFoundException { + public String readItem(final TPCCContext ctx, final int i_id) + throws EntityNotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx, i_id); methodLogger.logStart("readItem", paramString); final Item item = Item.builder().id(i_id).build(); - ctx.getRegistry().read(ctx, item); + ctx.getRegistry().read(item); ctx.commit(); final String json = JSON.serialize(item); @@ -255,12 +260,12 @@ public String readItem(final TPCCContext ctx, final int i_id) throws EntityNotFo */ @Transaction(intent = Transaction.TYPE.EVALUATE) public String readNewOrder(final TPCCContext ctx, final int w_id, final int d_id, final int o_id) - throws EntityNotFoundException { + throws EntityNotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx, w_id, d_id, o_id); methodLogger.logStart("readNewOrder", paramString); final NewOrder newOrder = NewOrder.builder().w_id(w_id).d_id(d_id).o_id(o_id).build(); - ctx.getRegistry().read(ctx, newOrder); + ctx.getRegistry().read(newOrder); ctx.commit(); final String json = JSON.serialize(newOrder); @@ -325,7 +330,7 @@ public String OJMLTEST__getCustomer( * @return The transaction output */ private DeliveryOutput delivery(final TPCCContext ctx, final DeliveryInput input) - throws EntityNotFoundException { + throws EntityNotFoundException, SerializationException { /* * [TPC-C 2.7.4.2] @@ -387,7 +392,7 @@ private DeliveryOutput delivery(final TPCCContext ctx, final DeliveryInput input * @return The transaction output */ private NewOrderOutput newOrder(final TPCCContext ctx, final NewOrderInput input) - throws EntityNotFoundException, EntityExistsException { + throws EntityNotFoundException, EntityExistsException, SerializationException { /* * [TPC-C 2.4.2.2] * For a given warehouse number (W_ID), district number (D_W_ID, @@ -405,7 +410,7 @@ private NewOrderOutput newOrder(final TPCCContext ctx, final NewOrderInput input * and W_TAX, the warehouse tax rate, is retrieved. */ final Warehouse warehouse = Warehouse.builder().id(input.getW_id()).build(); - registry.read(ctx, warehouse); + registry.read(warehouse); /* * [TPC-C 2.4.2.2 (4)] @@ -414,7 +419,7 @@ private NewOrderOutput newOrder(final TPCCContext ctx, final NewOrderInput input */ final District district = District.builder().w_id(warehouse.getW_id()).id(input.getD_id()).build(); - registry.read(ctx, district); + registry.read(district); /* * [TPC-C 2.4.2.2 (4) (continued)] * ... and D_NEXT_O_ID, the next available order number for the @@ -422,7 +427,7 @@ private NewOrderOutput newOrder(final TPCCContext ctx, final NewOrderInput input */ final int nextOrderId = district.getD_next_o_id(); district.incrementNextOrderID(); - registry.update(ctx, district); + registry.update(district); logger.debug( "Next available order number for DISTRICT with D_ID={} incremented; new DISTRICT: {}", district.getD_id(), @@ -441,7 +446,7 @@ private NewOrderOutput newOrder(final TPCCContext ctx, final NewOrderInput input .d_id(district.getD_id()) .id(input.getC_id()) .build(); - registry.read(ctx, customer); + registry.read(customer); /* * [TPC-C 2.4.2.2 (6)] @@ -454,7 +459,7 @@ private NewOrderOutput newOrder(final TPCCContext ctx, final NewOrderInput input .d_id(district.getD_id()) .w_id(warehouse.getW_id()) .build(); - registry.create(ctx, newOrder); + registry.create(newOrder); /* * [TPC-C 2.4.2.2 (6) (continued)] * ... O_CARRIER_ID is set to a null value. If the order includes @@ -476,7 +481,7 @@ private NewOrderOutput newOrder(final TPCCContext ctx, final NewOrderInput input .ol_cnt(input.getI_ids().length) .all_local(this.allMatch(input.getI_w_ids(), warehouse.getW_id()) ? 1 : 0) .build(); - registry.create(ctx, order); + registry.create(order); /* * [TPC-C 2.4.2.2 (8)] @@ -539,7 +544,7 @@ private NewOrderOutput newOrder(final TPCCContext ctx, final NewOrderInput input * @return The transaction output */ private OrderStatusOutput orderStatus(final TPCCContext ctx, final OrderStatusInput input) - throws NotFoundException, EntityNotFoundException { + throws NotFoundException, EntityNotFoundException, SerializationException { /* * [TPC-C 2.6.2.2] * For a given customer number (C_W_ID, C_D_ID, C_ID): ... @@ -627,7 +632,10 @@ private OrderStatusOutput orderStatus(final TPCCContext ctx, final OrderStatusIn * @return The JSON encoded query results according to the specification. */ private PaymentOutput payment(final TPCCContext ctx, final PaymentInput input) - throws EntityNotFoundException, EntityExistsException, NotFoundException { + throws EntityNotFoundException, + EntityExistsException, + NotFoundException, + SerializationException { /* * [TPC-C 2.5.2.2] * For a given warehouse number (W_ID), district number (D_W_ID, @@ -645,14 +653,14 @@ private PaymentOutput payment(final TPCCContext ctx, final PaymentInput input) * retrieved [...] */ final Warehouse warehouse = Warehouse.builder().id(input.getW_id()).build(); - registry.read(ctx, warehouse); + registry.read(warehouse); /* * [TPC-C 2.5.2.2 (3) (continued)] * ... and W_YTD, the warehouse's year-to-date balance, is * increased by H_AMOUNT. */ warehouse.increaseYTD(input.getH_amount()); - registry.update(ctx, warehouse); + registry.update(warehouse); /* * [TPC-C 2.5.2.2 (4)] @@ -662,14 +670,14 @@ private PaymentOutput payment(final TPCCContext ctx, final PaymentInput input) */ final District district = District.builder().w_id(warehouse.getW_id()).id(input.getD_id()).build(); - registry.read(ctx, district); + registry.read(district); /* * [TPC-C 2.5.2.2 (4) (continued)] * ... and D_YTD, the district's year-to-date balance, is * increased by H_AMOUNT. */ district.increaseYTD(input.getH_amount()); - registry.update(ctx, district); + registry.update(district); /* * [TPC-C 2.5.2.2 (5.1)] @@ -740,7 +748,7 @@ private PaymentOutput payment(final TPCCContext ctx, final PaymentInput input) * [TPC-C 2.5.2.2 (6) (continued)] * ... The selected customer is updated with the new C_DATA field. */ - registry.update(ctx, customer); + registry.update(customer); /* * [TPC-C 2.5.2.2 (7)] @@ -765,7 +773,7 @@ private PaymentOutput payment(final TPCCContext ctx, final PaymentInput input) .amount(input.getH_amount()) .data(h_data) .build(); - registry.create(ctx, history); + registry.create(history); /* * [TPC-C 2.5.3.3] @@ -801,7 +809,7 @@ private PaymentOutput payment(final TPCCContext ctx, final PaymentInput input) * @return The transaction output */ private StockLevelOutput stockLevel(final TPCCContext ctx, final StockLevelInput input) - throws EntityNotFoundException, NotFoundException { + throws EntityNotFoundException, NotFoundException, SerializationException { /* * [TPC-C 2.8.2.2] * For a given warehouse number (W_ID), district number (D_W_ID, @@ -814,7 +822,7 @@ private StockLevelOutput stockLevel(final TPCCContext ctx, final StockLevelInput * selected and D_NEXT_O_ID is retrieved. */ final District district = District.builder().w_id(input.getW_id()).id(input.getD_id()).build(); - ctx.getRegistry().read(ctx, district); + ctx.getRegistry().read(district); /* * [TPC-C 2.8.2.2 (4)] @@ -841,7 +849,7 @@ private StockLevelOutput stockLevel(final TPCCContext ctx, final StockLevelInput int lowStock = 0; for (final int i_id : recentItemIds) { final Stock stock = Stock.builder().w_id(input.getW_id()).i_id(i_id).build(); - ctx.getRegistry().read(ctx, stock); + ctx.getRegistry().read(stock); if (stock.getS_quantity() < input.getThreshold()) { logger.debug("The stock quantity is less than the threshold"); ++lowStock; @@ -898,7 +906,8 @@ private static String padDistrictInfo(final String info) { * @param ctx The transaction context * @throws EntityExistsException if a warehouse entry already exists on the ledger */ - private void initWarehouses(final ContextWithRegistry ctx) throws EntityExistsException { + private void initWarehouses(final ContextWithRegistry ctx) + throws EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx.toString()); methodLogger.logStart("initWarehouses", paramString); @@ -915,7 +924,7 @@ private void initWarehouses(final ContextWithRegistry ctx) throws EntityExistsEx .ytd(10000) .build(); - ctx.getRegistry().create(ctx, warehouse); + ctx.getRegistry().create(warehouse); methodLogger.logEnd("initWarehouses", paramString, ""); } @@ -929,7 +938,8 @@ private void initWarehouses(final ContextWithRegistry ctx) throws EntityExistsEx * @param ctx The transaction context * @throws EntityExistsException if a district entry already exists on the ledger */ - private void initDistricts(final ContextWithRegistry ctx) throws EntityExistsException { + private void initDistricts(final ContextWithRegistry ctx) + throws EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx.toString()); methodLogger.logStart("initDistricts", paramString); @@ -948,7 +958,7 @@ private void initDistricts(final ContextWithRegistry ctx) throws EntityExistsExc .next_o_id(3001) .build(); - ctx.getRegistry().create(ctx, district); + ctx.getRegistry().create(district); methodLogger.logEnd("initDistricts", paramString, ""); } @@ -962,7 +972,8 @@ private void initDistricts(final ContextWithRegistry ctx) throws EntityExistsExc * @param ctx The transaction context * @throws EntityExistsException if a customer entry already exists on the ledger */ - private void initCustomers(final ContextWithRegistry ctx) throws EntityExistsException { + private void initCustomers(final ContextWithRegistry ctx) + throws EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx.toString()); methodLogger.logStart("initCustomers", paramString); @@ -1015,9 +1026,9 @@ private void initCustomers(final ContextWithRegistry ctx) throws EntityExistsExc .data("Good credit") .build(); - final Registry registry = ctx.getRegistry(); - registry.create(ctx, alice); - registry.create(ctx, peter); + final hu.bme.mit.ftsrg.hypernate.Registry registry = ctx.getRegistry(); + registry.create(alice); + registry.create(peter); methodLogger.logEnd("initDistricts", paramString, ""); } @@ -1031,7 +1042,8 @@ private void initCustomers(final ContextWithRegistry ctx) throws EntityExistsExc * @param ctx The transaction context * @throws EntityExistsException if an item entry already exists on the ledger */ - private void initItems(final ContextWithRegistry ctx) throws EntityExistsException { + private void initItems(final ContextWithRegistry ctx) + throws EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx.toString()); methodLogger.logStart("initItems", paramString); @@ -1042,10 +1054,10 @@ private void initItems(final ContextWithRegistry ctx) throws EntityExistsExcepti final Item glass = Item.builder().id(3).im_id(456).name("Glass").price(78.00).data("GENERIC").build(); - final Registry registry = ctx.getRegistry(); - registry.create(ctx, cup); - registry.create(ctx, plate); - registry.create(ctx, glass); + final hu.bme.mit.ftsrg.hypernate.Registry registry = ctx.getRegistry(); + registry.create(cup); + registry.create(plate); + registry.create(glass); methodLogger.logEnd("initItems", paramString, ""); } @@ -1059,7 +1071,8 @@ private void initItems(final ContextWithRegistry ctx) throws EntityExistsExcepti * @param ctx The transaction context * @throws EntityExistsException if a stock entry already exists on the ledger */ - private void initStocks(final ContextWithRegistry ctx) throws EntityExistsException { + private void initStocks(final ContextWithRegistry ctx) + throws EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx.toString()); methodLogger.logStart("initStocks", paramString); @@ -1100,10 +1113,10 @@ private void initStocks(final ContextWithRegistry ctx) throws EntityExistsExcept .data("GENERIC") .build(); - final Registry registry = ctx.getRegistry(); - registry.create(ctx, stock1); - registry.create(ctx, stock2); - registry.create(ctx, stock3); + final hu.bme.mit.ftsrg.hypernate.Registry registry = ctx.getRegistry(); + registry.create(stock1); + registry.create(stock2); + registry.create(stock3); methodLogger.logEnd("initStocks", paramString, ""); } @@ -1148,13 +1161,13 @@ private String generateHistoryInformation( */ private OrderLineData getOrderLineDataForOrder( final ContextWithRegistry ctx, final Order order, final int number) - throws EntityNotFoundException { + throws EntityNotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx.toString(), order.toString(), String.valueOf(number)); methodLogger.logStart("getOrderLineDataForOrder", paramString); final OrderLine orderLine = OrderLine.builder().fromOrder(order).number(number).build(); - ctx.getRegistry().read(ctx, orderLine); + ctx.getRegistry().read(orderLine); final OrderLineData orderLineData = OrderLineData.builder().fromOrderLine(orderLine).build(); @@ -1181,13 +1194,13 @@ private DeliveredOrder getOldestNewOrderForDistrict( final int d_id, final int o_carrier_id, final String ol_delivery_d) - throws EntityNotFoundException { + throws EntityNotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString( methodLogger.generateParamsString(ctx, w_id, d_id, o_carrier_id), ol_delivery_d); methodLogger.logStart("getOldestNewOrderForDistrict", paramString); - final Registry registry = ctx.getRegistry(); + final hu.bme.mit.ftsrg.hypernate.Registry registry = ctx.getRegistry(); /* * [TPC-C 2.7.4.2 (3)] @@ -1198,7 +1211,7 @@ private DeliveredOrder getOldestNewOrderForDistrict( */ final List matchingNewOrders = registry - .select(ctx, new NewOrder()) + .select(new NewOrder()) /* TODO this code causes a StackOverflowError for some reason .matching( new Registry.Matcher() { @@ -1244,7 +1257,7 @@ public int compare(final NewOrder a, final NewOrder b) { * [TPC-C 2.7.4.2 (4)] * The selected row in the NEW-ORDER table is deleted. */ - registry.delete(ctx, oldestNewOrder); + registry.delete(oldestNewOrder); /* * [TPC-C 2.7.4.2 (5)] @@ -1254,13 +1267,13 @@ public int compare(final NewOrder a, final NewOrder b) { */ final Order order = Order.builder().w_id(w_id).d_id(d_id).id(oldestNewOrder.getNo_o_id()).build(); - registry.read(ctx, order); + registry.read(order); /* * [TPC-C 2.7.4.2 (5) (continued)] * ... and O_CARRIER_ID is updated. */ order.setO_carrier_id(o_carrier_id); - registry.update(ctx, order); + registry.update(order); /* * [TPC-C 2.7.4.2 (6)] @@ -1281,7 +1294,7 @@ public int compare(final NewOrder a, final NewOrder b) { */ final Customer customer = Customer.builder().w_id(w_id).d_id(d_id).id(order.getO_c_id()).build(); - registry.read(ctx, customer); + registry.read(customer); /* * [TPC-C 2.7.4.2 (7) (continued)] * ... and C_BALANCE is increased by the sum of all order-line @@ -1293,7 +1306,7 @@ public int compare(final NewOrder a, final NewOrder b) { * ... C_DELIVERY_CNT is incremented by 1. */ customer.incrementDeliveryCount(); - registry.update(ctx, customer); + registry.update(customer); final DeliveredOrder deliveredOrder = DeliveredOrder.builder().d_id(d_id).o_id(order.getO_id()).build(); @@ -1328,7 +1341,7 @@ private double getOrderLineAmount( final int o_id, final int number, final String ol_delivery_d) - throws EntityNotFoundException { + throws EntityNotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString( methodLogger.generateParamsString(ctx, w_id, d_id, o_id, number), ol_delivery_d); @@ -1342,7 +1355,7 @@ private double getOrderLineAmount( */ final OrderLine orderLine = OrderLine.builder().w_id(w_id).d_id(d_id).o_id(o_id).number(number).build(); - ctx.getRegistry().read(ctx, orderLine); + ctx.getRegistry().read(orderLine); /* * [TPC-C 2.7.4.2 (6) (continued)] * ... All OL_DELIVERY_D, the delivery dates, are updated to the @@ -1353,7 +1366,7 @@ private double getOrderLineAmount( * [TPC-C 2.7.4.2 (6) (continued)] * ... and the sum of all OL_AMOUNT is retrieved. */ - ctx.getRegistry().update(ctx, orderLine); + ctx.getRegistry().update(orderLine); methodLogger.logEnd( "getOrderLineAmount", paramString, String.valueOf(orderLine.getOl_amount())); @@ -1404,7 +1417,7 @@ private double createOrderLineAndGetAmount( final int nextOrderId, final int number, final Collection itemsDataCollection) - throws EntityNotFoundException, EntityExistsException { + throws EntityNotFoundException, EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString( methodLogger.generateParamsString( @@ -1412,7 +1425,7 @@ private double createOrderLineAndGetAmount( itemsDataCollection.toString()); methodLogger.logStart("createOrderLineAndGetAmount", paramString); - final Registry registry = ctx.getRegistry(); + final hu.bme.mit.ftsrg.hypernate.Registry registry = ctx.getRegistry(); /* * [TPC-C 2.4.2.2 (8.1)] @@ -1424,7 +1437,7 @@ private double createOrderLineAndGetAmount( * (see Clause 2.4.2.3). */ final Item item = Item.builder().id(i_id).build(); - registry.read(ctx, item); + registry.read(item); /* * [TPC-C 2.4.2.2 (8.2)] @@ -1435,7 +1448,7 @@ private double createOrderLineAndGetAmount( * [...] */ final Stock stock = Stock.builder().w_id(i_w_id).i_id(i_id).build(); - registry.read(ctx, stock); + registry.read(stock); /* * [TPC-C 2.4.2.2 (8.2) (continued)] * ... If the retrieved value for S_QUANTITY exceeds OL_QUANTITY @@ -1461,7 +1474,7 @@ private double createOrderLineAndGetAmount( * incremented by 1. */ if (i_w_id != w_id) stock.incrementRemoteCount(); - registry.update(ctx, stock); + registry.update(stock); /* * [TPC-C 2.4.2.2 (8.3)] @@ -1503,7 +1516,7 @@ private double createOrderLineAndGetAmount( .amount(orderLineAmount) .dist_info(padDistrictInfo("s_dist_" + stockDistrictId)) .build(); - registry.create(ctx, orderLine); + registry.create(orderLine); /* * [TPC-C 2.4.3.3] @@ -1559,7 +1572,7 @@ private Customer getCustomerByIDOrLastName( final int c_d_id, final Integer c_id, final String c_last) - throws EntityNotFoundException, NotFoundException { + throws EntityNotFoundException, NotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString( methodLogger.generateParamsString(ctx, c_w_id, c_d_id, c_id), c_last); @@ -1570,13 +1583,12 @@ private Customer getCustomerByIDOrLastName( if (c_id != null) { final Customer customer = - ctx.getRegistry() - .read(ctx, Customer.builder().w_id(c_w_id).d_id(c_d_id).id(c_id).build()); + ctx.getRegistry().read(Customer.builder().w_id(c_w_id).d_id(c_d_id).id(c_id).build()); methodLogger.logEnd("getCustomerByIDOrLastName", paramString, JSON.serialize(customer)); return customer; } else { final List allCustomers = - ctx.getRegistry().readAll(ctx, Customer.builder().w_id(c_w_id).d_id(c_d_id).build()); + ctx.getRegistry().readAll(Customer.builder().w_id(c_w_id).d_id(c_d_id).build()); // Stream-based one-liner replaced with below code to accommodate OpenJML... final List matchingCustomers = new ArrayList<>(); @@ -1607,13 +1619,13 @@ private Customer getCustomerByIDOrLastName( */ private Order getLastOrderOfCustomer( final ContextWithRegistry ctx, final int o_w_id, final int o_d_id, final int o_c_id) - throws NotFoundException { + throws NotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx, o_w_id, o_d_id, o_c_id); methodLogger.logStart("getLastOrderOfCustomer", paramString); - Registry registry = ctx.getRegistry(); + hu.bme.mit.ftsrg.hypernate.Registry registry = ctx.getRegistry(); final List allOrders = - registry.readAll(ctx, Order.builder().w_id(o_w_id).d_id(o_d_id).build()); + registry.readAll(Order.builder().w_id(o_w_id).d_id(o_d_id).build()); if (allOrders.isEmpty()) throw new NotFoundException("No orders found"); // Stream-based one-liner replaced with below code to accommodate OpenJML... @@ -1650,7 +1662,7 @@ private List getItemIdsOfRecentOrders( final int d_id, final int o_id_min, final int o_id_max) - throws EntityNotFoundException, NotFoundException { + throws EntityNotFoundException, NotFoundException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx, w_id, d_id, o_id_min, o_id_max); methodLogger.logStart("getItemIdsOfRecentOrders", paramString); @@ -1660,7 +1672,7 @@ private List getItemIdsOfRecentOrders( final Order order = Order.builder().w_id(w_id).d_id(d_id).id(current_o_id).build(); try { - ctx.getRegistry().read(ctx, order); + ctx.getRegistry().read(order); } catch (EntityNotFoundException _e) { logger.warn( "Order with o_id={} not found while looking up recent orders; ignoring", current_o_id); @@ -1670,7 +1682,7 @@ private List getItemIdsOfRecentOrders( for (int ol_number = 1; ol_number <= order.getO_ol_cnt(); ol_number++) { final OrderLine orderLine = OrderLine.builder().w_id(w_id).d_id(d_id).o_id(current_o_id).number(ol_number).build(); - ctx.getRegistry().read(ctx, orderLine); + ctx.getRegistry().read(orderLine); itemIds.add(orderLine.getOl_i_id()); } } diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Customer.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Customer.java index 28cedff..40bdc17 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Customer.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Customer.java @@ -2,8 +2,8 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.KeyPart; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; +import hu.bme.mit.ftsrg.hypernate.entity.KeyPart; import lombok.EqualsAndHashCode; import org.hyperledger.fabric.contract.annotation.DataType; import org.hyperledger.fabric.contract.annotation.Property; @@ -11,7 +11,7 @@ /** Essentially, the CUSTOMER table. */ @EqualsAndHashCode @DataType() -public class Customer extends SerializableEntityBase { +public class Customer implements Entity { /** The customer ID. Primary key. */ @KeyPart diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/District.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/District.java index 808e650..6e811e8 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/District.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/District.java @@ -2,8 +2,8 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.KeyPart; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; +import hu.bme.mit.ftsrg.hypernate.entity.KeyPart; import lombok.EqualsAndHashCode; import org.hyperledger.fabric.contract.annotation.DataType; import org.hyperledger.fabric.contract.annotation.Property; @@ -11,7 +11,7 @@ /** Essentially, the DISTRICT table. */ @EqualsAndHashCode @DataType() -public final class District extends SerializableEntityBase { +public final class District implements Entity { /** The district ID. Primary key. */ @KeyPart diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/History.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/History.java index 19dd98a..8369bd6 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/History.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/History.java @@ -2,8 +2,8 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.KeyPart; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; +import hu.bme.mit.ftsrg.hypernate.entity.KeyPart; import lombok.EqualsAndHashCode; import org.hyperledger.fabric.contract.annotation.DataType; import org.hyperledger.fabric.contract.annotation.Property; @@ -11,7 +11,7 @@ /** Essentially, the HISTORY table. */ @EqualsAndHashCode @DataType -public final class History extends SerializableEntityBase { +public final class History implements Entity { /** The customer ID. Primary key. */ @KeyPart diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Item.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Item.java index 426b9db..d63ef0f 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Item.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Item.java @@ -2,8 +2,8 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.KeyPart; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; +import hu.bme.mit.ftsrg.hypernate.entity.KeyPart; import lombok.EqualsAndHashCode; import org.hyperledger.fabric.contract.annotation.DataType; import org.hyperledger.fabric.contract.annotation.Property; @@ -11,7 +11,7 @@ /** Essentially, the ITEM table. */ @EqualsAndHashCode @DataType -public final class Item extends SerializableEntityBase { +public final class Item implements Entity { /** The ID of the item. Primary key. */ @KeyPart diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/NewOrder.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/NewOrder.java index 0133ce9..5e54647 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/NewOrder.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/NewOrder.java @@ -2,8 +2,8 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.KeyPart; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; +import hu.bme.mit.ftsrg.hypernate.entity.KeyPart; import lombok.EqualsAndHashCode; import org.hyperledger.fabric.contract.annotation.DataType; import org.hyperledger.fabric.contract.annotation.Property; @@ -11,7 +11,7 @@ /** Essentially, the NEW-ORDER table. */ @EqualsAndHashCode @DataType -public final class NewOrder extends SerializableEntityBase { +public final class NewOrder implements Entity { /** The order ID. Primary key. */ @KeyPart diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Order.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Order.java index 8cb03f8..5780d0d 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Order.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Order.java @@ -2,8 +2,8 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.KeyPart; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; +import hu.bme.mit.ftsrg.hypernate.entity.KeyPart; import lombok.EqualsAndHashCode; import org.hyperledger.fabric.contract.annotation.DataType; import org.hyperledger.fabric.contract.annotation.Property; @@ -11,7 +11,7 @@ /** Essentially, the ORDER table. */ @EqualsAndHashCode @DataType -public final class Order extends SerializableEntityBase { +public final class Order implements Entity { /** The order ID. Primary key. */ @KeyPart diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/OrderLine.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/OrderLine.java index d7e972e..b2935e1 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/OrderLine.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/OrderLine.java @@ -2,8 +2,8 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.KeyPart; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; +import hu.bme.mit.ftsrg.hypernate.entity.KeyPart; import lombok.EqualsAndHashCode; import org.hyperledger.fabric.contract.annotation.DataType; import org.hyperledger.fabric.contract.annotation.Property; @@ -11,7 +11,7 @@ /** Essentially, the ORDER-LINE table. */ @EqualsAndHashCode @DataType -public final class OrderLine extends SerializableEntityBase { +public final class OrderLine implements Entity { /** The order ID associated with the order line. Primary key. */ @KeyPart diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Stock.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Stock.java index 999be05..1524704 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Stock.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Stock.java @@ -2,8 +2,8 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.KeyPart; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; +import hu.bme.mit.ftsrg.hypernate.entity.KeyPart; import lombok.EqualsAndHashCode; import org.hyperledger.fabric.contract.annotation.DataType; import org.hyperledger.fabric.contract.annotation.Property; @@ -11,7 +11,7 @@ /** Essentially, the STOCK table. */ @EqualsAndHashCode @DataType -public final class Stock extends SerializableEntityBase { +public final class Stock implements Entity { /** The ID of the item associated with the stock. Primary key. */ @KeyPart diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Warehouse.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Warehouse.java index 0eab617..c7f0e87 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Warehouse.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/entity/Warehouse.java @@ -2,8 +2,8 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.data.entity; -import hu.bme.mit.ftsrg.chaincode.dataaccess.KeyPart; -import hu.bme.mit.ftsrg.chaincode.dataaccess.SerializableEntityBase; +import hu.bme.mit.ftsrg.hypernate.entity.Entity; +import hu.bme.mit.ftsrg.hypernate.entity.KeyPart; import lombok.EqualsAndHashCode; import org.hyperledger.fabric.contract.annotation.DataType; import org.hyperledger.fabric.contract.annotation.Property; @@ -11,7 +11,7 @@ /** Essentially, the WAREHOUSE table. */ @EqualsAndHashCode @DataType -public class Warehouse extends SerializableEntityBase { +public class Warehouse implements Entity { /** The warehouse ID. Primary key. */ @KeyPart diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/LoggingStubMiddleware.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/LoggingStubMiddleware.java index 3f93699..4766ab8 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/LoggingStubMiddleware.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/LoggingStubMiddleware.java @@ -1,6 +1,6 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.middleware; -import hu.bme.mit.ftsrg.chaincode.dataaccess.ChaincodeStubMiddlewareBase; +import hu.bme.mit.ftsrg.hypernate.middleware.ChaincodeStubMiddlewareBase; import java.util.Arrays; import org.hyperledger.fabric.shim.ChaincodeStub; import org.slf4j.Logger; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/TPCCContext.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/TPCCContext.java index 21a0657..b22712a 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/TPCCContext.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/TPCCContext.java @@ -1,6 +1,6 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.middleware; -import hu.bme.mit.ftsrg.chaincode.dataaccess.ContextWithRegistry; +import hu.bme.mit.ftsrg.hypernate.context.ContextWithRegistry; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/UpdateThrottledChaincodeStubMiddleware.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/UpdateThrottledChaincodeStubMiddleware.java index 8759ef6..4e4ba2e 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/UpdateThrottledChaincodeStubMiddleware.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/UpdateThrottledChaincodeStubMiddleware.java @@ -2,7 +2,7 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.middleware; -import hu.bme.mit.ftsrg.chaincode.dataaccess.ChaincodeStubMiddlewareBase; +import hu.bme.mit.ftsrg.hypernate.middleware.ChaincodeStubMiddlewareBase; import org.hyperledger.fabric.shim.ChaincodeStub; /** diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/WriteBackCachedChaincodeStubMiddleware.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/WriteBackCachedChaincodeStubMiddleware.java index bea70bb..a1c1c4e 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/WriteBackCachedChaincodeStubMiddleware.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/middleware/WriteBackCachedChaincodeStubMiddleware.java @@ -2,7 +2,7 @@ package hu.bme.mit.ftsrg.chaincode.tpcc.middleware; -import hu.bme.mit.ftsrg.chaincode.dataaccess.ChaincodeStubMiddlewareBase; +import hu.bme.mit.ftsrg.hypernate.middleware.ChaincodeStubMiddlewareBase; import java.util.Arrays; import java.util.HashMap; import java.util.Map;