Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Matúš Valko
Online Gaming Management System
Commits
82e2c611
Commit
82e2c611
authored
Jun 14, 2022
by
Marek Kadlečík
Browse files
Added join fetch method to load matches with relational attributes
parent
e6fd3bdc
Pipeline
#144749
passed with stage
in 1 minute and 6 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
gaming-api/src/main/java/cz/muni/fi/pa165/facade/MatchFacade.java
View file @
82e2c611
...
...
@@ -2,6 +2,7 @@ package cz.muni.fi.pa165.facade;
import
cz.muni.fi.pa165.dto.MatchDTO
;
import
cz.muni.fi.pa165.dto.PlayerDTO
;
import
cz.muni.fi.pa165.entity.MatchEntity
;
import
java.util.List
;
...
...
@@ -12,6 +13,8 @@ public interface MatchFacade {
List
<
MatchDTO
>
findAllMatches
();
List
<
MatchDTO
>
findAllMatchesWithPlayersAndTeams
();
MatchDTO
getMatchById
(
String
uuid
);
String
createMatch
(
MatchDTO
matchDTO
);
...
...
gaming-persistence/src/main/java/cz/muni/fi/pa165/dao/match/MatchDao.java
View file @
82e2c611
...
...
@@ -3,8 +3,11 @@ package cz.muni.fi.pa165.dao.match;
import
cz.muni.fi.pa165.dao.BaseDao
;
import
cz.muni.fi.pa165.entity.MatchEntity
;
import
java.util.List
;
/**
* @author Dominik Kozubík
*/
public
interface
MatchDao
extends
BaseDao
<
MatchEntity
>
{
List
<
MatchEntity
>
findAllWithPlayersAndTeams
();
}
gaming-persistence/src/main/java/cz/muni/fi/pa165/dao/match/MatchDaoImpl.java
View file @
82e2c611
...
...
@@ -6,16 +6,23 @@ import org.springframework.stereotype.Repository;
import
javax.persistence.EntityManager
;
import
javax.persistence.PersistenceContext
;
import
java.util.List
;
/**
* @author Dominik Kozubík
*/
@Repository
public
class
MatchDaoImpl
extends
BaseDaoImpl
<
MatchEntity
>
implements
MatchDao
{
// @PersistenceContext
// private EntityManager em;
@PersistenceContext
private
EntityManager
em
;
public
MatchDaoImpl
()
{
super
(
MatchEntity
.
class
);
}
@Override
public
List
<
MatchEntity
>
findAllWithPlayersAndTeams
()
{
return
em
.
createQuery
(
"select m from "
+
entityClass
.
getName
()
+
" m join fetch m.teams"
,
entityClass
).
getResultList
();
}
}
gaming-service/src/main/java/cz/muni/fi/pa165/facade/MatchFacadeImpl.java
View file @
82e2c611
...
...
@@ -40,6 +40,11 @@ public class MatchFacadeImpl implements MatchFacade {
return
beanMappingService
.
mapTo
(
matchService
.
findAll
(),
MatchDTO
.
class
);
}
@Override
public
List
<
MatchDTO
>
findAllMatchesWithPlayersAndTeams
()
{
return
beanMappingService
.
mapTo
(
matchService
.
findAllWithPlayersAndTeams
(),
MatchDTO
.
class
);
}
@Override
public
MatchDTO
getMatchById
(
String
uuid
)
{
return
beanMappingService
.
mapTo
(
matchService
.
findById
(
uuid
),
MatchDTO
.
class
);
...
...
@@ -64,7 +69,9 @@ public class MatchFacadeImpl implements MatchFacade {
var
mappedTeams
=
new
HashSet
<
TeamEntity
>();
for
(
var
teamID
:
matchDTO
.
getTeamsIds
())
{
mappedTeams
.
add
(
teamService
.
findById
(
teamID
));
var
team
=
teamService
.
findById
(
teamID
);
team
.
getMatches
().
add
(
match
);
mappedTeams
.
add
(
team
);
}
match
.
setTeams
(
mappedTeams
);
match
.
setTournament
(
tournamentService
.
findById
(
matchDTO
.
getTournamentId
()));
...
...
gaming-service/src/main/java/cz/muni/fi/pa165/services/match/MatchService.java
View file @
82e2c611
...
...
@@ -14,6 +14,8 @@ public interface MatchService {
List
<
MatchEntity
>
findAll
();
List
<
MatchEntity
>
findAllWithPlayersAndTeams
();
MatchEntity
findById
(
String
id
);
String
update
(
MatchEntity
match
);
...
...
gaming-service/src/main/java/cz/muni/fi/pa165/services/match/MatchServiceImpl.java
View file @
82e2c611
...
...
@@ -32,6 +32,11 @@ public class MatchServiceImpl implements MatchService {
return
matchDao
.
findAll
();
}
@Override
public
List
<
MatchEntity
>
findAllWithPlayersAndTeams
()
{
return
matchDao
.
findAllWithPlayersAndTeams
();
}
@Override
public
MatchEntity
findById
(
String
id
)
{
if
(
id
==
null
)
{
...
...
gaming-spring-mvc/src/main/java/cz/muni/fi/pa165/mvc/controllers/MatchController.java
View file @
82e2c611
...
...
@@ -48,7 +48,7 @@ public class MatchController {
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
public
String
list
(
Model
model
)
{
List
<
MatchDTO
>
matchDTOList
=
matchFacade
.
findAllMatches
();
List
<
MatchDTO
>
matchDTOList
=
matchFacade
.
findAllMatches
WithPlayersAndTeams
();
model
.
addAttribute
(
"matches"
,
matchDTOList
);
return
"/match/list"
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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