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
9bab9437
Commit
9bab9437
authored
Oct 04, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
cacd490f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
30 deletions
+40
-30
AttachmentRepository.java
...ain/java/com/jh/boot/attachment/AttachmentRepository.java
+40
-30
No files found.
src/main/java/com/jh/boot/attachment/AttachmentRepository.java
View file @
9bab9437
package
com
.
jh
.
boot
.
attachment
;
import
java.util.Collections
;
import
java.util.List
;
import
javax.persistence.TypedQuery
;
import
org.springframework.stereotype.Repository
;
import
com.jh.boot.jpa.AbstractHibernateRepository
;
import
com.jh.boot.web.list.Page
;
import
com.jh.boot.web.list.PagingInfo
;
/**
...
...
@@ -24,18 +26,14 @@ public class AttachmentRepository extends AbstractHibernateRepository {
* @param paging the paging
* @return the page
*/
public
List
<
Attachment
>
findForUnitIdAndObject
(
Long
unitId
,
String
objectType
,
Long
objectId
,
PagingInfo
paging
)
{
// Criteria c = criteria(Attachment.class);
// c.add(Restrictions.eq("unitId", unitId));
// c.add(Restrictions.eq("objectType", objectType));
// c.add(Restrictions.eq("objectId", objectId));
public
Page
<
Attachment
>
findForUnitIdAndObject
(
Long
unitId
,
String
objectType
,
Long
objectId
,
PagingInfo
paging
)
{
TypedQuery
<
Attachment
>
query
=
getListQuery
(
unitId
,
objectType
,
objectId
);
query
.
setFirstResult
(
paging
.
getPage
()
*
paging
.
getPageSize
());
query
.
setMaxResults
(
paging
.
getPageSize
());
// c.addOrder(Order.desc("uploaded"));
// c.addOrder(Order.desc("name"));
// return pagedResult(c, paging);
return
Collections
.
emptyList
();
//return new Page<>(0, 0, 0, 0, null, objectType, null);
//FIXME
return
Page
.
empty
();
}
/**
...
...
@@ -47,25 +45,37 @@ public class AttachmentRepository extends AbstractHibernateRepository {
* @return the list
*/
public
List
<
Attachment
>
findForUnitIdAndObject
(
Long
unitId
,
String
objectType
,
Long
objectId
)
{
return
Collections
.
emptyList
();
TypedQuery
<
Attachment
>
query
=
getListQuery
(
unitId
,
objectType
,
objectId
);
return
query
.
getResultList
();
}
/**
* Find for unit id and id.
*
* @param unitId the unit id
* @param attachmentId the attachment id
* @return the attachment
*/
public
Attachment
findForUnitIdAndId
(
Long
unitId
,
Long
attachmentId
)
{
// Criteria c = criteria(Attachment.class);
//
// c.add(Restrictions.eq("unitId", unitId));
// c.add(Restrictions.idEq(attachmentId));
//
// return (Attachment) c.uniqueResult();
return
null
;
protected
TypedQuery
<
Attachment
>
getListQuery
(
Long
unitId
,
String
objectType
,
Long
objectId
)
{
String
hql
=
"select a from Attachment a"
;
if
(
unitId
!=
null
||
objectType
!=
null
||
objectId
!=
null
)
{
hql
+=
" where "
;
if
(
unitId
!=
null
)
{
hql
+=
" a.unitId = :unitId"
;
}
if
(
objectType
!=
null
)
{
hql
+=
" a.objectType = :objectType"
;
}
if
(
objectId
!=
null
)
{
hql
+=
" a.objectId = :objectId"
;
}
}
TypedQuery
<
Attachment
>
query
=
entityManager
.
createQuery
(
hql
,
Attachment
.
class
);
if
(
unitId
!=
null
)
{
query
.
setParameter
(
"unitId"
,
unitId
);
}
if
(
objectType
!=
null
)
{
query
.
setParameter
(
"objectType"
,
objectType
);
}
if
(
objectId
!=
null
)
{
query
.
setParameter
(
"objectId"
,
objectId
);
}
return
query
;
}
...
...
@@ -78,8 +88,8 @@ public class AttachmentRepository extends AbstractHibernateRepository {
* @param attachmentId the attachment id
* @param name the name
*/
public
void
rename
(
Long
unitId
,
String
objectType
,
Long
objectId
,
Long
attachmentId
,
String
name
)
{
Attachment
a
=
find
ForUnitIdAndId
(
unitId
,
attachmentId
);
public
void
rename
(
Long
attachmentId
,
String
name
)
{
Attachment
a
=
find
ById
(
attachmentId
);
a
.
setName
(
name
);
}
...
...
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