use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class LanguagePersistenceImpl method createLanguage.
/*
* (non-Javadoc)
*
* @see
* cn.edu.zju.acm.onlinejudge.persistence.sql.LanguagePersistence#createLanguage(cn.edu.zju.acm.onlinejudge.bean
* .enumeration.Language, long)
*/
public void createLanguage(Language language, long user) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
synchronized (this.allLanguages) {
try {
ps = conn.prepareStatement(LanguagePersistenceImpl.INSERT_LANGUAGE);
ps.setLong(1, language.getId());
ps.setString(2, language.getName());
ps.setString(3, language.getDescription());
ps.setString(4, language.getOptions());
ps.setString(5, language.getCompiler());
ps.setLong(6, user);
ps.setTimestamp(7, new Timestamp(new Date().getTime()));
ps.setLong(8, user);
ps.setTimestamp(9, new Timestamp(new Date().getTime()));
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
this.allLanguages.put(language.getId(), language);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to create language.", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class LanguagePersistenceImpl method deleteLanguage.
/*
* (non-Javadoc)
*
* @see cn.edu.zju.acm.onlinejudge.persistence.sql.LanguagePersistence#deleteLanguage(long, long)
*/
// TODO(xuchuan): this is a very dangerous operation. Check if necessary.
public void deleteLanguage(long id, long user) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
conn.setAutoCommit(false);
synchronized (this.allLanguages) {
PreparedStatement ps = null;
ps = conn.prepareStatement(LanguagePersistenceImpl.DELETE_SUBMISSION);
try {
ps.setLong(1, id);
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
try {
ps = conn.prepareStatement(LanguagePersistenceImpl.DELETE_LANGUAGE_CONTEST);
ps.setLong(1, id);
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
try {
ps = conn.prepareStatement(LanguagePersistenceImpl.DELETE_LANGUAGE);
ps.setLong(1, id);
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
conn.commit();
this.allLanguages.remove(id);
}
} catch (Exception e) {
Database.rollback(conn);
throw new PersistenceException("Failed to delete language.", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class SubmissionPersistenceImpl method changeQQStatus.
public void changeQQStatus(long pid, long uid, String status) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement("UPDATE submission_status SET status=? WHERE problem_id=? AND user_profile_id=?");
ps.setString(1, status);
ps.setLong(2, pid);
ps.setLong(3, uid);
int changes = ps.executeUpdate();
if (changes == 0) {
ps = conn.prepareStatement("INSERT INTO submission_status (problem_id, user_profile_id, status) VALUES (?,?,?)");
ps.setLong(1, pid);
ps.setLong(2, uid);
ps.setString(3, status);
ps.executeUpdate();
}
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to update the QQs", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class UserPersistenceImpl method searchUserProfilesCount.
public int searchUserProfilesCount(UserCriteria criteria) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = this.getUserSearchSql(conn, criteria, true, 0, 0);
ResultSet rs = ps.executeQuery();
rs.next();
return rs.getInt(1);
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to search user.", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceException in project zoj by licheng.
the class UserPersistenceImpl method createUserProfile.
/**
* <p>
* Creates the specified user profile in persistence layer.
* </p>
*
* @param profile
* the UserProfile instance to create
* @param user
* the id of the user who made this modification
* @throws NullPointerException
* if argument is null
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public void createUserProfile(UserProfile profile, long user) throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(UserPersistenceImpl.INSERT_USER);
ps.setString(1, profile.getHandle());
ps.setString(2, profile.getPassword());
ps.setString(3, profile.getEmail());
ps.setTimestamp(4, new Timestamp(new Date().getTime()));
ps.setString(5, profile.getFirstName());
ps.setString(6, profile.getLastName());
ps.setString(7, profile.getAddressLine1());
ps.setString(8, profile.getAddressLine2());
ps.setString(9, profile.getCity());
ps.setString(10, profile.getState());
ps.setLong(11, profile.getCountry().getId());
ps.setString(12, profile.getZipCode());
ps.setString(13, profile.getPhoneNumber());
ps.setTimestamp(14, new Timestamp(profile.getBirthDate().getTime()));
ps.setString(15, "" + profile.getGender());
ps.setString(16, profile.getSchool());
ps.setString(17, profile.getMajor());
ps.setBoolean(18, profile.isGraduateStudent());
ps.setInt(19, profile.getGraduationYear());
ps.setString(20, profile.getStudentNumber());
ps.setBoolean(21, profile.isConfirmed());
ps.setLong(22, user);
ps.setTimestamp(23, new Timestamp(new Date().getTime()));
ps.setLong(24, user);
ps.setTimestamp(25, new Timestamp(new Date().getTime()));
ps.setString(26, profile.getNickName());
ps.executeUpdate();
} finally {
Database.dispose(ps);
}
try {
ps = conn.prepareStatement(UserPersistenceImpl.GET_LAST_ID);
ResultSet rs = ps.executeQuery();
rs.next();
profile.setId(rs.getLong(1));
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to create user.", e);
} finally {
Database.dispose(conn);
}
}
Aggregations