Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Antonio Rueda
/
reserva-hoteles
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b1007865
authored
Nov 06, 2024
by
Antonio Rueda
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Añadido cacheado de hoteles por id y localidad
parent
3c3b4c84
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
2 deletions
pom.xml
src/main/java/es/ujaen/dae/reservahoteles/app/ReservaHoteles.java
src/main/java/es/ujaen/dae/reservahoteles/repositorios/RepositorioHoteles.java
pom.xml
View file @
b1007865
...
...
@@ -35,6 +35,11 @@
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-cache
</artifactId>
</dependency>
<dependency>
<groupId>
com.mysql
</groupId>
<artifactId>
mysql-connector-j
</artifactId>
</dependency>
...
...
src/main/java/es/ujaen/dae/reservahoteles/app/ReservaHoteles.java
View file @
b1007865
...
...
@@ -4,6 +4,7 @@ package es.ujaen.dae.reservahoteles.app;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.domain.EntityScan
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
/**
...
...
@@ -16,6 +17,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
})
@EntityScan
(
basePackages
=
"es.ujaen.dae.reservahoteles.entidades"
)
//@EnableScheduling
@EnableCaching
public
class
ReservaHoteles
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ReservaHoteles
.
class
);
...
...
src/main/java/es/ujaen/dae/reservahoteles/repositorios/RepositorioHoteles.java
View file @
b1007865
...
...
@@ -9,6 +9,9 @@ import jakarta.persistence.PersistenceContext;
import
java.time.LocalDate
;
import
java.util.List
;
import
java.util.Optional
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cache.annotation.Caching
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -23,6 +26,7 @@ public class RepositorioHoteles {
@PersistenceContext
EntityManager
em
;
@Cacheable
(
"hoteles"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
)
public
Optional
<
Hotel
>
buscarPorId
(
int
id
)
{
return
Optional
.
ofNullable
(
em
.
find
(
Hotel
.
class
,
id
));
...
...
@@ -32,7 +36,7 @@ public class RepositorioHoteles {
public
Optional
<
Hotel
>
buscarPorIdBloqueando
(
int
id
)
{
return
Optional
.
ofNullable
(
em
.
find
(
Hotel
.
class
,
id
,
LockModeType
.
PESSIMISTIC_WRITE
));
}
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
)
public
List
<
Hotel
>
buscarPorNombreLocalidad
(
String
nombre
,
String
localidad
)
{
return
em
.
createQuery
(
"select h from Hotel h where "
+
...
...
@@ -41,7 +45,8 @@ public class RepositorioHoteles {
.
setParameter
(
2
,
"%"
+
normalizar
(
localidad
)
+
"%"
)
.
getResultList
();
}
@Cacheable
(
value
=
"hotelesPorLocalidad"
,
key
=
"T(es.ujaen.dae.reservahoteles.util.UtilString).normalizar(#localidad)"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
)
public
List
<
Hotel
>
buscarPorLocalidad
(
String
localidad
)
{
return
em
.
createQuery
(
"select h from Hotel h where "
+
...
...
@@ -60,6 +65,10 @@ public class RepositorioHoteles {
em
.
persist
(
hotel
);
}
@Caching
(
evict
={
@CacheEvict
(
value
=
"hoteles"
,
key
=
"#hotel.id()"
),
@CacheEvict
(
value
=
"hotelesPorLocalidad"
,
key
=
"T(es.ujaen.dae.reservahoteles.util.UtilString).normalizar(#hotel.localidad())"
)
})
public
Hotel
actualizar
(
Hotel
hotel
)
{
return
em
.
merge
(
hotel
);
}
...
...
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