Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit d14faa6

Browse files
committed
Updated the task for transactional-user-service
1 parent a882f68 commit d14faa6

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

transactional-user-service/src/main/java/com/bobocode/config/JpaConfig.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
55
import org.springframework.orm.jpa.JpaVendorAdapter;
66
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
7+
import org.springframework.orm.jpa.vendor.Database;
78
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
89

910
import javax.sql.DataSource;
@@ -16,9 +17,7 @@
1617
* todo: 1. Mark this class as spring config
1718
* todo: 2. Configure a bean of {@link DataSource}
1819
* todo: 3. Configure a bean of {@link JpaVendorAdapter}
19-
* todo: 4. Set adapter database to tell Hibernate which dialect to use
20-
* todo: 5. Configure bean {@link javax.persistence.EntityManagerFactory} with name "entityManagerFactory"
21-
* todo: 6. Configure package "com.bobocode.model" to scan for JPA entities
20+
* todo: 4. Configure bean {@link javax.persistence.EntityManagerFactory} with name "entityManagerFactory"
2221
*
2322
*/
2423
public class JpaConfig {
@@ -30,7 +29,7 @@ public DataSource dataSource() {
3029

3130
public JpaVendorAdapter jpaVendorAdapter() {
3231
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
33-
// todo: 4. Set adapter database to tell Hibernate which dialect to use
32+
adapter.setDatabase(Database.H2);
3433
adapter.setShowSql(true);
3534
adapter.setGenerateDdl(true); // this sets hibernate.hbm2ddl.auto=update (Hibernate will generate db tables)
3635
return adapter;
@@ -40,7 +39,7 @@ public LocalContainerEntityManagerFactoryBean localContainerEMF(DataSource dataS
4039
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
4140
emf.setDataSource(dataSource);
4241
emf.setJpaVendorAdapter(jpaVendorAdapter);
43-
// todo: 6. Configure package "com.bobocode.model" to scan for JPA entities
42+
// todo: 5. Configure package "com.bobocode.model" to scan for JPA entities
4443
return emf;
4544
}
4645
}

transactional-user-service/src/main/java/com/bobocode/dao/impl/JpaUserDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* <p>
1515
* todo: 1. Configure {@link JpaUserDao} bean as Spring Repository with name "userDao"
1616
* todo: 2. Enable transaction management on class level
17-
* todo: 3. Inject persistence context into {@link EntityManager} field
17+
* todo: 3. Inject {@link EntityManager} using @{@link PersistenceContext} annotation
1818
*/
1919
public class JpaUserDao implements UserDao {
2020
private EntityManager entityManager;

transactional-user-service/src/main/java/com/bobocode/service/UserService.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ public List<User> getAll() {
3030
}
3131

3232
public List<User> getAllAdmins() {
33-
return userDao.findAll().stream()
34-
.filter(user -> user.getRoles().stream()
35-
.map(Role::getRoleType)
36-
.anyMatch(roleType -> roleType.equals(RoleType.ADMIN)))
37-
.collect(toList());
33+
throw new UnsupportedOperationException("Don't be lazy and implement the method");
3834
}
3935

4036
public void addRole(Long userId, RoleType roleType) {

0 commit comments

Comments
 (0)