Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlong committed Mar 19, 2024
1 parent 0894ffb commit 176249a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ when you're creating threads, or working with Java 8 streams and gatherers, you'

Fun fact: lambdas were first introduced in 2014's Java 8 release. (Yes, that was a _decade_ ago! People were doing the ice bucket challenges, the world was obsessed with selfie sticks, _Froezen_, and _Flappy Bird_.)

The `RowMapper<T>` contract in spring's jdbc suport is very interesting. It makes the point very nicely:
The `RowMapper<T>` contract in spring's jdbc support is very interesting. It makes the point very nicely:



Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
<java.version>22</java.version>
</properties>
<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/example/demo/AnonymousLambdaParameters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.demo;

import org.springframework.jdbc.core.simple.JdbcClient;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

@Component
class AnonymousLambdaParameters implements LanguageDemonstrationRunner {

private final JdbcClient db;

AnonymousLambdaParameters(DataSource db) {
this.db = JdbcClient.create(db);
}

record Customer(Integer id, String name) {
}

@Override
public void run() throws Throwable {
var allCustomers = this.db.sql("select * from customer ")
.query((rs, _) -> new Customer(rs.getInt("id"), rs.getString("name")))
.list();
System.out.println("all: " + allCustomers);
}

}
3 changes: 2 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
spring.application.name=demo
spring.threads.virtual.enabled=true
spring.threads.virtual.enabled=true
spring.sql.init.mode=always
9 changes: 9 additions & 0 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
insert into customer(name ) values ('Brian');
insert into customer(name ) values ('Thomas');
insert into customer(name ) values ('Alina');
insert into customer(name ) values ('Stuart');
insert into customer(name ) values ('Sharat');
insert into customer(name ) values ('James');
insert into customer(name ) values ('Ron');
insert into customer(name ) values ('Billy');
insert into customer(name ) values ('Heather');
5 changes: 5 additions & 0 deletions src/main/resources/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
create table if not exists customer
(
id serial primary key,
name text not null
);

0 comments on commit 176249a

Please sign in to comment.