Author: athimel Date: 2012-05-31 12:46:40 +0200 (Thu, 31 May 2012) New Revision: 2570 Url: http://nuiton.org/repositories/revision/topia/2570 Log: fixes #2084 Add a method isPersisted() on TopiaEntity Added: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/persistence/IsPersistentTest.java Modified: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/deletetest/DeleteEntityTest.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-05-31 10:08:21 UTC (rev 2569) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-05-31 10:46:40 UTC (rev 2570) @@ -248,6 +248,7 @@ public void delete(E e) throws TopiaException { try { getEntityManager().remove(e); + e.notifyDeleted(); getContext().getFiresSupport().warnOnDeleteEntity(e); } catch (PersistenceException eee) { throw new TopiaPersistenceException("Unable to perform delete", eee); Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java 2012-05-31 10:08:21 UTC (rev 2569) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntity.java 2012-05-31 10:46:40 UTC (rev 2570) @@ -133,6 +133,24 @@ void setTopiaCreateDate(Date date); /** + * This method must be used to know if the current entity is present on the + * persistent support. If the entity is not yet persisted or if the entity + * has been removed, this method will return false. + * + * @return true if the entity is persisted and not yet deleted + * @since 3.0 + */ + boolean isPersisted(); + + /** + * Notifies the current entity instance than it has been removed from the + * persistent support. + * + * @since 3.0 + */ + void notifyDeleted(); + + /** * @return all object that must be deleted if this object is deleted * @throws TopiaException if any pb * @deprecated since 3.0, prefer use the dao method {@link TopiaDAO#getComposite(TopiaEntity)}. Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2012-05-31 10:08:21 UTC (rev 2569) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2012-05-31 10:46:40 UTC (rev 2570) @@ -57,6 +57,8 @@ protected Date topiaCreateDate = new Date(); + transient protected boolean deleted = false; + transient protected TopiaContext topiaContext; transient protected VetoableChangeSupport readVetoables; @@ -145,6 +147,20 @@ this.topiaCreateDate = topiaCreateDate; } + @Override + public boolean isPersisted() { + // Is or was the entity persisted ? + boolean result = topiaId != null; + // Is the entity deleted ? + result &= !deleted; + return result; + } + + @Override + public void notifyDeleted() { + deleted = true; + } + public TopiaContext getTopiaContext() { return topiaContext; } @@ -157,7 +173,7 @@ if (topiaContext == null) { topiaContext = context; } else { - // XXX AThimel 30/05/2012 Use deprecated TRE because this will be removed with http://nuiton.org/issues/2078 + // XXX AThimel 30/05/2012 Use deprecated TopiaRruntimeException because this will be removed with http://nuiton.org/issues/2078 throw new TopiaRuntimeException("Remplacement du contexte interdit"); } } Modified: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/deletetest/DeleteEntityTest.java =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/deletetest/DeleteEntityTest.java 2012-05-31 10:08:21 UTC (rev 2569) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/deletetest/DeleteEntityTest.java 2012-05-31 10:46:40 UTC (rev 2570) @@ -116,8 +116,6 @@ Party2 res2 = dao2.findByTopiaId(idPersonne2); assertNull(res2); log.debug("ENTITY PERSONNE DELETED !"); - - } /** @@ -174,7 +172,6 @@ Contact2 res2 = contactDAO.findByTopiaId(idContact); assertNull(res2); log.debug("ENTITY PERSONNE DELETED !"); - } } Added: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/persistence/IsPersistentTest.java =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/persistence/IsPersistentTest.java (rev 0) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/persistence/IsPersistentTest.java 2012-05-31 10:46:40 UTC (rev 2570) @@ -0,0 +1,61 @@ +/* + * #%L + * ToPIA :: Persistence :: Test Compatibility Kit + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.topia.tck.it.persistence; + +import junit.framework.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.tck.TopiaDatabase; +import org.nuiton.topia.tck.it.Company; +import org.nuiton.topia.tck.it.CompanyDAO; +import org.nuiton.topia.tck.it.TopiaDatabaseIt; +import org.nuiton.topia.tck.it.TopiaTckItDAOHelper; + +/** + * @author Arnaud Thimel <thimel@codelutin.com> + */ +public class IsPersistentTest { + + @Rule + public final TopiaDatabase db = new TopiaDatabaseIt(); + + @Test + public void testIsPersistent() throws TopiaException { + TopiaContext context = db.beginTransaction(); + CompanyDAO companyDAO = TopiaTckItDAOHelper.getCompanyDAO(context); + + Company company = companyDAO.newInstance(); + Assert.assertFalse(company.isPersisted()); + + company.setName("Code Lutin"); + companyDAO.create(company); + Assert.assertTrue(company.isPersisted()); + + companyDAO.delete(company); + Assert.assertFalse(company.isPersisted()); + } + +} Property changes on: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/persistence/IsPersistentTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native