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