Skip to content

Commit

Permalink
Merge pull request #372 from katarinaking/812
Browse files Browse the repository at this point in the history
MNEMONIC-812: Enhancing Mnemonic Order Entity
  • Loading branch information
katarinaking committed Jan 26, 2024
2 parents 9958e0d + 4c7398c commit 8e11529
Showing 1 changed file with 141 additions and 57 deletions.
198 changes: 141 additions & 57 deletions mnemonic-examples/src/main/java/org/apache/mnemonic/examples/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,71 +29,155 @@

import java.util.Date;

/**
* Represents an order entity that is durable.
*/
@DurableEntity
public abstract class Order implements Durable {
protected transient EntityFactoryProxy[] m_node_efproxies;
protected transient DurableType[] m_node_gftypes;

@Override
public void initializeAfterCreate() {
}

@Override
public void initializeAfterRestore() {
}

@Override
public void setupGenericInfo(EntityFactoryProxy[] efproxies, DurableType[] gftypes) {
m_node_efproxies = efproxies;
m_node_gftypes = gftypes;
}

@DurableGetter
public abstract String getId() throws RetrieveDurableEntityError;

@DurableSetter
public abstract void setId(String str, boolean destroy)
throws OutOfHybridMemory, RetrieveDurableEntityError;


public Date getDate() {
return new Date(getTimestamp());
}
// Define transient fields for entity factory proxies and durable types
protected transient EntityFactoryProxy[] m_node_efproxies;
protected transient DurableType[] m_node_gftypes;

public void setDate(Date date, boolean destroy) {
setTimestamp(date.getTime(), destroy);
}

@DurableGetter
public abstract Long getTimestamp() throws RetrieveDurableEntityError;

@DurableSetter
public abstract void setTimestamp(Long ts, boolean destroy)
throws OutOfHybridMemory, RetrieveDurableEntityError;
/**
* Initializes the entity after creation.
*/
@Override
public void initializeAfterCreate() {
}

@DurableGetter
public abstract Customer getCustomer() throws RetrieveDurableEntityError;
/**
* Initializes the entity after restoration.
*/
@Override
public void initializeAfterRestore() {
}

@DurableSetter
public abstract void setCustomer(Customer customer, boolean destroy) throws RetrieveDurableEntityError;
/**
* Sets up generic information for the entity.
*
* @param efproxies entity factory proxies
* @param gftypes durable types
*/
@Override
public void setupGenericInfo(EntityFactoryProxy[] efproxies, DurableType[] gftypes) {
m_node_efproxies = efproxies;
m_node_gftypes = gftypes;
}

@DurableGetter(Id = 2L, EntityFactoryProxies = "m_node_efproxies", GenericFieldTypes = "m_node_gftypes")
public abstract DurableSinglyLinkedList<Product> getItems() throws RetrieveDurableEntityError;
/**
* Gets the ID of the order.
*
* @return the ID of the order
* @throws RetrieveDurableEntityError if unable to retrieve the durable entity
*/
@DurableGetter
public abstract String getId() throws RetrieveDurableEntityError;

/**
* Sets the ID of the order.
*
* @param str the ID of the order
* @param destroy specifies whether to destroy the order
* @throws OutOfHybridMemory if out of hybrid memory
* @throws RetrieveDurableEntityError if unable to retrieve the durable entity
*/
@DurableSetter
public abstract void setId(String str, boolean destroy)
throws OutOfHybridMemory, RetrieveDurableEntityError;

/**
* Gets the date of the order.
*
* @return the date of the order
*/
public Date getDate() {
return new Date(getTimestamp());
}

@DurableSetter
public abstract void setItems(DurableSinglyLinkedList<Product> items, boolean destroy)
throws RetrieveDurableEntityError;
/**
* Sets the date of the order.
*
* @param date the date of the order
* @param destroy specifies whether to destroy the order
*/
public void setDate(Date date, boolean destroy) {
setTimestamp(date.getTime(), destroy);
}

public void show() {
System.out.printf("Order ID: %s \n", getId());
System.out.printf("Order Date: %s \n", getDate().toString());
System.out.printf("Order Customer: ");
getCustomer().show();
System.out.printf("Order Items: --BEGIN-- \n");
DurableSinglyLinkedList<Product> prodlist = getItems();
for (Product prod : prodlist) {
prod.show();
/**
* Gets the timestamp of the order.
*
* @return the timestamp of the order
* @throws RetrieveDurableEntityError if unable to retrieve the durable entity
*/
@DurableGetter
public abstract Long getTimestamp() throws RetrieveDurableEntityError;

/**
* Sets the timestamp of the order.
*
* @param ts the timestamp of the order
* @param destroy specifies whether to destroy the order
* @throws OutOfHybridMemory if out of hybrid memory
* @throws RetrieveDurableEntityError if unable to retrieve the durable entity
*/
@DurableSetter
public abstract void setTimestamp(Long ts, boolean destroy)
throws OutOfHybridMemory, RetrieveDurableEntityError;

/**
* Gets the customer of the order.
*
* @return the customer of the order
* @throws RetrieveDurableEntityError if unable to retrieve the durable entity
*/
@DurableGetter
public abstract Customer getCustomer() throws RetrieveDurableEntityError;

/**
* Sets the customer of the order.
*
* @param customer the customer of the order
* @param destroy specifies whether to destroy the order
* @throws RetrieveDurableEntityError if unable to retrieve the durable entity
*/
@DurableSetter
public abstract void setCustomer(Customer customer, boolean destroy) throws RetrieveDurableEntityError;

/**
* Gets the items of the order.
*
* @return the items of the order
* @throws RetrieveDurableEntityError if unable to retrieve the durable entity
*/
@DurableGetter(Id = 2L, EntityFactoryProxies = "m_node_efproxies", GenericFieldTypes = "m_node_gftypes")
public abstract DurableSinglyLinkedList<Product> getItems() throws RetrieveDurableEntityError;

/**
* Sets the items of the order.
*
* @param items the items of the order
* @param destroy specifies whether to destroy the order
* @throws RetrieveDurableEntityError if unable to retrieve the durable entity
*/
@DurableSetter
public abstract void setItems(DurableSinglyLinkedList<Product> items, boolean destroy)
throws RetrieveDurableEntityError;

/**
* Shows the details of the order.
*/
public void show() {
System.out.printf("Order ID: %s \n", getId());
System.out.printf("Order Date: %s \n", getDate().toString());
System.out.printf("Order Customer: ");
getCustomer().show();
System.out.printf("Order Items: --BEGIN-- \n");
DurableSinglyLinkedList<Product> prodlist = getItems();
for (Product prod : prodlist) {
prod.show();
}
System.out.printf("Order Items: -- END -- \n");
}
System.out.printf("Order Items: -- END -- \n");
}
}

0 comments on commit 8e11529

Please sign in to comment.