Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNEMONIC-812: Enhancing Mnemonic Order Entity #372

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
Loading