Java 11 migrate all remaining s (#1120)

* Moves saga to Java 11

* Moves semaphore to Java 11

* Moves servant to Java 11

* Moves serverless to Java 11

* Moves service-layer to Java 11

* Moves service-locator to Java 11

* Moves sharding to Java 11

* Moves singleton to Java 11

* Moves spatial-partition to Java 11

* Moves specification to Java 11

* Moves state to Java 11

* Moves step-builder to Java 11

* Moves strategy to Java 11

* Moves subclass-sandbox to Java 11

* Fixes checkstyle issues
This commit is contained in:
Anurag Agarwal
2020-01-04 22:06:08 +05:30
committed by Ilkka Seppälä
parent 310ae50248
commit cd2a2e7711
98 changed files with 718 additions and 855 deletions

View File

@ -31,7 +31,6 @@ import com.iluwatar.servicelayer.spellbook.Spellbook;
import com.iluwatar.servicelayer.spellbook.SpellbookDaoImpl;
import com.iluwatar.servicelayer.wizard.Wizard;
import com.iluwatar.servicelayer.wizard.WizardDaoImpl;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -178,29 +177,21 @@ public class App {
* Query the data.
*/
public static void queryData() {
var service =
new MagicServiceImpl(new WizardDaoImpl(), new SpellbookDaoImpl(), new SpellDaoImpl());
var wizardDao = new WizardDaoImpl();
var spellbookDao = new SpellbookDaoImpl();
var spellDao = new SpellDaoImpl();
var service = new MagicServiceImpl(wizardDao, spellbookDao, spellDao);
LOGGER.info("Enumerating all wizards");
for (Wizard w : service.findAllWizards()) {
LOGGER.info(w.getName());
}
service.findAllWizards().stream().map(Wizard::getName).forEach(LOGGER::info);
LOGGER.info("Enumerating all spellbooks");
for (Spellbook s : service.findAllSpellbooks()) {
LOGGER.info(s.getName());
}
service.findAllSpellbooks().stream().map(Spellbook::getName).forEach(LOGGER::info);
LOGGER.info("Enumerating all spells");
for (Spell s : service.findAllSpells()) {
LOGGER.info(s.getName());
}
service.findAllSpells().stream().map(Spell::getName).forEach(LOGGER::info);
LOGGER.info("Find wizards with spellbook 'Book of Idores'");
List<Wizard> wizardsWithSpellbook = service.findWizardsWithSpellbook("Book of Idores");
for (Wizard w : wizardsWithSpellbook) {
LOGGER.info("{} has 'Book of Idores'", w.getName());
}
var wizardsWithSpellbook = service.findWizardsWithSpellbook("Book of Idores");
wizardsWithSpellbook.forEach(w -> LOGGER.info("{} has 'Book of Idores'", w.getName()));
LOGGER.info("Find wizards with spell 'Fireball'");
List<Wizard> wizardsWithSpell = service.findWizardsWithSpell("Fireball");
for (Wizard w : wizardsWithSpell) {
LOGGER.info("{} has 'Fireball'", w.getName());
}
var wizardsWithSpell = service.findWizardsWithSpell("Fireball");
wizardsWithSpell.forEach(w -> LOGGER.info("{} has 'Fireball'", w.getName()));
}
}

View File

@ -52,10 +52,9 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
@Override
public E find(Long id) {
var session = getSessionFactory().openSession();
Transaction tx = null;
E result = null;
try {
E result;
try (var session = getSessionFactory().openSession()) {
tx = session.beginTransaction();
var criteria = session.createCriteria(persistentClass);
criteria.add(Restrictions.idEq(id));
@ -66,17 +65,14 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
tx.rollback();
}
throw e;
} finally {
session.close();
}
return result;
}
@Override
public void persist(E entity) {
var session = getSessionFactory().openSession();
Transaction tx = null;
try {
try (var session = getSessionFactory().openSession()) {
tx = session.beginTransaction();
session.persist(entity);
tx.commit();
@ -85,17 +81,14 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
tx.rollback();
}
throw e;
} finally {
session.close();
}
}
@Override
public E merge(E entity) {
var session = getSessionFactory().openSession();
Transaction tx = null;
E result = null;
try {
try (var session = getSessionFactory().openSession()) {
tx = session.beginTransaction();
result = (E) session.merge(entity);
tx.commit();
@ -104,17 +97,14 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
tx.rollback();
}
throw e;
} finally {
session.close();
}
return result;
}
@Override
public void delete(E entity) {
var session = getSessionFactory().openSession();
Transaction tx = null;
try {
try (var session = getSessionFactory().openSession()) {
tx = session.beginTransaction();
session.delete(entity);
tx.commit();
@ -123,17 +113,14 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
tx.rollback();
}
throw e;
} finally {
session.close();
}
}
@Override
public List<E> findAll() {
var session = getSessionFactory().openSession();
Transaction tx = null;
List<E> result = null;
try {
List<E> result;
try (var session = getSessionFactory().openSession()) {
tx = session.beginTransaction();
Criteria criteria = session.createCriteria(persistentClass);
result = criteria.list();
@ -142,8 +129,6 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
tx.rollback();
}
throw e;
} finally {
session.close();
}
return result;
}

View File

@ -54,14 +54,15 @@ public final class HibernateUtil {
public static synchronized SessionFactory getSessionFactory() {
if (sessionFactory == null) {
try {
sessionFactory =
new Configuration().addAnnotatedClass(Wizard.class).addAnnotatedClass(Spellbook.class)
.addAnnotatedClass(Spell.class)
.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
.setProperty("hibernate.connection.url", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")
.setProperty("hibernate.current_session_context_class", "thread")
.setProperty("hibernate.show_sql", "false")
.setProperty("hibernate.hbm2ddl.auto", "create-drop").buildSessionFactory();
sessionFactory = new Configuration()
.addAnnotatedClass(Wizard.class)
.addAnnotatedClass(Spellbook.class)
.addAnnotatedClass(Spell.class)
.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
.setProperty("hibernate.connection.url", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")
.setProperty("hibernate.current_session_context_class", "thread")
.setProperty("hibernate.show_sql", "false")
.setProperty("hibernate.hbm2ddl.auto", "create-drop").buildSessionFactory();
} catch (Throwable ex) {
LOGGER.error("Initial SessionFactory creation failed.", ex);
throw new ExceptionInInitializerError(ex);

View File

@ -35,7 +35,7 @@ public class SpellDaoImpl extends DaoBaseImpl<Spell> implements SpellDao {
@Override
public Spell findByName(String name) {
Transaction tx = null;
Spell result = null;
Spell result;
try (var session = getSessionFactory().openSession()) {
tx = session.beginTransaction();
var criteria = session.createCriteria(persistentClass);

View File

@ -34,24 +34,19 @@ public class SpellbookDaoImpl extends DaoBaseImpl<Spellbook> implements Spellboo
@Override
public Spellbook findByName(String name) {
var session = getSessionFactory().openSession();
Transaction tx = null;
Spellbook result = null;
try {
Spellbook result;
try (var session = getSessionFactory().openSession()) {
tx = session.beginTransaction();
var criteria = session.createCriteria(persistentClass);
criteria.add(Restrictions.eq("name", name));
result = (Spellbook) criteria.uniqueResult();
result.getSpells().size();
result.getWizards().size();
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
session.close();
}
return result;
}

View File

@ -24,9 +24,6 @@
package com.iluwatar.servicelayer.wizard;
import com.iluwatar.servicelayer.common.DaoBaseImpl;
import com.iluwatar.servicelayer.spellbook.Spellbook;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
@ -37,25 +34,19 @@ public class WizardDaoImpl extends DaoBaseImpl<Wizard> implements WizardDao {
@Override
public Wizard findByName(String name) {
Session session = getSessionFactory().openSession();
Transaction tx = null;
Wizard result = null;
try {
Wizard result;
try (var session = getSessionFactory().openSession()) {
tx = session.beginTransaction();
Criteria criteria = session.createCriteria(persistentClass);
var criteria = session.createCriteria(persistentClass);
criteria.add(Restrictions.eq("name", name));
result = (Wizard) criteria.uniqueResult();
for (Spellbook s : result.getSpellbooks()) {
s.getSpells().size();
}
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
session.close();
}
return result;
}