Note that there are some explanatory texts on larger screens.

plurals
  1. POHashtable update in WebService java
    primarykey
    data
    text
    <p>I developed a simple distrusted system in Java RMI, now I have to change it to Web Services. I have a problem with my data structure:</p> <p><code>Hashtable&lt;String, ArrayList&lt;Records&gt;&gt; recordsTable;</code> </p> <p><strong>it does not serialize/update my objects correctly.</strong></p> <p>I'm clueless how to change my data structure to overcome such problem? </p> <p>[Edited]</p> <p>For simplicity, say I have this data structure: </p> <p><code>Hashtable&lt;String, Integer&gt; store = new Hashtable&lt;String, Integer&gt;();</code></p> <p>I have a buy() and display() service that is published. Initially I have 100 Apples in store, so when I buy() 10 apples it will print a result of 90 apples. <strong>BUT</strong> when I invoke display later it will print 100 apples.</p> <p>So there is a serialization problem I have no idea how to fix that.</p> <pre><code>public class StoreServer{ Hashtable&lt;String, Integer&gt; store= new Hashtable&lt;String, Integer&gt;(); public StoreServer() { store.put("Coffee", 20); store.put("Apple", 100); store.put("Banana", 50); display(); } public String buy(String item, int quantity) { if(store.containsKey(item)) { int oldQuantity = store.get(item); int newQuantity; if(oldQuantity-quantity&gt;=0) { newQuantity= oldQuantity -quantity; store.put(item, newQuantity); return quantity+" "+item+" were successfully purchased!\n" + ("1. Coffee: "+store.get("Coffee")+"\n")+ ("2. Apples: "+store.get("Apple")+"\n")+ ("3. Bananas: "+store.get("Banana")+"\n")+ ("---------------------------\n"); } else { return "error with your purchase"; } } else { return "error with your purchase"; } } public void display() { System.out.println("------Store Inventory-----"); System.out.println("1. Coffee: "+store.get("Coffee")); System.out.println("2. Apples: "+store.get("Apple")); System.out.println("3. Bananas: "+store.get("Banana")); System.out.println("---------------------------"); }} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload