Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Michal Čížek
flea-market-manager
Commits
1b19d0d4
Commit
1b19d0d4
authored
May 25, 2022
by
Norbert Komiňák
Browse files
Moved Dao Exception from Service to Dao layer.
parent
c56faef8
Changes
12
Hide whitespace changes
Inline
Side-by-side
backend/flea-market-manager-persistence/src/main/java/cz/fi/muni/pa165/flea/market/manager/dao/MarketEventDao.java
View file @
1b19d0d4
...
...
@@ -2,6 +2,7 @@ package cz.fi.muni.pa165.flea.market.manager.dao;
import
com.mysema.query.jpa.impl.JPAQuery
;
import
cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDaoImpl
;
import
cz.fi.muni.pa165.flea.market.manager.dao.exception.DaoException
;
import
cz.fi.muni.pa165.flea.market.manager.entity.MarketEvent
;
import
cz.fi.muni.pa165.flea.market.manager.entity.QMarketEvent
;
import
lombok.NonNull
;
...
...
@@ -22,10 +23,14 @@ public class MarketEventDao extends DomainDaoImpl<MarketEvent, QMarketEvent> {
}
public
List
<
MarketEvent
>
findAllByMarketLocation
(
@NonNull
String
marketLocationId
)
{
try
{
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
return
query
.
from
(
qEntity
)
.
where
(
qEntity
.
location
.
id
.
eq
(
marketLocationId
))
.
list
(
qEntity
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
}
backend/flea-market-manager-persistence/src/main/java/cz/fi/muni/pa165/flea/market/manager/dao/MarketLocationDao.java
View file @
1b19d0d4
...
...
@@ -2,13 +2,12 @@ package cz.fi.muni.pa165.flea.market.manager.dao;
import
com.mysema.query.jpa.impl.JPAQuery
;
import
cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDaoImpl
;
import
cz.fi.muni.pa165.flea.market.manager.dao.exception.DaoException
;
import
cz.fi.muni.pa165.flea.market.manager.entity.MarketLocation
;
import
cz.fi.muni.pa165.flea.market.manager.entity.QMarketLocation
;
import
lombok.NonNull
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
/**
* DAO for entity {@link MarketLocation}
*
...
...
@@ -22,10 +21,14 @@ public class MarketLocationDao extends DomainDaoImpl<MarketLocation, QMarketLoca
}
public
MarketLocation
findByAddress
(
@NonNull
String
address
)
{
try
{
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
return
query
.
from
(
qEntity
)
.
where
(
qEntity
.
address
.
eq
(
address
))
.
singleResult
(
qEntity
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
}
backend/flea-market-manager-persistence/src/main/java/cz/fi/muni/pa165/flea/market/manager/dao/StandDao.java
View file @
1b19d0d4
...
...
@@ -2,15 +2,13 @@ package cz.fi.muni.pa165.flea.market.manager.dao;
import
com.mysema.query.jpa.impl.JPAQuery
;
import
cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDaoImpl
;
import
cz.fi.muni.pa165.flea.market.manager.dao.exception.DaoException
;
import
cz.fi.muni.pa165.flea.market.manager.entity.QStand
;
import
cz.fi.muni.pa165.flea.market.manager.entity.Stand
;
import
cz.fi.muni.pa165.flea.market.manager.entity.StandType
;
import
cz.fi.muni.pa165.flea.market.manager.enums.ItemCategory
;
import
lombok.NonNull
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
import
java.util.Objects
;
/**
* Dao for {@link Stand} entity that provides basic CRUD operations.
...
...
@@ -25,27 +23,39 @@ public class StandDao extends DomainDaoImpl<Stand, QStand> {
}
public
List
<
Stand
>
findAllBySellerId
(
@NonNull
String
sellerId
)
{
try
{
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
return
query
.
from
(
qEntity
)
.
where
(
qEntity
.
seller
.
id
.
eq
(
sellerId
))
.
list
(
qEntity
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
public
List
<
Stand
>
findAllByEventId
(
@NonNull
String
eventId
)
{
try
{
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
return
query
.
from
(
qEntity
)
.
where
(
qEntity
.
event
.
id
.
eq
(
eventId
))
.
list
(
qEntity
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
public
List
<
Stand
>
findAllByStandType
(
@NonNull
String
standTypeId
)
{
try
{
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
return
query
.
from
(
qEntity
)
.
where
(
qEntity
.
standType
.
id
.
eq
(
standTypeId
))
.
list
(
qEntity
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
}
backend/flea-market-manager-persistence/src/main/java/cz/fi/muni/pa165/flea/market/manager/dao/StandTypeDao.java
View file @
1b19d0d4
package
cz.fi.muni.pa165.flea.market.manager.dao
;
import
com.mysema.query.jpa.impl.JPAQuery
;
import
cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDaoImpl
;
import
cz.fi.muni.pa165.flea.market.manager.entity.QStandType
;
import
cz.fi.muni.pa165.flea.market.manager.entity.StandType
;
import
lombok.NonNull
;
import
org.springframework.stereotype.Repository
;
/**
...
...
backend/flea-market-manager-persistence/src/main/java/cz/fi/muni/pa165/flea/market/manager/dao/UserDao.java
View file @
1b19d0d4
package
cz.fi.muni.pa165.flea.market.manager.dao
;
import
cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDaoImpl
;
import
com.mysema.query.jpa.impl.JPAQuery
;
import
cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDaoImpl
;
import
cz.fi.muni.pa165.flea.market.manager.dao.exception.DaoException
;
import
cz.fi.muni.pa165.flea.market.manager.entity.QUser
;
import
cz.fi.muni.pa165.flea.market.manager.entity.User
;
import
lombok.NonNull
;
...
...
@@ -19,10 +20,14 @@ public class UserDao extends DomainDaoImpl<User, QUser> {
}
public
User
findByEmail
(
@NonNull
String
email
)
{
try
{
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
return
query
.
from
(
qEntity
)
.
where
(
qEntity
.
email
.
eq
(
email
))
.
singleResult
(
qEntity
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
}
backend/flea-market-manager-persistence/src/main/java/cz/fi/muni/pa165/flea/market/manager/dao/domain/DomainDaoImpl.java
View file @
1b19d0d4
...
...
@@ -2,6 +2,7 @@ package cz.fi.muni.pa165.flea.market.manager.dao.domain;
import
com.mysema.query.jpa.impl.JPAQuery
;
import
com.mysema.query.types.path.EntityPathBase
;
import
cz.fi.muni.pa165.flea.market.manager.dao.exception.DaoException
;
import
cz.fi.muni.pa165.flea.market.manager.entity.domain.DomainEntity
;
import
lombok.NonNull
;
import
org.springframework.data.repository.NoRepositoryBean
;
...
...
@@ -30,28 +31,48 @@ public abstract class DomainDaoImpl<ENTITY extends DomainEntity, Q_ENTITY extend
@Override
public
ENTITY
create
(
@NonNull
ENTITY
object
)
{
entityManager
.
persist
(
object
);
return
object
;
try
{
entityManager
.
persist
(
object
);
return
object
;
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
@Override
public
ENTITY
findById
(
@NonNull
String
id
)
{
return
entityManager
.
find
(
entityClass
,
id
);
try
{
return
entityManager
.
find
(
entityClass
,
id
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
@Override
public
List
<
ENTITY
>
findAll
()
{
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
return
query
.
from
(
qEntity
).
list
(
qEntity
);
try
{
JPAQuery
query
=
new
JPAQuery
(
entityManager
);
return
query
.
from
(
qEntity
).
list
(
qEntity
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
@Override
public
ENTITY
update
(
@NonNull
ENTITY
object
)
{
return
entityManager
.
merge
(
object
);
try
{
return
entityManager
.
merge
(
object
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
@Override
public
void
delete
(
@NonNull
ENTITY
object
)
{
entityManager
.
remove
(
object
);
try
{
entityManager
.
remove
(
object
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
}
}
backend/flea-market-manager-
s
er
vi
ce/src/main/java/cz/fi/muni/pa165/flea/market/manager/exception/DaoException.java
→
backend/flea-market-manager-
p
er
sisten
ce/src/main/java/cz/fi/muni/pa165/flea/market/manager/
dao/
exception/DaoException.java
View file @
1b19d0d4
package
cz.fi.muni.pa165.flea.market.manager.exception
;
package
cz.fi.muni.pa165.flea.market.manager.
dao.
exception
;
import
org.springframework.dao.DataAccessException
;
...
...
backend/flea-market-manager-service/src/main/java/cz/fi/muni/pa165/flea/market/manager/service/MarketLocationService.java
View file @
1b19d0d4
...
...
@@ -6,7 +6,6 @@ import cz.fi.muni.pa165.flea.market.manager.dto.marketlocation.MarketLocationCre
import
cz.fi.muni.pa165.flea.market.manager.dto.marketlocation.MarketLocationUpdateDTO
;
import
cz.fi.muni.pa165.flea.market.manager.entity.MarketEvent
;
import
cz.fi.muni.pa165.flea.market.manager.entity.MarketLocation
;
import
cz.fi.muni.pa165.flea.market.manager.exception.DaoException
;
import
cz.fi.muni.pa165.flea.market.manager.service.domain.DomainServiceImpl
;
import
lombok.NonNull
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -48,11 +47,7 @@ public class MarketLocationService extends DomainServiceImpl<MarketLocation> {
}
public
MarketLocation
findByAddress
(
@NonNull
String
address
)
{
try
{
return
locationDao
.
findByAddress
(
address
);
}
catch
(
Exception
e
){
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
return
locationDao
.
findByAddress
(
address
);
}
public
MarketLocation
constructLocationFromDTO
(
@NonNull
MarketLocationCreateDTO
dto
){
...
...
backend/flea-market-manager-service/src/main/java/cz/fi/muni/pa165/flea/market/manager/service/StandService.java
View file @
1b19d0d4
...
...
@@ -7,14 +7,12 @@ import cz.fi.muni.pa165.flea.market.manager.dto.stand.StandDTO;
import
cz.fi.muni.pa165.flea.market.manager.dto.stand.StandUpdateDTO
;
import
cz.fi.muni.pa165.flea.market.manager.entity.Stand
;
import
cz.fi.muni.pa165.flea.market.manager.enums.ItemCategory
;
import
cz.fi.muni.pa165.flea.market.manager.exception.DaoException
;
import
cz.fi.muni.pa165.flea.market.manager.service.domain.DomainServiceImpl
;
import
lombok.NonNull
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
...
...
@@ -44,19 +42,11 @@ public class StandService extends DomainServiceImpl<Stand> {
}
public
List
<
Stand
>
findAllBySellerId
(
@NonNull
String
sellerId
)
{
try
{
return
dao
.
findAllBySellerId
(
sellerId
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
return
dao
.
findAllBySellerId
(
sellerId
);
}
public
List
<
Stand
>
findAllByEventId
(
@NonNull
String
eventId
)
{
try
{
return
dao
.
findAllByEventId
(
eventId
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
return
dao
.
findAllByEventId
(
eventId
);
}
public
Stand
constructStandFromDTO
(
@NonNull
StandCreateDTO
standCreateDTO
)
{
...
...
backend/flea-market-manager-service/src/main/java/cz/fi/muni/pa165/flea/market/manager/service/StandTypeService.java
View file @
1b19d0d4
...
...
@@ -7,7 +7,6 @@ import cz.fi.muni.pa165.flea.market.manager.dto.standType.StandTypeDTO;
import
cz.fi.muni.pa165.flea.market.manager.dto.standType.StandTypeUpdateDTO
;
import
cz.fi.muni.pa165.flea.market.manager.entity.Stand
;
import
cz.fi.muni.pa165.flea.market.manager.entity.StandType
;
import
cz.fi.muni.pa165.flea.market.manager.exception.DaoException
;
import
cz.fi.muni.pa165.flea.market.manager.service.domain.DomainServiceImpl
;
import
lombok.NonNull
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
backend/flea-market-manager-service/src/main/java/cz/fi/muni/pa165/flea/market/manager/service/UserService.java
View file @
1b19d0d4
...
...
@@ -6,7 +6,6 @@ import cz.fi.muni.pa165.flea.market.manager.dto.user.UserDTO;
import
cz.fi.muni.pa165.flea.market.manager.dto.user.UserUpdateDTO
;
import
cz.fi.muni.pa165.flea.market.manager.entity.User
;
import
cz.fi.muni.pa165.flea.market.manager.enums.UserRole
;
import
cz.fi.muni.pa165.flea.market.manager.exception.DaoException
;
import
cz.fi.muni.pa165.flea.market.manager.service.domain.DomainServiceImpl
;
import
lombok.NonNull
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -34,11 +33,7 @@ public class UserService extends DomainServiceImpl<User> {
}
public
User
findByEmail
(
@NonNull
String
email
)
{
try
{
return
dao
.
findByEmail
(
email
);
}
catch
(
Exception
e
)
{
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
return
dao
.
findByEmail
(
email
);
}
public
String
hashPassword
(
String
password
)
{
...
...
backend/flea-market-manager-service/src/main/java/cz/fi/muni/pa165/flea/market/manager/service/domain/DomainServiceImpl.java
View file @
1b19d0d4
...
...
@@ -2,7 +2,6 @@ package cz.fi.muni.pa165.flea.market.manager.service.domain;
import
cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDao
;
import
cz.fi.muni.pa165.flea.market.manager.entity.domain.DomainEntity
;
import
cz.fi.muni.pa165.flea.market.manager.exception.DaoException
;
import
lombok.NonNull
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -26,46 +25,26 @@ public abstract class DomainServiceImpl<ENTITY extends DomainEntity> implements
@Override
public
ENTITY
create
(
@NonNull
ENTITY
object
)
{
try
{
return
dao
.
create
(
object
);
}
catch
(
Exception
e
){
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
return
dao
.
create
(
object
);
}
@Override
public
ENTITY
findById
(
@NonNull
String
id
)
{
try
{
return
dao
.
findById
(
id
);
}
catch
(
Exception
e
){
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
return
dao
.
findById
(
id
);
}
@Override
public
List
<
ENTITY
>
findAll
()
{
try
{
return
dao
.
findAll
();
}
catch
(
Exception
e
){
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
return
dao
.
findAll
();
}
@Override
public
ENTITY
update
(
@NonNull
ENTITY
object
)
{
try
{
return
dao
.
update
(
object
);
}
catch
(
Exception
e
){
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
return
dao
.
update
(
object
);
}
@Override
public
void
delete
(
@NonNull
ENTITY
object
)
{
try
{
dao
.
delete
(
object
);
}
catch
(
Exception
e
){
throw
new
DaoException
(
e
.
getMessage
(),
e
);
}
dao
.
delete
(
object
);
}
}
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