/** * resets the cached data * * @param partIds parts to reset - if no parts are given, all parts will be reset. */ public void reset(String... partIds) { nextBatchParts.clear(); if (partIds.length == 0) { partIds = (String[]) cache.keySet().toArray(); } for (int i = 0; i < partIds.length; i++) { if (cache.remove(partIds[i]) == null) { throw ManagedException.implementationError("cache item couldn't be removed!", partIds[i], cache.keySet()); } } } }
/** * evaluates the query name by arguments * * @param <T> type of bean * @param beanType bean type * @param args query arguments * @return named query name (like 'MyBeanClassPath.findById') */ protected String getNamedQueryByArguments(Class<?> beanType, Object... args) { final String prefix = getNamedQueryPrefix(beanType); final int alength = args.length; switch (alength) { case 0: return prefix + NAMEDQUERY_ALL; case 1: return prefix + NAMEDQUERY_ID; case 2: return prefix + NAMEDQUERY_BETWEEN; default: throw ManagedException.implementationError("evaluation of named queries only available for zero or one argument (findAll and findById)", args); } }
/** * get cached result as single object. use {@link #get(Class, String)} to obtain a list of elements. * * @param <T> result type * @param type result type * @param partId part id, identifying the data * @return data or null */ public <T> T getSingle(Class<T> type, String partId) { Collection<T> result = get(type, partId); if (result != null) { if (result.size() == 1) { return result.iterator().next(); } else { throw ManagedException.implementationError("the cache for " + type + "|" + partId + " is not a single result. the cache contains" + result.size() + " elements for that!", "getSingle()", "get()"); } } return null; }
/** * removes the given standard-attributes from bean (given names must be contained in standard-bean-definition. not * performance-optimized, because standard names have to be evaluated first!) * * @param attributeNamesToRemove attributes to remove */ public void removeAttributes(String... attributeNamesToRemove) { ArrayList<String> names = new ArrayList<String>(Arrays.asList(getAttributeNames())); int currentSize = names.size(); names.removeAll(Arrays.asList(attributeNamesToRemove)); if (names.size() + attributeNamesToRemove.length != currentSize) { throw ManagedException.implementationError("not all of given attributes were removed!", attributeNamesToRemove, getAttributeNames()); } setAttributeFilter(names.toArray(new String[0])); }
/** * get cached result list * * @param <T> result type * @param type result type * @param partId part id, identifying the data * @return data or null */ public <T> Collection<T> get(Class<T> type, String partId) { Part<?> part = cache.get(partId); if (part == null && nextBatchParts.contains(new Part(partId))) { if (mode == MODE_AUTO) { execute(); } else { throw ManagedException.implementationError("the batch-loading wasn't started yet! you have to call 'execute' before getting the data", partId); } } return (Collection<T>) (part != null ? part.getResult() : null); }
/** * gets an attribute of this bean. if you defined a filter, only attributes defined in that filter are accessible. * if you try to access a virtual beanvalue ({@link BeanValue#isVirtual()=true}) you don't have to use the real * attribute name (this would be always {@link IValueAccess#ATTR_VALUE} but the description ( * {@link BeanValue#getDescription()}). * * @param name attribute name (on virtual attributes it is the description of the {@link BeanValue}). * @return attribute */ @Override public IAttributeDefinition getAttribute(String name) { IAttributeDefinition definition = getAttributeDefinitions().get(name); if (definition == null) { if (!allDefinitionsCached) { if (isVirtual()) { throw ManagedException .implementationError( "The attribute " + name + " was not defined in this virtual bean!\nPlease define this attribute through addAttribute(...)", name); } definition = createAttributeDefinition(name); attributeDefinitions.put(name, definition); } else { throw new IllegalArgumentException("The attribute '" + name + "' is not defined in bean " + this); } } return definition; }
/** * injectRuleCover * * @param attr new attribute definition to connect to rule cover instance */ protected void injectIntoRuleCover() { LOG.info("doing rule-cover injection on bean-value " + this + "..."); if (!AttributeCover.hasRuleCover(this)) throw ManagedException.implementationError("no injection into rule-covers should be done, no rule cover defined for this attribute", this, AttributeCover.cachedConnectionEndTypes); //connect optional rule-covers (use accessor instead of BeanDefinition to avoid stackoverflow injectIntoRuleCover(new PrivateAccessor<>(this), getInstance()); }
@Override public T action() throws Exception { if (!hasInstanceAsFirstParameter()) throw ManagedException.implementationError("First parameter of method " + this + " must be invoking instance!", getInstance(), parameters()); Object[] args = getArgumentValues(); return (T) method().invoke(getInstance(), args); }
if (type == null) { throw ManagedException .implementationError( "The conversion from string to object is only available, if the ValueExpression was created with a class type argument!", "type of value-expression '" + toString() + "' is null");
/** * evaluates unique method argument names either through its parameter types or {@link Action#argNames()}. * * @return unique argument names */ public String[] getArgumentNames() { Action ana; if (method().isAnnotationPresent(Action.class) && (ana = method.getAnnotation(Action.class)).argNames().length > 0) { if (ana.argNames().length != getArgumentTypes().length) throw ManagedException.implementationError("The annotation " + ana + " must define exactly the argument-names for the method " + method(), ana.argNames(), getArgumentTypes()); return ana.argNames(); } else { return getValidMethodParameterNames(); } }
throw ManagedException.implementationError("give at least one attribute-name to be filled!", null); .implementationError( "if you don't give a separation-character, you should give at least one column-index in your attribute-names", null);
/** * creates a new bean through informations of argument names and constraints * * @return */ public BeanDefinition toBean(Object instance) { Bean b = new Bean(); b.setInstance(instance); b.setName(getShortDescription()); String[] args = getArgumentNames(); Constraint[] c = getConstraints(); if (c != null && args.length != c.length) ManagedException.implementationError("The annotated argNames do not relate to the real methods arguments", StringUtil.toString(args, -1)); for (int i = 0; i < args.length; i++) { b.addAttribute(new BeanValue<T>(new ValueHolder(null), args[i], c != null && c.length > i && c[i] != null ? c[i] : new Constraint(getArgumentTypes()[i]))); } b.addAction(this); b.setDefault(false); return b; }