コード例 #1
0
 public void flush() {
   try {
     this.entityManagerHolder.getEntityManager().flush();
   } catch (RuntimeException ex) {
     throw DataAccessUtils.translateIfNecessary(ex, getJpaDialect());
   }
 }
コード例 #2
0
 @Override
 protected void doCommit(DefaultTransactionStatus status) {
   JpaTransactionObject txObject = (JpaTransactionObject) status.getTransaction();
   if (status.isDebug()) {
     logger.debug(
         "Committing JPA transaction on EntityManager ["
             + txObject.getEntityManagerHolder().getEntityManager()
             + "]");
   }
   try {
     EntityTransaction tx = txObject.getEntityManagerHolder().getEntityManager().getTransaction();
     tx.commit();
   } catch (RollbackException ex) {
     if (ex.getCause() instanceof RuntimeException) {
       DataAccessException dex =
           getJpaDialect().translateExceptionIfPossible((RuntimeException) ex.getCause());
       if (dex != null) {
         throw dex;
       }
     }
     throw new TransactionSystemException("Could not commit JPA transaction", ex);
   } catch (RuntimeException ex) {
     // Assumably failed to flush changes to database.
     throw DataAccessUtils.translateIfNecessary(ex, getJpaDialect());
   }
 }
コード例 #3
0
 @Override
 public DateTime getNewestPortalEventTimestamp() {
   final TypedQuery<DateTime> query =
       this.createQuery(this.findNewestPersistentPortalEventTimestampQuery);
   final List<DateTime> results = query.getResultList();
   return DataAccessUtils.uniqueResult(results);
 }
コード例 #4
0
 @Override
 public CmsContent findFirstByCreatedDay(String site, Date createdDay) {
   Date end = DateUtils.addDays(createdDay, 1);
   String sql = SELECT_FROM + " where  site = ? and date_created between ? and ? limit 1";
   return (CmsContent)
       DataAccessUtils.singleResult(
           getSimpleJdbcTemplate().query(sql, getEntityRowMapper(), site, createdDay, end));
 }
コード例 #5
0
  @Override
  public int getFormsCount(Person owner) {
    DetachedCriteria criteria = DetachedCriteria.forClass(type);
    criteria.setProjection(Projections.distinct(Projections.countDistinct("formName")));
    if (owner != null) criteria.add(Restrictions.eq("person.personId", owner.getPersonId()));

    return DataAccessUtils.intResult(getHibernateTemplate().findByCriteria(criteria));
  }
コード例 #6
0
 @Override
 public CmsContent getById(Date dateCreated, long id) {
   Date end = DateUtils.addDays(dateCreated, 1);
   String sql = SELECT_FROM + " where  id = ?  and date_created between ? and ?";
   return (CmsContent)
       DataAccessUtils.singleResult(
           getSimpleJdbcTemplate().query(sql, getEntityRowMapper(), id, dateCreated, end));
 }
コード例 #7
0
 @Override
 public QNameFilter find(Long id) {
   final String sql = "select id,name,workspace_id from " + this.tableName + " where id=?";
   final QNameFilter filter =
       DataAccessUtils.uniqueResult(this.jt.query(sql, new FilterMapper(), id));
   addFilterMembers(filter);
   return filter;
 }
コード例 #8
0
 /**
  * Return a {@link SocialAccount} by id and {@link Account}.
  *
  * @param socialAccountId
  * @param account
  * @return
  */
 @SuppressWarnings("unchecked")
 public final SocialAccount getSocialAccount(final Long socialAccountId, final Account account) {
   final DetachedCriteria criteria = DetachedCriteria.forClass(SocialAccount.class);
   criteria.add(Restrictions.eq("account", account));
   criteria.add(Restrictions.eq("id", socialAccountId));
   return (SocialAccount)
       DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
 }
コード例 #9
0
 /**
  * This method finds record (Person) that have userName identical with searched userName. Search
  * only one record, because userName is unique.
  *
  * @param userName - userName of searched Person
  * @return Person with searched userName
  */
 public Person getPerson(String userName) {
   String HQLselect = "from Person person where person.username = :userName";
   Person foundUser =
       (Person)
           DataAccessUtils.uniqueResult(
               getHibernateTemplate().findByNamedParam(HQLselect, "userName", userName));
   return foundUser;
 }
