Skip to content

Commit ac0faee

Browse files
committed
Add FirmRepository.java
1 parent c892aa2 commit ac0faee

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package spring.oldboy.repository;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.beans.factory.config.BeanDefinition;
5+
import org.springframework.context.annotation.Scope;
6+
import spring.oldboy.entity.Company;
7+
import spring.oldboy.pool.StarterConnectionPool;
8+
9+
import javax.annotation.PostConstruct;
10+
import java.util.List;
11+
import java.util.Optional;
12+
13+
/*
14+
Специально не помечаем данный класс, но его bean будет
15+
создан исходя из настроек resources/application.xml
16+
17+
Поставим scope не singleton - он по умолчанию. И теперь
18+
на каждый новый запрос, мы будем получать новый bean и
19+
не из IoC контейнера.
20+
*/
21+
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
22+
public class FirmRepository implements CrudRepository<Integer, Company> {
23+
24+
private final StarterConnectionPool pool1;
25+
private final List<StarterConnectionPool> pools;
26+
private final Integer poolSize;
27+
28+
public FirmRepository(StarterConnectionPool pool1,
29+
List<StarterConnectionPool> pools,
30+
@Value("${db.pool.size}") Integer poolSize) {
31+
this.pool1 = pool1;
32+
this.pools = pools;
33+
this.poolSize = poolSize;
34+
}
35+
36+
@PostConstruct
37+
private void init() {
38+
System.out.println("init company repository");
39+
}
40+
41+
@Override
42+
public Optional<Company> findById(Integer id) {
43+
System.out.println("findById method...");
44+
return Optional.of(new Company(id));
45+
}
46+
47+
@Override
48+
public void delete(Company entity) {
49+
System.out.println("delete method...");
50+
}
51+
}

0 commit comments

Comments
 (0)