mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 06:53:09 +00:00
Migrate to org.hibernate.type.TextType from our custom LobType
This commit is contained in:
@@ -100,7 +100,7 @@ public class ResourcePolicy implements ReloadableEntity<Integer> {
|
||||
private String rptype;
|
||||
|
||||
@Lob
|
||||
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType")
|
||||
@Type(type = "org.hibernate.type.TextType")
|
||||
@Column(name = "rpdescription")
|
||||
private String rpdescription;
|
||||
|
||||
|
@@ -60,7 +60,7 @@ public class MetadataValue implements ReloadableEntity<Integer> {
|
||||
* The value of the field
|
||||
*/
|
||||
@Lob
|
||||
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType")
|
||||
@Type(type = "org.hibernate.type.TextType")
|
||||
@Column(name = "text_value")
|
||||
private String value;
|
||||
|
||||
|
@@ -80,7 +80,7 @@ public class OrcidHistory implements ReloadableEntity<Integer> {
|
||||
* A description of the synchronized resource.
|
||||
*/
|
||||
@Lob
|
||||
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType")
|
||||
@Type(type = "org.hibernate.type.TextType")
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
@@ -89,7 +89,7 @@ public class OrcidHistory implements ReloadableEntity<Integer> {
|
||||
* the owner itself.
|
||||
*/
|
||||
@Lob
|
||||
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType")
|
||||
@Type(type = "org.hibernate.type.TextType")
|
||||
@Column(name = "metadata")
|
||||
private String metadata;
|
||||
|
||||
@@ -104,7 +104,7 @@ public class OrcidHistory implements ReloadableEntity<Integer> {
|
||||
* The response message incoming from ORCID.
|
||||
*/
|
||||
@Lob
|
||||
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType")
|
||||
@Type(type = "org.hibernate.type.TextType")
|
||||
@Column(name = "response_message")
|
||||
private String responseMessage;
|
||||
|
||||
|
@@ -65,7 +65,7 @@ public class OrcidQueue implements ReloadableEntity<Integer> {
|
||||
* A description of the resource to be synchronized.
|
||||
*/
|
||||
@Lob
|
||||
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType")
|
||||
@Type(type = "org.hibernate.type.TextType")
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
@@ -89,7 +89,7 @@ public class OrcidQueue implements ReloadableEntity<Integer> {
|
||||
*/
|
||||
@Lob
|
||||
@Column(name = "metadata")
|
||||
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType")
|
||||
@Type(type = "org.hibernate.type.TextType")
|
||||
private String metadata;
|
||||
|
||||
/**
|
||||
|
@@ -71,7 +71,7 @@ public class Process implements ReloadableEntity<Integer> {
|
||||
private ProcessStatus processStatus;
|
||||
|
||||
@Lob
|
||||
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType")
|
||||
@Type(type = "org.hibernate.type.TextType")
|
||||
@Column(name = "parameters")
|
||||
private String parameters;
|
||||
|
||||
|
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.storage.rdbms.hibernate;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
|
||||
import org.hibernate.type.descriptor.java.StringTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.ClobTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.LongVarcharTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||
|
||||
/**
|
||||
* A Hibernate @Type used to properly support the CLOB in both Postgres and Oracle.
|
||||
* PostgreSQL doesn't have a CLOB type, instead it's a TEXT field.
|
||||
* Normally, you'd use org.hibernate.type.TextType to support TEXT, but that won't work for Oracle.
|
||||
* https://github.com/hibernate/hibernate-orm/blob/5.6/hibernate-core/src/main/java/org/hibernate/type/TextType.java
|
||||
*
|
||||
* This Type checks if we are using PostgreSQL.
|
||||
* If so, it configures Hibernate to map CLOB to LongVarChar (same as org.hibernate.type.TextType)
|
||||
* If not, it uses default CLOB (which works for other databases).
|
||||
*/
|
||||
public class DatabaseAwareLobType extends AbstractSingleColumnStandardBasicType<String> {
|
||||
|
||||
public static final DatabaseAwareLobType INSTANCE = new DatabaseAwareLobType();
|
||||
|
||||
public DatabaseAwareLobType() {
|
||||
super( getDbDescriptor(), StringTypeDescriptor.INSTANCE );
|
||||
}
|
||||
|
||||
public static SqlTypeDescriptor getDbDescriptor() {
|
||||
if ( isPostgres() ) {
|
||||
return LongVarcharTypeDescriptor.INSTANCE;
|
||||
} else {
|
||||
return ClobTypeDescriptor.DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isPostgres() {
|
||||
ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
String dbDialect = configurationService.getProperty("db.dialect");
|
||||
|
||||
return StringUtils.containsIgnoreCase(dbDialect, "PostgreSQL");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "database_aware_lob";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user