コード例 #10
0
 /**
  * Get Account Connection.
  *
  * @param accountId
  * @param proviver
  * @return
  */
 @SuppressWarnings("unchecked")
 public SocialAccount getAccountConnection(final String accountId, final SocialProvider provider) {
   final DetachedCriteria criteria = DetachedCriteria.forClass(SocialAccount.class);
   criteria.createAlias("userAccout", "userAccout");
   criteria.add(Restrictions.eq("userAccout.uid", accountId));
   criteria.add(Restrictions.eq("accounType", provider));
   return (SocialAccount)
       DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
 }
コード例 #11
0
 /*
  * (non-Javadoc)
  * @see org.encuestame.persistence.dao.IAccountDao#findAccountConnectionBySocialProfileId(org.encuestame.persistence.domain.social.SocialProvider, java.lang.String)
  */
 @SuppressWarnings("unchecked")
 public SocialAccount findAccountConnectionBySocialProfileId(
     final SocialProvider provider, final String socialProfileId) {
   final DetachedCriteria criteria = DetachedCriteria.forClass(SocialAccount.class);
   criteria.add(Restrictions.eq("socialProfileId", socialProfileId));
   criteria.add(Restrictions.eq("accounType", provider));
   return (SocialAccount)
       DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
 }
コード例 #12
0
  /**
   * This method finds record (Person) that have hashCode identical with searched hashCode. Search
   * only one record, because hashCode is unique.
   *
   * @param hashCode - hashCode of searched Person
   * @return Person with searched hashCode
   */
  public Person getPersonByHash(String hashCode) {
    String HQLselect = "from Person person where person.authenticationHash = :hashCode";

    Person foundUser =
        (Person)
            DataAccessUtils.uniqueResult(
                getHibernateTemplate().findByNamedParam(HQLselect, "hashCode", hashCode));
    return foundUser;
  }
コード例 #13
0
  public Person getPersonByFbUid(String facebookId) {
    String HQLselect = "from Person person where person.facebookId = :facebookId";

    Person foundUser =
        (Person)
            DataAccessUtils.uniqueResult(
                getHibernateTemplate().findByNamedParam(HQLselect, "facebookId", facebookId));

    return foundUser;
  }
コード例 #14
0
  @Override
  @SuppressWarnings("unchecked")
  public FormLayout getLayout(String formName, String layoutName) {
    DetachedCriteria criteria = DetachedCriteria.forClass(type);
    criteria.add(Restrictions.eq("formName", formName));
    criteria.add(Restrictions.eq("layoutName", layoutName));

    return DataAccessUtils.singleResult(
        (List<FormLayout>) getHibernateTemplate().findByCriteria(criteria));
  }
コード例 #15
0
 @Override
 public Person getPersonForDetail(int id) {
   String HQLselect =
       "from Person person left join fetch person.researchGroups left join fetch person.personOptParamVals paramVal left join fetch paramVal.personOptParamDef paramDef where person.personId = :id";
   Person foundUser =
       (Person)
           DataAccessUtils.uniqueResult(
               getHibernateTemplate().findByNamedParam(HQLselect, "id", id));
   return foundUser;
 }
コード例 #16
0
  @Override
  public int getLayoutsCount(Person owner, String formName, FormLayoutType templateType) {
    DetachedCriteria criteria = DetachedCriteria.forClass(type);
    criteria.setProjection(Projections.rowCount());
    if (owner != null) criteria.add(Restrictions.eq("person.personId", owner.getPersonId()));
    if (formName != null) criteria.add(Restrictions.eq("formName", formName));
    if (templateType != null) criteria.add(Restrictions.eq("type", templateType));

    return DataAccessUtils.intResult(getHibernateTemplate().findByCriteria(criteria));
  }
コード例 #17
0
  @Override
  public FragmentDefinition getFragmentDefinitionByOwner(String ownerId) {
    final TypedQuery<FragmentDefinition> query =
        this.createCachedQuery(this.findFragmentByOwnerQuery);
    query.setParameter(this.ownerParameter, ownerId);

    final List<FragmentDefinition> list = query.getResultList();
    final FragmentDefinition rslt = DataAccessUtils.uniqueResult(list);
    return rslt;
  }
コード例 #18
0
  /**
   * @param ownerUsername
   * @param visitorUsername
   * @return
   */
  protected OwnerDefinedRelationship internalRetrieveRelationship(
      final String ownerUsername, final String visitorUsername) {
    List<OwnerDefinedRelationship> relationships =
        this.simpleJdbcTemplate.query(
            "select * from owner_adhoc_authz where owner_username = ? and visitor_username = ?",
            new OwnerDefinedRelationshipRowMapper(),
            ownerUsername,
            visitorUsername);

    return (OwnerDefinedRelationship) DataAccessUtils.singleResult(relationships);
  }
コード例 #19
0
 @Override
 public CmsContent findLastBySite(String site) {
   Date start = DateUtils.addDays(new Date(), -13);
   Date end = new Date();
   String sql =
       SELECT_FROM
           + " where site = ? and date_created between ? and ? order by date_created desc limit 1";
   return (CmsContent)
       DataAccessUtils.singleResult(
           getSimpleJdbcTemplate().query(sql, getEntityRowMapper(), site, start, end));
 }
コード例 #20
0
 @Override //
 public CmsContent getPreCmsContent(Date dateCreated, String site, long id) {
   Date start = DateUtils.addDays(dateCreated, -14);
   Date end = DateUtils.addDays(dateCreated, 1);
   String sql =
       SELECT_FROM
           + " where site = ? and id < ? and date_created between ? and ? order by id desc limit 1";
   return (CmsContent)
       DataAccessUtils.singleResult(
           getSimpleJdbcTemplate().query(sql, getEntityRowMapper(), site, id, start, end));
 }
コード例 #21
0
  @Override
  @DialectAwareTransactional(value = PostgreSQL81Dialect.class, exclude = false)
  @PortalTransactionalReadOnly
  @OpenEntityManager(unitName = PERSISTENCE_UNIT_NAME)
  public IPortletDefinition getPortletDefinitionByName(String name) {
    final TypedQuery<PortletDefinitionImpl> query =
        this.createCachedQuery(this.findDefinitionByNameQuery);
    query.setParameter(this.nameParameter, name);

    final List<PortletDefinitionImpl> portletDefinitions = query.getResultList();
    return DataAccessUtils.uniqueResult(portletDefinitions);
  }
コード例 #22
0
  @Transactional(readOnly = true)
  public MediaFile getRequiredMediaFile(Long id) {
    final StringBuilder sb = new StringBuilder();
    sb.append("from MediaFile mf ");
    sb.append("left outer join fetch mf.audioCodecs ");
    sb.append("left outer join fetch mf.subtitles ");
    sb.append("left outer join fetch mf.stageFiles ");
    sb.append("where mf.id = :id");

    List<MediaFile> objects = this.mediaDao.findById(sb, id);
    return DataAccessUtils.requiredUniqueResult(objects);
  }
コード例 #23
0
  @Override
  public final void importData(final Source source, PortalDataKey portalDataKey) {
    // Get a StAX reader for the source to determine info about the data to import
    final BufferedXMLEventReader bufferedXmlEventReader = createSourceXmlEventReader(source);

    // If no PortalDataKey was passed build it from the source
    if (portalDataKey == null) {
      final StartElement rootElement = StaxUtils.getRootElement(bufferedXmlEventReader);
      portalDataKey = new PortalDataKey(rootElement);
      bufferedXmlEventReader.reset();
    }

    final String systemId = source.getSystemId();

    // Post Process the PortalDataKey to see if more complex import operations are needed
    final IPortalDataType portalDataType = this.dataKeyTypes.get(portalDataKey);
    if (portalDataType == null) {
      throw new RuntimeException(
          "No IPortalDataType configured for "
              + portalDataKey
              + ", the resource will be ignored: "
              + getPartialSystemId(systemId));
    }
    final Set<PortalDataKey> postProcessedPortalDataKeys =
        portalDataType.postProcessPortalDataKey(systemId, portalDataKey, bufferedXmlEventReader);
    bufferedXmlEventReader.reset();

    // If only a single result from post processing import
    if (postProcessedPortalDataKeys.size() == 1) {
      this.importOrUpgradeData(
          systemId,
          DataAccessUtils.singleResult(postProcessedPortalDataKeys),
          bufferedXmlEventReader);
    }
    // If multiple results from post processing ordering is needed
    else {
      // Iterate over the data key order list to run the imports in the correct order
      for (final PortalDataKey orderedPortalDataKey : this.dataKeyImportOrder) {
        if (postProcessedPortalDataKeys.contains(orderedPortalDataKey)) {
          // Reset the to start of the XML document for each import/upgrade call
          bufferedXmlEventReader.reset();
          this.importOrUpgradeData(systemId, orderedPortalDataKey, bufferedXmlEventReader);
        }
      }
    }
  }
