Anonymous type can be replaced with lambda
This commit is contained in:
committed by
Josh Cummings
parent
05f42a4995
commit
fb39d9c255
@@ -16,13 +16,10 @@
|
||||
|
||||
package sample.contact;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
|
||||
/**
|
||||
@@ -38,44 +35,32 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
|
||||
public void create(final Contact contact) {
|
||||
getJdbcTemplate().update("insert into contacts values (?, ?, ?)",
|
||||
new PreparedStatementSetter() {
|
||||
public void setValues(PreparedStatement ps) throws SQLException {
|
||||
ps.setLong(1, contact.getId());
|
||||
ps.setString(2, contact.getName());
|
||||
ps.setString(3, contact.getEmail());
|
||||
}
|
||||
ps -> {
|
||||
ps.setLong(1, contact.getId());
|
||||
ps.setString(2, contact.getName());
|
||||
ps.setString(3, contact.getEmail());
|
||||
});
|
||||
}
|
||||
|
||||
public void delete(final Long contactId) {
|
||||
getJdbcTemplate().update("delete from contacts where id = ?",
|
||||
new PreparedStatementSetter() {
|
||||
public void setValues(PreparedStatement ps) throws SQLException {
|
||||
ps.setLong(1, contactId);
|
||||
}
|
||||
});
|
||||
ps -> ps.setLong(1, contactId));
|
||||
}
|
||||
|
||||
public void update(final Contact contact) {
|
||||
getJdbcTemplate().update(
|
||||
"update contacts set contact_name = ?, address = ? where id = ?",
|
||||
new PreparedStatementSetter() {
|
||||
public void setValues(PreparedStatement ps) throws SQLException {
|
||||
ps.setString(1, contact.getName());
|
||||
ps.setString(2, contact.getEmail());
|
||||
ps.setLong(3, contact.getId());
|
||||
}
|
||||
ps -> {
|
||||
ps.setString(1, contact.getName());
|
||||
ps.setString(2, contact.getEmail());
|
||||
ps.setLong(3, contact.getId());
|
||||
});
|
||||
}
|
||||
|
||||
public List<Contact> findAll() {
|
||||
return getJdbcTemplate().query(
|
||||
"select id, contact_name, email from contacts order by id",
|
||||
new RowMapper<Contact>() {
|
||||
public Contact mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
return mapContact(rs);
|
||||
}
|
||||
});
|
||||
(rs, rowNum) -> mapContact(rs));
|
||||
}
|
||||
|
||||
public List<String> findAllPrincipals() {
|
||||
@@ -92,11 +77,7 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
public Contact getById(Long id) {
|
||||
List<Contact> list = getJdbcTemplate().query(
|
||||
"select id, contact_name, email from contacts where id = ? order by id",
|
||||
new RowMapper<Contact>() {
|
||||
public Contact mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
return mapContact(rs);
|
||||
}
|
||||
}, id);
|
||||
(rs, rowNum) -> mapContact(rs), id);
|
||||
|
||||
if (list.size() == 0) {
|
||||
return null;
|
||||
|
||||
@@ -34,8 +34,6 @@ import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -166,12 +164,10 @@ public class DataSourcePopulator implements InitializingBean {
|
||||
for (int i = 1; i < createEntities; i++) {
|
||||
final ObjectIdentity objectIdentity = new ObjectIdentityImpl(Contact.class,
|
||||
(long) i);
|
||||
tt.execute(new TransactionCallback<Object>() {
|
||||
public Object doInTransaction(TransactionStatus arg0) {
|
||||
mutableAclService.createAcl(objectIdentity);
|
||||
tt.execute(arg0 -> {
|
||||
mutableAclService.createAcl(objectIdentity);
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -273,12 +269,10 @@ public class DataSourcePopulator implements InitializingBean {
|
||||
}
|
||||
|
||||
private void updateAclInTransaction(final MutableAcl acl) {
|
||||
tt.execute(new TransactionCallback<Object>() {
|
||||
public Object doInTransaction(TransactionStatus arg0) {
|
||||
mutableAclService.updateAcl(acl);
|
||||
tt.execute(arg0 -> {
|
||||
mutableAclService.updateAcl(acl);
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user