예제 #1
0
 /**
  * Get sql query for all admins
  *
  * @param wrapperConnection wrapper connection from the connection pool
  * @return list of admins
  * @throws SQLException
  */
 @Override
 protected List<DBEntity> getAllEntities(WrapperConnectionProxy wrapperConnection)
     throws SQLException {
   List<DBEntity> admins = new ArrayList<>();
   Statement st = wrapperConnection.createStatement();
   ResultSet rs = st.executeQuery(SQL_FOR_ALL_ADMINS);
   while (rs.next()) {
     admins.add(getAdmin(rs));
   }
   return admins;
 }
예제 #2
0
 /**
  * Get admin by id
  *
  * @param wrapperConnection wrapper connection regarding to which prepared statement might be
  *     created
  * @param id admin id
  * @return prepared statement
  * @throws SQLException
  */
 @Override
 protected DBEntity getEntityById(WrapperConnectionProxy wrapperConnection, int id)
     throws SQLException {
   PreparedStatement ps = wrapperConnection.prepareStatement(SQL_FOR_ADMIN_BY_ID);
   ps.setInt(1, id);
   ResultSet rs = ps.executeQuery();
   if (rs.next()) {
     return getAdmin(rs);
   }
   return null;
 }
예제 #3
0
 /**
  * Insert entity into the data base from the object oriented entity
  *
  * @param wrapperConnection wrapper connection from the connection pool
  * @param entity entity might be inserting into the data base
  * @throws SQLException
  */
 @Override
 protected void insertEntity(WrapperConnectionProxy wrapperConnection, DBEntity entity)
     throws SQLException {
   Admin admin = (Admin) entity;
   PreparedStatement ps = wrapperConnection.prepareStatement(SQL_FOR_ADMIN_INSERTING);
   ps.setString(1, admin.getFirstName());
   ps.setString(2, admin.getLastName());
   ps.setString(3, admin.getAdminType().toString());
   ps.setString(4, admin.getEmail());
   ps.setString(5, admin.getLogin());
   ps.setString(6, admin.getPassword());
   ps.executeUpdate();
 }
예제 #4
0
 /**
  * Delete entity from the data base by id
  *
  * @param wrapperConnection wrapper conection
  * @param id entity id
  * @throws SQLException
  */
 @Override
 protected void deleteById(WrapperConnectionProxy wrapperConnection, int id) throws SQLException {
   PreparedStatement ps = wrapperConnection.prepareStatement(SQL_FOR_DELETING_BY_ID);
   ps.setInt(1, id);
   ps.executeUpdate();
 }