001 /** 002 * Copyright (C) 2009 Erik Putrycz <erik.putrycz@gmail.com> 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package net.ep.db4o.activator; 018 019 import net.ep.db4o.javassist.ActivateOnAllMethods; 020 import net.ep.db4o.javassist.ActivateOnMethodPolicy; 021 import net.ep.db4o.javassist.JVSTReflector; 022 import net.ep.db4o.javassist.PersistOnMethodPolicy; 023 024 import com.db4o.config.Configuration; 025 import com.db4o.config.ConfigurationItem; 026 import com.db4o.internal.InternalObjectContainer; 027 import com.db4o.ta.TransparentPersistenceSupport; 028 029 public class ProxyActivationSupport implements ConfigurationItem { 030 031 private JVSTReflector _reflector; 032 private boolean _threadLocal; 033 private PersistOnMethodPolicy _persistPolicy = null; 034 private ActivateOnMethodPolicy _activatePolicy = new ActivateOnAllMethods(); 035 private boolean _ignoreNullActivator = false; 036 037 public ProxyActivationSupport ignoreNullActivator() { 038 _ignoreNullActivator = true; 039 return this; 040 } 041 042 public ProxyActivationSupport threadLocalActivator() { 043 _threadLocal = true; 044 return this; 045 } 046 047 public ProxyActivationSupport withActivationPolicy(ActivateOnMethodPolicy activatePolicy) { 048 _activatePolicy = activatePolicy; 049 return this; 050 } 051 052 public ProxyActivationSupport withPersistPolicy(PersistOnMethodPolicy persistPolicy) { 053 _persistPolicy = persistPolicy; 054 return this; 055 } 056 057 058 059 private ProxyActivationSupport() { 060 } 061 062 public static ProxyActivationSupport create() { 063 return new ProxyActivationSupport(); 064 } 065 066 public void apply(InternalObjectContainer container) { 067 //_reflector.setDiagnostics(container.handlers()._diagnosticProcessor); 068 // nothing to do 069 } 070 071 public void prepare(Configuration configuration) { 072 // configuration.reflectWith(new CGLibReflector(Thread.currentThread() 073 // .getContextClassLoader())); 074 _reflector = new JVSTReflector(Thread.currentThread() 075 .getContextClassLoader()); 076 _reflector.setThreadLocal(_threadLocal); 077 _reflector.setIgnoreNullActivator(_ignoreNullActivator); 078 _reflector.setPersistPolicy(_persistPolicy); 079 _reflector.setActivationPolicy(_activatePolicy); 080 configuration.reflectWith(_reflector); 081 configuration.add(new TransparentPersistenceSupport()); 082 //configuration.add(new TransparentActivationSupport()); 083 } 084 085 }