Hello guys,

I'm workin on an application that is supposed to be generating certificates.

Here are the steps:

1- input certificate data
2- generate certificate number
3- create the certificate and save its data in the database

i have a table in the database which will hold certificates. The database number should be Symbol-Number-Year (ex. TS105-2014) the symbol is static but, i want the number to be auto generated in a sequnce and the year to be incrumented also.

Thanks in advance

Recommended Answers

All 2 Replies

Not enough information. What kind of "certificates"? How are they formatted? Is this a public/private key certificate? Are you using PGP keys? Show your work.

package main.model;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.TreeSet;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.MapKeyTemporal;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.TemporalType;

@Entity(name = "Certificate")
@Table(name = "Certificate")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Certificate extends AbstractModel implements Serializable {

    protected enum CalibrationEnvironment {
        lab, site
    };

    protected static final long serialVersionUID = 5853171067393399280L;

    protected long certificateID;
    protected Date issueDate;

    protected double minCalRange;
    protected double maxCalRange;
    protected String statusBefore;
    protected String statusAfter;
    protected double acceptedLimit;

    protected CalibrationProcedure calProcedure;
    protected InternationalStandard intStandard;

    protected Collection<CalibrationInstrument> calibrationInstrumentsList = new TreeSet<>();

    protected CalibrationEnvironment calEnvironment;

    protected double environmentTemp;
    protected double environmentHumidity;

    protected double uncertianity;

    protected String certificateStatus;

    protected Date receivedDate;
    protected Date calibrationDate;
    protected Date dueDate;

    protected String calibratedBy;
    protected String approvedBy;

    protected Company company;
    protected Sensor sensor;

    /**
     * @return the certificateID
     */
    @Id
    @GeneratedValue
    @Column(name = "Certificate_ID")
    public long getCertificateID() {
        return certificateID;
    }

    /**
     * @param certificateID
     *            the certificateID to set
     */
    public void setCertificateID(long certificateID) {
        this.certificateID = certificateID;
    }

    /**
     * @return the minCalRange
     */
    public double getMinCalRange() {
        return minCalRange;
    }

    /**
     * @param minCalRange
     *            the minCalRange to set
     */
    public void setMinCalRange(double minCalRange) {
        this.minCalRange = minCalRange;
    }

    /**
     * @return the maxCalRange
     */
    public double getMaxCalRange() {
        return maxCalRange;
    }

    /**
     * @param maxCalRange
     *            the maxCalRange to set
     */
    public void setMaxCalRange(double maxCalRange) {
        this.maxCalRange = maxCalRange;
    }

    /**
     * @return the statusBefore
     */
    public String getStatusBefore() {
        return statusBefore;
    }

    /**
     * @param statusBefore
     *            the statusBefore to set
     */
    public void setStatusBefore(String statusBefore) {
        this.statusBefore = statusBefore;
    }

    /**
     * @return the statusAfter
     */
    public String getStatusAfter() {
        return statusAfter;
    }

    /**
     * @param statusAfter
     *            the statusAfter to set
     */
    public void setStatusAfter(String statusAfter) {
        this.statusAfter = statusAfter;
    }

    /**
     * @return the acceptedLimit
     */
    public double getAcceptedLimit() {
        return acceptedLimit;
    }

    /**
     * @param acceptedLimit
     *            the acceptedLimit to set
     */
    public void setAcceptedLimit(double acceptedLimit) {
        this.acceptedLimit = acceptedLimit;
    }

    /**
     * @return the calProcedure
     */
    public CalibrationProcedure getCalProcedure() {
        return calProcedure;
    }

    /**
     * @param calProcedure
     *            the calProcedure to set
     */
    public void setCalProcedure(CalibrationProcedure calProcedure) {
        this.calProcedure = calProcedure;
    }

    /**
     * @return the intStandard
     */
    public InternationalStandard getIntStandard() {
        return intStandard;
    }

    /**
     * @param intStandard
     *            the intStandard to set
     */
    public void setIntStandard(InternationalStandard intStandard) {
        this.intStandard = intStandard;
    }

    /**
     * @return the calEnvironment
     */
    public CalibrationEnvironment getCalEnvironment() {
        return calEnvironment;
    }

    /**
     * @param calEnvironment
     *            the calEnvironment to set
     */
    public void setCalEnvironment(CalibrationEnvironment calEnvironment) {
        this.calEnvironment = calEnvironment;
    }

    /**
     * @return the environmentTemp
     */
    public double getEnvironmentTemp() {
        return environmentTemp;
    }

    /**
     * @param environmentTemp
     *            the environmentTemp to set
     */
    public void setEnvironmentTemp(double environmentTemp) {
        this.environmentTemp = environmentTemp;
    }

    /**
     * @return the environmentHumidity
     */
    public double getEnvironmentHumidity() {
        return environmentHumidity;
    }

    /**
     * @param environmentHumidity
     *            the environmentHumidity to set
     */
    public void setEnvironmentHumidity(double environmentHumidity) {
        this.environmentHumidity = environmentHumidity;
    }

    /**
     * @return the uncertianity
     */
    public double getUncertianity() {
        return uncertianity;
    }

    /**
     * @param uncertianity
     *            the uncertianity to set
     */
    public void setUncertianity(double uncertianity) {
        this.uncertianity = uncertianity;
    }

    /**
     * @return the certificateStatus
     */
    public String getCertificateStatus() {
        return certificateStatus;
    }

    /**
     * @param certificateStatus
     *            the certificateStatus to set
     */
    public void setCertificateStatus(String certificateStatus) {
        this.certificateStatus = certificateStatus;
    }

    /**
     * @return the receivedDate
     */
    public Date getReceivedDate() {
        return receivedDate;
    }

    /**
     * @param receivedDate
     *            the receivedDate to set
     */
    public void setReceivedDate(Date receivedDate) {
        this.receivedDate = receivedDate;
    }

    /**
     * @return the calibrationDate
     */
    public Date getCalibrationDate() {
        return calibrationDate;
    }

    /**
     * @param calibrationDate
     *            the calibrationDate to set
     */
    public void setCalibrationDate(Date calibrationDate) {
        this.calibrationDate = calibrationDate;
    }

    /**
     * @return the calibratedBy
     */
    public String getCalibratedBy() {
        return calibratedBy;
    }

    /**
     * @param calibratedBy
     *            the calibratedBy to set
     */
    public void setCalibratedBy(String calibratedBy) {
        this.calibratedBy = calibratedBy;
    }

    /**
     * @return the approvedBy
     */
    public String getApprovedBy() {
        return approvedBy;
    }

    /**
     * @param approvedBy
     *            the approvedBy to set
     */
    public void setApprovedBy(String approvedBy) {
        this.approvedBy = approvedBy;
    }

    /**
     * @return the issueDate
     */
    @Column(name = "Issue_Date")
    @MapKeyTemporal(TemporalType.DATE)
    public Date getIssueDate() {
        return issueDate;
    }

    /**
     * @param issueDate
     *            the issueDate to set
     */
    public void setIssueDate(Date issueDate) {
        this.issueDate = issueDate;
    }

    /**
     * @return the dueDate
     */
    @Column(name = "Due_Date", nullable = false)
    @MapKeyTemporal(TemporalType.DATE)
    public Date getDueDate() {
        return dueDate;
    }

    /**
     * @param dueDate
     *            the dueDate to set
     */
    public void setDueDate(Date dueDate) {
        this.dueDate = dueDate;
    }

    /**
     * @return the sensor
     */
    @OneToOne
    @JoinColumn(name = "Sensor_ID", nullable = false)
    public Sensor getSensor() {
        return sensor;
    }

    /**
     * @param sensor
     *            the sensor to set
     */
    public void setSensor(Sensor sensor) {
        if (company != null) {
            this.sensor = sensor;
        } else {
            throw new IllegalArgumentException("Sensor Cann't be null");
        }

    }

    /**
     * @return the company
     */
    @ManyToOne
    @JoinColumn(name = "Company_ID")
    public Company getCompany() {
        return company;
    }

    /**
     * @param company
     *            the company to set
     */
    public void setCompany(Company company) {
        if (company != null) {
            this.company = company;
        } else {
            throw new IllegalArgumentException("Company Cann't be null");
        }
    }

    /**
     * @return the miniRange
     */
    public double getMiniRange() {
        return minCalRange;
    }

    /**
     * @param miniRange
     *            the miniRange to set
     */
    public void setMiniRange(double miniRange) {
        this.minCalRange = miniRange;
    }

    /**
     * @return the maxRange
     */
    public double getMaxRange() {
        return maxCalRange;
    }

    /**
     * @param maxRange
     *            the maxRange to set
     */
    public void setMaxRange(double maxRange) {
        this.maxCalRange = maxRange;
    }

    /**
     * @param relBefore
     *            the relBefore to set
     */
    public void setRelBefore(int relBefore) {
        this.environmentHumidity = relBefore;
    }

    /**
     * @return the calibrationInstrumentsList
     */
    @OneToMany
    @JoinTable(name = "Certificate_CalibrationInstruments_used", joinColumns = @JoinColumn(name = "Certificate_ID"), inverseJoinColumns = @JoinColumn(name = "CalibrationInstrument_ID"))
    public Collection<CalibrationInstrument> getCalibrationInstrumentsList() {
        return calibrationInstrumentsList;
    }

    /**
     * @param calibrationInstrumentsList
     *            the calibrationInstrumentsList to set
     */
    public void setCalibrationInstrumentsList(
            Collection<CalibrationInstrument> calibrationInstrumentsList) {
        this.calibrationInstrumentsList = calibrationInstrumentsList;
    }

    /**
     * @return the environment
     */
    public CalibrationEnvironment getEnvironment() {
        return calEnvironment;
    }

    /**
     * @param environment
     *            the environment to set
     */
    public void setEnvironment(CalibrationEnvironment environment) {
        this.calEnvironment = environment;
    }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.