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/README.md b/smart-contract/hyperledger-fabric/v2/java/README.md index 5a3aed0..3ec87c9 100644 --- a/smart-contract/hyperledger-fabric/v2/java/README.md +++ b/smart-contract/hyperledger-fabric/v2/java/README.md @@ -15,6 +15,16 @@ However, note that normally, you do not need to locally build the chaincode. The [test network](../../../../test-network/README.adoc) will build generate this JAR as part of a [dockerized](https://www.docker.com/) build process. Build directly only if you know what you are doing. +## Development + +You most likely do not want to build with OpenJML for local development, eg in your IDE. +To disable OpenJML, simply set the `withoutOpenJML` Gradle property to `true`. +For example, in `gradle.properties`: + +```properties +withoutOpenJML = "true" +``` + ## License diff --git a/smart-contract/hyperledger-fabric/v2/java/build.gradle.kts b/smart-contract/hyperledger-fabric/v2/java/build.gradle.kts index cae3f95..d9cc825 100644 --- a/smart-contract/hyperledger-fabric/v2/java/build.gradle.kts +++ b/smart-contract/hyperledger-fabric/v2/java/build.gradle.kts @@ -1,9 +1,8 @@ /* Originally based on https://github.com/mingyang91/openjml-template */ -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 +import org.gradle.api.tasks.testing.logging.TestLogEvent val openJMLDir = layout.projectDirectory.dir(".openjml") val openJMLJavaHomeDir = openJMLDir.dir("jdk") @@ -12,13 +11,18 @@ val downloadDir = layout.buildDirectory.dir("tmp/download") val jmlavac = openJMLJavaHomeDir.file("bin/jmlavac") val jmlava = openJMLJavaHomeDir.file("bin/jmlava") +val withoutOpenJML: String? by project +val noOpenJML: Boolean = withoutOpenJML != null && withoutOpenJML.toBoolean() + plugins { application id("com.github.johnrengelman.shadow") version "7.1.2" id("com.diffplug.spotless") version "6.19.0" } -group = "hu.bme.mit.ftsrg.tpcc" +// java { toolchain { languageVersion.set(JavaLanguageVersion.of(17) } } + +group = "hu.bme.mit.ftsrg.chaincode.tpcc" version = "0.1.0" @@ -28,7 +32,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") @@ -37,6 +43,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")) @@ -49,73 +56,83 @@ dependencies { application { mainClass.set("org.hyperledger.fabric.contract.ContractRouter") } tasks.named("shadowJar") { - if (System.getenv("NO_JML") == "") dependsOn(tasks.named("initOpenJML")) - archiveBaseName.set("chaincode") archiveClassifier.set("") archiveVersion.set("") } -tasks.named("test") { useJUnitPlatform() } +tasks.register("initOpenJML") { + val openJMLVersion: String by project -tasks.test { - java { - executable = "$openJMLDir/bin/jmlava" - jvmArgs = listOf("-Dorg.jmlspecs.openjml.rac=exception") - } + val zipFile: File = downloadDir.get().file("openjml.zip").asFile + downloadOpenJML(openJMLVersion, zipFile, logger) + extractOpenJML(zipFile, openJMLDir, logger) + + // `jmlavac' is what we call `javac' that is actually + // OpenJML's javac; likewise, `jmlava' is a wrapper for `java' with + // OpenJML already in the classpath + generateJmlavac(jmlavac.asFile, openJMLJavaHomeDir, logger) + replaceJavac(openJMLJavaHomeDir, jmlavac.asFile, logger) + generateJmlava(jmlava.asFile, openJMLJavaHomeDir, logger) + replaceJava(openJMLJavaHomeDir, jmlava.asFile, logger) + logger.lifecycle("✅ OpenJML successfully initialized in $openJMLDir") } -// java { -// sourceCompatibility = JavaVersion.VERSION_17 -// targetCompatibility = JavaVersion.VERSION_17 -// } +if (!noOpenJML) { + tasks.named("shadowJar") { dependsOn(tasks.named("initOpenJML")) } + + tasks.test { + java { + executable = "$openJMLDir/bin/jmlava" + jvmArgs = listOf("-Dorg.jmlspecs.openjml.rac=exception") + } + } -tasks.withType().configureEach { - // Only when not compiling because of Spotless - if (!gradle.startParameter.taskNames.any { it.contains("spotlessApply") } && - System.getenv("NO_JML") == "") { + tasks.withType().configureEach { dependsOn(tasks.named("initOpenJML")) - val mode = - 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/")) - options.forkOptions.javaHome = openJMLJavaHomeDir.asFile + // 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" + } + options.isFork = true + options.compilerArgs.addAll( + listOf( + "-jml", + "-$mode", + "-timeout", + "30", + "--nullable-by-default", + "--specs-path", + "specs/")) + options.forkOptions.javaHome = openJMLJavaHomeDir.asFile + } } } -configure { +tasks.test { + useJUnitPlatform() + testLogging { + showExceptions = true + events = setOf(TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED) + } +} + +spotless { java { importOrder() removeUnusedImports() googleJavaFormat() formatAnnotations() toggleOffOn() + licenseHeader("/* SPDX-License-Identifier: Apache-2.0 */") } kotlin { target("src/*/kotlin/**/*.kt", "buildSrc/src/*/kotlin/**/*.kt") ktfmt() + licenseHeader("/* SPDX-License-Identifier: Apache-2.0 */") } kotlinGradle { ktfmt() } } - -tasks.register("initOpenJML") { - val openJMLVersion: String by project - - val zipFile: File = downloadDir.get().file("openjml.zip").asFile - downloadOpenJML(openJMLVersion, zipFile, logger) - extractOpenJML(zipFile, openJMLDir, logger) - - // `jmlavac' is what we call `javac' that is actually - // OpenJML's javac; likewise, `jmlava' is a wrapper for `java' with - // OpenJML already in the classpath - generateJmlavac(jmlavac.asFile, openJMLJavaHomeDir, logger) - replaceJavac(openJMLJavaHomeDir, jmlavac.asFile, logger) - generateJmlava(jmlava.asFile, openJMLJavaHomeDir, logger) - replaceJava(openJMLJavaHomeDir, jmlava.asFile, logger) - logger.lifecycle("✅ OpenJML successfully initialized in $openJMLDir") -} diff --git a/smart-contract/hyperledger-fabric/v2/java/buildSrc/src/main/kotlin/hu/bme/mit/ftsrg/openjmlhelper/OpenJMLHelper.kt b/smart-contract/hyperledger-fabric/v2/java/buildSrc/src/main/kotlin/hu/bme/mit/ftsrg/openjmlhelper/OpenJMLHelper.kt index d2ff6f9..26cbc27 100644 --- a/smart-contract/hyperledger-fabric/v2/java/buildSrc/src/main/kotlin/hu/bme/mit/ftsrg/openjmlhelper/OpenJMLHelper.kt +++ b/smart-contract/hyperledger-fabric/v2/java/buildSrc/src/main/kotlin/hu/bme/mit/ftsrg/openjmlhelper/OpenJMLHelper.kt @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: Apache-2.0 */ package hu.bme.mit.ftsrg.openjmlhelper import java.io.File 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..0197780 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; @@ -57,4 +57,9 @@ public final class TPCC implements ContractInterface { @*/ private StockLevelOutput stockLevel(final TPCCContext ctx, final StockLevelInput input) throws EntityNotFoundException, NotFoundException; + + /*@ + @ requires c_id < 2; + @*/ + public String OJMLTEST__getCustomer(final TPCCContext ctx, final int c_w_id, final int c_d_id, final int c_id); } 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 fc42e92..d6f830f 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,7 @@ +/* SPDX-License-Identifier: Apache-2.0 */ 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; @@ -42,7 +43,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/api/NotFoundException.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/api/NotFoundException.java index b6be956..7afab25 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/api/NotFoundException.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/api/NotFoundException.java @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: Apache-2.0 */ package hu.bme.mit.ftsrg.chaincode.tpcc.api; public final class NotFoundException extends Exception { diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/api/TPCCBusinessAPI.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/api/TPCCBusinessAPI.java index c1c1bc7..83b14dc 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/api/TPCCBusinessAPI.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/api/TPCCBusinessAPI.java @@ -1,19 +1,19 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.api; 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.*; 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; 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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +39,7 @@ class TPCCBusinessAPI { * @return The transaction output */ static DeliveryOutput delivery(final TPCCContext ctx, final DeliveryInput input) - throws EntityNotFoundException { + throws EntityNotFoundException, SerializationException { /* * [TPC-C 2.7.4.2] @@ -101,7 +101,7 @@ static DeliveryOutput delivery(final TPCCContext ctx, final DeliveryInput input) * @return The transaction output */ static 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, @@ -119,7 +119,7 @@ static 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)] @@ -128,7 +128,7 @@ static 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 @@ -136,7 +136,7 @@ static 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(), @@ -155,7 +155,7 @@ static 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)] @@ -168,7 +168,7 @@ static 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 @@ -190,7 +190,7 @@ static NewOrderOutput newOrder(final TPCCContext ctx, final NewOrderInput input) .ol_cnt(input.getI_ids().length) .all_local(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)] @@ -213,7 +213,7 @@ static NewOrderOutput newOrder(final TPCCContext ctx, final NewOrderInput input) */ final Item item = Item.builder().id(i_ids[i]).build(); try { - registry.read(ctx, item); + registry.read(item); } catch (EntityNotFoundException e) { /* * [TPC-C 2.4.2.3] @@ -304,7 +304,7 @@ static NewOrderOutput newOrder(final TPCCContext ctx, final NewOrderInput input) * @return The transaction output */ static 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): ... @@ -392,7 +392,10 @@ static OrderStatusOutput orderStatus(final TPCCContext ctx, final OrderStatusInp * @return The JSON encoded query results according to the specification. */ static 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, @@ -410,14 +413,14 @@ static 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)] @@ -427,14 +430,14 @@ static 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)] @@ -506,7 +509,7 @@ static 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)] @@ -531,7 +534,7 @@ static 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] @@ -568,7 +571,7 @@ static PaymentOutput payment(final TPCCContext ctx, final PaymentInput input) * @return The transaction output */ static 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, @@ -581,7 +584,7 @@ static 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)] @@ -608,7 +611,7 @@ static 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; @@ -635,7 +638,7 @@ static StockLevelOutput stockLevel(final TPCCContext ctx, final StockLevelInput * * @param ctx The transaction context */ - static void init(final TPCCContext ctx) throws EntityExistsException { + static void init(final TPCCContext ctx) throws EntityExistsException, SerializationException { initWarehouses(ctx); initDistricts(ctx); initCustomers(ctx); @@ -686,7 +689,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 static void initWarehouses(final ContextWithRegistry ctx) throws EntityExistsException { + private static void initWarehouses(final ContextWithRegistry ctx) + throws EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx.toString()); methodLogger.logStart("initWarehouses", paramString); @@ -703,7 +707,7 @@ private static void initWarehouses(final ContextWithRegistry ctx) throws EntityE .ytd(10000) .build(); - ctx.getRegistry().create(ctx, warehouse); + ctx.getRegistry().create(warehouse); methodLogger.logEnd("initWarehouses", paramString, ""); } @@ -717,7 +721,8 @@ private static void initWarehouses(final ContextWithRegistry ctx) throws EntityE * @param ctx The transaction context * @throws EntityExistsException if a district entry already exists on the ledger */ - private static void initDistricts(final ContextWithRegistry ctx) throws EntityExistsException { + private static void initDistricts(final ContextWithRegistry ctx) + throws EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx.toString()); methodLogger.logStart("initDistricts", paramString); @@ -736,7 +741,7 @@ private static void initDistricts(final ContextWithRegistry ctx) throws EntityEx .next_o_id(3001) .build(); - ctx.getRegistry().create(ctx, district); + ctx.getRegistry().create(district); methodLogger.logEnd("initDistricts", paramString, ""); } @@ -750,7 +755,8 @@ private static void initDistricts(final ContextWithRegistry ctx) throws EntityEx * @param ctx The transaction context * @throws EntityExistsException if a customer entry already exists on the ledger */ - private static void initCustomers(final ContextWithRegistry ctx) throws EntityExistsException { + private static void initCustomers(final ContextWithRegistry ctx) + throws EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx.toString()); methodLogger.logStart("initCustomers", paramString); @@ -804,8 +810,8 @@ private static void initCustomers(final ContextWithRegistry ctx) throws EntityEx .build(); final Registry registry = ctx.getRegistry(); - registry.create(ctx, alice); - registry.create(ctx, peter); + registry.create(alice); + registry.create(peter); methodLogger.logEnd("initDistricts", paramString, ""); } @@ -819,7 +825,8 @@ private static void initCustomers(final ContextWithRegistry ctx) throws EntityEx * @param ctx The transaction context * @throws EntityExistsException if an item entry already exists on the ledger */ - private static void initItems(final ContextWithRegistry ctx) throws EntityExistsException { + private static void initItems(final ContextWithRegistry ctx) + throws EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx.toString()); methodLogger.logStart("initItems", paramString); @@ -831,9 +838,9 @@ private static void initItems(final ContextWithRegistry ctx) throws EntityExists 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); + registry.create(cup); + registry.create(plate); + registry.create(glass); methodLogger.logEnd("initItems", paramString, ""); } @@ -847,7 +854,8 @@ private static void initItems(final ContextWithRegistry ctx) throws EntityExists * @param ctx The transaction context * @throws EntityExistsException if a stock entry already exists on the ledger */ - private static void initStocks(final ContextWithRegistry ctx) throws EntityExistsException { + private static void initStocks(final ContextWithRegistry ctx) + throws EntityExistsException, SerializationException { final String paramString = methodLogger.generateParamsString(ctx.toString()); methodLogger.logStart("initStocks", paramString); @@ -889,9 +897,9 @@ private static void initStocks(final ContextWithRegistry ctx) throws EntityExist .build(); final Registry registry = ctx.getRegistry(); - registry.create(ctx, stock1); - registry.create(ctx, stock2); - registry.create(ctx, stock3); + registry.create(stock1); + registry.create(stock2); + registry.create(stock3); methodLogger.logEnd("initStocks", paramString, ""); } @@ -937,13 +945,13 @@ private static String generateHistoryInformation( */ private static 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(); @@ -970,7 +978,7 @@ private static DeliveredOrder deliverOldestNewOrderForDistrict( 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); @@ -987,7 +995,7 @@ private static DeliveredOrder deliverOldestNewOrderForDistrict( */ final List matchingNewOrders = registry - .select(ctx, new NewOrder()) + .select(new NewOrder()) /* TODO this code causes a StackOverflowError for some reason .matching( new Registry.Matcher() { @@ -1037,7 +1045,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)] @@ -1047,13 +1055,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)] @@ -1075,7 +1083,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 @@ -1087,7 +1095,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(); @@ -1105,7 +1113,7 @@ public int compare(final NewOrder a, final NewOrder b) { * *

NOTE: this code has been factored out of {@link TPCCContractAPI#delivery(TPCCContext, * String)} (and then consequently from {@link - * TPCCContractAPI#deliverOldestNewOrderForDistrict(ContextWithRegistry, int, int, int, String)}) + * TPCCBusinessAPI#deliverOldestNewOrderForDistrict(ContextWithRegistry, int, int, int, String)}) * only so that OpenJML won't choke on the exceedingly long method. * * @param ctx The transaction context @@ -1123,7 +1131,7 @@ private static double getOrderLineAmountAndUpdateTime( 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); @@ -1137,7 +1145,7 @@ private static double getOrderLineAmountAndUpdateTime( */ 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 @@ -1148,7 +1156,7 @@ private static double getOrderLineAmountAndUpdateTime( * [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( "getOrderLineAmountAndUpdateTime", paramString, String.valueOf(orderLine.getOl_amount())); @@ -1200,7 +1208,7 @@ private static 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( @@ -1219,7 +1227,7 @@ private static 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 @@ -1250,7 +1258,7 @@ private static double createOrderLineAndGetAmount( if (i_w_id != w_id) { stock.incrementRemoteCount(); } - registry.update(ctx, stock); + registry.update(stock); /* * [TPC-C 2.4.2.2 (8.3)] @@ -1291,7 +1299,7 @@ private static double createOrderLineAndGetAmount( .amount(orderLineAmount) .dist_info(padDistrictInfo(stock.getS_dist(d_id))) .build(); - registry.create(ctx, orderLine); + registry.create(orderLine); /* * [TPC-C 2.4.3.3] @@ -1347,7 +1355,7 @@ private static 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); @@ -1359,13 +1367,12 @@ private static 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<>(); @@ -1410,13 +1417,13 @@ public int compare(final Customer a, final Customer b) { */ private static 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(); 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"); } @@ -1460,7 +1467,7 @@ private static 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); @@ -1470,7 +1477,7 @@ private static 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); @@ -1480,7 +1487,7 @@ private static 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/api/TPCCContractAPI.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/api/TPCCContractAPI.java index e0b4c7a..3599e7c 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/api/TPCCContractAPI.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/api/TPCCContractAPI.java @@ -1,15 +1,15 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.api; 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 hu.bme.mit.ftsrg.chaincode.tpcc.data.entity.*; import hu.bme.mit.ftsrg.chaincode.tpcc.data.input.*; import hu.bme.mit.ftsrg.chaincode.tpcc.middleware.TPCCContext; import hu.bme.mit.ftsrg.chaincode.tpcc.util.JSON; +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 org.hyperledger.fabric.contract.Context; import org.hyperledger.fabric.contract.ContractInterface; import org.hyperledger.fabric.contract.annotation.Contact; @@ -60,7 +60,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 = @@ -81,7 +81,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 = @@ -100,7 +100,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 = @@ -122,7 +122,7 @@ 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 = @@ -143,7 +143,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 = @@ -159,7 +159,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); TPCCBusinessAPI.init(ctx); @@ -175,12 +175,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); @@ -199,12 +199,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); @@ -220,12 +220,12 @@ 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); @@ -244,12 +244,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); 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..737c5d5 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 @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: Apache-2.0 */ - 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 +10,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..77343e1 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 @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: Apache-2.0 */ - 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 +10,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..d16c22d 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 @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: Apache-2.0 */ - 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 +10,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..ea9a67a 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 @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: Apache-2.0 */ - 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 +10,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..19115cc 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 @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: Apache-2.0 */ - 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 +10,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..c638092 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 @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: Apache-2.0 */ - 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 +10,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..fcce364 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 @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: Apache-2.0 */ - 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 +10,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 3c52aae..f5bb6a0 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 @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: Apache-2.0 */ - 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 +10,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..16b0b64 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 @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: Apache-2.0 */ - 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 +10,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/data/extra/DeliveredOrder.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/extra/DeliveredOrder.java index 201c48a..0c73764 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/extra/DeliveredOrder.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/extra/DeliveredOrder.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.extra; import hu.bme.mit.ftsrg.chaincode.tpcc.data.output.DeliveryOutput; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/extra/ItemsData.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/extra/ItemsData.java index 87874ec..6e4ee9a 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/extra/ItemsData.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/extra/ItemsData.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.extra; import hu.bme.mit.ftsrg.chaincode.tpcc.data.output.NewOrderOutput; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/extra/OrderLineData.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/extra/OrderLineData.java index fac8e5c..c8c6c8c 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/extra/OrderLineData.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/extra/OrderLineData.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.extra; import hu.bme.mit.ftsrg.chaincode.tpcc.data.entity.OrderLine; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/DeliveryInput.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/DeliveryInput.java index fa952d8..4fd0c72 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/DeliveryInput.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/DeliveryInput.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.input; import lombok.EqualsAndHashCode; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/NewOrderInput.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/NewOrderInput.java index 0d1c923..2272094 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/NewOrderInput.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/NewOrderInput.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.input; import lombok.EqualsAndHashCode; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/OrderStatusInput.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/OrderStatusInput.java index 298da91..c204f8b 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/OrderStatusInput.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/OrderStatusInput.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.input; import lombok.EqualsAndHashCode; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/PaymentInput.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/PaymentInput.java index bb80d94..7a2b2a1 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/PaymentInput.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/PaymentInput.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.input; import lombok.EqualsAndHashCode; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/StockLevelInput.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/StockLevelInput.java index 8c1d792..bc9ac24 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/StockLevelInput.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/input/StockLevelInput.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.input; import lombok.EqualsAndHashCode; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/DeliveryOutput.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/DeliveryOutput.java index 1860868..83b2fc6 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/DeliveryOutput.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/DeliveryOutput.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.output; import hu.bme.mit.ftsrg.chaincode.tpcc.data.extra.DeliveredOrder; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/NewOrderOutput.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/NewOrderOutput.java index 05535a8..3a30785 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/NewOrderOutput.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/NewOrderOutput.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.output; import hu.bme.mit.ftsrg.chaincode.tpcc.data.entity.Customer; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/OrderStatusOutput.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/OrderStatusOutput.java index 1877a38..0225bcc 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/OrderStatusOutput.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/OrderStatusOutput.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.output; import hu.bme.mit.ftsrg.chaincode.tpcc.data.entity.Customer; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/PaymentOutput.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/PaymentOutput.java index 35e81cf..30398bb 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/PaymentOutput.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/PaymentOutput.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.output; import hu.bme.mit.ftsrg.chaincode.tpcc.data.entity.Customer; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/StockLevelOutput.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/StockLevelOutput.java index b084c5c..48e6309 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/StockLevelOutput.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/data/output/StockLevelOutput.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.data.output; import hu.bme.mit.ftsrg.chaincode.tpcc.data.input.StockLevelInput; 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..70fac07 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,7 @@ +/* SPDX-License-Identifier: Apache-2.0 */ 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..77a55e8 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,7 @@ +/* SPDX-License-Identifier: Apache-2.0 */ 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..b8a7149 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 @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: Apache-2.0 */ - 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 9abd4c2..c609c15 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 @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: Apache-2.0 */ - 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; diff --git a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/util/JSON.java b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/util/JSON.java index afcb0d6..d340d05 100644 --- a/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/util/JSON.java +++ b/smart-contract/hyperledger-fabric/v2/java/src/main/java/hu/bme/mit/ftsrg/chaincode/tpcc/util/JSON.java @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: Apache-2.0 */ - package hu.bme.mit.ftsrg.chaincode.tpcc.util; import com.google.gson.Gson;