Skip to content

Commit a5c1d77

Browse files
author
eugenp
committed
initial compilation fixes
1 parent 8f86fe9 commit a5c1d77

File tree

3 files changed

+43
-58
lines changed

3 files changed

+43
-58
lines changed

spring-hibernate4/src/test/java/org/baeldung/persistence/service/FooSortingServiceTest.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
package org.baeldung.persistence.service;
22

3-
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
3+
import static org.junit.Assert.assertNull;
44

5-
import org.baeldung.persistence.model.Foo;
6-
import org.baeldung.persistence.service.IFooService;
7-
import org.baeldung.spring.PersistenceConfig;
8-
import org.junit.Ignore;
9-
import org.junit.Test;
10-
import org.junit.runner.RunWith;
11-
import org.springframework.beans.factory.annotation.Autowired;
12-
import org.springframework.dao.DataAccessException;
13-
import org.springframework.dao.DataIntegrityViolationException;
14-
import org.springframework.dao.InvalidDataAccessApiUsageException;
15-
import org.springframework.test.context.ContextConfiguration;
16-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
17-
import org.springframework.test.context.support.AnnotationConfigContextLoader;
18-
import static org.junit.Assert.*;
19-
import org.junit.BeforeClass;
20-
import org.junit.Test;
21-
import org.junit.After;
225
import java.util.List;
236
import java.util.Set;
7+
8+
import org.baeldung.persistence.model.Bar;
9+
import org.baeldung.persistence.model.Foo;
10+
import org.baeldung.spring.PersistenceConfig;
2411
import org.hibernate.Criteria;
2512
import org.hibernate.NullPrecedence;
2613
import org.hibernate.Query;
@@ -29,8 +16,13 @@
2916
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
3017
import org.hibernate.cfg.Configuration;
3118
import org.hibernate.criterion.Order;
32-
import com.cc.example.hibernate.Foo;
33-
import com.cc.example.hibernate.Bar;
19+
import org.junit.After;
20+
import org.junit.BeforeClass;
21+
import org.junit.Test;
22+
import org.junit.runner.RunWith;
23+
import org.springframework.test.context.ContextConfiguration;
24+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
25+
import org.springframework.test.context.support.AnnotationConfigContextLoader;
3426

3527
@RunWith(SpringJUnit4ClassRunner.class)
3628
@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class)
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,78 @@
11
package org.baeldung.persistence.model;
22

33
import java.io.Serializable;
4+
import java.util.List;
45

6+
import javax.persistence.CascadeType;
57
import javax.persistence.Column;
68
import javax.persistence.Entity;
9+
import javax.persistence.FetchType;
710
import javax.persistence.GeneratedValue;
811
import javax.persistence.GenerationType;
912
import javax.persistence.Id;
10-
import javax.persistence.CascadeType;
13+
import javax.persistence.OneToMany;
14+
import javax.persistence.OrderBy;
1115

