Example usage for org.hibernate.type LongType INSTANCE

List of usage examples for org.hibernate.type LongType INSTANCE

Introduction

In this page you can find the example usage for org.hibernate.type LongType INSTANCE.

Prototype

LongType INSTANCE

To view the source code for org.hibernate.type LongType INSTANCE.

Click Source Link

Usage

From source file:org.linagora.linshare.core.repository.hibernate.GenericQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforDefaultQuotaInSubDomains(AbstractDomain domain, Long quota, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT child.id AS child_id FROM quota AS father");
            sb.append(" JOIN quota AS child");
            sb.append(" ON child.domain_parent_id = father.domain_id");
            sb.append(" AND child.quota_type = :domainType ");
            sb.append(" AND father.domain_parent_id = :domainId ");
            sb.append(" AND father.default_quota_override = false");
            sb.append(" WHERE father.quota_type = :domainType");
            if (containerType != null) {
                sb.append(" AND child.container_type = :containerType");
            }//from  www  .  j  a  v a 2  s  .  c o  m
            sb.append(" AND child.default_quota_override = false");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("child_id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            if (containerType != null) {
                query.setString("containerType", containerType.name());
            }
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("child_ids :" + res);
            return res;
        }
    };
    return getHibernateTemplate().execute(action);
}

From source file:org.linagora.linshare.core.repository.hibernate.GenericQuotaRepositoryImpl.java

License:Open Source License

public List<Long> getQuotaIdforQuotaInSubDomains(AbstractDomain domain, Long quota, QuotaType type,
        ContainerQuotaType containerType) {
    HibernateCallback<List<Long>> action = new HibernateCallback<List<Long>>() {
        public List<Long> doInHibernate(final Session session) throws HibernateException, SQLException {
            StringBuilder sb = new StringBuilder();
            sb.append("SELECT DISTINCT child.id AS child_id FROM quota AS father");
            sb.append(" JOIN quota AS child");
            sb.append(" ON child.domain_parent_id = father.domain_id");
            sb.append(" AND child.quota_type = :domainType ");
            sb.append(" AND father.domain_parent_id = :domainId ");
            sb.append(" AND father.quota_override = false");
            if (containerType != null) {
                sb.append(" AND father.container_type = :containerType");
            }// w w  w .j  a  va2s .  com
            sb.append(" WHERE father.quota_type = :domainType");
            if (containerType != null) {
                sb.append(" AND child.container_type = :containerType");
            }
            sb.append(" AND child.quota_override = false");
            sb.append(";");
            final SQLQuery query = session.createSQLQuery(sb.toString());
            query.setLong("domainId", domain.getPersistenceId());
            query.addScalar("child_id", LongType.INSTANCE);
            query.setString("domainType", type.name());
            if (containerType != null) {
                query.setString("containerType", containerType.name());
            }
            @SuppressWarnings("unchecked")
            List<Long> res = query.list();
            logger.debug("child_ids :" + res);
            return res;
        }
    };
    return getHibernateTemplate().execute(action);
}

From source file:org.mousephenotype.dcc.exportlibrary.fullTraverser.FullTraverser.java

License:Apache License

private void loadSubmissionTrackerIDs(Calendar date) {
    if (date == null) {
        logger.info("loading every submission by trackerID");
        trackerIDs = this.hibernateManager.nativeQuery(
                "select distinct trackerID from SUBMISSION  where trackerID >= 5867 order by trackerID");
    } else {/* ww w  . j  a  v a 2  s  . co m*/
        Table<String, Class, Object> parameters = HashBasedTable.create();
        parameters.put("colonyID", Calendar.class, date);

        Map<String, org.hibernate.type.Type> scalars = ImmutableMap.<String, org.hibernate.type.Type>builder()
                .put("trackerID", LongType.INSTANCE).build();

        trackerIDs = this.hibernateManager.nativeQuery(
                "select distinct trackerID from SUBMISSION submission order by trackerID where submission.submissionDate < :submissionDate",
                scalars, parameters);
    }
}

From source file:org.openlmis.referencedata.repository.custom.impl.FacilityTypeApprovedProductRepositoryImpl.java

License:Open Source License

private Query createNativeQuery(StringBuilder builder, Map<String, Object> params, boolean count) {
    Query nativeQuery = entityManager.createNativeQuery(builder.toString());
    params.forEach(nativeQuery::setParameter);

    if (!count) {
        SQLQuery sqlQuery = nativeQuery.unwrap(SQLQuery.class);
        sqlQuery.addScalar("id", PostgresUUIDType.INSTANCE);
        sqlQuery.addScalar("versionNumber", LongType.INSTANCE);
    }/*w w  w. j  a  va  2s.  c om*/

    return nativeQuery;
}

From source file:org.openlmis.referencedata.repository.custom.impl.IdealStockAmountRepositoryImpl.java

License:Open Source License

private void prepareCountQuery(Query query) {
    SQLQuery sql = query.unwrap(SQLQuery.class);
    sql.addScalar("count", LongType.INSTANCE);
}

From source file:org.openlmis.referencedata.repository.custom.impl.OrderableRepositoryImpl.java

License:Open Source License

