-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb29875
commit fb0095a
Showing
9 changed files
with
81 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
aws-lambda-project/src/main/java/com/learning/awslambda/config/logging/Loggable.java
This file was deleted.
Oops, something went wrong.
81 changes: 0 additions & 81 deletions
81
aws-lambda-project/src/main/java/com/learning/awslambda/config/logging/LoggingAspect.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 51 additions & 3 deletions
54
aws-lambda-project/src/main/java/com/learning/awslambda/repositories/ActorRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,57 @@ | ||
package com.learning.awslambda.repositories; | ||
|
||
import com.learning.awslambda.entities.Actor; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
import org.springframework.jdbc.core.simple.JdbcClient; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
public interface ActorRepository extends JpaRepository<Actor, Long> { | ||
Optional<Actor> findByNameLike(String name); | ||
@Repository | ||
public class ActorRepository { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ActorRepository.class); | ||
|
||
private final JdbcClient jdbcClient; | ||
private final NamedParameterJdbcTemplate jdbcTemplate; | ||
|
||
public ActorRepository(JdbcClient jdbcClient, NamedParameterJdbcTemplate jdbcTemplate) { | ||
this.jdbcClient = jdbcClient; | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public Optional<Actor> findByNameLike(String name) { | ||
String sql = "select id, name from actors where name like :name"; | ||
return jdbcClient.sql(sql).param("name", name).query(Actor.class).optional(); | ||
} | ||
|
||
@Transactional | ||
public void deleteAll() { | ||
String sql = "delete from actors"; | ||
int count = jdbcClient.sql(sql).update(); | ||
LOGGER.info("deleted {} rows", count); | ||
} | ||
|
||
@Transactional | ||
public List<Actor> saveAll(List<Actor> actorList) { | ||
|
||
List<Object[]> batch = actorList.stream() | ||
.map(customer -> new Object[] {customer.getName()}) | ||
.toList(); | ||
|
||
String sql = "INSERT INTO actors(name) values :batch RETURNING id, name"; | ||
|
||
return jdbcTemplate.query(sql, new MapSqlParameterSource("batch", batch), rs -> { | ||
List<Actor> actors = new ArrayList<>(); | ||
while (rs.next()) { | ||
actors.add(new Actor(rs.getLong(1), rs.getString(2))); | ||
} | ||
return actors; | ||
}); | ||
} | ||
} |
10 changes: 4 additions & 6 deletions
10
aws-lambda-project/src/test/java/com/learning/awslambda/SchemaValidationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters