Esempio n. 1
0
  @Override
  public void removeRequest(Requests request) {
    if (null != request) {

      org.hibernate.Session sess = sessionFactory.getCurrentSession();
      request = (Requests) sess.get(Requests.class, request.getId());
      List<Contacts> contTemp = request.getContacts();
      List<Products> prodTemp = request.getProducts();

      if (contTemp != null && contTemp.size() != 0) {

        sess.enableFetchProfile("requests-with-products");
        contTemp = contactsDAO.getFromProxy(contTemp);
        for (Contacts contact : contTemp) {
          contact.getConnectedRequests().remove(request);
          sess.update(contact);
        }
      }
      if (prodTemp != null && prodTemp.size() != 0) {
        sess.enableFetchProfile("requests-with-products");
        prodTemp = productsDAO.getFromProxy(prodTemp);
        for (Products product : prodTemp) {
          product.getRequestsForProduct().remove(request);
          sess.update(product);
        }
      }
      sess.update(request);
      sessionFactory.getCurrentSession().delete(request);
    }
  }
Esempio n. 2
0
  @Override
  public void addRequest(Requests request) {

    sessionFactory.getCurrentSession().save(request);
    List<Contacts> contTemp = request.getContacts();
    List<Products> prodTemp = request.getProducts();

    if (contTemp != null && contTemp.size() != 0) {
      org.hibernate.Session sess = sessionFactory.getCurrentSession();
      sess.enableFetchProfile("requests-with-products");
      contTemp = contactsDAO.getFromProxy(contTemp);
      for (Contacts contact : contTemp) {
        contact.getConnectedRequests().add(request);
        contactsDAO.changeContact(contact);
      }
    }
    if (prodTemp != null && prodTemp.size() != 0) {
      org.hibernate.Session sess = sessionFactory.getCurrentSession();
      sess.enableFetchProfile("requests-with-products");
      prodTemp = productsDAO.getFromProxy(prodTemp);
      for (Products product : prodTemp) {
        product.getRequestsForProduct().add(request);
        productsDAO.changeProduct(product);
      }
    }
  }
  @Override
  public List<Visiting> getVisitngsToBeCreatedForAnotherThreeMonths() throws Exception {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, -3);
    Date date = calendar.getTime();
    System.out.println("BEFORE THREE MONTHS :" + date);

    String queryString =
        "SELECT visiting_id as visiting_id"
            + " FROM visiting"
            + " WHERE start_date IN (SELECT Max(start_date)"
            + " FROM visiting"
            + " WHERE visiting_status='ACTIVE'"
            + " GROUP BY avg_time_per_appointment, created_user, no_of_patients, hospital_doctor_id, day_of_week)";

    SQLQuery sqlQuery = sessionFactory.getCurrentSession().createSQLQuery(queryString);
    sqlQuery.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    List<Map> result = sqlQuery.list();
    List<String> results = new ArrayList<String>();
    for (Map map : result) {
      results.add((String) map.get("visiting_id"));
    }

    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Visiting.class);
    criteria.add(
        Restrictions.conjunction()
            .add(Restrictions.in("visitingId", results))
            .add(Restrictions.le("startDate", date)));

    return criteria.list();
  }
  public void addMansion(Mansion m) {

    Session session = sf.getCurrentSession();

    session.beginTransaction();

    session.save(m);

    session.getTransaction().commit();

    Session session2 = sf.getCurrentSession();

    session2.beginTransaction();

    Query query = session2.createQuery("from Mansion");
    List<Mansion> mlist = query.list();
    for (Mansion onem : mlist) {
      System.out.println(onem.getA().size());
    }

    Query query2 = session2.createQuery("from Aristocrat");
    List<Aristocrat> alist = query2.list();
    for (Aristocrat onea : alist) {
      System.out.println("An aristocrat...");
    }

    session2.close();
  }
Esempio n. 5
0
 @Override
 public void save(HibernateAccount account, HibernateUserAccountInfo userAccountInfo) {
   sessionFactory.getCurrentSession().saveOrUpdate(account);
   log.info("Account saved with id: " + account.getID());
   sessionFactory.getCurrentSession().saveOrUpdate(userAccountInfo);
   log.info("UserAccountInfo saved with id: " + userAccountInfo.getID());
 }
Esempio n. 6
0
  /** @param username */
  public void removeContact(String username) {
    Contact contact = (Contact) sessionFactory.getCurrentSession().load(Contact.class, username);

    if (null != contact) {
      sessionFactory.getCurrentSession().delete(contact);
    }
  }
 public void removeUnit_Files_Links(Integer id) {
   Unit_Files_Links unit_Files_Links =
       (Unit_Files_Links) sessionFactory.getCurrentSession().load(Unit_Files_Links.class, id);
   if (null != unit_Files_Links) {
     sessionFactory.getCurrentSession().delete(unit_Files_Links);
   }
 }
  public CustomerInvoices findById(int id) {
    try {
      if (!sessionFactory.getCurrentSession().getTransaction().isActive()) {
        sessionFactory.getCurrentSession().getTransaction().begin();
      }
      Query query =
          sessionFactory
              .getCurrentSession()
              .createQuery(
                  "select invoice,account,caterer,worker from CustomerInvoices invoice join invoice.accounts account join invoice.caterers caterer left join invoice.workers worker where invoice.id = :id ORDER BY invoice.id DESC");
      query.setParameter("id", id);
      List list = query.list();
      Iterator ite = list.iterator();
      List<CustomerInvoices> listSupplierInvoiceses = new ArrayList<>();

      while (ite.hasNext()) {
        Object[] obj = (Object[]) ite.next();
        CustomerInvoices supInvoice = new CustomerInvoices();
        supInvoice = (CustomerInvoices) obj[0];
        listSupplierInvoiceses.add(supInvoice);
      }
      return listSupplierInvoiceses.get(0);
    } catch (Exception ex) {
      ex.printStackTrace();
      return null;
    } finally {
      sessionFactory.getCurrentSession().close();
    }
  }
Esempio n. 9
0
  private void processDefaultHolder(
      Entity entity, AnnotationMetadata<DefaultHolder> defaultHolder) {

    Query query = ContextUtil.getEntityFactory().buildQuery(entity.getEntityType());
    for (String filter : defaultHolder.getAnnotation().filters()) {
      query.addCriterion(
          new Path(filter),
          Condition.EQ,
          ContextUtil.getMRS()
              .getPropertyMetadata(entity.getEntityType(), filter)
              .getValue(entity));
    }
    List<Entity> existingEntities = ContextUtil.getDRS().findByQuery(query);
    PropertyMetadata propertyMetadata =
        ContextUtil.getMRS()
            .getPropertyMetadata(entity.getEntityType(), defaultHolder.getField().getName());
    boolean currentValue = (Boolean) propertyMetadata.getValue(entity);

    if (existingEntities.size() > 1 && currentValue) {
      for (Entity existingEntity : existingEntities) {
        if (!existingEntity.equals(entity) && (Boolean) propertyMetadata.getValue(existingEntity)) {
          propertyMetadata.setValue(existingEntity, false);
          sessionFactory.getCurrentSession().saveOrUpdate(existingEntity);
        }
      }
    } else if (existingEntities.size() == 1 && !currentValue) {
      propertyMetadata.setValue(entity, true);
      sessionFactory.getCurrentSession().saveOrUpdate(entity);
    }
  }
Esempio n. 10
0
 @Override
 public List<Transaccion> buscarTodos() {
   session.getCurrentSession().beginTransaction();
   List<Transaccion> lista;
   lista = session.getCurrentSession().createQuery("from Transaccion").list();
   return lista;
 }
Esempio n. 11
0
  public List<?> getCategoryItems(Integer catid) {
    Criteria cr = sessionFactory.getCurrentSession().createCriteria(Product.class);

    Category cat = (Category) sessionFactory.getCurrentSession().get(Category.class, catid);
    cr.add(Restrictions.eq("category", cat));

    return cr.list();
  }
 @Override
 public void setTransactionBoundSession(CompassSession session) {
   if (session == null) {
     currentSessionMap.remove(sessionFactory.getCurrentSession().getTransaction());
   } else {
     currentSessionMap.put(sessionFactory.getCurrentSession().getTransaction(), session);
   }
 }
  /** @deprecated see reportingcompatibility module */
  @Deprecated
  public void deleteReportObject(Integer reportObjectId) throws DAOException {
    ReportObjectWrapper wrappedReportObject = new ReportObjectWrapper();
    wrappedReportObject =
        (ReportObjectWrapper)
            sessionFactory.getCurrentSession().get(ReportObjectWrapper.class, reportObjectId);

    sessionFactory.getCurrentSession().delete(wrappedReportObject);
  }
 @Override
 public void saveOrUpdate(ChannelSeverity channelSeverity) {
   if (channelSeverity.getSeverityMap() != null) {
     sessionFactory.getCurrentSession().saveOrUpdate(channelSeverity.getSeverityMap());
   }
   sessionFactory.getCurrentSession().saveOrUpdate(channelSeverity);
   sessionFactory.getCurrentSession().flush();
   sessionFactory.getCurrentSession().refresh(channelSeverity);
 }
 public OrderedItem save(OrderedItem orderedItem) {
   if (orderedItem.getObjectId() == 0) {
     sessionFactory.getCurrentSession().persist(orderedItem);
     return (OrderedItem)
         sessionFactory.getCurrentSession().get(OrderedItem.class, orderedItem.getObjectId());
   } else {
     return (OrderedItem) sessionFactory.getCurrentSession().merge(orderedItem);
   }
 }
 public void startTransaction() {
   if (!sessionFactory.getCurrentSession().getTransaction().isActive()
       || sessionFactory.getCurrentSession().getTransaction().wasCommitted()) {
     log.debug("Starting a database transaction");
     sessionFactory.getCurrentSession().beginTransaction();
   } else {
     log.debug("A transaction is in progress");
   }
 }
