Migrate to org.hibernate.type.TextType from our custom LobType

This commit is contained in:
Tim Donohue
2023-05-03 14:47:16 -05:00
parent 7a209d228a
commit dac7ed2f09
6 changed files with 8 additions and 65 deletions

View File

@@ -100,7 +100,7 @@ public class ResourcePolicy implements ReloadableEntity<Integer> {
private String rptype; private String rptype;
@Lob @Lob
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType") @Type(type = "org.hibernate.type.TextType")
@Column(name = "rpdescription") @Column(name = "rpdescription")
private String rpdescription; private String rpdescription;

View File

@@ -60,7 +60,7 @@ public class MetadataValue implements ReloadableEntity<Integer> {
* The value of the field * The value of the field
*/ */
@Lob @Lob
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType") @Type(type = "org.hibernate.type.TextType")
@Column(name = "text_value") @Column(name = "text_value")
private String value; private String value;

View File

@@ -80,7 +80,7 @@ public class OrcidHistory implements ReloadableEntity<Integer> {
* A description of the synchronized resource. * A description of the synchronized resource.
*/ */
@Lob @Lob
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType") @Type(type = "org.hibernate.type.TextType")
@Column(name = "description") @Column(name = "description")
private String description; private String description;
@@ -89,7 +89,7 @@ public class OrcidHistory implements ReloadableEntity<Integer> {
* the owner itself. * the owner itself.
*/ */
@Lob @Lob
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType") @Type(type = "org.hibernate.type.TextType")
@Column(name = "metadata") @Column(name = "metadata")
private String metadata; private String metadata;
@@ -104,7 +104,7 @@ public class OrcidHistory implements ReloadableEntity<Integer> {
* The response message incoming from ORCID. * The response message incoming from ORCID.
*/ */
@Lob @Lob
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType") @Type(type = "org.hibernate.type.TextType")
@Column(name = "response_message") @Column(name = "response_message")
private String responseMessage; private String responseMessage;

View File

@@ -65,7 +65,7 @@ public class OrcidQueue implements ReloadableEntity<Integer> {
* A description of the resource to be synchronized. * A description of the resource to be synchronized.
*/ */
@Lob @Lob
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType") @Type(type = "org.hibernate.type.TextType")
@Column(name = "description") @Column(name = "description")
private String description; private String description;
@@ -89,7 +89,7 @@ public class OrcidQueue implements ReloadableEntity<Integer> {
*/ */
@Lob @Lob
@Column(name = "metadata") @Column(name = "metadata")
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType") @Type(type = "org.hibernate.type.TextType")
private String metadata; private String metadata;
/** /**

View File

@@ -71,7 +71,7 @@ public class Process implements ReloadableEntity<Integer> {
private ProcessStatus processStatus; private ProcessStatus processStatus;
@Lob @Lob
@Type(type = "org.dspace.storage.rdbms.hibernate.DatabaseAwareLobType") @Type(type = "org.hibernate.type.TextType")
@Column(name = "parameters") @Column(name = "parameters")
private String parameters; private String parameters;

View File

@@ -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";
}
}