Skip to content

Commit

Permalink
#174 force intraObjectCache enabled till #175 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Jul 5, 2016
1 parent c42e646 commit c3dfb41
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 12 deletions.
31 changes: 25 additions & 6 deletions src/main/java/de/cismet/cids/dynamics/CidsBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ public void setProperty(final String name, final Object value) throws Exception
}

/**
* DOCUMENT ME!
* Sets a property but does not set the change status flag.
*
* @param name DOCUMENT ME!
* @param value DOCUMENT ME!
Expand Down Expand Up @@ -681,10 +681,12 @@ public void listElementsAdded(final String arrayfield,
// Anlegen eines Dummy-Objektes
MetaObject dummy = (MetaObject)oa.getValue();
if (dummy == null) {
final int classId = oa.isVirtualOneToManyAttribute() ? (-1 * mai.getForeignKeyClassId())
: mai.getForeignKeyClassId();
final Sirius.server.localserver.object.Object dummyO =
new Sirius.server.localserver.object.DefaultObject(
getMetaObject().getID(),
oa.getMai().getForeignKeyClassId());
classId);
dummy = new DefaultMetaObject(dummyO, getMetaObject().getDomain());
dummy.setReferencingObjectAttribute(oa);
dummy.setDummy(true);
Expand All @@ -705,6 +707,7 @@ public void listElementsAdded(final String arrayfield,
cb.getMetaObject(),
cb.getMetaObject().getMetaClass().getAttributePolicy());
entryToAddOA.setParentObject(dummy);
entryToAddOA.setClassKey(mai.getForeignKeyClassId() + "@" + dummy.getDomain());
entryToAddOA.setChanged(true);
dummy.addAttribute(entryToAddOA);
cb.getMetaObject().setReferencingObjectAttribute(entryToAddOA);
Expand Down Expand Up @@ -742,6 +745,7 @@ public void listElementsAdded(final String arrayfield,
arrayElement,
zwischenTabellenKlasse.getAttributePolicy());
dummyOA.setParentObject(dummy);
dummyOA.setClassKey(mai.getForeignKeyClassId() + "@" + zwischenTabellenKlasse.getDomain());
dummyOA.setChanged(true);
dummy.addAttribute(dummyOA);
arrayElement.setReferencingObjectAttribute(dummyOA);
Expand Down Expand Up @@ -1077,7 +1081,9 @@ public static CidsBean createNewCidsBeanFromJSON(final boolean intraObjectCacheE
if (intraObjectCacheEnabled) {
return intraObjectCacheMapper.readValue(json, CidsBean.class);
} else {
return mapper.readValue(json, CidsBean.class);
LOG.warn("ignoring intraObjectCache disabled flag! https://github.com/cismet/cids-server/issues/175");
// return mapper.readValue(json, CidsBean.class);
return intraObjectCacheMapper.readValue(json, CidsBean.class);
}
}

Expand All @@ -1095,9 +1101,22 @@ public static Collection<CidsBean> createNewCidsBeansFromJSONCollection(final bo
final String json) throws Exception {
final TypeFactory t = TypeFactory.defaultInstance();

final Collection<CidsBean> jsonBeans = intraObjectCacheMapper.readValue(
json,
t.constructCollectionType(Collection.class, CidsBean.class));
final Collection<CidsBean> jsonBeans;
// #174 boolean flag intraObjectCacheEnabled in CidsBean.createNewCidsBeanFromJSON() is not evaluated
if (intraObjectCacheEnabled) {
jsonBeans = intraObjectCacheMapper.readValue(
json,
t.constructCollectionType(Collection.class, CidsBean.class));
} else {
LOG.warn("ignoring intraObjectCache disabled flag! https://github.com/cismet/cids-server/issues/175");
// jsonBeans = mapper..readValue(
// json,
// t.constructCollectionType(Collection.class, CidsBean.class));
jsonBeans = intraObjectCacheMapper.readValue(
json,
t.constructCollectionType(Collection.class, CidsBean.class));
}

return jsonBeans;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ public CidsBean deserialize(final JsonParser _jp, final DeserializationContext d
IntraObjectCacheJsonParser jp = null;
if (_jp instanceof IntraObjectCacheJsonParser) {
jp = (IntraObjectCacheJsonParser)_jp;
// if (LOG.isDebugEnabled()) {
// LOG.debug("reusing IntraObjectCacheJsonParser with " + jp.size() + " cached instances");
// }
} else {
jp = new IntraObjectCacheJsonParser(_jp);
// LOG.info("initializing new IntraObjectCacheJsonParser");
}

final HashMap<String, Object> propValueMap = new HashMap<String, Object>();
Expand All @@ -149,8 +153,14 @@ public CidsBean deserialize(final JsonParser _jp, final DeserializationContext d
keySet = true;
if (isIntraObjectCacheEnabled() && jp.containsKey(key) && !key.equals("-1")) {
cb = jp.get(key);
// if (LOG.isDebugEnabled()) {
// LOG.debug("using cached bean '" + cb.getCidsBeanInfo().getJsonObjectKey() + "'");
// }
cacheHit = true;
} else {
// if (LOG.isDebugEnabled()) {
// LOG.debug("creating new bean instance '" + key + "'");
// }
cb = CidsBean.createNewCidsBeanFromTableName(bInfo.getDomainKey(), bInfo.getClassKey()); // test
cb.quiteSetProperty(cb.getPrimaryKeyFieldname().toLowerCase(),
Integer.parseInt(bInfo.getObjectKey()));
Expand All @@ -162,7 +172,15 @@ public CidsBean deserialize(final JsonParser _jp, final DeserializationContext d
while (jp.nextValue() != JsonToken.END_ARRAY) {
final CidsBean arrayObject = jp.readValueAs(CidsBean.class);
if (arrayObject != null) {
if (isIntraObjectCacheEnabled() && (arrayObject.getPrimaryKeyValue() != -1)) {
if (isIntraObjectCacheEnabled()
&& (arrayObject.getPrimaryKeyValue() != -1)
&& !jp.containsKey(arrayObject.getCidsBeanInfo().getJsonObjectKey())) {
if (LOG.isDebugEnabled()) {
LOG.debug("caching array bean '"
+ arrayObject.getCidsBeanInfo().getJsonObjectKey()
+ "' of parent bean"
+ cb.getCidsBeanInfo().getJsonObjectKey() + "'");
}
jp.put(arrayObject.getCidsBeanInfo().getJsonObjectKey(), arrayObject);
}
array.add(arrayObject);
Expand All @@ -174,7 +192,14 @@ public CidsBean deserialize(final JsonParser _jp, final DeserializationContext d

case START_OBJECT: {
final CidsBean subObject = jp.readValueAs(CidsBean.class);
if (isIntraObjectCacheEnabled() && (subObject.getPrimaryKeyValue() != -1)) {
if (isIntraObjectCacheEnabled()
&& ((subObject.getPrimaryKeyValue() != -1)
&& !jp.containsKey(subObject.getCidsBeanInfo().getJsonObjectKey()))) {
if (LOG.isDebugEnabled()) {
LOG.debug("caching child bean '"
+ subObject.getCidsBeanInfo().getJsonObjectKey() + "' of parent bean '"
+ cb.getCidsBeanInfo().getJsonObjectKey() + "'");
}
jp.put(subObject.getCidsBeanInfo().getJsonObjectKey(), subObject);
}
propValueMap.put(fieldName, subObject);
Expand Down Expand Up @@ -328,9 +353,19 @@ public CidsBean deserialize(final JsonParser _jp, final DeserializationContext d

cb.getMetaObject().forceStatus(MetaObject.NO_STATUS);
if (isIntraObjectCacheEnabled() && (cb.getPrimaryKeyValue() != -1)) {
// if (LOG.isDebugEnabled()) {
// LOG.debug("caching bean '" + cb.getCidsBeanInfo().getJsonObjectKey() + "'");
// }
if (jp.containsKey(key)) {
LOG.warn("bean '" + cb.getCidsBeanInfo().getJsonObjectKey()
+ "' already cached! -> possible self-cycle detected");
}
jp.put(key, cb);
}
}
// if (LOG.isDebugEnabled()) {
// LOG.debug("bean '" + cb.getCidsBeanInfo().getJsonObjectKey() + "' created");
// }
return cb;
} catch (Exception ex) {
throw new RuntimeException("Error during creation of new CidsBean key=" + key, ex); // NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* ... and it just works.
*
****************************************************/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.cismet.cids.json;

import com.fasterxml.jackson.core.JsonParser;
Expand Down Expand Up @@ -78,4 +74,13 @@ public CidsBean get(final String key) {
public void put(final String key, final CidsBean bean) {
ioc.put(key, bean);
}

/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public int size() {
return ioc.size();
}
}

0 comments on commit c3dfb41

Please sign in to comment.