Esempio n. 17
0
  @Override
  public void delete(Long clientId) {

    if (clientId == null) throw new IllegalArgumentException("Client id argument cannot be null");
    Client client = (Client) sessionFactory.getCurrentSession().load(Client.class, clientId);

    if (client == null)
      throw new IllegalArgumentException("There is no Client record for id " + clientId);
    sessionFactory.getCurrentSession().delete(client);
  }
Esempio n. 18
0
 @Override
 public List<Daily> SelectTasksForEmployee(Employees empl) {
   Long id = empl.getId();
   Employees implementer = (Employees) sessionFactory.getCurrentSession().get(Employees.class, id);
   return sessionFactory
       .getCurrentSession()
       .createCriteria(Daily.class)
       .add(Restrictions.eq("implementer", implementer))
       .list();
 }
Esempio n. 19
0
 @Override
 public List<Transaccion> buscarTodosDoc(String documento) {
   session.getCurrentSession().beginTransaction();
   List<Transaccion> lista =
       session
           .getCurrentSession()
           .createQuery("from Transaccion where idtipotransaccion='" + documento + "'")
           .list();
   return lista;
 }
Esempio n. 20
0
 @Override
 public List<Transaccion> buscarTurno(int turno) {
   session.getCurrentSession().beginTransaction();
   List<Transaccion> lista;
   lista =
       session
           .getCurrentSession()
           .createQuery("from Transaccion where idestado=" + turno + " and anulado=false")
           .list();
   return lista;
 }
Esempio n. 21
0
  /** 解密文件 */
  public void notlockFile(String notfileId, String notlick_password) {

    int id = Integer.parseInt(notfileId);

    String sqlL = "update File f set f.isLock=0 where f.id=" + id;
    Query qL = sessionFactory.getCurrentSession().createQuery(sqlL);
    qL.executeUpdate();

    String sqlp = "update File f set f.password ='' where f.id=" + id;
    Query qp = sessionFactory.getCurrentSession().createQuery(sqlp);
    qp.executeUpdate();
  }
Esempio n. 22
0
 public void delete(Project persistentInstance) {
   log.debug("deleting Project instance");
   try {
     sessionFactory.getCurrentSession().beginTransaction();
     sessionFactory.getCurrentSession().delete(persistentInstance);
     sessionFactory.getCurrentSession().getTransaction().commit();
     log.debug("delete successful");
   } catch (RuntimeException re) {
     log.error("delete failed", re);
     throw re;
   }
 }
Esempio n. 23
0
 public void attachDirty(Project instance) {
   log.debug("attaching dirty Project instance");
   try {
     sessionFactory.getCurrentSession().beginTransaction();
     sessionFactory.getCurrentSession().saveOrUpdate(instance);
     sessionFactory.getCurrentSession().getTransaction().commit();
     log.debug("attach successful");
   } catch (RuntimeException re) {
     log.error("attach failed", re);
     throw re;
   }
 }
Esempio n. 24
0
 public void persist(Project transientInstance) {
   log.debug("persisting Project instance");
   try {
     sessionFactory.getCurrentSession().beginTransaction();
     sessionFactory.getCurrentSession().persist(transientInstance);
     sessionFactory.getCurrentSession().getTransaction().commit();
     log.debug("persist successful");
   } catch (RuntimeException re) {
     log.error("persist failed", re);
     throw re;
   }
 }
 @Override
 public List<Country> getAllCountries() {
   Criteria criteria =
       sessionFactory
           .getCurrentSession()
           .createCriteria(Country.class)
           .setCacheable(true)
           .setCacheRegion("query-cache");
   List<Country> countries = criteria.list();
   CacheStatisticsUtil.printCacheStatistics(sessionFactory.getCurrentSession());
   return countries;
 }
Esempio n. 26
0
 @Override
 public Transaccion buscarPorNumero(String numero) {
   session.getCurrentSession().beginTransaction();
   Transaccion trans;
   trans =
       (Transaccion)
           session
               .getCurrentSession()
               .createQuery("from Transaccion where numerovale='" + numero + "'")
               .uniqueResult();
   return trans;
 }
Esempio n. 27
0
  /** 分享文件 */
  public void shareFile(String path, File file, User user, HttpSession httpSession) {
    // 分享时间
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    String createDate = df.format(new Date());
    // 文件的location
    String location = path + "\\" + file.getName();
    // 文件的类型type
    String type = file.getType();
    // 文件的描述
    User u = (User) httpSession.getAttribute("u");
    String description = u.getStuNo() + "分享给我的文件";

    File fileShare = new File();
    fileShare.setUser(user);
    fileShare.setSize(file.getSize());
    fileShare.setPath(path);
    fileShare.setName(file.getName());
    fileShare.setType(type);
    fileShare.setPassword("");
    fileShare.setIsLock(0);
    fileShare.setIsShare(0);
    fileShare.setShareDownload(0);
    fileShare.setDescription(description);
    fileShare.setLocation(location);
    fileShare.setShareUrl("");
    fileShare.setCreateDate(createDate);

    sessionFactory.getCurrentSession().save(fileShare);

    // 更改被分享的文件属性,是否被分享
    String sql = "update File f set f.isShare=1 where f.id=" + file.getId();
    Query q = sessionFactory.getCurrentSession().createQuery(sql);
    q.executeUpdate();

    // 更改被分享的文件属性,被分享次数
    int shareNun = file.getShareDownload() + 1;
    String sqlS = "update File f set f.shareDownload=" + shareNun + "  where f.id=" + file.getId();
    Query qS = sessionFactory.getCurrentSession().createQuery(sqlS);
    qS.executeUpdate();

    // 分享文件后,网盘中的分享文件数量要更改
    // 得到网盘中的分享文件数量
    String sqlN = "select count(*) from File f where f.user.id=" + u.getId() + " and f.isShare=1";
    Query qN = sessionFactory.getCurrentSession().createQuery(sqlN);
    long shareNumL = (Long) qN.uniqueResult();
    int shareNum = (int) shareNumL;

    // 更新网盘分享文件的数量
    String sqlSD = "update Disk d set d.shareNumber=" + shareNum + " where d.user.id=" + u.getId();
    Query qSD = sessionFactory.getCurrentSession().createQuery(sqlSD);
    qSD.executeUpdate();
  }
Esempio n. 28
0
 @SuppressWarnings("deprecation")
 public void attachClean(Project instance) {
   log.debug("attaching clean Project instance");
   try {
     sessionFactory.getCurrentSession().beginTransaction();
     sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
     sessionFactory.getCurrentSession().getTransaction().commit();
     log.debug("attach successful");
   } catch (RuntimeException re) {
     log.error("attach failed", re);
     throw re;
   }
 }
Esempio n. 29
0
 /**
  * This method is to save the client object.
  *
  * @param clients
  * @return saved client Id else 0.
  */
 public long saveClients(Clients clients) {
   try {
     if (clients.getClientId() == 0) {
       return (Long) sessionFactory.getCurrentSession().save(clients);
     } else {
       sessionFactory.getCurrentSession().saveOrUpdate(clients);
       return 1;
     }
   } catch (Exception e) {
     log.error("Exception in save client: DAO : " + ExceptionUtils.getStackTrace(e));
   }
   return 0;
 }
Esempio n. 30
0
 @Override
 @Transactional(readOnly = true)
 public Doctor getDoctorByUser(User user) throws DataAccessException {
   Session session = sessionFactory.getCurrentSession();
   Query searchUserTable = session.createQuery("from Doctor doc where doc.user.id=:userId");
   searchUserTable.setParameter("userId", user.getId());
   sessionFactory.getCurrentSession().clear();
   Doctor doctor = (Doctor) searchUserTable.uniqueResult();
   if (doctor == null) {
     throw new DataAccessException("null");
   }
   return doctor;
 }