small cleanup work
This commit is contained in:
parent
1e9eefc833
commit
a9738345e8
@ -1,16 +1,21 @@
|
||||
package org.baeldung.persistence.hibernate;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.baeldung.persistence.model.Bar;
|
||||
import org.baeldung.persistence.model.Foo;
|
||||
import org.baeldung.spring.PersistenceConfig;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.NullPrecedence;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -21,12 +26,13 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@SuppressWarnings("unchecked")
|
||||
public class FooSortingPersistenceServiceTest {
|
||||
private SessionFactory sf;
|
||||
private Session sess;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
public final void before() {
|
||||
final Configuration configuration = new Configuration().configure();
|
||||
final StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
|
||||
sf = configuration.buildSessionFactory(builder.build());
|
||||
@ -36,10 +42,10 @@ public class FooSortingPersistenceServiceTest {
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
//
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
/* @Test
|
||||
@Test
|
||||
public final void whenHQlSortingByOneAttribute_thenPrintSortedResults() {
|
||||
final String hql = "FROM Foo f ORDER BY f.name";
|
||||
final Query query = sess.createQuery(hql);
|
||||
@ -47,7 +53,6 @@ public class FooSortingPersistenceServiceTest {
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -55,11 +60,11 @@ public class FooSortingPersistenceServiceTest {
|
||||
final String hql = "FROM Foo f ORDER BY f.name NULLS LAST";
|
||||
final Query query = sess.createQuery(hql);
|
||||
final List<Foo> fooList = query.list();
|
||||
|
||||
assertNull(fooList.get(fooList.toArray().length - 1).getName());
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -72,7 +77,6 @@ public class FooSortingPersistenceServiceTest {
|
||||
System.out.println("Name:" + foo.getName());
|
||||
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -81,11 +85,8 @@ public class FooSortingPersistenceServiceTest {
|
||||
final Query query = sess.createQuery(hql);
|
||||
final List<Foo> fooList = query.list();
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId()
|
||||
|
||||
);
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -94,11 +95,8 @@ public class FooSortingPersistenceServiceTest {
|
||||
final Query query = sess.createQuery(hql);
|
||||
final List<Foo> fooList = query.list();
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId()
|
||||
|
||||
);
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -109,7 +107,6 @@ public class FooSortingPersistenceServiceTest {
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -120,7 +117,6 @@ public class FooSortingPersistenceServiceTest {
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Id: " + foo.getId() + ", FirstName: " + foo.getName());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -132,7 +128,6 @@ public class FooSortingPersistenceServiceTest {
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Id: " + foo.getId() + ", FirstName: " + foo.getName());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -144,7 +139,6 @@ public class FooSortingPersistenceServiceTest {
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Id: " + foo.getId() + ", FirstName: " + foo.getName());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -155,10 +149,8 @@ public class FooSortingPersistenceServiceTest {
|
||||
assertNull(fooList.get(0).getName());
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Id: " + foo.getId() + ", FirstName: " + foo.getName());
|
||||
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void whenSortingBars_thenBarsWithSortedFoos() {
|
||||
@ -170,10 +162,8 @@ public class FooSortingPersistenceServiceTest {
|
||||
System.out.println("Bar Id:" + bar.getId());
|
||||
for (final Foo foo : fooSet) {
|
||||
System.out.println("FooName:" + foo.getName());
|
||||
|
||||
}
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user