public BeanCollection<?> createReference(EntityBean parentBean) { BeanCollection<?> ref = help.createReference(parentBean); setValue(parentBean, ref); return ref; }
/** * A Many (element collection) property in bean cache to held as JSON. */ @Override public void setCacheDataValue(EntityBean bean, Object cacheData, PersistenceContext context) { try { String asJson = (String) cacheData; if (asJson != null && !asJson.isEmpty()) { Object collection = jsonReadCollection(asJson); setValue(bean, collection); } } catch (Exception e) { logger.error("Error setting value from L2 cache", e); } }
/** * Add the bean to the appropriate collection on the parent bean. */ @Override public void addBeanToCollectionWithCreate(EntityBean parentBean, EntityBean detailBean, boolean withCheck) { BeanCollection<?> bc = (BeanCollection<?>) super.getValue(parentBean); if (bc == null) { bc = help.createEmpty(parentBean); setValue(parentBean, bc); } help.add(bc, detailBean, withCheck); }
@Override public void refresh(BeanCollection<?> bc, EntityBean parentBean) { BeanList<?> newBeanList = (BeanList<?>) bc; List<?> currentList = (List<?>) many.getValue(parentBean); newBeanList.setModifyListening(many.getModifyListenMode()); if (currentList == null) { // the currentList is null? Not really expecting this... many.setValue(parentBean, newBeanList); } else if (currentList instanceof BeanList<?>) { // normally this case, replace just the underlying list BeanList<?> currentBeanList = (BeanList<?>) currentList; currentBeanList.setActualList(newBeanList.getActualList()); currentBeanList.setModifyListening(many.getModifyListenMode()); } else { // replace the entire list with the BeanList many.setValue(parentBean, newBeanList); } }
@Override public void refresh(BeanCollection<?> bc, EntityBean parentBean) { BeanMap<?, ?> newBeanMap = (BeanMap<?, ?>) bc; Map<?, ?> current = (Map<?, ?>) many.getValue(parentBean); newBeanMap.setModifyListening(many.getModifyListenMode()); if (current == null) { // the currentMap is null? Not really expecting this... many.setValue(parentBean, newBeanMap); } else if (current instanceof BeanMap<?, ?>) { // normally this case, replace just the underlying list BeanMap<?, ?> currentBeanMap = (BeanMap<?, ?>) current; currentBeanMap.setActualMap(newBeanMap.getActualMap()); currentBeanMap.setModifyListening(many.getModifyListenMode()); } else { // replace the entire set many.setValue(parentBean, newBeanMap); } }
@Override public void refresh(BeanCollection<?> bc, EntityBean parentBean) { BeanSet<?> newBeanSet = (BeanSet<?>) bc; Set<?> current = (Set<?>) many.getValue(parentBean); newBeanSet.setModifyListening(many.getModifyListenMode()); if (current == null) { // the currentList is null? Not really expecting this... many.setValue(parentBean, newBeanSet); } else if (current instanceof BeanSet<?>) { // normally this case, replace just the underlying list BeanSet<?> currentBeanSet = (BeanSet<?>) current; currentBeanSet.setActualSet(newBeanSet.getActualSet()); currentBeanSet.setModifyListening(many.getModifyListenMode()); } else { // replace the entire set many.setValue(parentBean, newBeanSet); } }
/** * Read the JSON for this property. */ public void jsonRead(SpiJsonReader readJson, EntityBean parentBean) throws IOException { if (!this.many.jsonDeserialize) { return; } JsonParser parser = readJson.getParser(); JsonToken event = parser.nextToken(); if (JsonToken.VALUE_NULL == event) { return; } if (many.isTransient()) { jsonReadTransientUsingObjectMapper(readJson, parentBean); return; } if (JsonToken.START_ARRAY != event) { throw new JsonParseException(parser, "Unexpected token " + event + " - expecting start_array"); } many.setValue(parentBean, many.jsonReadCollection(readJson, parentBean)); }
/** * Use Jackson ObjectMapper to read the transient 'many' property. */ void jsonReadUsingObjectMapper(BeanPropertyAssocMany<?> many, SpiJsonReader readJson, EntityBean parentBean) throws IOException { ObjectMapper mapper = readJson.getObjectMapper(); ManyType manyType = many.getManyType(); Object value; if (manyType.isMap()) { // read map using Jackson object mapper with unknown key type TypeFactory typeFactory = mapper.getTypeFactory(); JavaType target = typeFactory.constructType(many.getTargetType()); MapType jacksonType = typeFactory.constructMapType(LinkedHashMap.class, TypeFactory.unknownType(), target); value = mapper.readValue(readJson.getParser(), jacksonType); } else { // read list or set using Jackson object mapper CollectionType jacksonType = mapper.getTypeFactory().constructCollectionType(manyType.getCollectionType(), many.getTargetType()); value = mapper.readValue(readJson.getParser(), jacksonType); } many.setValue(parentBean, value); } }
public BeanCollection<?> createReference(EntityBean parentBean) { BeanCollection<?> ref = help.createReference(parentBean); setValue(parentBean, ref); return ref; }
/** * A Many (element collection) property in bean cache to held as JSON. */ @Override public void setCacheDataValue(EntityBean bean, Object cacheData, PersistenceContext context) { try { String asJson = (String) cacheData; if (asJson != null && !asJson.isEmpty()) { Object collection = jsonReadCollection(asJson); setValue(bean, collection); } } catch (Exception e) { logger.error("Error setting value from L2 cache", e); } }
many.setValue(parentBean, emptyCollection); query.setLoadDescription("+refresh", null); } else {
/** * Add the bean to the appropriate collection on the parent bean. */ @Override public void addBeanToCollectionWithCreate(EntityBean parentBean, EntityBean detailBean, boolean withCheck) { BeanCollection<?> bc = (BeanCollection<?>) super.getValue(parentBean); if (bc == null) { bc = help.createEmpty(parentBean); setValue(parentBean, bc); } help.add(bc, detailBean, withCheck); }
@Override public void refresh(BeanCollection<?> bc, EntityBean parentBean) { BeanList<?> newBeanList = (BeanList<?>) bc; List<?> currentList = (List<?>) many.getValue(parentBean); newBeanList.setModifyListening(many.getModifyListenMode()); if (currentList == null) { // the currentList is null? Not really expecting this... many.setValue(parentBean, newBeanList); } else if (currentList instanceof BeanList<?>) { // normally this case, replace just the underlying list BeanList<?> currentBeanList = (BeanList<?>) currentList; currentBeanList.setActualList(newBeanList.getActualList()); currentBeanList.setModifyListening(many.getModifyListenMode()); } else { // replace the entire list with the BeanList many.setValue(parentBean, newBeanList); } }
@Override public void refresh(BeanCollection<?> bc, EntityBean parentBean) { BeanMap<?, ?> newBeanMap = (BeanMap<?, ?>) bc; Map<?, ?> current = (Map<?, ?>) many.getValue(parentBean); newBeanMap.setModifyListening(many.getModifyListenMode()); if (current == null) { // the currentMap is null? Not really expecting this... many.setValue(parentBean, newBeanMap); } else if (current instanceof BeanMap<?, ?>) { // normally this case, replace just the underlying list BeanMap<?, ?> currentBeanMap = (BeanMap<?, ?>) current; currentBeanMap.setActualMap(newBeanMap.getActualMap()); currentBeanMap.setModifyListening(many.getModifyListenMode()); } else { // replace the entire set many.setValue(parentBean, newBeanMap); } }
@Override public void refresh(BeanCollection<?> bc, EntityBean parentBean) { BeanSet<?> newBeanSet = (BeanSet<?>) bc; Set<?> current = (Set<?>) many.getValue(parentBean); newBeanSet.setModifyListening(many.getModifyListenMode()); if (current == null) { // the currentList is null? Not really expecting this... many.setValue(parentBean, newBeanSet); } else if (current instanceof BeanSet<?>) { // normally this case, replace just the underlying list BeanSet<?> currentBeanSet = (BeanSet<?>) current; currentBeanSet.setActualSet(newBeanSet.getActualSet()); currentBeanSet.setModifyListening(many.getModifyListenMode()); } else { // replace the entire set many.setValue(parentBean, newBeanSet); } }
/** * Read the JSON for this property. */ public void jsonRead(SpiJsonReader readJson, EntityBean parentBean) throws IOException { if (!this.many.jsonDeserialize) { return; } JsonParser parser = readJson.getParser(); JsonToken event = parser.nextToken(); if (JsonToken.VALUE_NULL == event) { return; } if (many.isTransient()) { jsonReadTransientUsingObjectMapper(readJson, parentBean); return; } if (JsonToken.START_ARRAY != event) { throw new JsonParseException(parser, "Unexpected token " + event + " - expecting start_array"); } many.setValue(parentBean, many.jsonReadCollection(readJson, parentBean)); }
/** * Use Jackson ObjectMapper to read the transient 'many' property. */ void jsonReadUsingObjectMapper(BeanPropertyAssocMany<?> many, SpiJsonReader readJson, EntityBean parentBean) throws IOException { ObjectMapper mapper = readJson.getObjectMapper(); ManyType manyType = many.getManyType(); Object value; if (manyType.isMap()) { // read map using Jackson object mapper with unknown key type TypeFactory typeFactory = mapper.getTypeFactory(); JavaType target = typeFactory.constructType(many.getTargetType()); MapType jacksonType = typeFactory.constructMapType(LinkedHashMap.class, TypeFactory.unknownType(), target); value = mapper.readValue(readJson.getParser(), jacksonType); } else { // read list or set using Jackson object mapper CollectionType jacksonType = mapper.getTypeFactory().constructCollectionType(manyType.getCollectionType(), many.getTargetType()); value = mapper.readValue(readJson.getParser(), jacksonType); } many.setValue(parentBean, value); } }
many.setValue(parentBean, emptyCollection); query.setLoadDescription("+refresh", null); } else {