1216
@Entity
1317
public class Bar implements Serializable {
14-
18+
1519
@Id
1620
@GeneratedValue(strategy = GenerationType.AUTO)
1721
private long id;
18-
22+
1923
@Column(nullable = false)
2024
private String name;
21-
25+
2226
@OneToMany(mappedBy = "bar", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
2327
@OrderBy("name ASC")
2428
List<Foo> fooList;
25-
29+
2630
public Bar() {
2731
super();
2832
}
29-
33+
3034
public Bar(final String name) {
3135
super();
32-
36+
3337
this.name = name;
3438
}
35-
39+
3640
// API
37-
41+
3842
public long getId() {
3943
return id;
4044
}
41-
45+
4246
public void setId(final long id) {
4347
this.id = id;
4448
}
45-
49+
4650
public String getName() {
4751
return name;
4852
}
49-
53+
5054
public void setName(final String name) {
5155
this.name = name;
5256
}
53-
57+
5458
public List<Foo> getFooList() {
5559
return fooList;
5660
}
57-
61+
5862
public void setFooList(final List<Foo> fooList) {
5963
this.fooList = fooList;
6064
}
61-
65+
6266
//
63-
67+
6468
@Override
6569
public int hashCode() {
6670
final int prime = 31;
6771
int result = 1;
6872
result = prime * result + ((name == null) ? 0 : name.hashCode());
6973
return result;
7074
}
71-
75+
7276
@Override
7377
public boolean equals(final Object obj) {
7478
if (this == obj)
@@ -85,12 +89,12 @@ public boolean equals(final Object obj) {
8589
return false;
8690
return true;
8791
}
88-
92+
8993
@Override
9094
public String toString() {
9195
final StringBuilder builder = new StringBuilder();
9296
builder.append("Bar [name=").append(name).append("]");
9397
return builder.toString();
9498
}
95-
99+
96100
}

spring-jpa/src/test/java/org/baeldung/persistence/service/FooServiceSortingTests.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.baeldung.persistence.service;
22

3-
import static org.junit.Assert.*;
3+
import static org.junit.Assert.assertNull;
4+
45
import java.util.List;
6+
57
import javax.persistence.EntityManager;
68
import javax.persistence.EntityManagerFactory;
79
import javax.persistence.EntityTransaction;
@@ -11,11 +13,13 @@
1113
import javax.persistence.criteria.CriteriaBuilder;
1214
import javax.persistence.criteria.CriteriaQuery;
1315
import javax.persistence.criteria.Root;
14-
import com.google.common.collect.Lists;
16+
17+
import org.baeldung.persistence.model.Bar;
18+
import org.baeldung.persistence.model.Foo;
1519
import org.junit.BeforeClass;
1620
import org.junit.Test;
17-
import com.cc.jpa.example.Foo;
18-
import com.cc.jpa.example.Bar;
21+
22+
import com.google.common.collect.Lists;
1923

2024
public class FooServiceSortingTests {
2125
private static EntityManager entityManager;
@@ -25,7 +29,6 @@ public class FooServiceSortingTests {
2529

2630
@BeforeClass
2731
public static void before() {
28-
2932
emf = Persistence.createEntityManagerFactory("punit");
3033
entityManager = emf.createEntityManager();
3134
entityTransaction = entityManager.getTransaction();
@@ -35,43 +38,36 @@ public static void before() {
3538

3639
@Test
3740
public final void whenSortingByOneAttributeDefaultOrder_thenPrintSortedResult() {
38-
3941
final String jql = "Select f from Foo as f order by f.id";
4042
final Query sortQuery = entityManager.createQuery(jql);
4143
final List<Foo> fooList = sortQuery.getResultList();
4244
for (final Foo foo : fooList) {
4345
System.out.println("Name:" + foo.getName() + "-------Id:" + foo.getId());
4446
}
45-
4647
}
4748

4849
@Test
4950
public final void whenSortingByOneAttributeSetOrder_thenSortedPrintResult() {
50-
5151
final String jql = "Select f from Foo as f order by f.id desc";
5252
final Query sortQuery = entityManager.createQuery(jql);
5353
final List<Foo> fooList = sortQuery.getResultList();
5454
for (final Foo foo : fooList) {
5555
System.out.println("Name:" + foo.getName() + "-------Id:" + foo.getId());
5656
}
57-
5857
}
5958

6059
@Test
6160
public final void whenSortingByTwoAttributes_thenPrintSortedResult() {
62-
6361
final String jql = "Select f from Foo as f order by f.name asc, f.id desc";
6462
final Query sortQuery = entityManager.createQuery(jql);
6563
final List<Foo> fooList = sortQuery.getResultList();
6664
for (final Foo foo : fooList) {
6765
System.out.println("Name:" + foo.getName() + "-------Id:" + foo.getId());
6866
}
69-
7067
}
7168

7269
@Test
7370
public final void whenSortingFooByBar_thenBarsSorted() {
74-
7571
final String jql = "Select f from Foo as f order by f.name, f.bar.id";
7672
final Query barJoinQuery = entityManager.createQuery(jql);
7773
final List<Foo> fooList = barJoinQuery.getResultList();
@@ -82,7 +78,6 @@ public final void whenSortingFooByBar_thenBarsSorted() {
8278

8379
@Test
8480
public final void whenSortinfBar_thenPrintBarsSortedWithFoos() {
85-
8681
final String jql = "Select b from Bar as b order by b.id";
8782
final Query barQuery = entityManager.createQuery(jql);
8883
final List<Bar> barList = barQuery.getResultList();
@@ -92,12 +87,10 @@ public final void whenSortinfBar_thenPrintBarsSortedWithFoos() {
9287
System.out.println("FooName:" + foo.getName());
9388
}
9489
}
95-
9690
}
9791

9892
@Test
9993
public final void whenSortingByStringNullLast_thenLastNull() {
100-
10194
final String jql = "Select f from Foo as f order by f.name desc NULLS LAST";
10295
final Query sortQuery = entityManager.createQuery(jql);
10396
final List<Foo> fooList = sortQuery.getResultList();
@@ -109,7 +102,6 @@ public final void whenSortingByStringNullLast_thenLastNull() {
109102

110103
@Test
111104
public final void whenSortingByStringNullFirst_thenFirstNull() {
112-
113105
final Foo nullNameFoo = new Foo();
114106
nullNameFoo.setName(null);
115107

@@ -133,7 +125,6 @@ public final void whenSortingByStringNullFirst_thenFirstNull() {
133125

134126
@Test
135127
public final void whenSortingFooWithCriteria_thenPrintSortedFoos() {
136-
137128
criteriaBuilder = entityManager.getCriteriaBuilder();
138129
final CriteriaQuery<Foo> criteriaQuery = criteriaBuilder.createQuery(Foo.class);
139130
final Root<Foo> from = criteriaQuery.from(Foo.class);
@@ -144,12 +135,10 @@ public final void whenSortingFooWithCriteria_thenPrintSortedFoos() {
144135
for (final Foo foo : fooList) {
145136
System.out.println("Name:" + foo.getName() + "--------Id:" + foo.getId());
146137
}
147-
148138
}
149139

150140
@Test
151141
public final void whenSortingFooWithCriteriaAndMultipleAttributes_thenPrintSortedFoos() {
152-
153142
criteriaBuilder = entityManager.getCriteriaBuilder();
154143
final CriteriaQuery<Foo> criteriaQuery = criteriaBuilder.createQuery(Foo.class);
155144
final Root<Foo> from = criteriaQuery.from(Foo.class);

0 commit comments

Comments
 (0)