This is an automated email from the ASF dual-hosted git repository.
katarina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mnemonic.git
The following commit(s) were added to refs/heads/master by this push:
new 33bbaec MNEMONIC-807: Refactored, commented, improved readability,
generics.
new 5bd2676 Merge pull request #367 from katarinaking/807
33bbaec is described below
commit 33bbaecff515fcaf9cdc9cde3987df987235f8ae
Author: Katarina <[email protected]>
AuthorDate: Fri Dec 22 20:19:48 2023 +0000
MNEMONIC-807: Refactored, commented, improved readability, generics.
---
.../org/apache/mnemonic/examples/ShowOrder.java | 65 ++++++++++++----------
1 file changed, 36 insertions(+), 29 deletions(-)
diff --git
a/mnemonic-examples/src/main/java/org/apache/mnemonic/examples/ShowOrder.java
b/mnemonic-examples/src/main/java/org/apache/mnemonic/examples/ShowOrder.java
index a22c4af..c67f6fb 100644
---
a/mnemonic-examples/src/main/java/org/apache/mnemonic/examples/ShowOrder.java
+++
b/mnemonic-examples/src/main/java/org/apache/mnemonic/examples/ShowOrder.java
@@ -15,33 +15,40 @@
* limitations under the License.
*/
-package org.apache.mnemonic.examples;
+ package org.apache.mnemonic.examples;
+
+ import org.apache.mnemonic.DurableType;
+ import org.apache.mnemonic.EntityFactoryProxy;
+ import org.apache.mnemonic.EntityFactoryProxyHelper;
+ import org.apache.mnemonic.NonVolatileMemAllocator;
+ import org.apache.mnemonic.Utils;
+
+ public class ShowOrder {
+
+ public static void main(String[] argv) throws Exception {
+ // Create a non-volatile memory pool from a memory service
+ NonVolatileMemAllocator allocator = new NonVolatileMemAllocator(
+ Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
+ 1024L * 1024 * 1024, "./example_order.dat", false);
+
+ // Define durable types and entity factory proxies
+ DurableType[] listGenericFieldTypes = {DurableType.DURABLE};
+ EntityFactoryProxy[] listEntityFactoryProxies = {new
EntityFactoryProxyHelper<>(Product.class)};
+
+ long handler = 0L;
+
+ // Iterate over a range of key IDs (assuming key IDs are used to identify
orders)
+ for (long keyId = 1; keyId <= 3; keyId++) {
+ // Get the handler for the specified key ID
+ handler = allocator.getHandler(keyId);
+
+ // If the handler is valid, restore the Order and show its details
+ if (handler != 0L) {
+ Order order = OrderFactory.restore(allocator,
listEntityFactoryProxies, listGenericFieldTypes, handler, false);
+ order.show();
+ }
+ }
+ }
+ }
+
-import org.apache.mnemonic.DurableType;
-import org.apache.mnemonic.EntityFactoryProxy;
-import org.apache.mnemonic.EntityFactoryProxyHelper;
-import org.apache.mnemonic.NonVolatileMemAllocator;
-import org.apache.mnemonic.Utils;
-
-public class ShowOrder {
-
- public static void main(String[] argv) throws Exception {
-
- /* create a non-volatile memory pool from one of memory services */
- NonVolatileMemAllocator act = new
NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
- 1024L * 1024 * 1024, "./example_order.dat", false);
-
- DurableType listgftypes[] = {DurableType.DURABLE};
-
- EntityFactoryProxy listefproxies[] = {new
EntityFactoryProxyHelper<Product>(Product.class) };
-
- long hdl = 0L;
- for (long keyid = 1; keyid <= 3; keyid++) {
- hdl = act.getHandler(keyid);
- if (0L != hdl) {
- Order o = OrderFactory.restore(act, listefproxies, listgftypes, hdl,
false);
- o.show();
- }
- }
- }
-}