Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jh-boot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jan Hrabal
jh-boot
Commits
6cfa95a8
Commit
6cfa95a8
authored
Oct 04, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
9bab9437
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
AbstractHibernateAttachmentService.java
...h/boot/attachment/AbstractHibernateAttachmentService.java
+7
-2
FileBasedAttachmentService.java
...va/com/jh/boot/attachment/FileBasedAttachmentService.java
+15
-0
No files found.
src/main/java/com/jh/boot/attachment/AbstractHibernateAttachmentService.java
View file @
6cfa95a8
...
@@ -19,7 +19,6 @@ public abstract class AbstractHibernateAttachmentService implements AttachmentSe
...
@@ -19,7 +19,6 @@ public abstract class AbstractHibernateAttachmentService implements AttachmentSe
protected
abstract
void
saveData
(
Attachment
attachment
,
InputStream
stream
);
protected
abstract
void
saveData
(
Attachment
attachment
,
InputStream
stream
);
@Override
@Override
public
Attachment
saveAttachment
(
Attachment
attachment
)
{
public
Attachment
saveAttachment
(
Attachment
attachment
)
{
repository
.
save
(
attachment
);
repository
.
save
(
attachment
);
...
@@ -39,9 +38,15 @@ public abstract class AbstractHibernateAttachmentService implements AttachmentSe
...
@@ -39,9 +38,15 @@ public abstract class AbstractHibernateAttachmentService implements AttachmentSe
@Override
@Override
public
void
deleteAttachment
(
Long
attachmentId
)
{
public
void
deleteAttachment
(
Long
attachmentId
)
{
throw
new
UnsupportedOperationException
(
"Not implemented"
);
Attachment
a
=
repository
.
findById
(
attachmentId
);
if
(
a
!=
null
)
{
repository
.
delete
(
a
);
deleteData
(
a
);
}
}
}
protected
abstract
void
deleteData
(
Attachment
attachment
);
@Autowired
(
required
=
false
)
@Autowired
(
required
=
false
)
public
void
setRepository
(
AttachmentRepository
repository
)
{
public
void
setRepository
(
AttachmentRepository
repository
)
{
...
...
src/main/java/com/jh/boot/attachment/FileBasedAttachmentService.java
View file @
6cfa95a8
...
@@ -31,7 +31,21 @@ public class FileBasedAttachmentService extends AbstractHibernateAttachmentServi
...
@@ -31,7 +31,21 @@ public class FileBasedAttachmentService extends AbstractHibernateAttachmentServi
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Cannot write data"
,
e
);
throw
new
RuntimeException
(
"Cannot write data"
,
e
);
}
}
}
@Override
protected
void
deleteData
(
Attachment
attachment
)
{
File
file
=
file
(
attachment
);
if
(
file
.
exists
())
{
file
.
delete
();
file
=
file
.
getParentFile
();
if
(
file
.
listFiles
().
length
==
0
)
{
//delete ?
file
.
delete
();
}
}
}
}
protected
File
file
(
Attachment
attachment
)
{
protected
File
file
(
Attachment
attachment
)
{
...
@@ -51,4 +65,5 @@ public class FileBasedAttachmentService extends AbstractHibernateAttachmentServi
...
@@ -51,4 +65,5 @@ public class FileBasedAttachmentService extends AbstractHibernateAttachmentServi
this
.
dataDirectory
=
dataDirectory
;
this
.
dataDirectory
=
dataDirectory
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment