View Javadoc

1   /**
2    * Copyright (C) 2009 Erik Putrycz <erik.putrycz@gmail.com>
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.ep.db4o.activator;
18  
19  import net.ep.db4o.javassist.ActivateOnAllMethods;
20  import net.ep.db4o.javassist.ActivateOnMethodPolicy;
21  import net.ep.db4o.javassist.JVSTReflector;
22  import net.ep.db4o.javassist.PersistOnMethodPolicy;
23  
24  import com.db4o.config.Configuration;
25  import com.db4o.config.ConfigurationItem;
26  import com.db4o.internal.InternalObjectContainer;
27  import com.db4o.ta.TransparentPersistenceSupport;
28  
29  public class ProxyActivationSupport implements ConfigurationItem {
30  
31  	private JVSTReflector _reflector;
32  	private boolean _threadLocal;
33  	private PersistOnMethodPolicy _persistPolicy = null;
34  	private ActivateOnMethodPolicy _activatePolicy = new ActivateOnAllMethods();
35  	private boolean _ignoreNullActivator = false;
36  	
37  	public ProxyActivationSupport ignoreNullActivator() {
38  		_ignoreNullActivator = true;
39  		return this;
40  	}
41  	
42  	public ProxyActivationSupport threadLocalActivator() {
43  		_threadLocal = true;
44  		return this;
45  	}
46  	
47  	public ProxyActivationSupport withActivationPolicy(ActivateOnMethodPolicy activatePolicy) {
48  		_activatePolicy = activatePolicy;
49  		return this;
50  	}
51  	
52  	public ProxyActivationSupport withPersistPolicy(PersistOnMethodPolicy persistPolicy) {
53  		_persistPolicy = persistPolicy;
54  		return this;
55  	}
56  	
57  	
58  	
59  	private ProxyActivationSupport() {
60  	}
61  
62  	public static ProxyActivationSupport create() {
63  		return new ProxyActivationSupport();
64  	}
65  	
66  	public void apply(InternalObjectContainer container) {
67  		//_reflector.setDiagnostics(container.handlers()._diagnosticProcessor);
68  		// nothing to do
69  	}
70  
71  	public void prepare(Configuration configuration) {
72  		// configuration.reflectWith(new CGLibReflector(Thread.currentThread()
73  		// .getContextClassLoader()));
74  		_reflector = new JVSTReflector(Thread.currentThread()
75  				.getContextClassLoader());
76  		_reflector.setThreadLocal(_threadLocal);
77  		_reflector.setIgnoreNullActivator(_ignoreNullActivator);
78  		_reflector.setPersistPolicy(_persistPolicy);
79  		_reflector.setActivationPolicy(_activatePolicy);
80  		configuration.reflectWith(_reflector);
81  		configuration.add(new TransparentPersistenceSupport());
82  		//configuration.add(new TransparentActivationSupport());
83  	}
84  
85  }