List of usage examples for org.apache.commons.beanutils BeanMap keySet
public Set keySet()
From source file:de.hska.ld.content.service.impl.AbstractContentService.java
public List<String> compare(T oldT, T newT) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { BeanMap map = new BeanMap(oldT); PropertyUtilsBean propUtils = new PropertyUtilsBean(); //StringBuilder sb = new StringBuilder(); //sb.append("UPDATE process: >> object=[class=" + newT.getClass() + ", " + newT.getId() + "]:"); List<String> differentProperties = new ArrayList<>(); for (Object propNameObject : map.keySet()) { String propertyName = (String) propNameObject; if (propertyName.endsWith("List")) continue; try {//from ww w. j a va 2 s . co m Object property1 = propUtils.getProperty(oldT, propertyName); Object property2 = propUtils.getProperty(newT, propertyName); if (property1 != null) { if (!(property1 instanceof List) && !(property1 instanceof Date)) { if (property1.equals(property2)) { //sb.append(" ||" + propertyName + " is equal ||"); } else { try { //sb.append(" ||> " + propertyName + " is different (oldValue=\"" + property1 + "\", newValue=\"" + property2 + "\") ||"); differentProperties.add(propertyName); } catch (Exception e) { //sb.append(" ||> " + propertyName + " is different (newValue=\"" + property2 + "\") ||"); differentProperties.add(propertyName); } } } } else { if (property2 == null) { //sb.append(" ||" + propertyName + " is equal ||"); } else { if (!(property2 instanceof List) && !(property2 instanceof Date)) { //sb.append(" ||> " + propertyName + " is different (newValue=\"" + property2 + "\") ||"); differentProperties.add(propertyName); } } } } catch (Exception e) { //sb.append(" ||> Could not compute difference for property with name=" + propertyName + "||"); } } //sb.append(" <<"); //LOGGER.info(sb.toString()); return differentProperties; }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
private void prepareEnsureUnique(String id, JsonObject instance, RBatch redissonBatch, ArrayList<String> pList, String parent) throws RepositoryException { try {//from w ww .j av a 2s . c om BeanMap pMap = new BeanMap(cls.newInstance()); pMap.keySet().forEach(e -> { if ("class".equals(e) || instance.getValue(e.toString()) == null) { return; } Class type = pMap.getType(e.toString()); String fieldName = (parent == null ? "" : parent.concat(".")).concat(e.toString()); if (isRedisEntity(type)) { try { RedisRepositoryImpl innerRepo = (RedisRepositoryImpl) factory.instance(type); innerRepo.prepareEnsureUnique(id, instance.getJsonObject(e.toString()), redissonBatch, pList, fieldName); } catch (RepositoryException ex) { throw new RuntimeException(ex); } } else { try { if (cls.getDeclaredField(e.toString()).isAnnotationPresent(RedissonUnique.class)) { redissonBatch.getMap(getUniqueKey(e.toString())) .putIfAbsentAsync(instance.getValue(e.toString()), id); pList.add(fieldName); } } catch (NoSuchFieldException | SecurityException ex) { throw new RuntimeException(ex); } } }); } catch (InstantiationException | IllegalAccessException | RuntimeException ex) { throw new RepositoryException(ex); } }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
private void prepareUndoUnique(String id, JsonObject instance, RBatch redissonBatch, ArrayList<String> pList, String parent) throws RepositoryException { try {//from ww w .ja v a2 s . com BeanMap pMap = new BeanMap(cls.newInstance()); pMap.keySet().forEach(e -> { if ("class".equals(e) || instance.getValue(e.toString()) == null) { return; } Class type = pMap.getType(e.toString()); String fieldName = (parent == null ? "" : parent.concat(".")).concat(e.toString()); if (isRedisEntity(type)) { try { RedisRepositoryImpl innerRepo = (RedisRepositoryImpl) factory.instance(type); innerRepo.prepareUndoUnique(id, instance.getJsonObject(e.toString()), redissonBatch, pList, fieldName); } catch (RepositoryException ex) { throw new RuntimeException(ex); } } else { try { if (cls.getDeclaredField(e.toString()).isAnnotationPresent(RedissonUnique.class) && pList.contains(fieldName)) { redissonBatch.getMap(getUniqueKey(e.toString())) .removeAsync(instance.getValue(e.toString()), id); } } catch (NoSuchFieldException | SecurityException ex) { throw new RuntimeException(ex); } } }); } catch (InstantiationException | IllegalAccessException | RuntimeException ex) { throw new RepositoryException(ex); } }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
private T prepareInstanceAndFetchList(String id, RBatch redissonBatch, ArrayList<String> pList, String parent, Boolean deepFetch) throws InstantiationException, IllegalAccessException { BeanMap pMap = new BeanMap(cls.newInstance()); try {//w w w .j a v a 2 s. c om pMap.keySet().forEach(e -> { if ("class".equals(e)) { return; } Class type = pMap.getType(e.toString()); String fieldName = (parent == null ? "" : parent.concat(".")).concat(e.toString()); if (isRedisEntity(type)) { if (deepFetch) { try { RedisRepositoryImpl innerRepo = (RedisRepositoryImpl) factory.instance(type); pMap.put(e.toString(), innerRepo.prepareInstanceAndFetchList(id, redissonBatch, pList, fieldName, deepFetch)); } catch (InstantiationException | IllegalAccessException | RepositoryException ex) { throw new RuntimeException(ex); } } } else { if ("id".equals(e)) { redissonBatch.getMap(getStorageKey(), StringCodec.INSTANCE).getAsync(id); } else { redissonBatch.getMap(getStorageKey(e.toString())).getAsync(id); } pList.add(fieldName); } }); } catch (RuntimeException ex) { throw new InstantiationException(); } return (T) pMap.getBean(); }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
private void prepareEnsuerIndex(String id, T r, JsonObject instance, Boolean isNew, RBatch redissonBatch, ArrayList<String> pList, String parent) throws RepositoryException { try {/*from w w w .java 2 s.com*/ BeanMap pMap = new BeanMap(r == null ? cls.newInstance() : r); pMap.keySet().forEach(e -> { if ("class".equals(e) || instance.getValue(e.toString()) == null) { return; } Class type = pMap.getType(e.toString()); String fieldName = (parent == null ? "" : parent.concat(".")).concat(e.toString()); if (isRedisEntity(type)) { try { RedisRepositoryImpl innerRepo = (RedisRepositoryImpl) factory.instance(type); innerRepo.prepareEnsuerIndex(id, pMap.get(e), instance.getJsonObject(e.toString()), isNew, redissonBatch, pList, fieldName); } catch (RepositoryException ex) { throw new RuntimeException(ex); } } else { try { if (cls.getDeclaredField(e.toString()).isAnnotationPresent(RedissonIndex.class)) { RedissonIndex index = cls.getDeclaredField(e.toString()) .getAnnotation(RedissonIndex.class); if (index.indexOnSave()) { prepareEnsuerIndex(id, r, instance, redissonBatch, index, e.toString(), pMap.get(e)); } } else if (cls.getDeclaredField(e.toString()) .isAnnotationPresent(RedissonIndex.List.class)) { RedissonIndex.List indexList = cls.getDeclaredField(e.toString()) .getAnnotation(RedissonIndex.List.class); Arrays.stream(indexList.value()).filter(f -> f.indexOnSave()) .forEach(index -> prepareEnsuerIndex(id, r, instance, redissonBatch, index, e.toString(), pMap.get(e))); } if (cls.getDeclaredField(e.toString()).isAnnotationPresent(RedissonCounter.class)) { RedissonCounter counter = cls.getDeclaredField(e.toString()) .getAnnotation(RedissonCounter.class); prepareEnsuerCounter(id, r, instance, isNew, redissonBatch, counter, e.toString(), pMap.get(e)); } else if (cls.getDeclaredField(e.toString()) .isAnnotationPresent(RedissonCounter.List.class)) { RedissonCounter.List counterList = cls.getDeclaredField(e.toString()) .getAnnotation(RedissonCounter.List.class); Arrays.stream(counterList.value()).forEach(index -> prepareEnsuerCounter(id, r, instance, isNew, redissonBatch, index, e.toString(), pMap.get(e))); } } catch (NoSuchFieldException ex) { throw new RuntimeException(ex); } } }); } catch (InstantiationException | IllegalAccessException | RuntimeException ex) { throw new RepositoryException(ex); } }
From source file:org.beanfuse.model.EntityUtils.java
/** * ().<br>//from ww w . j a v a 2s. co m * * <pre> * hibernate????. * (Entity)???id??. * ? * <code> * Component * </code> * ? * ?????????. * // evict collection * if (value instanceof Collection) { * if (((Collection) value).isEmpty()) * map.put(attr, null); * } * </pre> * * @see ValidEntityPredicate * @param entity */ public static void evictEmptyProperty(Object entity) { if (null == entity) { return; } boolean isEntity = false; if (entity instanceof Entity) { isEntity = true; } BeanMap map = new BeanMap(entity); List attList = new ArrayList(); attList.addAll(map.keySet()); attList.remove("class"); for (Iterator iter = attList.iterator(); iter.hasNext();) { String attr = (String) iter.next(); if (!PropertyUtils.isWriteable(entity, attr)) { continue; } Object value = map.get(attr); if (null == value) { continue; } else { // evict invalid entity key if (isEntity && attr.equals(((Entity) entity).key())) { if (!ValidEntityKeyPredicate.getInstance().evaluate(value)) { map.put(attr, null); } } // evict invalid entity if (value instanceof Entity && !ValidEntityPredicate.getInstance().evaluate(value)) { map.put(attr, null); } else if (value instanceof Component) { // evict component recursively evictEmptyProperty(value); } } } }
From source file:org.beanfuse.model.EntityUtils.java
/** * ?/*from ww w . j av a 2 s . c o m*/ * * @param entity * @param ignoreDefault * * @return */ public static boolean isEmpty(Entity entity, boolean ignoreDefault) { BeanMap map = new BeanMap(entity); List attList = new ArrayList(); attList.addAll(map.keySet()); attList.remove("class"); try { for (Iterator iter = attList.iterator(); iter.hasNext();) { String attr = (String) iter.next(); if (!PropertyUtils.isWriteable(entity, attr)) { continue; } Object value = map.get(attr); if (null == value) { continue; } if (ignoreDefault) { if (value instanceof Number) { if (((Number) value).intValue() != 0) { return false; } } else if (value instanceof String) { String str = (String) value; if (StringUtils.isNotEmpty(str)) { return false; } } else { return false; } } else { return false; } } } catch (Exception e) { logger.error("isEmpty error", e); } return true; }
From source file:org.beangle.model.persist.hibernate.CriterionUtils.java
/** * ?. ??./*from w w w.j a v a 2s .co m*/ * * @param entity * @param excludePropertes * @param mode * @return */ @SuppressWarnings("rawtypes") public static List<Criterion> getEntityCriterions(String nestedName, Object entity, String[] excludePropertes, MatchMode mode, boolean ignoreZero) { if (null == entity) { return Collections.emptyList(); } List<Criterion> criterions = CollectUtils.newArrayList(); BeanMap map = new BeanMap(entity); Set keySet = map.keySet(); Collection properties = null; if (null == excludePropertes) { List proList = CollectUtils.newArrayList(); proList.addAll(keySet); properties = proList; } else { properties = CollectionUtils.subtract(keySet, Arrays.asList(excludePropertes)); } properties.remove("class"); for (Iterator iter = properties.iterator(); iter.hasNext();) { String propertyName = (String) iter.next(); if (!PropertyUtils.isWriteable(entity, propertyName)) { continue; } Object value = map.get(propertyName); addCriterion(nestedName, entity, excludePropertes, propertyName, value, criterions, mode, ignoreZero); } return criterions; }
From source file:org.beangle.model.persist.hibernate.CriterionUtils.java
public static List<Criterion> getForeignerCriterions(Object entity) { BeanMap map = new BeanMap(entity); return getForeignerCriterions(entity, map.keySet()); }
From source file:org.beangle.model.persist.hibernate.CriterionUtils.java
/** * ?/*from w w w. j ava 2 s.co m*/ * * @param entity * @param property * ????outcomponent.innercomponent * @param excludePropertes * ??entityProperty.componentProperty * @param enableLike * @return */ private static List<Criterion> getComponentCriterions(String nestedName, Object entity, String property, String[] excludePropertes, MatchMode mode, boolean ignoreZero) { List<Criterion> criterions = CollectUtils.newArrayList(); Component component = null; try { component = (Component) PropertyUtils.getProperty(entity, property); } catch (Exception e) { return Collections.emptyList(); } if (null == component) { return Collections.emptyList(); } BeanMap map = new BeanMap(component); Set<String> properties = map.keySet(); Set<String> excludeSet = null; if (null == excludePropertes) { excludeSet = Collections.emptySet(); } else { excludeSet = CollectUtils.newHashSet(); excludeSet.addAll(Arrays.asList(excludePropertes)); } for (Iterator<String> iter = properties.iterator(); iter.hasNext();) { String propertyName = iter.next(); String cascadeName = property + "." + propertyName; if (excludeSet.contains(cascadeName) || "class".equals(propertyName)) { continue; } if (!PropertyUtils.isWriteable(component, propertyName)) { continue; } Object value = map.get(propertyName); addCriterion(nestedName, entity, excludePropertes, cascadeName, value, criterions, mode, ignoreZero); } return criterions; }