Skip to content
Snippets Groups Projects
Commit 63b94469 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Non-functioning commit of Hibernate upgrade adaptations

parent df8d2a9d
Branches
No related tags found
1 merge request!154Merge all Wildfly 26 compatible updates into develop
Showing
with 112 additions and 402 deletions
......@@ -171,7 +171,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
......
......@@ -26,6 +26,7 @@ import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
......@@ -37,9 +38,6 @@ import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import no.nibio.vips.logic.util.IntegerArrayUserType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
......@@ -48,7 +46,6 @@ import org.hibernate.annotations.TypeDefs;
@Entity
@Table(name = "crop_category")
@XmlRootElement
@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
@NamedQueries({
@NamedQuery(name = "CropCategory.findAll", query = "SELECT c FROM CropCategory c"),
@NamedQuery(name = "CropCategory.findByCropCategoryId", query = "SELECT c FROM CropCategory c WHERE c.cropCategoryId = :cropCategoryId"),
......@@ -70,7 +67,7 @@ public class CropCategory implements Serializable {
private String defaultName;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "cropCategoryId", fetch = FetchType.EAGER)
private Set<CropCategoryLocal> cropCategoryLocalSet;
@Type(type = "IntegerArray")
@Convert(converter = IntegerArrayUserType.class)
@Column(name = "crop_organism_ids")
private Integer[] cropOrganismIds;
@Column(name = "organization_id")
......
......@@ -21,6 +21,7 @@ package no.nibio.vips.logic.entity;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
......@@ -29,9 +30,6 @@ import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import no.nibio.vips.logic.util.IntegerArrayUserType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
......@@ -39,7 +37,6 @@ import org.hibernate.annotations.TypeDefs;
*/
@Entity
@Table(name = "crop_pest")
@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "CropPest.findAll", query = "SELECT c FROM CropPest c"),
......@@ -55,7 +52,7 @@ public class CropPest implements Serializable {
@NotNull
@Column(name = "crop_organism_id")
private Integer cropOrganismId;
@Type(type = "IntegerArray")
@Convert(converter = IntegerArrayUserType.class)
@Column(name = "pest_organism_ids")
private Integer[] pestOrganismIds;
@Column(name = "include_all_child_crops")
......
......@@ -42,13 +42,10 @@ import javax.xml.bind.annotation.XmlTransient;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.List;
import java.util.TimeZone;
import javax.persistence.Convert;
import javax.persistence.Transient;
import no.nibio.vips.logic.util.IntegerArrayUserType;
import no.nibio.vips.util.WeatherUtil;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
/**
* @copyright 2014-2016 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
......@@ -56,7 +53,6 @@ import org.hibernate.annotations.TypeDefs;
@Entity
@Table(name = "forecast_configuration")
@XmlRootElement
@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
@NamedQueries({
@NamedQuery(name = "ForecastConfiguration.findAll", query = "SELECT f FROM ForecastConfiguration f WHERE f.isPrivate = FALSE"),
@NamedQuery(name = "ForecastConfiguration.findByForecastConfigurationId", query = "SELECT f FROM ForecastConfiguration f WHERE f.forecastConfigurationId = :forecastConfigurationId"),
......@@ -85,6 +81,8 @@ import org.hibernate.annotations.TypeDefs;
@NamedQuery(name = "ForecastConfiguration.findByModelIdAndYear", query = "SELECT f FROM ForecastConfiguration f WHERE f.modelId = :modelId AND YEAR(f.dateStart) <= :year AND YEAR(f.dateEnd) >= :year AND f.isPrivate = FALSE")
})
public class ForecastConfiguration implements Serializable, Comparable {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "forecastConfiguration", fetch = FetchType.EAGER)
private Set<ForecastModelConfiguration> forecastModelConfigurationSet;
private static final long serialVersionUID = 1L;
......@@ -124,7 +122,7 @@ public class ForecastConfiguration implements Serializable, Comparable {
@Column(name = "is_private")
private Boolean isPrivate;
@Type(type = "IntegerArray")
@Convert(converter = IntegerArrayUserType.class)
@Column(name = "grid_weather_station_point_of_interest_ids")
private Integer[] gridWeatherStationPointOfInterestIds;
......
......@@ -27,6 +27,7 @@ import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
......@@ -44,9 +45,7 @@ import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import no.nibio.vips.logic.util.IntegerArrayUserType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
/**
* @copyright 2014 <a href="http://www.nibio.no/">NIBIO</a>
......@@ -55,7 +54,6 @@ import org.hibernate.annotations.TypeDefs;
@Entity
@Table(name = "message")
@XmlRootElement
@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
@NamedQueries({
@NamedQuery(name = "Message.findAll", query = "SELECT m FROM Message m"),
@NamedQuery(name = "Message.findByMessageId", query = "SELECT m FROM Message m WHERE m.messageId = :messageId"),
......@@ -276,7 +274,7 @@ public class Message implements Serializable {
/**
* @return the cropCategoryIds
*/
@Type(type = "IntegerArray")
@Convert(converter = IntegerArrayUserType.class)
@Column(name="crop_category_ids")
public Integer[] getCropCategoryIds() {
return cropCategoryIds;
......
......@@ -42,6 +42,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Convert;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.validation.constraints.Size;
......@@ -50,9 +51,7 @@ import no.nibio.vips.gis.GISUtil;
import no.nibio.vips.logic.entity.rest.ObservationListItem;
import no.nibio.vips.logic.util.StringJsonUserType;
import no.nibio.vips.observationdata.ObservationDataSchema;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
......@@ -61,7 +60,6 @@ import org.hibernate.annotations.TypeDefs;
@Entity
@Table(name = "observation")
@XmlRootElement
@TypeDefs( {@TypeDef( name= "StringJsonObject", typeClass = StringJsonUserType.class)})
@NamedQueries({
@NamedQuery(name = "Observation.findAll", query = "SELECT o FROM Observation o"),
@NamedQuery(name = "Observation.findByObservationId", query = "SELECT o FROM Observation o WHERE o.observationId = :observationId"),
......@@ -440,7 +438,7 @@ public class Observation implements Serializable, no.nibio.vips.observation.Obse
/**
* @return the observationData
*/
@Type(type = "StringJsonObject")
@Convert(converter = StringJsonUserType.class)
@Column(name = "observation_data")
@Override
public String getObservationData() {
......
......@@ -34,7 +34,6 @@ public class UserUuidPK implements Serializable {
@Basic(optional = false)
@NotNull
@Column(name = "user_uuid")
@org.hibernate.annotations.Type(type="pg-uuid") // Ugly implementation specific hack
private UUID userUuid;
@Basic(optional = false)
@NotNull
......
......@@ -21,13 +21,11 @@ package no.nibio.vips.logic.messaging;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import no.nibio.vips.logic.util.IntegerArrayUserType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
......@@ -35,7 +33,6 @@ import org.hibernate.annotations.TypeDefs;
*/
@Entity
@Table(name = "forecast_event_notification_subscription", schema = "messaging")
@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
public class ForecastEventNotificationSubscription {
@Id
......@@ -46,11 +43,11 @@ public class ForecastEventNotificationSubscription {
@Column(name = "universal_message_format_id")
private Integer universalMessageFormatId;
@Type(type = "IntegerArray")
@Convert(converter = IntegerArrayUserType.class)
@Column(name = "weather_station_ids")
private Integer[] weatherStationIds;
@Type(type = "IntegerArray")
@Convert(converter = IntegerArrayUserType.class)
@Column(name = "crop_category_ids")
private Integer[] cropCategoryIds;
......
......@@ -22,13 +22,12 @@ import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import no.nibio.vips.logic.util.IntegerArrayUserType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
......@@ -36,7 +35,6 @@ import org.hibernate.annotations.TypeDefs;
*/
@Entity
@Table(name = "message_notification_subscription", schema = "messaging")
@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
public class MessageNotificationSubscription implements Serializable {
@Id
......@@ -47,11 +45,11 @@ public class MessageNotificationSubscription implements Serializable {
@Column(name = "universal_message_format_id")
private Integer universalMessageFormatId;
@Type(type = "IntegerArray")
@Convert(converter = IntegerArrayUserType.class)
@Column(name = "message_tag_ids")
private Integer[] messageTagIds;
@Type(type = "IntegerArray")
@Convert(converter = IntegerArrayUserType.class)
@Column(name = "crop_category_ids")
private Integer[] cropCategoryIds;
......
......@@ -22,13 +22,11 @@ import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import no.nibio.vips.logic.util.IntegerArrayUserType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
......@@ -36,7 +34,6 @@ import org.hibernate.annotations.TypeDefs;
*/
@Entity
@Table(name = "observation_notification_subscription", schema = "messaging")
@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
public class ObservationNotificationSubscription implements Serializable {
@Id
......@@ -47,7 +44,7 @@ public class ObservationNotificationSubscription implements Serializable {
@Column(name = "universal_message_format_id")
private Integer universalMessageFormatId;
@Type(type = "IntegerArray")
@Convert(converter = IntegerArrayUserType.class)
@Column(name = "crop_category_ids")
private Integer[] cropCategoryIds;
......
......@@ -46,10 +46,9 @@ import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import com.ibm.icu.util.ULocale;
import javax.persistence.Convert;
import no.nibio.vips.logic.util.StringJsonUserType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
......@@ -58,7 +57,6 @@ import org.hibernate.annotations.TypeDefs;
@Entity
@Table(name = "universal_message", schema = "messaging")
@XmlRootElement
@TypeDefs( {@TypeDef( name= "StringJsonObject", typeClass = StringJsonUserType.class)})
@NamedQueries({
@NamedQuery(name = "UniversalMessage.findAll", query = "SELECT u FROM UniversalMessage u"),
@NamedQuery(name = "UniversalMessage.findByUniversalMessageId", query = "SELECT u FROM UniversalMessage u WHERE u.universalMessageId = :universalMessageId"),
......@@ -76,11 +74,11 @@ public class UniversalMessage implements Serializable {
//@Column(name = "distribution_list", columnDefinition = "json")
//@Convert(converter = PostgresJSONStringConverter.class)
// Documentation on StackOverflow: http://stackoverflow.com/questions/15974474/mapping-postgresql-json-column-to-hibernate-value-type
@Type(type = "StringJsonObject")
@Convert(converter = StringJsonUserType.class)
@Column(name = "distribution_list")
private String distributionList;
@Type(type = "StringJsonObject")
@Convert(converter = StringJsonUserType.class)
@Column(name = "message_local_versions")
private String messageLocalVersions;
......
......@@ -24,6 +24,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Arrays;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
......@@ -35,206 +36,84 @@ import org.hibernate.usertype.UserType;
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class IntegerArrayUserType implements UserType {
public class IntegerArrayUserType implements UserType<Integer[]> {
/**
* Return the SQL type codes for the columns mapped by this type. The
* codes are defined on <tt>java.sql.Types</tt>.
*
* @return int[] the typecodes
* @see java.sql.Types
*/
@Override
public int[] sqlTypes() {
return new int[] { Types.ARRAY };
public IntegerArrayUserType()
{
super();
}
/**
* The class returned by <tt>nullSafeGet()</tt>.
*
* @return Class
*/
@Override
public Class returnedClass() {
public Class<Integer[]> returnedClass() {
return Integer[].class;
}
/**
* Compare two instances of the class mapped by this type for persistence "equality".
* Equality of the persistent state.
* Are objects of this type mutable?
*
* @param x
* @param y
* @return boolean
*/
@Override
public boolean equals(Object x, Object y) throws HibernateException {
if( x== null){
return y== null;
}
return x.equals( y);
public boolean isMutable() {
return true;
}
/**
* Get a hashcode for the instance, consistent with persistence "equality"
*/
@Override
public int hashCode(Object x) throws HibernateException {
return x.hashCode();
public int getSqlType() {
return Types.ARRAY;
}
/**
* Retrieve an instance of the mapped class from a JDBC resultset. Implementors
* should handle possibility of null values.
*
* @param rs a JDBC result set
* @param names the column names
* @param session
* @param owner the containing entity @return Object
* @throws org.hibernate.HibernateException
*
* @throws java.sql.SQLException
*/
//@Override
public Object nullSafeGet(
ResultSet rs,
String[] names,
SessionImplementor session,
Object owner) throws HibernateException, SQLException {
if (rs.wasNull()) {
return null;
}
try
{
Integer[] array = (Integer[]) rs.getArray(names[0]).getArray();
return array;
}
catch(NullPointerException ex)
{
return new Integer[0];
}
}
@Override
public boolean equals(Integer[] x, Integer[] y) {
if( x== null){
/**
* Write an instance of the mapped class to a prepared statement. Implementors
* should handle possibility of null values. A multi-column type should be written
* to parameters starting from <tt>index</tt>.
*
* @param st a JDBC prepared statement
* @param value the object to write
* @param index statement parameter index
* @param session
* @throws org.hibernate.HibernateException
*
* @throws java.sql.SQLException
*/
//@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, Types.OTHER);
return;
return y== null;
}
Integer[] castObject = (Integer[]) value;
Array array = session.connection().createArrayOf("integer", castObject); // The postgres array data type
st.setArray(index, array);
return x.equals( y);
}
/**
* Return a deep copy of the persistent state, stopping at entities and at
* collections. It is not necessary to copy immutable objects, or null
* values, in which case it is safe to simply return the argument.
*
* @param value the object to be cloned, which may be null
* @return Object a copy
*/
@Override
public Object deepCopy(Object value) throws HibernateException {
return value;
public int hashCode(Integer[] j) {
return Arrays.hashCode(j);
}
/**
* Are objects of this type mutable?
*
* @return boolean
*/
@Override
public boolean isMutable() {
return true;
}
public void nullSafeSet(PreparedStatement ps, Integer[] j, int i, SharedSessionContractImplementor ssci) throws SQLException {
if (j == null) {
ps.setNull(i, Types.OTHER);
return;
}
/**
* Transform the object into its cacheable representation. At the very least this
* method should perform a deep copy if the type is mutable. That may not be enough
* for some implementations, however; for example, associations must be cached as
* identifier values. (optional operation)
*
* @param value the object to be cached
* @return a cachable representation of the object
* @throws org.hibernate.HibernateException
*
*/
@Override
public Serializable disassemble(Object value) throws HibernateException {
return (Integer[])this.deepCopy( value);
Integer[] castObject = (Integer[]) j;
Array array = ssci.getJdbcConnectionAccess().obtainConnection().createArrayOf("integer", castObject); // The postgres array data type
ps.setArray(i, array);
}
/**
* Reconstruct an object from the cacheable representation. At the very least this
* method should perform a deep copy if the type is mutable. (optional operation)
*
* @param cached the object to be cached
* @param owner the owner of the cached object
* @return a reconstructed object from the cachable representation
* @throws org.hibernate.HibernateException
*
*/
@Override
public Object assemble(Serializable cached, Object owner) throws HibernateException {
return this.deepCopy( cached);
public Integer[] deepCopy(Integer[] j) {
return j;
}
/**
* During merge, replace the existing (target) value in the entity we are merging to
* with a new (original) value from the detached entity we are merging. For immutable
* objects, or null values, it is safe to simply return the first parameter. For
* mutable objects, it is safe to return a copy of the first parameter. For objects
* with component values, it might make sense to recursively replace component values.
*
* @param original the value from the detached entity being merged
* @param target the value in the managed entity
* @return the value to be merged
*/
@Override
public Object replace(Object original, Object target, Object owner) throws HibernateException {
return original;
public Serializable disassemble(Integer[] j) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
/**
* Retrieve an instance of the mapped class from a JDBC resultset. Implementors
* should handle possibility of null values.
*
* @param rs a JDBC result set
* @param strings the column names
* @param ssci
* @throws org.hibernate.HibernateException
*
* @throws java.sql.SQLException
*/
@Override
public Object nullSafeGet(ResultSet rs, String[] strings, SharedSessionContractImplementor ssci, Object o) throws HibernateException, SQLException {
public Integer[] nullSafeGet(ResultSet rs, int i, SharedSessionContractImplementor ssci, Object o) throws SQLException {
if (rs.wasNull()) {
return null;
}
try
{
Integer[] array = (Integer[]) rs.getArray(strings[0]).getArray();
Integer[] array = (Integer[]) rs.getArray(i).getArray();
return array;
}
catch(NullPointerException ex)
......@@ -243,30 +122,12 @@ public class IntegerArrayUserType implements UserType {
}
}
/**
* Write an instance of the mapped class to a prepared statement. Implementors
* should handle possibility of null values. A multi-column type should be written
* to parameters starting from <tt>index</tt>.
*
* @param ps a JDBC prepared statement
* @param o the object to write
* @param i statement parameter index
* @param ssci
* @throws org.hibernate.HibernateException
*
* @throws java.sql.SQLException
*/
@Override
public void nullSafeSet(PreparedStatement ps, Object o, int i, SharedSessionContractImplementor ssci) throws HibernateException, SQLException {
if (o == null) {
ps.setNull(i, Types.OTHER);
return;
}
Integer[] castObject = (Integer[]) o;
Array array = ssci.connection().createArrayOf("integer", castObject); // The postgres array data type
ps.setArray(i, array);
public Integer[] assemble(Serializable srlzbl, Object o) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}
/*
* Copyright (c) 2015 NIBIO <http://www.nibio.no/>.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
package no.nibio.vips.logic.util;
import java.sql.Types;
import org.hibernate.dialect.PostgreSQL9Dialect;
/**
* @copyright 2015 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class JsonPostgreSQLDialect extends PostgreSQL9Dialect{
public JsonPostgreSQLDialect() {
super();
this.registerColumnType(Types.JAVA_OBJECT, "json");
}
}
......@@ -29,23 +29,13 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.usertype.UserType;
/**
* @copyright 2015-2019 <a href="http://www.nibio.no/">NIBIO</a>
* @copyright 2015-2024 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class StringJsonUserType implements UserType {
public class StringJsonUserType implements UserType<String> {
/**
* Return the SQL type codes for the columns mapped by this type. The
* codes are defined on <tt>java.sql.Types</tt>.
*
* @return int[] the typecodes
* @see java.sql.Types
*/
@Override
public int[] sqlTypes() {
return new int[] { Types.JAVA_OBJECT};
}
/**
* The class returned by <tt>nullSafeGet()</tt>.
......@@ -57,53 +47,7 @@ public class StringJsonUserType implements UserType {
return String.class;
}
/**
* Compare two instances of the class mapped by this type for persistence "equality".
* Equality of the persistent state.
*
* @param x
* @param y
* @return boolean
*/
@Override
public boolean equals(Object x, Object y) throws HibernateException {
if( x== null){
return y== null;
}
return x.equals( y);
}
/**
* Get a hashcode for the instance, consistent with persistence "equality"
*/
@Override
public int hashCode(Object x) throws HibernateException {
return x.hashCode();
}
/**
* Retrieve an instance of the mapped class from a JDBC resultset. Implementors
* should handle possibility of null values.
*
* @param rs a JDBC result set
* @param names the column names
* @param session
* @param owner the containing entity @return Object
* @throws org.hibernate.HibernateException
*
* @throws java.sql.SQLException
*/
//@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
if(rs.getString(names[0]) == null){
return null;
}
return rs.getString(names[0]);
}
/**
* Write an instance of the mapped class to a prepared statement. Implementors
......@@ -135,12 +79,12 @@ public class StringJsonUserType implements UserType {
*
* @param value the object to be cloned, which may be null
* @return Object a copy
*/
*
@Override
public Object deepCopy(Object value) throws HibernateException {
return value;
}
}*/
/**
* Are objects of this type mutable?
......@@ -152,95 +96,60 @@ public class StringJsonUserType implements UserType {
return true;
}
/**
* Transform the object into its cacheable representation. At the very least this
* method should perform a deep copy if the type is mutable. That may not be enough
* for some implementations, however; for example, associations must be cached as
* identifier values. (optional operation)
*
* @param value the object to be cached
* @return a cachable representation of the object
* @throws org.hibernate.HibernateException
*
*/
@Override
public Serializable disassemble(Object value) throws HibernateException {
return (String)this.deepCopy( value);
public int getSqlType() {
return Types.JAVA_OBJECT;
}
/**
* Reconstruct an object from the cacheable representation. At the very least this
* method should perform a deep copy if the type is mutable. (optional operation)
*
* @param cached the object to be cached
* @param owner the owner of the cached object
* @return a reconstructed object from the cachable representation
* @throws org.hibernate.HibernateException
*
*/
@Override
public Object assemble(Serializable cached, Object owner) throws HibernateException {
return this.deepCopy( cached);
public boolean equals(String x, String y) {
if( x== null){
return y== null;
}
return x.equals( y);
}
/**
* During merge, replace the existing (target) value in the entity we are merging to
* with a new (original) value from the detached entity we are merging. For immutable
* objects, or null values, it is safe to simply return the first parameter. For
* mutable objects, it is safe to return a copy of the first parameter. For objects
* with component values, it might make sense to recursively replace component values.
*
* @param original the value from the detached entity being merged
* @param target the value in the managed entity
* @return the value to be merged
*/
@Override
public Object replace(Object original, Object target, Object owner) throws HibernateException {
return original;
public int hashCode(String j) {
return j.hashCode();
}
/**
* Retrieve an instance of the mapped class from a JDBC resultset. Implementors
* should handle possibility of null values.
*
* @param rs a JDBC result set
* @param strings the column names
* @param ssci
* @throws org.hibernate.HibernateException
*
* @throws java.sql.SQLException
*/
@Override
public Object nullSafeGet(ResultSet rs, String[] strings, SharedSessionContractImplementor ssci, Object o) throws HibernateException, SQLException {
if(rs.getString(strings[0]) == null){
public String nullSafeGet(ResultSet rs, int i, SharedSessionContractImplementor ssci, Object o) throws SQLException {
if(rs.getString(i) == null){
return null;
}
return rs.getString(strings[0]);
return rs.getString(i);
}
/**
* Write an instance of the mapped class to a prepared statement. Implementors
* should handle possibility of null values. A multi-column type should be written
* to parameters starting from <tt>index</tt>.
*
* @param ps a JDBC prepared statement
* @param o the object to write
* @param i statement parameter index
* @param ssci
* @throws org.hibernate.HibernateException
*
* @throws java.sql.SQLException
*/
@Override
public void nullSafeSet(PreparedStatement ps, Object o, int i, SharedSessionContractImplementor ssci) throws HibernateException, SQLException {
if (o == null) {
public void nullSafeSet(PreparedStatement ps, String j, int i, SharedSessionContractImplementor ssci) throws SQLException {
if (j == null) {
ps.setNull(i, Types.OTHER);
return;
}
ps.setObject(i, o, Types.OTHER);
ps.setString(i, j);
}
@Override
public String deepCopy(String j) {
return j;
}
@Override
public Serializable disassemble(String j) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
@Override
public String assemble(Serializable srlzbl, Object o) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}
......@@ -20,6 +20,7 @@ package no.nibio.vips.observationdata;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
......@@ -28,8 +29,7 @@ import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import no.nibio.vips.logic.util.StringJsonUserType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
/**
* @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
......@@ -38,7 +38,6 @@ import org.hibernate.annotations.TypeDefs;
@Entity
@Table(name = "observation_data_schema")
@XmlRootElement
@TypeDefs( {@TypeDef( name= "StringJsonObject", typeClass = StringJsonUserType.class)})
@NamedQueries({
@NamedQuery(name = "ObservationDataSchema.findAll", query = "SELECT o FROM ObservationDataSchema o"),
@NamedQuery(name = "ObservationDataSchema.findByPK", query = "SELECT o FROM ObservationDataSchema o WHERE o.observationDataSchemaPK.organizationId = :organizationId AND o.observationDataSchemaPK.organismId = :organismId"),
......@@ -49,11 +48,11 @@ public class ObservationDataSchema implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected ObservationDataSchemaPK observationDataSchemaPK;
@Type(type = "StringJsonObject")
@Convert(converter = StringJsonUserType.class)
@Column(name = "data_schema")
private String dataSchema;
@Type(type = "StringJsonObject")
@Column(name = "data_model")
@Convert(converter = StringJsonUserType.class)
@Column(name = "data_model", columnDefinition="json")
private String dataModel;
public ObservationDataSchema() {
......
......@@ -25,8 +25,8 @@
<jta-data-source>java:/jboss/datasources/vipslogic</jta-data-source>
<class>no.nibio.vips.logic.messaging.MessageNotificationSubscription</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>
</properties>
<!--properties>
<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisPG10Dialect"/>
</properties-->
</persistence-unit>
</persistence>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment