Forum Stats

  • 3,875,875 Users
  • 2,266,977 Discussions
  • 7,912,363 Comments

Discussions

Need help in implementing persistence in my java desktop app

843810
843810 Member Posts: 46,938
edited Feb 3, 2010 10:18AM in Java Desktop Applications
Hi,

I am building a simple desktop app for displaying and editing comparative rates of different currencies.


- On the main form, I have a button which says "Show Currency Menu." It displays a new form which shows the comparative currency rates.
- I need to add a simple "Rates" table which will contain the rates.


The functionality that I want to achieve with the help of this table is:
- When Currency Menu is shown, its fields should contain/display the latest rates that were entered and saved.
- If the user changes some rates and clicks the "Save" button on the Currency Menu form, they should be saved for retrieval/display the next time round.


After creating the Rates entity class and the Currency Menu form, I am unable to access the test row that I inserted in the table. I want to know:

- How do I access the row(s) in the table through this entity class to display the latest rates when the Currency Menu form is displayed?
- How to save any changes to the rates?

Please help me on this!


The entity class that I have generated from the table is:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author WaQQa$
 */
@Entity
@Table(name = "RATES")
@NamedQueries({@NamedQuery(name = "Rates.findAll", query = "SELECT r FROM Rates r")})
public class Rates implements Serializable {
    private static final long serialVersionUID = 1L;
    @Basic(optional = false)
    @Column(name = "ENTRYID")
    private int entryid;
    @Id
    @Basic(optional = false)
    @Column(name = "ENTRYTIME")
    private Integer entrytime;
    @Column(name = "EUROPOUND")
    private Integer europound;
    @Column(name = "EURODOLLAR")
    private Integer eurodollar;
    @Column(name = "POUNDEURO")
    private Integer poundeuro;
    @Column(name = "POUNDDOLLAR")
    private Integer pounddollar;
    @Column(name = "DOLLAREURO")
    private Integer dollareuro;
    @Column(name = "DOLLARPOUND")
    private Integer dollarpound;

    public Rates() {
    }

    public Rates(Integer entrytime) {
        this.entrytime = entrytime;
    }

    public Rates(Integer entrytime, int entryid) {
        this.entrytime = entrytime;
        this.entryid = entryid;
    }

    public int getEntryid() {
        return entryid;
    }

    public void setEntryid(int entryid) {
        this.entryid = entryid;
    }

    public Integer getEntrytime() {
        return entrytime;
    }

    public void setEntrytime(Integer entrytime) {
        this.entrytime = entrytime;
    }

    public Integer getEuropound() {
        return europound;
    }

    public void setEuropound(Integer europound) {
        this.europound = europound;
    }

    public Integer getEurodollar() {
        return eurodollar;
    }

    public void setEurodollar(Integer eurodollar) {
        this.eurodollar = eurodollar;
    }

    public Integer getPoundeuro() {
        return poundeuro;
    }

    public void setPoundeuro(Integer poundeuro) {
        this.poundeuro = poundeuro;
    }

    public Integer getPounddollar() {
        return pounddollar;
    }

    public void setPounddollar(Integer pounddollar) {
        this.pounddollar = pounddollar;
    }

    public Integer getDollareuro() {
        return dollareuro;
    }

    public void setDollareuro(Integer dollareuro) {
        this.dollareuro = dollareuro;
    }

    public Integer getDollarpound() {
        return dollarpound;
    }

    public void setDollarpound(Integer dollarpound) {
        this.dollarpound = dollarpound;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (entrytime != null ? entrytime.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Rates)) {
            return false;
        }
        Rates other = (Rates) object;
        if ((this.entrytime == null && other.entrytime != null) || (this.entrytime != null && !this.entrytime.equals(other.entrytime))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Rates[entrytime=" + entrytime + "]";
    }

}
Edited by: waqqas on Jan 8, 2010 2:50 AM

Edited by: waqqas on Jan 8, 2010 2:52 AM

Comments

This discussion has been closed.