Hi,
Bu I don’t find the conversion of =?
in is null
when the value is null ?
The code exist ?
Thank you.
For information, the implementation of a version with a null value :
@MappedSuperclass
public class HermesBusinessObject extends GenericBusinessObject {
@Version
@Column(insertable = false)
private Timestamp dateModification;
public class EfluidOracleSqlAstTranslator extends OracleSqlAstTranslator {
public EfluidOracleSqlAstTranslator(SessionFactoryImplementor sessionFactory, Statement statement) {
super(sessionFactory, statement);
}
@Override
public JdbcOperation translate(JdbcParameterBindings jdbcParameterBindings, QueryOptions queryOptions) {
JdbcOperation translate = super.translate(jdbcParameterBindings, queryOptions);
return new AjoutClauseDateModificationNulle().ajouterClause(translate);
}
}
public final class AjoutClauseDateModificationNulle {
public static final String ATTRIBUT_SQL = "sql";
public static final String CLAUSE_WHERE_DATE_MODIFICATION = " and DATEMODIFICATION=?";
public static final String CLAUSE_WHERE_DATE_MODIFICATION_AVEC_GESTION_NULLE = " and (DATEMODIFICATION is null or DATEMODIFICATION=? ) ";
/**
* Uniquement si requête d'update ou delete
*/
public JdbcOperation ajouterClause(JdbcOperation abstractJdbcMutation) {
if (abstractJdbcMutation instanceof JdbcUpdateMutation || abstractJdbcMutation instanceof JdbcDeleteMutation) {
modifierField(abstractJdbcMutation);
}
return abstractJdbcMutation;
}
private static void modifierField(final JdbcOperation abstractJdbcMutation) {
try {
Field field = AbstractJdbcMutation.class.getDeclaredField(ATTRIBUT_SQL);
field.setAccessible(true);
String sql = (String) field.get(abstractJdbcMutation);
field.set(abstractJdbcMutation, sql.replace(CLAUSE_WHERE_DATE_MODIFICATION, CLAUSE_WHERE_DATE_MODIFICATION_AVEC_GESTION_NULLE));
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
public class EfluidDeleteCoordinator extends DeleteCoordinator {
public EfluidDeleteCoordinator(AbstractEntityPersister entityPersister, SessionFactoryImplementor factory) {
super(entityPersister, factory);
}
@Override
protected void doStaticDelete(Object entity, Object id, Object[] loadedState, Object version, SharedSessionContractImplementor session) {
super.doStaticDelete(entity, id, loadedState, getVersion(version), session);
}
/**
* Si la version (datemodification) est nulle, alors on applique une fausse date juste pour la construction de la requête.
* {@link com.efluid.hibernate.AjoutClauseDateModificationNulle}
*/
public static Object getVersion(Object version) {
if (version == null) {
return DateUtils.getDate(1977, 27, 07);
}
return version;
}
}
public class EfluidSingleTableEntityPersister extends SingleTableEntityPersister {
public EfluidSingleTableEntityPersister(PersistentClass persistentClass, EntityDataAccess cacheAccessStrategy, NaturalIdDataAccess naturalIdRegionAccessStrategy, PersisterCreationContext creationContext) throws HibernateException {
super(persistentClass, cacheAccessStrategy, naturalIdRegionAccessStrategy, creationContext);
}
@Override
public void delete(Object id, Object version, Object object, SharedSessionContractImplementor session) {
if (isEtatObjetPresent(object, session)) {
EfluidSoftDelete.of(this).softDelete(id, EfluidDeleteCoordinator.getVersion(version), object, session);
} else {
super.delete(id, version, object, session);
}
}
protected DeleteCoordinator buildDeleteCoordinator() {
return new EfluidDeleteCoordinator( this, getFactory() );
}
}