i have a class where i am inserting data into a array-list based on the id provided.
I am passing a bookId into my class and by comparing bookid i am get a book object. And after getting that object(book) ,am inserting into my arraylist.
Now I do't want to insert same data more then once. If a same bookid passes in the class then only it should store once.
i am storing my arraylist into session.
please check my code. And suggest me a solution for my problem.How to avoid duplicate insertion of data into my arraylist?
AddBookToSession.java
..................
...................
...................
private Integer bid; HttpServletRequest request = ServletActionContext.getRequest();
private Map<String, Object> session;
List<Bookdetails> books = new ArrayList<Bookdetails>();
private BookdetailsDAO dao = new BookdetailsDAO();
public String execute()
{
String bookid = request.getParameter("bid");
Bookdetails book = dao.listBookDetailsById(Integer.parseInt(bookid));
int checkduplicate=1;
//getting list from session to compare with the id
List list = (List) session.get( VisionBooksConstants.USER );
Iterator itr = list.iterator();
int bidd=0;
while(itr.hasNext())
{
Bookdetails bks=(Bookdetails) itr.next();
bidd=bks.getId(); //getting bookid from arraylist,which was stored in session
if (bidd==Integer.parseInt(bookid))
{
checkduplicate=0; //returns 0 ,so that i can compare it below to avoid duplicate data
}
}
//
if (book != null && checkduplicate==1 )
{
books = sessionBooks();
HttpServletRequest request = ServletActionContext.getRequest();
books.add(book);
System.out.println("books size"+books.size());
}
return SUCCESS;
}
........................
......................
Alternative solution
HashSet() update
public String execute()
{ HashSet<Bookdetails> books = new HashSet<Bookdetails>();
String bookid = request.getParameter("bid");
Bookdetails book = dao.listBookDetailsById(Integer.parseInt(bookid));
books = (HashSet<Bookdetails>) session.get(BillTransactionBooksConstants.BOK);
if ( books == null ) books = new HashSet<Bookdetails>();
boolean already_exists = false;
books.add(book);
System.out.println("books size"+books.size());
session.put(BillTransactionBooksConstants.BOK,books);
return SUCCESS;
}
Bookdetails.java(Pojo)
package v.esoft.pojos;
// Generated Nov 5, 2012 9:37:14 PM by Hibernate Tools 3.4.0.CR1
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* Bookdetails generated by hbm2java
*/
#Entity
#Table(name = "bookdetails", catalog = "vbsoftware")
public class Bookdetails implements java.io.Serializable {
private Integer id;
private String isbn;
private String bookTitile;
private String authFirstname;
private String authLastname;
private String editionYear;
private Integer subjectId;
private Integer coverId;
private Integer languageId;
private String publisherName;
private Integer editionId;
private Float price;
private String quantity;
private String description;
private Integer locationId;
private String remarks;
private String img1;
private String img2;
private String videoUrl;
private Integer createrId;
private Date createdDate;
private Integer updateId;
private Date updatedDate;
public Bookdetails() {
}
public Bookdetails(String isbn, String bookTitile, String authFirstname,
String authLastname, String editionYear, Integer subjectId,
Integer coverId, Integer languageId, String publisherName,
Integer editionId, Float price, String quantity,
String description, Integer locationId, String remarks,
String img1, String img2, String videoUrl, Integer createrId,
Date createdDate, Integer updateId, Date updatedDate) {
this.isbn = isbn;
this.bookTitile = bookTitile;
this.authFirstname = authFirstname;
this.authLastname = authLastname;
this.editionYear = editionYear;
this.subjectId = subjectId;
this.coverId = coverId;
this.languageId = languageId;
this.publisherName = publisherName;
this.editionId = editionId;
this.price = price;
this.quantity = quantity;
this.description = description;
this.locationId = locationId;
this.remarks = remarks;
this.img1 = img1;
this.img2 = img2;
this.videoUrl = videoUrl;
this.createrId = createrId;
this.createdDate = createdDate;
this.updateId = updateId;
this.updatedDate = updatedDate;
}
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
//###########################################################################
// FOR HASHSETS EQUALS
//###########################################################################
public Bookdetails(int i){ id = i; }
public boolean equals(Object obj){
System.err.println("called"); // Never happens
return id == ((Bookdetails)obj).id;
}
#Column(name = "isbn", length = 90)
public String getIsbn() {
return this.isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
#Column(name = "book_titile")
public String getBookTitile() {
return this.bookTitile;
}
public void setBookTitile(String bookTitile) {
this.bookTitile = bookTitile;
}
#Column(name = "auth_firstname", length = 120)
public String getAuthFirstname() {
return this.authFirstname;
}
public void setAuthFirstname(String authFirstname) {
this.authFirstname = authFirstname;
}
#Column(name = "auth_lastname", length = 120)
public String getAuthLastname() {
return this.authLastname;
}
public void setAuthLastname(String authLastname) {
this.authLastname = authLastname;
}
#Column(name = "edition_year", length = 20)
public String getEditionYear() {
return this.editionYear;
}
public void setEditionYear(String editionYear) {
this.editionYear = editionYear;
}
#Column(name = "subject_id")
public Integer getSubjectId() {
return this.subjectId;
}
public void setSubjectId(Integer subjectId) {
this.subjectId = subjectId;
}
#Column(name = "cover_id")
public Integer getCoverId() {
return this.coverId;
}
public void setCoverId(Integer coverId) {
this.coverId = coverId;
}
#Column(name = "language_id")
public Integer getLanguageId() {
return this.languageId;
}
public void setLanguageId(Integer languageId) {
this.languageId = languageId;
}
#Column(name = "publisher_name", length = 70)
public String getPublisherName() {
return this.publisherName;
}
public void setPublisherName(String publisherName) {
this.publisherName = publisherName;
}
#Column(name = "edition_id")
public Integer getEditionId() {
return this.editionId;
}
public void setEditionId(Integer editionId) {
this.editionId = editionId;
}
#Column(name = "price", precision = 12, scale = 0)
public Float getPrice() {
return this.price;
}
public void setPrice(Float price) {
this.price = price;
}
#Column(name = "quantity", length = 40)
public String getQuantity() {
return this.quantity;
}
public void setQuantity(String quantity) {
this.quantity = quantity;
}
#Column(name = "description", length = 65535)
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
#Column(name = "location_id")
public Integer getLocationId() {
return this.locationId;
}
public void setLocationId(Integer locationId) {
this.locationId = locationId;
}
#Column(name = "remarks", length = 65535)
public String getRemarks() {
return this.remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
#Column(name = "img1")
public String getImg1() {
return this.img1;
}
public void setImg1(String img1) {
this.img1 = img1;
}
#Column(name = "img2")
public String getImg2() {
return this.img2;
}
public void setImg2(String img2) {
this.img2 = img2;
}
#Column(name = "video_url", length = 65535)
public String getVideoUrl() {
return this.videoUrl;
}
public void setVideoUrl(String videoUrl) {
this.videoUrl = videoUrl;
}
#Column(name = "creater_id")
public Integer getCreaterId() {
return this.createrId;
}
public void setCreaterId(Integer createrId) {
this.createrId = createrId;
}
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "created_date", length = 19)
public Date getCreatedDate() {
return this.createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
#Column(name = "update_id")
public Integer getUpdateId() {
return this.updateId;
}
public void setUpdateId(Integer updateId) {
this.updateId = updateId;
}
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "updated_date", length = 19)
public Date getUpdatedDate() {
return this.updatedDate;
}
public void setUpdatedDate(Date updatedDate) {
this.updatedDate = updatedDate;
}
}
How to avoid duplicate insertion of data into my arraylist?
Use a Set instead.
Also, make sure you are implementing equals and hashcode correctly.
EDITED: It should work now.
public String execute()
{
String bookid = request.getParameter("bid");
Bookdetails book = dao.listBookDetailsById(Integer.parseInt(bookid));
books = (ArrayList) session.get( VisionBooksConstants.USER );
if ( books == null ) books = new ArrayList<Bookdetails>();
boolean already_exists = false;
for ( Bookdetails b : books ) {
if ( b.getID().equals(bookid) ) {
already_exists = true; break;
}
}
if (book != null && !already_exists )
{
books.add(book);
System.out.println("books size"+books.size());
session.put(VisionBooksConstants.USER,books);
}
return SUCCESS;
}
Related
I have a problem when using Long type attributes, I created an attribute called 'Cnh' which receives a 11 digit code, I already put the L in the end of the value, but when I run it in JUnit it still says Integer number too large: 06161567318l.
Is there any possible way I can avoid it
I don't wanna change the attribute type, because I have another which has the same problem but it is a 'hashcode' (it would be really tough to change)
SetUp Values
public void setUp() {
cli = new Cliente();
cli.setEmail("lucasoaresleite#gmail.com");
cli.setCpf(06161567318l);
cli.setCnh(06161567318l);
cli.setCnpj("--");
cli.setDataNascimento("23081998");
cli.setNomeCompleto("Lucas Soares");
cli.setNomeFantasia("--");
}
JUnit Test
public void testSetCnh() {
assertEquals(06161567318l, cli.getCnh());
}
public class Cliente implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#Column(name = "cpf")
private Long cpf;
#Basic(optional = false)
#Column(name = "nome_completo")
private String nomeCompleto;
#Basic(optional = false)
#Column(name = "data_nascimento")
private String dataNascimento;
#Basic(optional = false)
#Column(name = "email")
private String email;
#Basic(optional = false)
#Column(name = "cnh")
private Long cnh;
#Column(name = "cnpj")
private String cnpj;
#Column(name = "nome_fantasia")
private String nomeFantasia;
public Cliente() {
}
public Cliente(Long cpf) {
this.cpf = cpf;
}
public Cliente(Long cpf, String nomeCompleto, String dataNascimento, String email, Long cnh) {
this.cpf = cpf;
this.nomeCompleto = nomeCompleto;
this.dataNascimento = dataNascimento;
this.email = email;
this.cnh = cnh;
}
public Long getCpf() {
return cpf;
}
public void setCpf(Long cpf) {
this.cpf = cpf;
}
public String getNomeCompleto() {
return nomeCompleto;
}
public void setNomeCompleto(String nomeCompleto) {
this.nomeCompleto = nomeCompleto;
}
public String getDataNascimento() {
return dataNascimento;
}
public void setDataNascimento(String dataNascimento) {
this.dataNascimento = dataNascimento;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Long getCnh() {
return cnh;
}
public void setCnh(Long cnh) {
this.cnh = cnh;
}
public String getCnpj() {
return cnpj;
}
public void setCnpj(String cnpj) {
this.cnpj = cnpj;
}
public String getNomeFantasia() {
return nomeFantasia;
}
public void setNomeFantasia(String nomeFantasia) {
this.nomeFantasia = nomeFantasia;
}
#Override
public int hashCode() {
int hash = 0;
hash += (cpf != null ? cpf.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 Cliente)) {
return false;
}
Cliente other = (Cliente) object;
if ((this.cpf == null && other.cpf != null) || (this.cpf != null && !this.cpf.equals(other.cpf))) {
return false;
}
return true;
}
#Override
public String toString() {
return "alocar.java.models.Cliente[ cpf=" + cpf + " ]";
}
}
I need it to accept values way bigger than the limit(I know... but I also know you know what I'm talking about) ]:)
I had write a restful interface in NetbeansIDE8.2 ,and i have debug it with the PostMan App in chorme, and then an exception have experenced I will show the image down here :
the HTTP ERROR 500
and my code is here ,I have return a arryList to browser
#Path("/getStu")
#GET
public List<TfFreshstudent> queryStudentNoDomitory()
{
List<TfFreshstudent> studentList= cq.queryFreshstudentNoDomitory();
if (studentList.isEmpty()) {
return studentList;
}
return null;
}
and I have tried other sub of the automatic create code ,and the error is also happened:
#GET
public List<TfDormitory> getAllTfDormitories() {
log.debug("REST request to get all TfDormitories");
List<TfDormitory> tfDormitories = tfDormitoryFacade.findAll();
return tfDormitories;
}
I have think that it maybe the return type error maybe ArryList can't be show on browser, maybe I must parse it to json type or response
This is the entity which Jeddic was create
package com.freshV3.cart.model;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "tf_dormitory")
public class TfDormitory {
#Column(name = "id", table = "tf_dormitory", nullable = false, length = 22)
#Id
private String id;
#Column(name = "buildName", table = "tf_dormitory", length = 50)
#Basic
private String buildName;
#Column(name = "comment", table = "tf_dormitory")
#Basic
private String comment;
#Column(name = "freshStudentId", table = "tf_dormitory", length = 22)
#Basic
private String freshStudentId;
#Column(name = "isDelete", table = "tf_dormitory")
#Basic
private Integer isDelete;
#Column(name = "operator", table = "tf_dormitory", length = 20)
#Basic
private String operator;
#Column(name = "roomCode", table = "tf_dormitory", length = 32)
#Basic
private String roomCode;
#Column(name = "roomId", table = "tf_dormitory")
#Basic
private String roomId;
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String getBuildName() {
return this.buildName;
}
public void setBuildName(String buildName) {
this.buildName = buildName;
}
public String getComment() {
return this.comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getFreshStudentId() {
return this.freshStudentId;
}
public void setFreshStudentId(String freshStudentId) {
this.freshStudentId = freshStudentId;
}
public Integer getIsDelete() {
return this.isDelete;
}
public void setIsDelete(Integer isDelete) {
this.isDelete = isDelete;
}
public String getOperator() {
return this.operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public String getRoomCode() {
return this.roomCode;
}
public void setRoomCode(String roomCode) {
this.roomCode = roomCode;
}
public String getRoomId() {
return this.roomId;
}
public void setRoomId(String roomId) {
this.roomId = roomId;
}
}
I am new in java. i created a entity class. where i wanted a default value for a field. i tried #Column(name = "ProjectStatus", nullable = false,columnDefinition = "varchar(50) default 'start'") annotaions but getting errors
my entity class is
package com.ults.hrms.model;
// default package
// Generated 17 Jan, 2017 12:04:43 PM by Hibernate Tools 3.4.0.CR1
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.ColumnDefault;
#Entity
#Table(name = "t_projectmaster", catalog = "db_hrms")
public class Projectmaster implements java.io.Serializable {
private Integer projectId;
private String projectUserIdtemp;
private String projectUserIdper;
private String projectName;
private String clentName;
private String projectDesc;
private Double projectValue;
private String projectTax;
private Date targetDate;
private Integer accountmanager;
private Integer projectManager;
private byte[] pofile;
private byte[] agreementFile;
/*#Column(name = "ProjectStatus",columnDefinition = "varchar(50) default 'ToStart'")*/
private String projectStatus;
private Boolean actvieStatus;
private Date creationDate;
private Date modifiedDate;
private Integer userId;
private String remarks;
public Projectmaster() {
}
public Projectmaster(String projectStatus) {
this.projectStatus = projectStatus;
}
public Projectmaster(String projectUserIdtemp, String projectUserIdper,
String projectName, String clentName, String projectDesc,
Double projectValue, String projectTax, Date targetDate,
Integer accountmanager, Integer projectManager, byte[] pofile,
byte[] agreementFile, String projectStatus, Boolean actvieStatus,
Date creationDate, Date modifiedDate, Integer userId, String remarks) {
this.projectUserIdtemp = projectUserIdtemp;
this.projectUserIdper = projectUserIdper;
this.projectName = projectName;
this.clentName = clentName;
this.projectDesc = projectDesc;
this.projectValue = projectValue;
this.projectTax = projectTax;
this.targetDate = targetDate;
this.accountmanager = accountmanager;
this.projectManager = projectManager;
this.pofile = pofile;
this.agreementFile = agreementFile;
this.projectStatus = projectStatus;
this.actvieStatus = actvieStatus;
this.creationDate = creationDate;
this.modifiedDate = modifiedDate;
this.userId = userId;
this.remarks = remarks;
}
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "ProjectID", unique = true, nullable = false)
public Integer getProjectId() {
return this.projectId;
}
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
#Column(name = "ProjectUserIDTemp", length = 50)
public String getProjectUserIdtemp() {
return this.projectUserIdtemp;
}
public void setProjectUserIdtemp(String projectUserIdtemp) {
this.projectUserIdtemp = projectUserIdtemp;
}
#Column(name = "ProjectUserIDPer", length = 50)
public String getProjectUserIdper() {
return this.projectUserIdper;
}
public void setProjectUserIdper(String projectUserIdper) {
this.projectUserIdper = projectUserIdper;
}
#Column(name = "ProjectName")
public String getProjectName() {
return this.projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
#Column(name = "ClentName", length = 100)
public String getClentName() {
return this.clentName;
}
public void setClentName(String clentName) {
this.clentName = clentName;
}
#Column(name = "ProjectDesc", length = 65535)
public String getProjectDesc() {
return this.projectDesc;
}
public void setProjectDesc(String projectDesc) {
this.projectDesc = projectDesc;
}
#Column(name = "ProjectValue", precision = 22, scale = 0)
public Double getProjectValue() {
return this.projectValue;
}
public void setProjectValue(Double projectValue) {
this.projectValue = projectValue;
}
#Column(name = "ProjectTax", length = 50)
public String getProjectTax() {
return this.projectTax;
}
public void setProjectTax(String projectTax) {
this.projectTax = projectTax;
}
#Temporal(TemporalType.DATE)
#Column(name = "TargetDate", length = 10)
public Date getTargetDate() {
return this.targetDate;
}
public void setTargetDate(Date targetDate) {
this.targetDate = targetDate;
}
#Column(name = "Accountmanager")
public Integer getAccountmanager() {
return this.accountmanager;
}
public void setAccountmanager(Integer accountmanager) {
this.accountmanager = accountmanager;
}
#Column(name = "ProjectManager")
public Integer getProjectManager() {
return this.projectManager;
}
public void setProjectManager(Integer projectManager) {
this.projectManager = projectManager;
}
#Column(name = "POFile")
public byte[] getPofile() {
return this.pofile;
}
public void setPofile(byte[] pofile) {
this.pofile = pofile;
}
#Column(name = "AgreementFile")
public byte[] getAgreementFile() {
return this.agreementFile;
}
public void setAgreementFile(byte[] agreementFile) {
this.agreementFile = agreementFile;
}
#Column(name = "ProjectStatus", nullable = false,columnDefinition = "varchar(50) default 'start'")
public String getProjectStatus() {
return this.projectStatus;
}
public void setProjectStatus(String projectStatus) {
this.projectStatus = projectStatus;
}
#Column(name = "ActvieStatus")
public Boolean getActvieStatus() {
return this.actvieStatus;
}
public void setActvieStatus(Boolean actvieStatus) {
this.actvieStatus = actvieStatus;
}
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "CreationDate",columnDefinition = "DATE DEFAULT CURRENT_DATE", length = 19)
public Date getCreationDate() {
return this.creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "ModifiedDate", length = 19)
public Date getModifiedDate() {
return this.modifiedDate;
}
public void setModifiedDate(Date modifiedDate) {
this.modifiedDate = modifiedDate;
}
#Column(name = "UserID")
public Integer getUserId() {
return this.userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
#Column(name = "Remarks", length = 65535)
public String getRemarks() {
return this.remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
}
This will work for you,
Initialise the attribute while creating object only.
private String projectStatus = "start";
I developed an application using Java Spring (backend api), mysql (DB) and Anguljar JS (frontend) that is designed to let users schedule an appointment. The endtime of each appointment is five minutes after its starttime, between 8 o’clock and 2 p.m.
In my data base I have the following information:
• A table named “turno” which contains the parameters time and date of the appointments given.
• Another table contains all the available appointments.
I want to substract both arrays so as to see which appointments have not been given yet. The objective is not to allow users to fix an appointment that has already been made by someone else.
Does anyone have any idea how to do this?
Data examples:
Java Example:
#Entity
#Table(name = "turno")
public class Turno implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String solicitante;
private String telefono;
private TipoDocumento tipoDocumento;
private String numeroDocumento;
private String email;
private Horario horario;
private String numeroTurno;
private String fecha;
private Date formatfecha;
private Date controlFecha;
#Id
#GeneratedValue
#Column(name = "id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
#Column(name = "solicitante")
public String getSolicitante() {
return solicitante;
}
public void setSolicitante(String solicitante) {
this.solicitante = solicitante;
}
#Column(name = "telefono")
public String getTelefono() {
return telefono;
}
public void setTelefono(String telefono) {
this.telefono = telefono;
}
#Column(name = "numero_documento")
public String getNumeroDocumento() {
return numeroDocumento;
}
public void setNumeroDocumento(String numeroDocumento) {
this.numeroDocumento = numeroDocumento;
}
#Column(name = "email")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
#ManyToOne(cascade = CascadeType.MERGE)
#JoinColumn(name = "horario", referencedColumnName = "id")
public Horario getHorario() {
return horario;
}
public void setHorario(Horario horario) {
this.horario = horario;
}
#Column(name = "numero_turno")
public String getNumeroTurno() {
return numeroTurno;
}
public void setNumeroTurno(String numeroTurno) {
this.numeroTurno = numeroTurno;
}
#Column(name = "fecha")
public String getFecha() {
return fecha;
}
public void setFecha(String fecha) {
this.fecha = fecha;
}
#Column(insertable = false, updatable = false, name = "fecha")
public Date getFormatFecha() {
return formatfecha;
}
public void setFormatFecha(Date formatfecha) {
this.formatfecha = formatfecha;
}
#ManyToOne(cascade = CascadeType.MERGE)
#JoinColumn(name = "tipoDocumento", referencedColumnName = "id")
public TipoDocumento getTipoDocumento() {
return tipoDocumento;
}
public void setTipoDocumento(TipoDocumento tipoDocumento) {
this.tipoDocumento = tipoDocumento;
}
#Column(name = "fecha_control")
public Date getControlFecha() {
return controlFecha;
}
public void setControlFecha(Date controlFecha) {
this.controlFecha = controlFecha;
}
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((numeroTurno == null) ? 0 : numeroTurno.hashCode());
return result;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Turno other = (Turno) obj;
if (numeroTurno == null) {
if (other.numeroTurno != null)
return false;
} else if (!numeroTurno.equals(other.numeroTurno))
return false;
return true;
}
}
Updated
Heres how I fixed it in case anyone is interested:
Method in the controller:
#RequestMapping(value = "/horario/{fecha}", method = RequestMethod.GET)
#ResponseBody
public Object queryHorariosLibres(#PathVariable("fecha") Date fecha) {
List<Long> horariosLibres = null;
List<Long> turnosTomados = turnoService.getTurnosTomados(fecha);
Calendar dia = new GregorianCalendar();
dia.setTime(fecha);
Horario horario = horarioRepository.findByDia(dia.get(Calendar.DAY_OF_WEEK));
horariosLibres = horario.getHorariosLibres(turnosTomados);
if (horariosLibres == null) {
return "hola";
}
else
return horariosLibres;
}
Local methods:
#Transient
public List<Long> getHorarios(){
List<Long> horarios = new ArrayList<Long>();
for(Long i = horarioInicio; i <= horarioFin; i+=300){
horarios.add(i);
}
return horarios;
}
#Transient
public List<Long> getHorariosLibres(List<Long> horariosTomados){
List<Long> horariosLibres = getHorarios();
horariosLibres.removeAll(horariosTomados);
return horariosLibres;
}
i'm trying to develop a function that count number of rows with specific arguments: for example i want to count the number of dossier which the client is 'client a' i want to get it in a table the first case contain the name of client and the second contanint the number of dossier
for example
client a |5
client b |12
....
right now i just wrote a function that returns the number of all rows
public Object countrow(){
Query query=em.createQuery("SELECT COUNT(d) FROM Dossier d");
Object resultat= query.getSingleResult();
System.out.println(resultat);
return resultat;
}
here's my entity named dossier :
package model;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
#Entity
#NamedQueries({ #NamedQuery(name = "Dossier.findAll", query = "select o from Dossier o") })
public class Dossier implements Serializable {
#Column(name = "CAT_PROB", length = 4000)
private String catProb;
#Column(length = 4000)
private String client;
#Column(length = 4000)
private String contact;
#Temporal(TemporalType.DATE)
#Column(name = "DATE_APPEL")
private Date dateAppel;
#Temporal(TemporalType.DATE)
#Column(name = "DATE_CREATION")
private Date dateCreation;
#Temporal(TemporalType.DATE)
#Column(name = "DATE_FERMERTURE")
private Date dateFermerture;
#Column(name = "DEP_ID", length = 4000)
private String depId;
#Column(name = "DESCRI_PROB", length = 4000)
private String descriProb;
#Column(name = "DUREE_TRAITEMENT")
private Long dureeTraitement;
#Column(length = 4000)
private String etat;
#Column(name = "FINAL", length = 4000)
private String final_;
#Column(name = "HEURE_APPEL", length = 20)
private String heureAppel;
#Column(name = "HEURE_FERMETURE", length = 20)
private String heureFermeture;
#Id
#Column(name = "ID_DOSSIER", nullable = false, length = 4000)
private String idDossier;
#Column(name = "ING_AFF", length = 4000)
private String ingAff;
#Column(length = 4000)
private String motiftemp;
#Column(name = "OUVERT_PAR", length = 4000)
private String ouvertPar;
#Column(name = "TEL_CONTACT")
private BigDecimal telContact;
#Column(name = "TYPE_DOSSIER", length = 4000)
private String typeDossier;
public Dossier() {
}
public Dossier(String catProb, String client, String contact, Date dateAppel, Date dateCreation,
Date dateFermerture, String depId, String descriProb, Long dureeTraitement, String etat,
String final_, String heureAppel, String heureFermeture, String idDossier, String ingAff,
String motiftemp, String ouvertPar, BigDecimal telContact, String typeDossier) {
this.catProb = catProb;
this.client = client;
this.contact = contact;
this.dateAppel = dateAppel;
this.dateCreation = dateCreation;
this.dateFermerture = dateFermerture;
this.depId = depId;
this.descriProb = descriProb;
this.dureeTraitement = dureeTraitement;
this.etat = etat;
this.final_ = final_;
this.heureAppel = heureAppel;
this.heureFermeture = heureFermeture;
this.idDossier = idDossier;
this.ingAff = ingAff;
this.motiftemp = motiftemp;
this.ouvertPar = ouvertPar;
this.telContact = telContact;
this.typeDossier = typeDossier;
}
public String getCatProb() {
return catProb;
}
public void setCatProb(String catProb) {
this.catProb = catProb;
}
public String getClient() {
return client;
}
public void setClient(String client) {
this.client = client;
}
public String getContact() {
return contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public Date getDateAppel() {
return dateAppel;
}
public void setDateAppel(Date dateAppel) {
this.dateAppel = dateAppel;
}
public Date getDateCreation() {
return dateCreation;
}
public void setDateCreation(Date dateCreation) {
this.dateCreation = dateCreation;
}
public Date getDateFermerture() {
return dateFermerture;
}
public void setDateFermerture(Date dateFermerture) {
this.dateFermerture = dateFermerture;
}
public String getDepId() {
return depId;
}
public void setDepId(String depId) {
this.depId = depId;
}
public String getDescriProb() {
return descriProb;
}
public void setDescriProb(String descriProb) {
this.descriProb = descriProb;
}
public Long getDureeTraitement() {
return dureeTraitement;
}
public void setDureeTraitement(Long dureeTraitement) {
this.dureeTraitement = dureeTraitement;
}
public String getEtat() {
return etat;
}
public void setEtat(String etat) {
this.etat = etat;
}
public String getFinal_() {
return final_;
}
public void setFinal_(String final_) {
this.final_ = final_;
}
public String getHeureAppel() {
return heureAppel;
}
public void setHeureAppel(String heureAppel) {
this.heureAppel = heureAppel;
}
public String getHeureFermeture() {
return heureFermeture;
}
public void setHeureFermeture(String heureFermeture) {
this.heureFermeture = heureFermeture;
}
public String getIdDossier() {
return idDossier;
}
public void setIdDossier(String idDossier) {
this.idDossier = idDossier;
}
public String getIngAff() {
return ingAff;
}
public void setIngAff(String ingAff) {
this.ingAff = ingAff;
}
public String getMotiftemp() {
return motiftemp;
}
public void setMotiftemp(String motiftemp) {
this.motiftemp = motiftemp;
}
public String getOuvertPar() {
return ouvertPar;
}
public void setOuvertPar(String ouvertPar) {
this.ouvertPar = ouvertPar;
}
public BigDecimal getTelContact() {
return telContact;
}
public void setTelContact(BigDecimal telContact) {
this.telContact = telContact;
}
public String getTypeDossier() {
return typeDossier;
}
public void setTypeDossier(String typeDossier) {
this.typeDossier = typeDossier;
}
}