refa
This commit is contained in:
parent
33e71e078c
commit
bc85d6c0ff
|
@ -1,15 +1,6 @@
|
||||||
package org.bench4q.master.service.infrastructure;
|
package org.bench4q.master.service.infrastructure;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.bench4q.master.entity.TestPlanDB;
|
|
||||||
import org.bench4q.master.entity.User;
|
import org.bench4q.master.entity.User;
|
||||||
import org.bench4q.master.exception.ExceptionLog;
|
|
||||||
import org.bench4q.master.helper.CollectionHelper;
|
|
||||||
import org.bench4q.master.helper.HashHelper;
|
import org.bench4q.master.helper.HashHelper;
|
||||||
import org.bench4q.master.helper.SessionHelper;
|
import org.bench4q.master.helper.SessionHelper;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
|
@ -24,7 +15,6 @@ public class UserService {
|
||||||
private HashHelper hashHelper;
|
private HashHelper hashHelper;
|
||||||
public static byte NORAML_AUTHENTICATION = 0;
|
public static byte NORAML_AUTHENTICATION = 0;
|
||||||
public static byte SUPER_AUTHENTICATION = 1;
|
public static byte SUPER_AUTHENTICATION = 1;
|
||||||
private static Logger logger = Logger.getLogger(UserService.class);
|
|
||||||
|
|
||||||
private SessionHelper getSessionHelper() {
|
private SessionHelper getSessionHelper() {
|
||||||
return sessionHelper;
|
return sessionHelper;
|
||||||
|
@ -65,7 +55,9 @@ public class UserService {
|
||||||
transaction.rollback();
|
transaction.rollback();
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
releaseSession(session);
|
if (session != null) {
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +77,9 @@ public class UserService {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
releaseSession(session);
|
if (session != null) {
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +96,9 @@ public class UserService {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
releaseSession(session);
|
if (session != null) {
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,42 +110,9 @@ public class UserService {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
releaseSession(session);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TestPlanDB> querytestPlans(int userId) {
|
|
||||||
Session session = this.getSessionHelper().openSession();
|
|
||||||
try {
|
|
||||||
User user = (User) session.get(User.class, userId);
|
|
||||||
logger.info("User's testPlan count is "
|
|
||||||
+ user.getTestPlans().size());
|
|
||||||
return Collections.unmodifiableList(user.getTestPlans());
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(ExceptionLog.getStackTrace(e));
|
|
||||||
} finally {
|
|
||||||
releaseSession(session);
|
|
||||||
}
|
|
||||||
return new ArrayList<TestPlanDB>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TestPlanDB queryTestPlan(int userId, UUID testPlanRunId) {
|
|
||||||
Session session = this.getSessionHelper().openSession();
|
|
||||||
try {
|
|
||||||
return CollectionHelper.tryGetItemById(
|
|
||||||
((User) session.get(User.class, userId)).getTestPlans(),
|
|
||||||
testPlanRunId);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(ExceptionLog.getStackTrace(e));
|
|
||||||
} finally {
|
|
||||||
releaseSession(session);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void releaseSession(Session session) {
|
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue