Get a CachedInstanceQuery that will only cache during a request.

@param _type Type the query is based on
@return the 4 request
@throws EFapsException on error
518168
public static CachedInstanceQuery get4Request(final Type _type)
        throws EFapsException
    {
        return new CachedInstanceQuery(Context.getThreadContext().getRequestId(), _type).setLifespan(5)
                        .setLifespanUnit(TimeUnit.MINUTES);
    }
800479
public static DistributedSchedulingLock getDistributedScheduleByType(EntityManager em, long type) {
		requireArgument(em != null, "Entity manager can not be null.");
		
		TypedQuery<DistributedSchedulingLock> query = em.createNamedQuery("DistributedSchedulingLock.GetEntryById", DistributedSchedulingLock.class);
		query.setHint(QueryHints.REFRESH, HintValues.TRUE);
		try {
			query.setParameter("type", type);
			return query.getSingleResult();
		} catch (NoResultException ex) {
			return null;
		}
	}
27121
private <T> QueryRequest<T> query(String fql, JavaType type) {
		this.checkForBatchExecution();
		
		if (this.multiqueryRequest == null) {
			this.multiqueryRequest = new MultiqueryRequest(mapper, this.createUnmappedChain());
			this.graphRequests.add(this.multiqueryRequest);
		}
		
		// There is a circular reference between the extractor and request, so construction of the chain
		// is a little complicated
		QueryNodeExtractor extractor = new QueryNodeExtractor(this.multiqueryRequest);
		
		String name = "__q" + this.generatedQueryNameIndex++;
		QueryRequest<T> q =
			new QueryRequest<T>(fql, name,
				new MapperWrapper<T>(type, this.mapper,
						extractor));
		
		extractor.setRequest(q);
		
		this.multiqueryRequest.addQuery(q);
		return q;
	}
285311
public static StatusGroup get(final String _typeName)
        throws CacheReloadException
    {
        final Cache<String, StatusGroup> cache = InfinispanCache.get().<String, StatusGroup>getCache(
                        Status.NAMECACHE4GRP);
        if (!cache.containsKey(_typeName)) {
            Status.getStatusGroupFromDB(Status.SQL_NAME4GRP, _typeName);
        }
        return cache.get(_typeName);
    }
326179
protected static long getId4UUID(final UUID _typeUUID)
        throws CacheReloadException
    {
        long ret = 0;
        final Cache<UUID, Type> cache = InfinispanCache.get().<UUID, Type>getCache(Type.UUIDCACHE);
        if (cache.containsKey(_typeUUID)) {
            ret = cache.get(_typeUUID).getId();
        } else {
            Connection con = null;
            try {
                con = Context.getConnection();
                PreparedStatement stmt = null;
                try {
                    stmt = con.prepareStatement(Type.SQL_UUID);
                    stmt.setObject(1, _typeUUID.toString());
                    final ResultSet rs = stmt.executeQuery();
                    while (rs.next()) {
                        ret = rs.getLong(1);
                    }
                    rs.close();
                } finally {
                    if (stmt != null) {
                        stmt.close();
                    }
                }
                con.commit();
            } catch (final SQLException e) {
                throw new CacheReloadException("could not read child type ids", e);
            } catch (final EFapsException e) {
                throw new CacheReloadException("could not read child type ids", e);
            } finally {
                try {
                    if (con != null && !con.isClosed()) {
                        con.close();
                    }
                } catch (final SQLException e) {
                    throw new CacheReloadException("could not read child type ids", e);
                }
            }
        }
        return ret;
    }
1229510
public CachedInstanceQuery getCachedQuery(final String _key)
    {
        if (this.query == null) {
            try {
                this.query = new CachedInstanceQuery(_key, this.typeUUID)
                                .setIncludeChildTypes(isIncludeChildTypes())
                                .setCompanyDependent(isCompanyDependent());
                prepareQuery();
            } catch (final EFapsException e) {
                QueryBuilder.LOG.error("Could not open InstanceQuery for uuid: {}", this.typeUUID);
            }
        }
        return (CachedInstanceQuery) this.query;
    }
1109520
private static Set<Type> getChildTypes(final Type _type)
        throws CacheReloadException
    {
        final Set<Type> ret = new HashSet<Type>();
        ret.add(_type);
        for (final Type child : _type.getChildTypes()) {
            ret.addAll(getChildTypes(child));
        }
        return ret;
    }
110739
public static AbstractCI<?> getCI(final ICIPrintStmt _stmt)
        throws CacheReloadException
    {
        AbstractCI<?> ret = null;
        switch (_stmt.getCINature()) {
            case TYPE:
                final Type type;
                if (UUIDUtil.isUUID(_stmt.getCI())) {
                    type = Type.get(UUID.fromString(_stmt.getCI()));
                } else {
                    type = Type.get(_stmt.getCI());
                }
                if (type != null) {
                    final org.efaps.json.ci.Type jsonType = new org.efaps.json.ci.Type()
                                    .setName(type.getName())
                                    .setUUID(type.getUUID())
                                    .setId(type.getId());
                    for (final Attribute attr : type.getAttributes().values()) {
                        final AttributeType attrType = new AttributeType()
                                        .setName(attr.getAttributeType().getName());
                        switch (DMAttributeType.fromValue(attr.getAttributeType().getName())) {
                            case LINK:
                            case LINK_WITH_RANGES:
                            case STATUS:
                                if (attr.hasLink()) {
                                     attrType.setInfo(attr.getLink().getName() + ", " + attr.getLink().getUUID());
                                }
                                break;
                            default:
                                break;
                        }
                       jsonType.addAttribute(new org.efaps.json.ci.Attribute()
                                        .setName(attr.getName())
                                        .setType(attrType));
                    }
                    ret = jsonType;
                }
                break;
            default:
                break;
        }
        return ret;
    }
811063
@Override
    @SuppressWarnings("unchecked")
    public <T> T get(final Object key, final Class<T> type) {
        if (!cache.isEnabled()) {
            LOGGER.warn("Cache {} is disabled. Cannot get {} from cache", cache.getName(), key);
            return null;
        }

        Object value = getValue(key);
        if (value == null) {
            LOGGER.info("Cache miss. Get by key {} and type {} from cache {}", new Object[] { key, type, cache.getName() });
            return null;
        }

        if (value instanceof PertinentNegativeNull) {
            return null;
        }

        if (type != null && !type.isInstance(value)) {
            // in such case default Spring back end for EhCache throws IllegalStateException which interrupts
            // intercepted method invocation
            String msg = "Cached value is not of required type [" + type.getName() + "]: " + value;
            LOGGER.error(msg, new IllegalStateException(msg));
            return null;
        }

        LOGGER.info("Cache hit. Get by key {} and type {}  from cache {} value '{}'", new Object[] { key, type, cache.getName(), value });
        return (T) value;
    }
541071
public <E> CacheQuery<E> getQuery(HSQuery hSearchQuery, IndexedQueryMode queryMode) {
      if (timeoutExceptionFactory != null) {
         hSearchQuery.timeoutExceptionFactory(timeoutExceptionFactory);
      }
      Class<?>[] classes = hSearchQuery.getTargetedEntities().toPojosSet().toArray(new Class[hSearchQuery.getTargetedEntities().size()]);
      queryInterceptor.enableClasses(classes);

      if (queryMode == IndexedQueryMode.BROADCAST) {
         ExecutorService asyncExecutor = queryInterceptor.getAsyncExecutor();
         return new ClusteredCacheQueryImpl<>(new QueryDefinition(hSearchQuery), asyncExecutor, cache, keyTransformationHandler, null);
      } else {
         return new CacheQueryImpl<>(hSearchQuery, cache, keyTransformationHandler);
      }
   }
938686
public static ISearch getSearch()
        throws EFapsException
    {
        ISearch ret = null;
        if (EFapsSystemConfiguration.get().containsAttributeValue(KernelSettings.INDEXSEARCHCLASS)) {
            final String clazzname = EFapsSystemConfiguration.get().getAttributeValue(
                            KernelSettings.INDEXSEARCHCLASS);
            try {
                final Class<?> clazz = Class.forName(clazzname, false, EFapsClassLoader.getInstance());
                ret = (ISearch) clazz.newInstance();
            } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                throw new EFapsException(Index.class, "Could not instanciate IDirectoryProvider", e);
            }
        } else {
            ret = new ISearch()
            {
                /** The Constant serialVersionUID. */
                private static final long serialVersionUID = 1L;

                /** The query. */
                private String query;

                @Override
                public void setQuery(final String _query)
                {
                    this.query = _query;
                }

                @Override
                public String getQuery()
                {
                    return this.query;
                }
            };
        }
        return ret;
    }
465432
public static SearchResult search(final String _query)
        throws EFapsException
    {
        final ISearch searchDef = Index.getSearch();
        searchDef.setQuery(_query);
        return search(searchDef);
    }
1001363
private Type evalMainType(final Collection<Type> _baseTypes)
        throws EFapsException
    {
        final Type ret;
        if (_baseTypes.size() == 1) {
            ret = _baseTypes.iterator().next();
        } else {
            final List<List<Type>> typeLists = new ArrayList<>();
            for (final Type type : _baseTypes) {
                final List<Type> typesTmp = new ArrayList<>();
                typeLists.add(typesTmp);
                Type tmpType = type;
                while (tmpType != null) {
                    typesTmp.add(tmpType);
                    tmpType = tmpType.getParentType();
                }
            }

            final Set<Type> common = new LinkedHashSet<>();
            if (!typeLists.isEmpty()) {
                final Iterator<List<Type>> iterator = typeLists.iterator();
                common.addAll(iterator.next());
                while (iterator.hasNext()) {
                    common.retainAll(iterator.next());
                }
            }
            if (common.isEmpty()) {
                throw new EFapsException(Selection.class, "noCommon", _baseTypes);
            } else {
                // first common type
                ret = common.iterator().next();
            }
        }
        return ret;
    }
549049
@Override
    public Object get(final Attribute _attribute,
                      final Object _object)
        throws EFapsException
    {
        Object ret = null;
        if (_object != null && _attribute.getAttributeType().getDbAttrType() instanceof IFormattableType) {
            final IFormattableType attrType = (IFormattableType) _attribute.getAttributeType().getDbAttrType();
            if (_object instanceof List<?>) {
                final List<?> objectList = (List<?>) _object;
                final List<Object> temp = new ArrayList<>();
                for (final Object object : objectList) {
                    temp.add(attrType.format(object, this.pattern));
                }
                ret = temp;
            } else {
                ret = attrType.format(_object, this.pattern);
            }
        }
        return ret;
    }
648920
public InstanceQuery getQuery()
    {
        if (this.query == null) {
            try {
                this.query = new InstanceQuery(this.typeUUID)
                                .setIncludeChildTypes(isIncludeChildTypes())
                                .setCompanyDependent(isCompanyDependent());
                prepareQuery();
            } catch (final EFapsException e) {
                QueryBuilder.LOG.error("Could not open InstanceQuery for uuid: {}", this.typeUUID);
            }
        }
        return (InstanceQuery) this.query;
    }
163797
public static QueryBuilderFind fromType(Class<? extends WindupVertexFrame> type)
    {
        final Query query = new Query();
        // this query is going to be added after evaluate() method, because in some cases we need gremlin and in some
        // frames
        query.searchType = type;
        return query;
    }
1259740
public static AttributeType get(final long _id)
        throws CacheReloadException
    {
        final Cache<Long, AttributeType> cache = InfinispanCache.get().<Long, AttributeType>getCache(
                        AttributeType.IDCACHE);
        if (!cache.containsKey(_id)) {
            AttributeType.getAttributeTypeFromDB(AttributeType.SQL_ID, _id);
        }
        return cache.get(_id);
    }