#507 SonarQube blocker severity bugs
This commit is contained in:
		| @@ -48,8 +48,7 @@ public class FileLoader { | ||||
|    * Loads the data of the file specified. | ||||
|    */ | ||||
|   public String loadData() { | ||||
|     try { | ||||
|       BufferedReader br = new BufferedReader(new FileReader(new File(this.fileName))); | ||||
|     try (BufferedReader br = new BufferedReader(new FileReader(new File(this.fileName)))) { | ||||
|       StringBuilder sb = new StringBuilder(); | ||||
|       String line; | ||||
|  | ||||
| @@ -58,7 +57,6 @@ public class FileLoader { | ||||
|       } | ||||
|  | ||||
|       this.loaded = true; | ||||
|       br.close(); | ||||
|  | ||||
|       return sb.toString(); | ||||
|     } catch (Exception e) { | ||||
|   | ||||
| @@ -47,7 +47,7 @@ public class ServiceExecutor implements Runnable { | ||||
|    */ | ||||
|   public void run() { | ||||
|     try { | ||||
|       while (true) { | ||||
|       while (!Thread.currentThread().isInterrupted()) { | ||||
|         Message msg = msgQueue.retrieveMsg(); | ||||
|  | ||||
|         if (null != msg) { | ||||
|   | ||||
| @@ -27,6 +27,7 @@ import java.util.List; | ||||
|  | ||||
| import org.hibernate.Criteria; | ||||
| import org.hibernate.Session; | ||||
| import org.hibernate.SessionFactory; | ||||
| import org.hibernate.Transaction; | ||||
| import org.hibernate.criterion.Restrictions; | ||||
|  | ||||
| @@ -45,13 +46,17 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> { | ||||
|   protected Class<E> persistentClass = (Class<E>) ((ParameterizedType) getClass() | ||||
|       .getGenericSuperclass()).getActualTypeArguments()[0]; | ||||
|  | ||||
|   protected Session getSession() { | ||||
|     return HibernateUtil.getSessionFactory().openSession(); | ||||
|   /* | ||||
|    * Making this getSessionFactory() instead of getSession() so that it is the responsibility | ||||
|    * of the caller to open as well as close the session (prevents potential resource leak). | ||||
|    */ | ||||
|   protected SessionFactory getSessionFactory() { | ||||
|     return HibernateUtil.getSessionFactory(); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public E find(Long id) { | ||||
|     Session session = getSession(); | ||||
|     Session session = getSessionFactory().openSession(); | ||||
|     Transaction tx = null; | ||||
|     E result = null; | ||||
|     try { | ||||
| @@ -73,7 +78,7 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> { | ||||
|  | ||||
|   @Override | ||||
|   public void persist(E entity) { | ||||
|     Session session = getSession(); | ||||
|     Session session = getSessionFactory().openSession(); | ||||
|     Transaction tx = null; | ||||
|     try { | ||||
|       tx = session.beginTransaction(); | ||||
| @@ -91,7 +96,7 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> { | ||||
|  | ||||
|   @Override | ||||
|   public E merge(E entity) { | ||||
|     Session session = getSession(); | ||||
|     Session session = getSessionFactory().openSession(); | ||||
|     Transaction tx = null; | ||||
|     E result = null; | ||||
|     try { | ||||
| @@ -111,7 +116,7 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> { | ||||
|  | ||||
|   @Override | ||||
|   public void delete(E entity) { | ||||
|     Session session = getSession(); | ||||
|     Session session = getSessionFactory().openSession(); | ||||
|     Transaction tx = null; | ||||
|     try { | ||||
|       tx = session.beginTransaction(); | ||||
| @@ -129,7 +134,7 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> { | ||||
|  | ||||
|   @Override | ||||
|   public List<E> findAll() { | ||||
|     Session session = getSession(); | ||||
|     Session session = getSessionFactory().openSession(); | ||||
|     Transaction tx = null; | ||||
|     List<E> result = null; | ||||
|     try { | ||||
|   | ||||
| @@ -38,7 +38,7 @@ public class SpellDaoImpl extends DaoBaseImpl<Spell> implements SpellDao { | ||||
|  | ||||
|   @Override | ||||
|   public Spell findByName(String name) { | ||||
|     Session session = getSession(); | ||||
|     Session session = getSessionFactory().openSession(); | ||||
|     Transaction tx = null; | ||||
|     Spell result = null; | ||||
|     try { | ||||
|   | ||||
| @@ -38,7 +38,7 @@ public class SpellbookDaoImpl extends DaoBaseImpl<Spellbook> implements Spellboo | ||||
|  | ||||
|   @Override | ||||
|   public Spellbook findByName(String name) { | ||||
|     Session session = getSession(); | ||||
|     Session session = getSessionFactory().openSession(); | ||||
|     Transaction tx = null; | ||||
|     Spellbook result = null; | ||||
|     try { | ||||
|   | ||||
| @@ -39,7 +39,7 @@ public class WizardDaoImpl extends DaoBaseImpl<Wizard> implements WizardDao { | ||||
|  | ||||
|   @Override | ||||
|   public Wizard findByName(String name) { | ||||
|     Session session = getSession(); | ||||
|     Session session = getSessionFactory().openSession(); | ||||
|     Transaction tx = null; | ||||
|     Wizard result = null; | ||||
|     try { | ||||
|   | ||||
| @@ -52,11 +52,10 @@ public final class RainbowFishSerializer { | ||||
|     map.put("age", String.format("%d", rainbowFish.getAge())); | ||||
|     map.put("lengthMeters", String.format("%d", rainbowFish.getLengthMeters())); | ||||
|     map.put("weightTons", String.format("%d", rainbowFish.getWeightTons())); | ||||
|     FileOutputStream fileOut = new FileOutputStream(filename); | ||||
|     ObjectOutputStream objOut = new ObjectOutputStream(fileOut); | ||||
|     try (FileOutputStream fileOut = new FileOutputStream(filename); | ||||
|         ObjectOutputStream objOut = new ObjectOutputStream(fileOut)) { | ||||
|       objOut.writeObject(map); | ||||
|     objOut.close(); | ||||
|     fileOut.close(); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
| @@ -71,23 +70,24 @@ public final class RainbowFishSerializer { | ||||
|     map.put("angry", Boolean.toString(rainbowFish.getAngry())); | ||||
|     map.put("hungry", Boolean.toString(rainbowFish.getHungry())); | ||||
|     map.put("sleeping", Boolean.toString(rainbowFish.getSleeping())); | ||||
|     FileOutputStream fileOut = new FileOutputStream(filename); | ||||
|     ObjectOutputStream objOut = new ObjectOutputStream(fileOut); | ||||
|     try (FileOutputStream fileOut = new FileOutputStream(filename); | ||||
|         ObjectOutputStream objOut = new ObjectOutputStream(fileOut)) { | ||||
|       objOut.writeObject(map); | ||||
|     objOut.close(); | ||||
|     fileOut.close(); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Read V1 RainbowFish from file | ||||
|    */ | ||||
|   public static RainbowFish readV1(String filename) throws IOException, ClassNotFoundException { | ||||
|     FileInputStream fileIn = new FileInputStream(filename); | ||||
|     ObjectInputStream objIn = new ObjectInputStream(fileIn); | ||||
|     Map<String, String> map = (Map<String, String>) objIn.readObject(); | ||||
|     objIn.close(); | ||||
|     fileIn.close(); | ||||
|     return new RainbowFish(map.get("name"), Integer.parseInt(map.get("age")), Integer.parseInt(map | ||||
|         .get("lengthMeters")), Integer.parseInt(map.get("weightTons"))); | ||||
|     Map<String, String> map = null; | ||||
|  | ||||
|     try (FileInputStream fileIn = new FileInputStream(filename); | ||||
|         ObjectInputStream objIn = new ObjectInputStream(fileIn)) { | ||||
|       map = (Map<String, String>) objIn.readObject(); | ||||
|     } | ||||
|  | ||||
|     return new RainbowFish(map.get("name"), Integer.parseInt(map.get("age")), Integer.parseInt(map.get("lengthMeters")), | ||||
|         Integer.parseInt(map.get("weightTons"))); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user