Merge pull request #563 from sunilmogadati/SonarQubeBlockerBugs
#507 SonarQube blocker severity bugs
This commit is contained in:
commit
cd54cf5512
@ -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) {
|
||||
|
@ -35,27 +35,27 @@ import org.slf4j.LoggerFactory;
|
||||
public class ServiceExecutor implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
|
||||
private final MessageQueue msgQueue;
|
||||
|
||||
public ServiceExecutor(MessageQueue msgQueue) {
|
||||
this.msgQueue = msgQueue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The ServiceExecutor thread will retrieve each message and process it.
|
||||
*/
|
||||
public void run() {
|
||||
try {
|
||||
while (true) {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
Message msg = msgQueue.retrieveMsg();
|
||||
|
||||
|
||||
if (null != msg) {
|
||||
LOGGER.info(msg.toString() + " is served.");
|
||||
} else {
|
||||
LOGGER.info("Service Executor: Waiting for Messages to serve .. ");
|
||||
}
|
||||
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
} catch (InterruptedException ie) {
|
||||
|
@ -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);
|
||||
objOut.writeObject(map);
|
||||
objOut.close();
|
||||
fileOut.close();
|
||||
try (FileOutputStream fileOut = new FileOutputStream(filename);
|
||||
ObjectOutputStream objOut = new ObjectOutputStream(fileOut)) {
|
||||
objOut.writeObject(map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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);
|
||||
objOut.writeObject(map);
|
||||
objOut.close();
|
||||
fileOut.close();
|
||||
try (FileOutputStream fileOut = new FileOutputStream(filename);
|
||||
ObjectOutputStream objOut = new ObjectOutputStream(fileOut)) {
|
||||
objOut.writeObject(map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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")));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user