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.
|
* Loads the data of the file specified.
|
||||||
*/
|
*/
|
||||||
public String loadData() {
|
public String loadData() {
|
||||||
try {
|
try (BufferedReader br = new BufferedReader(new FileReader(new File(this.fileName)))) {
|
||||||
BufferedReader br = new BufferedReader(new FileReader(new File(this.fileName)));
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
@ -58,7 +57,6 @@ public class FileLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
br.close();
|
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -35,27 +35,27 @@ import org.slf4j.LoggerFactory;
|
|||||||
public class ServiceExecutor implements Runnable {
|
public class ServiceExecutor implements Runnable {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
private final MessageQueue msgQueue;
|
private final MessageQueue msgQueue;
|
||||||
|
|
||||||
public ServiceExecutor(MessageQueue msgQueue) {
|
public ServiceExecutor(MessageQueue msgQueue) {
|
||||||
this.msgQueue = msgQueue;
|
this.msgQueue = msgQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ServiceExecutor thread will retrieve each message and process it.
|
* The ServiceExecutor thread will retrieve each message and process it.
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (!Thread.currentThread().isInterrupted()) {
|
||||||
Message msg = msgQueue.retrieveMsg();
|
Message msg = msgQueue.retrieveMsg();
|
||||||
|
|
||||||
if (null != msg) {
|
if (null != msg) {
|
||||||
LOGGER.info(msg.toString() + " is served.");
|
LOGGER.info(msg.toString() + " is served.");
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("Service Executor: Waiting for Messages to serve .. ");
|
LOGGER.info("Service Executor: Waiting for Messages to serve .. ");
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.criterion.Restrictions;
|
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()
|
protected Class<E> persistentClass = (Class<E>) ((ParameterizedType) getClass()
|
||||||
.getGenericSuperclass()).getActualTypeArguments()[0];
|
.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
|
@Override
|
||||||
public E find(Long id) {
|
public E find(Long id) {
|
||||||
Session session = getSession();
|
Session session = getSessionFactory().openSession();
|
||||||
Transaction tx = null;
|
Transaction tx = null;
|
||||||
E result = null;
|
E result = null;
|
||||||
try {
|
try {
|
||||||
@ -73,7 +78,7 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void persist(E entity) {
|
public void persist(E entity) {
|
||||||
Session session = getSession();
|
Session session = getSessionFactory().openSession();
|
||||||
Transaction tx = null;
|
Transaction tx = null;
|
||||||
try {
|
try {
|
||||||
tx = session.beginTransaction();
|
tx = session.beginTransaction();
|
||||||
@ -91,7 +96,7 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public E merge(E entity) {
|
public E merge(E entity) {
|
||||||
Session session = getSession();
|
Session session = getSessionFactory().openSession();
|
||||||
Transaction tx = null;
|
Transaction tx = null;
|
||||||
E result = null;
|
E result = null;
|
||||||
try {
|
try {
|
||||||
@ -111,7 +116,7 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(E entity) {
|
public void delete(E entity) {
|
||||||
Session session = getSession();
|
Session session = getSessionFactory().openSession();
|
||||||
Transaction tx = null;
|
Transaction tx = null;
|
||||||
try {
|
try {
|
||||||
tx = session.beginTransaction();
|
tx = session.beginTransaction();
|
||||||
@ -129,7 +134,7 @@ public abstract class DaoBaseImpl<E extends BaseEntity> implements Dao<E> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<E> findAll() {
|
public List<E> findAll() {
|
||||||
Session session = getSession();
|
Session session = getSessionFactory().openSession();
|
||||||
Transaction tx = null;
|
Transaction tx = null;
|
||||||
List<E> result = null;
|
List<E> result = null;
|
||||||
try {
|
try {
|
||||||
|
@ -38,7 +38,7 @@ public class SpellDaoImpl extends DaoBaseImpl<Spell> implements SpellDao {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Spell findByName(String name) {
|
public Spell findByName(String name) {
|
||||||
Session session = getSession();
|
Session session = getSessionFactory().openSession();
|
||||||
Transaction tx = null;
|
Transaction tx = null;
|
||||||
Spell result = null;
|
Spell result = null;
|
||||||
try {
|
try {
|
||||||
|
@ -38,7 +38,7 @@ public class SpellbookDaoImpl extends DaoBaseImpl<Spellbook> implements Spellboo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Spellbook findByName(String name) {
|
public Spellbook findByName(String name) {
|
||||||
Session session = getSession();
|
Session session = getSessionFactory().openSession();
|
||||||
Transaction tx = null;
|
Transaction tx = null;
|
||||||
Spellbook result = null;
|
Spellbook result = null;
|
||||||
try {
|
try {
|
||||||
|
@ -39,7 +39,7 @@ public class WizardDaoImpl extends DaoBaseImpl<Wizard> implements WizardDao {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Wizard findByName(String name) {
|
public Wizard findByName(String name) {
|
||||||
Session session = getSession();
|
Session session = getSessionFactory().openSession();
|
||||||
Transaction tx = null;
|
Transaction tx = null;
|
||||||
Wizard result = null;
|
Wizard result = null;
|
||||||
try {
|
try {
|
||||||
|
@ -52,11 +52,10 @@ public final class RainbowFishSerializer {
|
|||||||
map.put("age", String.format("%d", rainbowFish.getAge()));
|
map.put("age", String.format("%d", rainbowFish.getAge()));
|
||||||
map.put("lengthMeters", String.format("%d", rainbowFish.getLengthMeters()));
|
map.put("lengthMeters", String.format("%d", rainbowFish.getLengthMeters()));
|
||||||
map.put("weightTons", String.format("%d", rainbowFish.getWeightTons()));
|
map.put("weightTons", String.format("%d", rainbowFish.getWeightTons()));
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
try (FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
ObjectOutputStream objOut = new ObjectOutputStream(fileOut);
|
ObjectOutputStream objOut = new ObjectOutputStream(fileOut)) {
|
||||||
objOut.writeObject(map);
|
objOut.writeObject(map);
|
||||||
objOut.close();
|
}
|
||||||
fileOut.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,23 +70,24 @@ public final class RainbowFishSerializer {
|
|||||||
map.put("angry", Boolean.toString(rainbowFish.getAngry()));
|
map.put("angry", Boolean.toString(rainbowFish.getAngry()));
|
||||||
map.put("hungry", Boolean.toString(rainbowFish.getHungry()));
|
map.put("hungry", Boolean.toString(rainbowFish.getHungry()));
|
||||||
map.put("sleeping", Boolean.toString(rainbowFish.getSleeping()));
|
map.put("sleeping", Boolean.toString(rainbowFish.getSleeping()));
|
||||||
FileOutputStream fileOut = new FileOutputStream(filename);
|
try (FileOutputStream fileOut = new FileOutputStream(filename);
|
||||||
ObjectOutputStream objOut = new ObjectOutputStream(fileOut);
|
ObjectOutputStream objOut = new ObjectOutputStream(fileOut)) {
|
||||||
objOut.writeObject(map);
|
objOut.writeObject(map);
|
||||||
objOut.close();
|
}
|
||||||
fileOut.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read V1 RainbowFish from file
|
* Read V1 RainbowFish from file
|
||||||
*/
|
*/
|
||||||
public static RainbowFish readV1(String filename) throws IOException, ClassNotFoundException {
|
public static RainbowFish readV1(String filename) throws IOException, ClassNotFoundException {
|
||||||
FileInputStream fileIn = new FileInputStream(filename);
|
Map<String, String> map = null;
|
||||||
ObjectInputStream objIn = new ObjectInputStream(fileIn);
|
|
||||||
Map<String, String> map = (Map<String, String>) objIn.readObject();
|
try (FileInputStream fileIn = new FileInputStream(filename);
|
||||||
objIn.close();
|
ObjectInputStream objIn = new ObjectInputStream(fileIn)) {
|
||||||
fileIn.close();
|
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")));
|
|
||||||
|
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