From 9324b47ae05f83d822916a281957e49209ff3340 Mon Sep 17 00:00:00 2001 From: Katarina Date: Wed, 19 Jun 2024 23:33:29 +0000 Subject: [PATCH] MNEMONIC-835: Annotated Durable Entity --- .../org/apache/mnemonic/examples/Product.java | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/mnemonic-examples/src/main/java/org/apache/mnemonic/examples/Product.java b/mnemonic-examples/src/main/java/org/apache/mnemonic/examples/Product.java index d82ac4ec..4bd10dfb 100644 --- a/mnemonic-examples/src/main/java/org/apache/mnemonic/examples/Product.java +++ b/mnemonic-examples/src/main/java/org/apache/mnemonic/examples/Product.java @@ -26,36 +26,88 @@ import org.apache.mnemonic.OutOfHybridMemory; import org.apache.mnemonic.RetrieveDurableEntityError; +/** + * The Product class represents a durable entity that can be persisted + * and restored from non-volatile memory. It implements the Durable interface, + * indicating it supports mnemonic protocol features. + */ @DurableEntity public abstract class Product implements Durable { + /** + * This method is called after the entity is created. It can be used to perform + * any initialization logic required after creation. Currently, it is empty. + */ @Override public void initializeAfterCreate() { } + /** + * This method is called after the entity is restored. It can be used to perform + * any initialization logic required after restoration. Currently, it is empty. + */ @Override public void initializeAfterRestore() { } + /** + * This method sets up the generic information for the entity. It is used to + * associate entity factory proxies and durable types with the entity. + * + * @param efproxies Array of entity factory proxies + * @param gftypes Array of durable types + */ @Override public void setupGenericInfo(EntityFactoryProxy[] efproxies, DurableType[] gftypes) { - + // Setup logic for generic information can be added here if needed } + /** + * Retrieves the name of the product. + * + * @return the name of the product + * @throws RetrieveDurableEntityError if an error occurs while retrieving the entity + */ @DurableGetter public abstract String getName() throws RetrieveDurableEntityError; + /** + * Sets the name of the product. + * + * @param name the name to set + * @param destroy whether to destroy the previous value + * @throws OutOfHybridMemory if there is insufficient memory to store the new value + * @throws RetrieveDurableEntityError if an error occurs while retrieving the entity + */ @DurableSetter public abstract void setName(String name, boolean destroy) throws OutOfHybridMemory, RetrieveDurableEntityError; + /** + * Retrieves the price of the product. + * + * @return the price of the product + * @throws RetrieveDurableEntityError if an error occurs while retrieving the entity + */ @DurableGetter public abstract Double getPrice() throws RetrieveDurableEntityError; + /** + * Sets the price of the product. + * + * @param price the price to set + * @param destroy whether to destroy the previous value + * @throws OutOfHybridMemory if there is insufficient memory to store the new value + * @throws RetrieveDurableEntityError if an error occurs while retrieving the entity + */ @DurableSetter public abstract void setPrice(Double price, boolean destroy) throws OutOfHybridMemory, RetrieveDurableEntityError; + /** + * Displays the product's name and price in a formatted string. + * This method is for demonstration purposes. + */ public void show() { System.out.printf("%s $%.2f \n", getName(), getPrice()); }