Re: Implements Comparable not work play 1.X

20 views
Skip to first unread message

Monteiro

unread,
Oct 8, 2012, 5:53:06 PM10/8/12
to play-fr...@googlegroups.com
Are you using Ebean?

The approach with an ORM is different. What ORM does is to create a query which is called inside the database. That has nothing to do with compareTo from the Java side. What you can do, is to fetch all the list, and do a Collection.sort(list) which will order the items in the list depending on the compareTo method you implemented.

Segunda-feira, 8 de Outubro de 2012 21:33:15 UTC+1, Apoena apoenam escreveu:
I have some models that implements comparable but when i call method FINDALL(), never pass through method 

compareTo.

Anyone knows why? How can i fix this?

My Class below.


@Entity

@Table(name = "TB_UF")

public class UfBO extends _BaseModel implements Comparable<UfBO> {


private static final long serialVersionUID = -3926358646464100718L;

@Id

@Column(name = "CO_UF")

private Long id;

@Column(name = "NO_UF")

private String name;

@Column(name = "NO_SIGLA_UF")

private String uf;


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// get/set

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public Long getId() {

return this.id;

}

public void setId(final Long id) {

this.id = id;

}

public String getName() {

return this.name;

}

public void setName(final String name) {

this.name = name;

}

public String getUf() {

return this.uf;

}

public void setUf(final String uf) {

this.uf = uf;

}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// * @see java.lang.Object#toString()

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@Override

public String toString() {

return this.getUf();

}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// * @see java.lang.Object#hashCode()

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@Override

public int hashCode() {

final int prime = 31;

int result = super.hashCode();

result = prime * result + (this.id == null ? 0 : this.id.hashCode());

return result;

}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// * @see java.lang.Object#equals(java.lang.Object)

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@Override

public boolean equals(final Object obj) {

if (this == obj) {

return true;

}

if (!super.equals(obj)) {

return false;

}

if (this.getClass() != obj.getClass()) {

return false;

}

final UfBO other = (UfBO) obj;

if (this.id == null) {

if (other.id != null) {

return false;

}

} else if (!this.id.equals(other.id)) {

return false;

}

return true;

}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// * @see java.lang.Comparable#compareTo(java.lang.Object)

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@Override

public int compareTo(final UfBO o) {

return StringUtil.removeSpecialsCharacters(this.getUf()).compareToIgnoreCase(StringUtil.removeSpecialsCharacters(o.getUf()));

}

}

Monteiro

unread,
Oct 8, 2012, 5:57:07 PM10/8/12
to play-fr...@googlegroups.com

List<ModelX> list =ModelX.findAll();

Collections.sort(list);

// list is now sorted according to the compareTo

Is this what you are looking for?
Reply all
Reply to author
Forward
0 new messages