コード例 #24
0
  @Override
  public CuentaCorriente getCuentaCorrienteByVenta(Venta venta) {

    DetachedCriteria criteria = DetachedCriteria.forClass(CuentaCorriente.class);
    if (venta != null) {
      criteria.createAlias("venta", "venta").add(Restrictions.eq("venta", venta));
    }
    List<CuentaCorriente> cuentasCorrientes = this.getHibernateTemplate().findByCriteria(criteria);

    CuentaCorriente cuentaCorriente = null;

    if (!cuentasCorrientes.isEmpty()) {
      cuentaCorriente = (CuentaCorriente) DataAccessUtils.requiredUniqueResult(cuentasCorrientes);
    }

    return cuentaCorriente;
  }
コード例 #25
0
  /** {@inheritDoc} */
  @Transactional(rollbackFor = {Throwable.class})
  public List<SavedSearchView> getSavedSearches(Long userProfileId) {
    UserProfile userProfile =
        (UserProfile)
            DataAccessUtils.uniqueResult(
                hibernateTemplate.findByCriteria(
                    DetachedCriteria.forClass(UserProfile.class)
                        .add(Restrictions.eq("ID", userProfileId))
                        .setFetchMode("savedSearches", FetchMode.JOIN)
                        .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)));

    List<SavedSearch> searches = userProfile.getSavedSearches();
    List<SavedSearchView> searchViews = new ArrayList<SavedSearchView>(searches.size());

    for (SavedSearch savedSearch : searches) {
      searchViews.add(new SavedSearchView(savedSearch));
    }

    return searchViews;
  }
コード例 #26
0
  /** {@inheritDoc} */
  @Transactional(rollbackFor = {Throwable.class})
  public void deleteSavedSearch(Long userProfileId, Long savedSearchId) {

    UserProfile userProfile =
        (UserProfile)
            DataAccessUtils.uniqueResult(
                hibernateTemplate.findByCriteria(
                    DetachedCriteria.forClass(UserProfile.class)
                        .add(Restrictions.eq("ID", userProfileId))
                        .setFetchMode("savedSearches", FetchMode.JOIN)
                        .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)));
    List<SavedSearch> savedSearches = userProfile.getSavedSearches();
    for (Iterator<SavedSearch> it = savedSearches.iterator(); it.hasNext(); ) {
      SavedSearch savedSearch = it.next();
      if (savedSearch.getID().equals(savedSearchId)) {
        it.remove();
      }
    }
    hibernateTemplate.update(userProfile);
  }
コード例 #27
0
  @Override
  public JuxtaXslt find(Long id) {
    final String sql =
        "select id, workspace_id, name, xslt, default_namespace from juxta_xslt where id=?";
    return DataAccessUtils.uniqueResult(
        this.jt.query(
            sql,
            new RowMapper<JuxtaXslt>() {

              @Override
              public JuxtaXslt mapRow(ResultSet rs, int rowNum) throws SQLException {
                JuxtaXslt xslt = new JuxtaXslt();
                xslt.setId(rs.getLong("id"));
                xslt.setWorkspaceId(rs.getLong("workspace_id"));
                xslt.setName(rs.getString("name"));
                xslt.setDefaultNamespace(rs.getString("default_namespace"));
                xslt.setXslt(rs.getString("xslt"));
                return xslt;
              }
            },
            id));
  }
コード例 #28
0
ファイル: CdrManagerImpl.java プロジェクト: anair/sipxecs
 public int getCdrCount(Date from, Date to, CdrSearch search, User user) {
   CdrsStatementCreator psc = new SelectCount(from, to, search, user, m_tz);
   RowMapper rowMapper = new SingleColumnRowMapper(Integer.class);
   List results = getJdbcTemplate().query(psc, rowMapper);
   return (Integer) DataAccessUtils.requiredUniqueResult(results);
 }
コード例 #29
0
 private PersonalAttendant findPersonalAttendant(User user) {
   Collection pas =
       getHibernateTemplate()
           .findByNamedQueryAndNamedParam("personalAttendantForUser", "user", user);
   return (PersonalAttendant) DataAccessUtils.singleResult(pas);
 }
コード例 #30
0
 public CmsContent getById(long id) {
   String sql = SELECT_FROM + " where  id = ? ";
   return (CmsContent)
       DataAccessUtils.singleResult(getSimpleJdbcTemplate().query(sql, getEntityRowMapper(), id));
 }