@Autowired
public InsuranceParamRepository(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
public List<Provider> findProvidersBy(String agencyId) {
return jdbcTemplate.query(FIND_PROVIDER_BY_AGENCY_ID,
new Object[] { agencyId }, (resultSet, i) -> new Provider(resultSet.getString("CODE"),
resultSet.getString("NAME"),
resultSet.getString("COUNTRY_CODE")));
}
return DSL.using(connection)
.select(YEAR_RESULT.DEPARTEMENT,
YEAR_RESULT.MANAGER,
YEAR_RESULT.NETPROFIT,
YEAR_RESULT.OPERATINGEXPENSE,
YEAR_RESULT.TURNOVER,
YEAR_RESULT.CREATION_DATE)
.from(YEAR_RESULT)
.where(YEAR_RESULT.DEPARTEMENT.eq(departement))
.orderBy(YEAR_RESULT.CREATION_DATE.asc())
.stream()
.map(r -> new YearReport(r.get(YEAR_RESULT.DEPARTEMENT),
r.get(YEAR_RESULT.MANAGER),
r.get(YEAR_RESULT.NETPROFIT),
r.get(YEAR_RESULT.OPERATINGEXPENSE),
r.get(YEAR_RESULT.TURNOVER),
r.get(YEAR_RESULT.CREATION_DATE, LocalDate.class)))
.collect(toList());
return DSL.using(connection)
.select(YEAR_RESULT.DEPARTEMENT,...)
.from(YEAR_RESULT)
.where(YEAR_RESULT.DEPARTEMENT.eq(departement))
.orderBy(YEAR_RESULT.CREATION_DATE.asc())
.stream()
.map(this::map)
.collect(toList());
private YearReport map(Record r) {
return new YearReport(r.get(YEAR_RESULT.DEPARTEMENT),
r.get(YEAR_RESULT.MANAGER),
r.get(YEAR_RESULT.NETPROFIT),
r.get(YEAR_RESULT.OPERATINGEXPENSE),
r.get(YEAR_RESULT.TURNOVER),
r.get(YEAR_RESULT.CREATION_DATE, LocalDate.class));
}
@Entity
@Table(name = "marques")
public class Marque {
@Id
private String code;
private String name;
private String logoUrl;
@Transient
private byte[] logo;
@Transient
private String logoName;
@OneToMany(mappedBy = "marque", fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
private List<Brochure> brochures;
public class MarqueDao {
@PersistenceContext
private EntityManager entityManager;
public Marque findByCode(String code) {
try {
Query query = entityManager.createQuery("from Marque to where to.code=:code").setParameter("code", code);
return (Marque) query.getSingleResult();
} catch (Exception e) {
throw new ResourceNotFoundException(e);
}
}
public Set<Commission> findCommissionsBy(Connection connection, ESite site, EModule module) throws SQLException {
return DSL.using(connection)
.selectDistinct(field(COL_REFMODULE),
field(COL_REFCUSTOMER),
field(COL_COMMISSION),
field(COL_CREATIONDATETIME, LocalDateTime.class))
.from(new TableImpl<>(BO_PRICE_LIST.toString()))
.where(COL_REFCUSTOMER.eq(site.getIntValue()))
.and(COL_REFMODULE.eq(module.getIntValue()))
.orderBy(field(COL_CREATIONDATETIME).desc())
.stream()
.map(record -> new Commission(EModule.fromIntValue(record.get(COL_REFMODULE, Integer.class)),
ESite.fromIntValue(record.get(COL_REFCUSTOMER, Integer.class)),
ECommissionType.valueOf(record.get(COL_COMMISSION, String.class)),
record.get(COL_CREATIONDATETIME, LocalDateTime.class)))
.collect(toSet());
}
SELECT distinct
COL_REFMODULE,
COL_REFCUSTOMER,
COL_COMMISSION,
COL_CREATIONDATETIME
FROM BO_PRICE_LIST
WHERE COL_REFCUSTOMER = 'amaguiz'
AND COL_REFMODULE = 'auto'
ORDER BY COL_CREATIONDATETIME
DESC;
Date creationDate = resultSet.getDate("creation_date");
LocalDateTime date = Instant.ofEpochMilli(creationDate.getTime())
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
public List<Tuple2<LocalDateTime, String>> findPlate(Connection connection)
throws SQLException {
return DSL.using(connection)
.fetch(FIND_PLATE_AND_CREATION_DATE)
.stream()
.map(r -> {
String plate = r.getValue(PLATE, String.class);
LocalDateTime date = r.getValue(CREATION_DATE, LocalDateTime.class);
return new Tuple2<>(date, plate);
}).collect(toList());
}
Tuple2<LocalDate, String> tuple =Tuple.tuple(now(), "Yolo");
Seq.of(1, 2, 3).concat(Seq.of(4, 5, 6)); // == Seq.of(1, 2, 3, 4, 5, 6);
Arrays.stream(dir.listFiles()).forEach(file -> {
try {
System.out.println(file.getCanonicalPath());
}
catch (IOException e) {
throw new RuntimeException(e);
}
});
Arrays.stream(dir.listFiles()).forEach(
Unchecked.consumer(file -> System.out.println(file.getCanonicalPath()))
);
<configuration>
<jdbc>
<driver>${db.driver}</driver>
<url>${db.url}</url>
<user>${db.username}</user>
<password>${db.password}</password>
</jdbc>
<generator>
<database>
<name>org.jooq.util.h2.H2Database</name>
<includes>.*</includes>
<excludes></excludes>
...
</database>
<generate>
<instanceFields>true</instanceFields>
</generate>
<target>
<packageName>com.lesfurets.db</packageName>
<directory>target/generated-sources</directory>
</target>
</generator>
</configuration>