001: package com.completex.objective.components.persistency.ocache.impl;
002:
003: import com.completex.objective.components.ocache.*;
004: import com.completex.objective.components.ocache.impl.DefaultCacheFactoryImpl;
005:
006: import java.util.Iterator;
007: import java.util.Map;
008:
009: /**
010: * @author Gennady Krizhevsky
011: */
012: public class PersistencyCacheFactoryImpl extends
013: DefaultCacheFactoryImpl implements OdalCacheFactoryManager {
014:
015: public static final PoKeyFactory PO_KEY_FACTORY = new PoKeyFactory();
016: private PoKeyFactory poKeyFactory = PO_KEY_FACTORY;
017:
018: {
019: setValueTransformer(new PoValueTransformer());
020: }
021:
022: public PersistencyCacheFactoryImpl() {
023: }
024:
025: public PersistencyCacheFactoryImpl(boolean transactionSensitive,
026: boolean flatten, boolean clone) {
027: this (null, transactionSensitive, flatten, clone);
028: }
029:
030: public PersistencyCacheFactoryImpl(
031: ValueTransformer valueTransformer,
032: boolean transactionSensitive, boolean flatten, boolean clone) {
033: setValueTransformer(valueTransformer);
034: setTransactionSensitive(transactionSensitive);
035: setFlatten(flatten);
036: setClone(clone);
037: }
038:
039: public PersistencyCacheFactoryImpl(
040: PoValueTransformer valueTransformer) {
041: setValueTransformer(valueTransformer);
042: }
043:
044: public void registerCache(OdalCache cache) {
045: registerCache(cache, null, null);
046: }
047:
048: public void registerCache(OdalCache cache,
049: OdalCacheConfig cacheConfig) {
050: registerCache(cache, null, cacheConfig);
051: }
052:
053: public synchronized void registerCache(OdalCache cache,
054: OdalKeyFactory keyFactory) {
055: registerCache(cache, keyFactory, null);
056: }
057:
058: public synchronized void registerCache(OdalCache cache,
059: OdalKeyFactory keyFactory, OdalCacheConfig cacheConfig) {
060: if (cache instanceof OdalMultiIndexCache) {
061: throw new OdalRuntimeCacheException(
062: "Multi Index cache has to be registered through MultiIndexCacheFactory, "
063: + "which then gets registered through registerCacheFactory(MultiIndexCacheFactory cacheFactory) method");
064: }
065: if (keyFactory == null) {
066: keyFactory = poKeyFactory;
067: }
068: super .registerCache(cache, keyFactory, cacheConfig);
069: }
070:
071: public boolean isFlatten() {
072: return valueTransformer().isFlatten();
073: }
074:
075: public void setFlatten(boolean flatten) {
076: valueTransformer().setFlatten(flatten);
077: }
078:
079: public boolean isClone() {
080: return valueTransformer().isClone();
081: }
082:
083: public void setClone(boolean clone) {
084: valueTransformer().setClone(clone);
085: }
086:
087: public PoKeyFactory getDefaultPoOdalKeyFactory() {
088: return poKeyFactory;
089: }
090:
091: public PoValueTransformer valueTransformer() {
092: return (PoValueTransformer) getValueTransformer();
093: }
094:
095: public void setDefaultPoOdalKeyFactory(PoKeyFactory poKeyFactory) {
096: if (poKeyFactory != null) {
097: this .poKeyFactory = poKeyFactory;
098: }
099: }
100:
101: public void registerCacheFactory(
102: OdalMultiIndexCacheFactory cacheFactory) {
103: Map map = cacheFactory.getRegisteredMultiIndexCaches();
104: if (map == null || map.isEmpty()) {
105: throw new OdalRuntimeCacheException(
106: "MultiIndexCacheFactory cache-participants map is empty. "
107: + "Register all cache participants first "
108: + "with MultiIndexCacheFactory and then register the factory itself with OdalCacheFactoryManager");
109: }
110: for (Iterator it = map.keySet().iterator(); it.hasNext();) {
111: Object key = it.next();
112: OdalKeyedCache multiIndexCache = (OdalKeyedCache) map
113: .get(key);
114: getCaches().put(key, multiIndexCache);
115: }
116: }
117:
118: public void unregisterCacheFactory(
119: OdalMultiIndexCacheFactory cacheFactory) {
120: Map map = cacheFactory.getRegisteredMultiIndexCaches();
121: for (Iterator it = map.keySet().iterator(); it.hasNext();) {
122: Object key = it.next();
123: getCaches().remove(key);
124: }
125: }
126:
127: }
|