public RevisionInfoConfiguration(GlobalConfiguration globalCfg) { this.globalCfg = globalCfg; if ( globalCfg.isUseRevisionEntityWithNativeId() ) { revisionInfoEntityName = "org.hibernate.envers.DefaultRevisionEntity"; } else { revisionInfoEntityName = "org.hibernate.envers.enhanced.SequenceIdRevisionEntity"; } revisionInfoIdData = new PropertyData( "id", "id", "field", null ); revisionInfoTimestampData = new PropertyData( "timestamp", "timestamp", "field", null ); modifiedEntityNamesData = new PropertyData( "modifiedEntityNames", "modifiedEntityNames", "field", null ); revisionInfoTimestampType = new LongType(); revisionPropType = "integer"; }
private List<Long> fromInclusiveModificationsForPipelineRange(Session session, String pipelineName, Integer fromCounter, Integer toCounter) { String pipelineIdsSql = queryExtensions.queryFromInclusiveModificationsForPipelineRange(pipelineName, fromCounter, toCounter); SQLQuery pipelineIdsQuery = session.createSQLQuery(pipelineIdsSql); final List ids = pipelineIdsQuery.list(); if (ids.isEmpty()) { return new ArrayList<>(); } String minMaxQuery = " SELECT mods1.materialId as materialId, min(mods1.id) as min, max(mods1.id) as max" + " FROM modifications mods1 " + " INNER JOIN pipelineMaterialRevisions pmr ON (mods1.id >= pmr.actualFromRevisionId AND mods1.id <= pmr.toRevisionId) AND mods1.materialId = pmr.materialId " + " WHERE pmr.pipelineId IN (:ids) " + " GROUP BY mods1.materialId"; SQLQuery query = session.createSQLQuery("SELECT mods.id " + " FROM modifications mods" + " INNER JOIN (" + minMaxQuery + ") as edges on edges.materialId = mods.materialId and mods.id >= min and mods.id <= max" + " ORDER BY mods.materialId ASC, mods.id DESC"); query.addScalar("id", new LongType()); query.setParameterList("ids", ids); return query.list(); }
private Map<PipelineId, Set<Long>> relevantToLookedUpDependencyMap(Session session, List<Long> pipelineIds) { final int LOOKED_UP_PIPELINE_ID = 2; final int RELEVANT_PIPELINE_ID = 0; final int RELEVANT_PIPELINE_NAME = 1; String pipelineIdsSql = queryExtensions.queryRelevantToLookedUpDependencyMap(pipelineIds); SQLQuery pipelineIdsQuery = session.createSQLQuery(pipelineIdsSql); pipelineIdsQuery.addScalar("id", new LongType()); pipelineIdsQuery.addScalar("name", new StringType()); pipelineIdsQuery.addScalar("lookedUpId", new LongType()); final List<Object[]> ids = pipelineIdsQuery.list(); Map<Long, List<PipelineId>> lookedUpToParentMap = new HashMap<>(); CollectionUtil.CollectionValueMap<Long, PipelineId> lookedUpToRelevantMap = CollectionUtil.collectionValMap(lookedUpToParentMap, new CollectionUtil.ArrayList<>()); for (Object[] relevantAndLookedUpId : ids) { lookedUpToRelevantMap.put((Long) relevantAndLookedUpId[LOOKED_UP_PIPELINE_ID], new PipelineId((String) relevantAndLookedUpId[RELEVANT_PIPELINE_NAME], (Long) relevantAndLookedUpId[RELEVANT_PIPELINE_ID])); } return CollectionUtil.reverse(lookedUpToParentMap); }
List<Object[]> allModifications = query. addEntity("mods", Modification.class). addScalar("pmrPipelineId", new LongType()). addScalar("pmrPipelineName", new StringType()). addScalar("materialType", new StringType()).
public Long latestModificationRunByPipeline(final CaseInsensitiveString pipelineName, final Material material) { final long materialId = findMaterialInstance(material).getId(); String key = cacheKeyForLatestPmrForPipelineKey(materialId, pipelineName.toLower()); Long modificationId = (Long) goCache.get(key); if (modificationId == null) { synchronized (key) { modificationId = (Long) goCache.get(key); if (modificationId == null) { modificationId = (Long) getHibernateTemplate().execute((HibernateCallback) session -> { SQLQuery sqlQuery = session.createSQLQuery("SELECT MAX(pmr.toRevisionId) toRevisionId " + "FROM (SELECT torevisionid, pipelineid FROM pipelineMaterialRevisions WHERE materialid = :material_id) AS pmr\n" + "INNER JOIN pipelines p ON ( p.name = :pipeline_name AND p.id = pmr.pipelineId)"); sqlQuery.setParameter("material_id", materialId); sqlQuery.setParameter("pipeline_name", pipelineName.toString()); sqlQuery.addScalar("toRevisionId", new LongType()); return sqlQuery.uniqueResult(); }); if (modificationId == null) { modificationId = -1L; } goCache.put(key, modificationId); } } } return modificationId; }
private void addRules (Map<String,Object> ruleMap, Journal journal, List acctHierarchy, int offset) throws HibernateException { Query q = session.createQuery ( "from org.jpos.gl.RuleInfo where journal=:journal and account in (:accts) order by id" ); q.setParameter ("journal", journal); q.setParameterList ("accts", acctHierarchy, new LongType()); q.setCacheable (true); q.setCacheRegion ("rules"); Iterator iter = q.iterate(); while (iter.hasNext()) { RuleInfo ri = (RuleInfo) iter.next(); RuleEntry k = new RuleEntry (ri, ri.getAccount()); RuleEntry re = (RuleEntry) ruleMap.get (k.getKey()); if (re == null) ruleMap.put (k.getKey(), re = k); re.addOffset (offset); } } private void applyRules (GLTransaction txn, Collection rules)
@Override public void visitSql(final SqlRestriction restriction) { if (restriction.getParameters() != null && restriction.getParameters().length > 0) { // Map our {@link Type} enum values to {@link org.hibernate.type.Type} equivalents org.hibernate.type.Type[] types = Arrays.stream(restriction.getTypes()).map(t -> { switch(t) { case FLOAT: return new FloatType(); case INTEGER: return new IntegerType(); case LONG: return new LongType(); case STRING: return new StringType(); case TIMESTAMP: return new TimestampType(); default: throw new UnsupportedOperationException("Unsupported type specified in SqlRestriction"); } }).collect(Collectors.toList()).toArray(new org.hibernate.type.Type[restriction.getTypes().length]); m_criterions.add(org.hibernate.criterion.Restrictions.sqlRestriction(restriction.getAttribute(), restriction.getParameters(), types)); } else { m_criterions.add(org.hibernate.criterion.Restrictions.sqlRestriction(restriction.getAttribute())); } }
public static final NullableType LONG = new LongType();