private Query prepareNativeQuery(SearchParams searchParams, boolean count, Pageable pageable) {
    String startNativeQuery = count ? NATIVE_COUNT_ORDERABLES : NATIVE_SELECT_ORDERABLES_IDENTITIES;
    StringBuilder builder = new StringBuilder(startNativeQuery);
    Map<String, Object> params = Maps.newHashMap();
    List<String> where = Lists.newArrayList();

    if (null != searchParams) {
        if (null != searchParams.getProgramCode()) {
            builder.append(NATIVE_PROGRAM_ORDERABLE_INNER_JOIN).append(NATIVE_PROGRAM_INNER_JOIN).append(AND)
                    .append(NATIVE_PROGRAM_CODE);
            params.put("programCode", searchParams.getProgramCode().toLowerCase());
        }/* w ww .  j a v a  2s  . co  m*/

        if (isEmpty(searchParams.getIdentityPairs())) {
            builder.append(NATIVE_LATEST_ORDERABLE_INNER_JOIN);
        } else {
            where.add(searchParams.getIdentityPairs().stream()
                    .map(pair -> String.format(NATIVE_IDENTITY, pair.getLeft(), pair.getRight()))
                    .collect(Collectors.joining(OR)));
        }

        if (isNotBlank(searchParams.getCode())) {
            where.add(NATIVE_PRODUCT_CODE);
            params.put("orderableCode", "%" + searchParams.getCode().toLowerCase() + "%");
        }

        if (isNotBlank(searchParams.getName())) {
            where.add(NATIVE_PRODUCT_NAME);
            params.put("orderableName", "%" + searchParams.getName().toLowerCase() + "%");
        }
    } else {
        builder.append(NATIVE_LATEST_ORDERABLE_INNER_JOIN);
    }

    if (!where.isEmpty()) {
        builder.append(WHERE).append(String.join(AND, where));
    }

    if (!count) {
        Optional.ofNullable(pageable)
                .ifPresent(p -> builder.append(GROUP_BY_ID_VERSION_NUMBER_AND_FULL_PRODUCT_NAME)
                        .append(ORDER_BY).append(PageableUtil.getOrderPredicate(p, "o.", ASC_SORT)));
        setPagination(builder, params, pageable);
    }

    Query nativeQuery = entityManager.createNativeQuery(builder.toString());
    params.forEach(nativeQuery::setParameter);

    if (!count) {
        SQLQuery sqlQuery = nativeQuery.unwrap(SQLQuery.class);
        sqlQuery.addScalar("id", PostgresUUIDType.INSTANCE);
        sqlQuery.addScalar("versionNumber", LongType.INSTANCE);
    }

    return nativeQuery;
}

From source file:org.optaplanner.persistence.jpa.impl.score.AbstractScoreHibernateType.java

License:Apache License

@Override
public void nullSafeSet(PreparedStatement statement, Object value, int parameterIndex,
        SessionImplementor session) throws SQLException {
    int levelsSize = scoreDefinition.getLevelsSize();
    if (value == null) {
        for (int i = 0; i < levelsSize; i++) {
            statement.setNull(parameterIndex + i, type.sqlType());
        }/* w w w  .  j  ava2s . c  om*/
        return;
    }
    Score score = (Score) value;
    Number[] levelNumbers = score.toLevelNumbers();
    if (levelNumbers.length != levelsSize) {
        throw new IllegalStateException("The levelNumbers length (" + levelNumbers.length + ") for score ("
                + score + ") must be equal to the levelsSize (" + levelsSize + ") for "
                + getClass().getSimpleName() + ".");
    }
    for (int i = 0; i < levelsSize; i++) {
        if (type == IntegerType.INSTANCE) {
            statement.setInt(parameterIndex + i, (Integer) levelNumbers[i]);
        } else if (type == LongType.INSTANCE) {
            statement.setLong(parameterIndex + i, (Long) levelNumbers[i]);
        } else if (type == DoubleType.INSTANCE) {
            statement.setDouble(parameterIndex + i, (Double) levelNumbers[i]);
        } else if (type == BigDecimalType.INSTANCE) {
            statement.setBigDecimal(parameterIndex + i, (BigDecimal) levelNumbers[i]);
        } else {
            throw new IllegalStateException("The type (" + type + ") is not yet supported.");
        }
    }
}

From source file:org.primeframework.persistence.hibernate.DateTimeType.java

License:Open Source License

@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    Long l = (Long) LongType.INSTANCE.nullSafeGet(rs, names, session, owner);
    if (l == null) {
        return null;
    }//from w  w  w .j a  v  a2s  . c o  m

    return new DateTime(l.longValue(), DateTimeZone.UTC);
}

From source file:org.primeframework.persistence.hibernate.DateTimeType.java

License:Open Source License

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    DateTime dt = (DateTime) value;//from   w ww .j  a v  a  2  s . c  o m
    if (dt != null) {
        LongType.INSTANCE.nullSafeSet(st, dt.getMillis(), index, session);
    } else {
        LongType.INSTANCE.nullSafeSet(st, null, index, session);
    }
}

From source file:org.squashtest.tm.internal.domain.report.common.hibernate.HibernateRequirementCoverageByTestsQuery.java

License:Open Source License

private List<Long> idsByMilestones(Session session) {
    Object[] milestoneIds = this.getCriterions().get(MILESTONE_IDS).getParameters();

    Collection<Long> mIds = new ArrayList<>(milestoneIds.length);
    for (Object o : milestoneIds) {
        mIds.add(Long.valueOf(o.toString()));
    }//from  w  w  w.j ava2  s.  c o  m

    String hql = "select req.id from Requirement req join req.versions version join version.milestones mstones "
            + "where mstones.id in (:milestones)";

    Query q = session.createQuery(hql);
    q.setParameterList("milestones", mIds, LongType.INSTANCE);

    return q.list();

}