/* * Hibernate, Relational Persistence for Idiomatic Java * * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. */ package org.hibernate.spatial.integration.jts; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.io.ParseException; import org.geolatte.geom.codec.Wkt; import org.geolatte.geom.codec.WktDecoder; import org.geolatte.geom.jts.JTS; import org.hibernate.spatial.testing.TestDataElement; /** * Test class used in unit testing. */ @Entity @Table(name = "geomtest") public class GeomEntity { @Id private Integer id; private String type; private Geometry geom; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getType() { return type; } public void setType(String type) { this.type = type; } public Geometry getGeom() { return geom; } public void setGeom(Geometry geom) { this.geom = geom; } public static GeomEntity createFrom(TestDataElement element) throws ParseException { WktDecoder decoder = Wkt.newDecoder( Wkt.Dialect.POSTGIS_EWKT_1 ); Geometry geom = JTS.to( decoder.decode( element.wkt ) ); GeomEntity result = new GeomEntity(); result.setId( element.id ); result.setGeom( geom ); result.setType( element.type ); return result; } @Override public boolean equals(Object o) { if ( this == o ) { return true; } if ( o == null || getClass() != o.getClass() ) { return false; } GeomEntity geomEntity = (GeomEntity) o; if ( !id.equals( geomEntity.id ) ) { return false; } return true; } @Override public int hashCode() { return id; } }