All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.damap.base.domain.converter.StringDatabaseConverter Maven / Gradle / Ivy

The newest version!
package org.damap.base.domain.converter;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

/** StringDatabaseConverter class. */
@Converter(autoApply = true)
public class StringDatabaseConverter implements AttributeConverter {

  /*
     This converter serves to equalize the behavior of different databases (postgres and oracle in our case).
     One stores empty/null strings as empty, the other as null. Now both will always return null from the database.
  */

  /** {@inheritDoc} */
  @Override
  public String convertToDatabaseColumn(String s) {
    return s;
  }

  /** {@inheritDoc} */
  @Override
  public String convertToEntityAttribute(String s) {
    if (s == null) return null;

    if (s.isEmpty()) return null;

    return s;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy