Skip to content
Snippets Groups Projects
Commit 026ccf29 authored by buczekp's avatar buczekp
Browse files

[LMS-2366] fixed broken deletion of attachments

SVN: 22166
parent f983e89e
No related branches found
No related tags found
No related merge requests found
......@@ -75,7 +75,7 @@ public interface IAttachmentDAO extends IGenericDAO<AttachmentPE>
* Deletes all attachment versions with specified <var>fileName</var> and <var>owner</var>.
* There will be no error if no such attachment exist.
* <p>
* NOTE: Attachments are removed from DB - not from the owner object.
* NOTE: Attachments are removed from DB and from the owner object.
*
* @return number of attachments deleted
*/
......
......@@ -44,8 +44,8 @@ final class AttachmentDAO extends AbstractGenericEntityDAO<AttachmentPE> impleme
private final static String TABLE_NAME = ATTACHMENT_CLASS.getSimpleName();
private static final Logger operationLog =
LogFactory.getLogger(LogCategory.OPERATION, AttachmentDAO.class);
private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION,
AttachmentDAO.class);
AttachmentDAO(final SessionFactory sessionFactory, final DatabaseInstancePE databaseInstance)
{
......@@ -191,8 +191,9 @@ final class AttachmentDAO extends AbstractGenericEntityDAO<AttachmentPE> impleme
{
if (fileName.equals(att.getFileName()))
{
deletedRows++;
owner.removeAttachment(att);
hibernateTemplate.delete(att);
deletedRows++;
}
}
......
......@@ -48,8 +48,8 @@ public abstract class AttachmentHolderPE implements Serializable, IIdentifierHol
//
public static final char HIDDEN_EXPERIMENT_PROPERTY_PREFIX_CHARACTER = '$';
public static final String HIDDEN_EXPERIMENT_PROPERTY_PREFIX =
Character.toString(HIDDEN_EXPERIMENT_PROPERTY_PREFIX_CHARACTER);
public static final String HIDDEN_EXPERIMENT_PROPERTY_PREFIX = Character
.toString(HIDDEN_EXPERIMENT_PROPERTY_PREFIX_CHARACTER);
public static final String HIDDEN_EXPERIMENT_PROPERTY_PREFIX2 =
HIDDEN_EXPERIMENT_PROPERTY_PREFIX + HIDDEN_EXPERIMENT_PROPERTY_PREFIX;
......@@ -127,6 +127,13 @@ public abstract class AttachmentHolderPE implements Serializable, IIdentifierHol
getInternalAttachments().add(child);
}
// Should be called ONLY before deletion of the attachment.
// Doesn't clear connection with parent - it is handled by cascade delete.
public void removeAttachment(final AttachmentPE child)
{
getInternalAttachments().remove(child);
}
public final static boolean isHiddenFile(final String fileName)
{
return fileName.startsWith(HIDDEN_EXPERIMENT_PROPERTY_PREFIX)
......
......@@ -41,8 +41,7 @@ public final class AttachmentDAOTest extends AbstractDAOTest
private static final String ATT_CONTENTS_TABLE = "attachment_contents";
@Test(groups = "broken")
// FIXME
@Test
public final void testDeleteAttachment()
{
IAttachmentDAO attachmentDAO = daoFactory.getAttachmentDAO();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment