Get a CachedMultiPrintQuery that will only cache during a request.

@param _instances instance to be updated.
@return the 4 request
@throws EFapsException on error
345323
public static CachedMultiPrintQuery get4Request(final List<Instance> _instances)
        throws EFapsException
    {
        return new CachedMultiPrintQuery(_instances, Context.getThreadContext().getRequestId()).setLifespan(5)
                        .setLifespanUnit(TimeUnit.MINUTES);
    }
888851
@Override
    public Object getValue(final Object _object)
        throws EFapsException
    {
        final Instance inst = (Instance) super.getValue(_object);
        if (this.esjp == null) {
            try {
                final Class<?> clazz = Class.forName(this.className, false, EFapsClassLoader.getInstance());
                this.esjp = (IEsjpSelect) clazz.newInstance();
                final List<Instance> instances = new ArrayList<>();
                for (final Object obj : getOneSelect().getObjectList()) {
                    instances.add((Instance) super.getValue(obj));
                }
                if (this.parameters.isEmpty()) {
                    this.esjp.initialize(instances);
                } else {
                    this.esjp.initialize(instances, this.parameters.toArray(new String[this.parameters.size()]));
                }
            } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                LOG.error("Catched error", e);
            }
        }
        return this.esjp.getValue(inst);
    }
865740
public static void index(final List<Instance> _instances)
        throws EFapsException
    {
        Indexer.index(new IndexContext().setAnalyzer(Index.getAnalyzer()).setDirectory(Index.getDirectory())
                        .setLanguage(Context.getThreadContext().getLanguage())
                        .setCompanyId(Context.getThreadContext().getCompany().getId()), _instances);
    }
90758
@Override
	public Object getObjectInstance(Object obj, Name name, Context context, Hashtable<?,?> environment) throws Exception
	{
		if (!(obj instanceof Reference))
			throw new IllegalStateException("Object is not a reference : "+obj);
		
        Reference reference = (Reference)obj;
        String objClassName = reference.getClassName();
        
        // Queue
        if (objClassName.equals(QueueRef.class.getName()))
        {
        	String queueName = getRequiredAttribute(reference, "queueName");
        	return new QueueRef(queueName);
        }
        
        // Topic
        if (objClassName.equals(TopicRef.class.getName()))
        {
        	String topicName = getRequiredAttribute(reference, "topicName");
        	return new TopicRef(topicName);
        }
        
        // ConnectionFactory
        if (objClassName.equals(FFMQConnectionFactory.class.getName()))
        	return new FFMQConnectionFactory(recreateConnectionFactoryEnv(reference));
        
        // QueueConnectionFactory
        if (objClassName.equals(FFMQQueueConnectionFactory.class.getName()))
        	return new FFMQQueueConnectionFactory(recreateConnectionFactoryEnv(reference));
        
        // TopicConnectionFactory
        if (objClassName.equals(FFMQTopicConnectionFactory.class.getName()))
        	return new FFMQTopicConnectionFactory(recreateConnectionFactoryEnv(reference));

        // We don't know how to handle this
        return null; 
	}
710512
protected List<Instance> getSuper(final Instance _instance)
        throws EFapsException
    {
        final List<Instance> ret = new ArrayList<>();
        final QueryBuilder queryBldr = new QueryBuilder(getClassName4Type2Type());
        queryBldr.addWhereAttrEqValue(CIAdminProgram.Program2Program.From, _instance.getId());
        final MultiPrintQuery multi = queryBldr.getPrint();
        multi.addAttribute(CIAdminProgram.Program2Program.To);
        multi.execute();
        if (multi.next()) {
            final Instance instance = Instance.get(getClassName4Type().getType(),
                                             multi.<Long>getAttribute(CIAdminProgram.Program2Program.To));
            ret.add(instance);
            ret.addAll(getSuper(instance));
        }
        return ret;
    }
976896
public static PermissionSet getPermissionSet(final Instance _instance,
                                                 final boolean _evaluate)
        throws EFapsException
    {
        Evaluation.LOG.debug("Retrieving PermissionSet for {}", _instance);
        final Key accessKey = Key.get4Instance(_instance);
        final PermissionSet ret;
        if (AccessCache.getPermissionCache().containsKey(accessKey)) {
            ret = AccessCache.getPermissionCache().get(accessKey);
        } else if (_evaluate) {
            ret = new PermissionSet().setPersonId(accessKey.getPersonId()).setCompanyId(accessKey.getCompanyId())
                            .setTypeId(accessKey.getTypeId());
            Evaluation.eval(ret);
            AccessCache.getPermissionCache().put(accessKey, ret);
        } else {
            ret = null;
        }
        Evaluation.LOG.debug("Retrieved PermissionSet {}", ret);
        return ret;
    }
5405
public Instance getLink(final String _key)
        throws EFapsException
    {
        return Instance.get(getValue(_key, ConfType.LINK));
    }
719386
private long getProgID(final String _typeName)
        throws EFapsException
    {
        long id = 0;
        final QueryBuilder queryBldr = new QueryBuilder(CIAdminProgram.Java);
        queryBldr.addWhereAttrEqValue(CIAdminProgram.Java.Name, this.program);
        final InstanceQuery query = queryBldr.getQuery();
        query.executeWithoutAccessCheck();
        if (query.next()) {
            id = query.getCurrentValue().getId();
        } else {
            Event.LOG.error("type[" + _typeName + "]." + "Program [" + this.program + "]: " + "' not found");
        }
        return id;
    }
584660
public static void index()
        throws EFapsException
    {
        final List<IndexDefinition> defs = IndexDefinition.get();
        for (final IndexDefinition def : defs) {
            final QueryBuilder queryBldr = new QueryBuilder(def.getUUID());
            final InstanceQuery query = queryBldr.getQuery();
            index(query.execute());
        }
    }
129583
protected AttributeQuery getAttributeQuery()
        throws EFapsException
    {
        AttributeQuery ret = this.getAttributeQuery(getSelectAttributeName());
        // check if in the linkto chain is one before this one
        if (!this.attrQueryBldrs.isEmpty()) {
            final QueryBuilder queryBldr = this.attrQueryBldrs.values().iterator().next();
            queryBldr.addWhereAttrInQuery(queryBldr.getLinkAttributeName(), ret);
            ret = queryBldr.getAttributeQuery();
        }
        return ret;
    }
842136
public static PermissionSet getPermissionSet(final Instance _instance)
        throws EFapsException
    {
        Evaluation.LOG.debug("Evaluation PermissionSet for {}", _instance);
        final Key accessKey = Key.get4Instance(_instance);
        final PermissionSet ret = AccessCache.getPermissionCache().get(accessKey);
        Evaluation.LOG.debug("Evaluated PermissionSet {}", ret);
        return ret;
    }
110479
public static IndexDefinition get(final UUID _uuid)
        throws EFapsException
    {
        initialize(true);
        final Cache<UUID, IndexDefinition> cache = InfinispanCache.get().<UUID, IndexDefinition>getCache(
                        IndexDefinition.UUIDCACHE);
        if (!cache.containsKey(_uuid)) {
            IndexDefinition.loadDefinition(_uuid);
        }
        final IndexDefinition ret = cache.get(_uuid);
        return ret == null || ret.equals(NULLINDEXDEF) ? null : ret;
    }
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;
    }
116025
public static Status getStatus(final Instance _instance)
        throws EFapsException
    {
        Evaluation.LOG.debug("Retrieving Status for {}", _instance);
        long statusId = 0;
        if (_instance.getType().isCheckStatus()) {
            final Cache<String, Long> cache = AccessCache.getStatusCache();
            if (cache.containsKey(_instance.getKey())) {
                statusId = cache.get(_instance.getKey());
            } else {
                final PrintQuery print = new PrintQuery(_instance);
                print.addAttribute(_instance.getType().getStatusAttribute());
                print.executeWithoutAccessCheck();
                final Long statusIdTmp = print.getAttribute(_instance.getType().getStatusAttribute());
                statusId = statusIdTmp == null ? 0 : statusIdTmp;
                cache.put(_instance.getKey(), statusId);
            }
        }
        final Status ret = statusId > 0 ? Status.get(statusId) : null;
        Evaluation.LOG.debug("Retrieve Status: {}", ret);
        return ret;
    }
465241
public static Key get4Instance(final Instance _instance)
        throws EFapsException
    {
        Key.LOG.debug("Retrieving Key for {}", _instance);
        final Key ret = new Key();
        ret.setPersonId(Context.getThreadContext().getPersonId());

        final Type type = _instance.getType();
        ret.setTypeId(type.getId());
        if (type.isCompanyDependent()) {
            ret.setCompanyId(Context.getThreadContext().getCompany().getId());
        }
        Key.LOG.debug("Retrieved Key {}", ret);
        return ret;
    }
82186
private void load()
        throws EFapsException
    {
        final QueryBuilder queryBldr = new QueryBuilder(CIAdminCommon.MsgPhraseConfigAbstract);
        queryBldr.addWhereAttrEqValue(CIAdminCommon.MsgPhraseConfigAbstract.AbstractLink, getId());
        final MultiPrintQuery multi = queryBldr.getPrint();
        multi.addAttribute(CIAdminCommon.MsgPhraseConfigAbstract.CompanyLink,
                        CIAdminCommon.MsgPhraseConfigAbstract.LanguageLink,
                        CIAdminCommon.MsgPhraseConfigAbstract.Value,
                        CIAdminCommon.MsgPhraseConfigAbstract.Int1);
        multi.executeWithoutAccessCheck();
        while (multi.next()) {
            AbstractConfig conf = null;
            if (multi.getCurrentInstance().getType().isCIType(CIAdminCommon.MsgPhraseArgument)) {
                conf = new Argument();
                ((Argument) conf).setIndex(multi.<Integer>getAttribute(CIAdminCommon.MsgPhraseConfigAbstract.Int1));
                arguments.add((Argument) conf);
            } else if (multi.getCurrentInstance().getType().isCIType(CIAdminCommon.MsgPhraseLabel)) {
                conf = new Label();
                labels.add((Label) conf);
            }
            if (conf == null) {
                LOG.error("Wrong type: ", this);
            } else {
                conf.setCompanyId(multi.<Long>getAttribute(CIAdminCommon.MsgPhraseConfigAbstract.CompanyLink));
                conf.setLanguageId(multi.<Long>getAttribute(CIAdminCommon.MsgPhraseConfigAbstract.LanguageLink));
                conf.setValue(multi.<String>getAttribute(CIAdminCommon.MsgPhraseConfigAbstract.Value));
            }
        }
    }
226666
private Map<String, IEsjpSelect> getEsjpSelect(final List<Instance> _instances)
        throws Exception
    {
        final Map<String, IEsjpSelect> ret = new HashMap<>();
        if (!_instances.isEmpty()) {
            for (final Entry<String, AbstractSelect> entry : getAlias2Selects().entrySet()) {
                if (entry.getValue() instanceof ExecSelect) {
                    final Class<?> clazz = Class.forName(entry.getValue().getSelect(), false, EFapsClassLoader
                                    .getInstance());
                    final IEsjpSelect esjp = (IEsjpSelect) clazz.newInstance();
                    final List<String> parameters = ((ExecSelect) entry.getValue()).getParameters();
                    if (parameters.isEmpty()) {
                        esjp.initialize(_instances);
                    } else {
                        esjp.initialize(_instances, parameters.toArray(new String[parameters.size()]));
                    }
                    ret.put(entry.getKey(), esjp);
                }
            }
        }
        return ret;
    }