This commit is contained in:
coderfengyun 2014-01-06 17:18:35 +08:00
parent 33e71e078c
commit bc85d6c0ff
1 changed files with 12 additions and 49 deletions

View File

@ -1,15 +1,6 @@
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.exception.ExceptionLog;
import org.bench4q.master.helper.CollectionHelper;
import org.bench4q.master.helper.HashHelper;
import org.bench4q.master.helper.SessionHelper;
import org.hibernate.Session;
@ -24,7 +15,6 @@ public class UserService {
private HashHelper hashHelper;
public static byte NORAML_AUTHENTICATION = 0;
public static byte SUPER_AUTHENTICATION = 1;
private static Logger logger = Logger.getLogger(UserService.class);
private SessionHelper getSessionHelper() {
return sessionHelper;
@ -65,7 +55,9 @@ public class UserService {
transaction.rollback();
return false;
} finally {
releaseSession(session);
if (session != null) {
session.close();
}
}
}
@ -85,7 +77,9 @@ public class UserService {
e.printStackTrace();
return false;
} finally {
releaseSession(session);
if (session != null) {
session.close();
}
}
}
@ -102,7 +96,9 @@ public class UserService {
e.printStackTrace();
return null;
} finally {
releaseSession(session);
if (session != null) {
session.close();
}
}
}
@ -114,42 +110,9 @@ public class UserService {
e.printStackTrace();
return null;
} 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) {
session.close();
if (session != null) {
session.close();
}
}
}
}