EMMA Coverage Report (generated Sat Nov 03 21:53:04 GMT 2007)
[all classes][sf.qof.customizer]

COVERAGE SUMMARY FOR SOURCE FILE [SessionContextConnectionFactoryCustomizer.java]

nameclass, %method, %block, %line, %
SessionContextConnectionFactoryCustomizer.java100% (1/1)100% (5/5)95%  (71/75)95%  (20/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SessionContextConnectionFactoryCustomizer100% (1/1)100% (5/5)95%  (71/75)95%  (20/21)
emitGetConnection (Class, Class, ClassEmitter): void 100% (1/1)89%  (34/38)91%  (10/11)
<static initializer> 100% (1/1)100% (19/19)100% (4/4)
SessionContextConnectionFactoryCustomizer (): void 100% (1/1)100% (3/3)100% (1/1)
emitFields (Class, Class, ClassEmitter): void 100% (1/1)100% (1/1)100% (1/1)
emitSetConnection (Class, Class, ClassEmitter): void 100% (1/1)100% (14/14)100% (4/4)

1/*
2 * Copyright 2007 brunella ltd
3 *
4 * Licensed under the LGPL Version 3 (the "License");
5 * you may not use this file except in compliance with the License.
6 *
7 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
8 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
11 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
12 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
13 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
14 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
15 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
16 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
17 * THE POSSIBILITY OF SUCH DAMAGE.
18 */
19package sf.qof.customizer;
20 
21import static sf.qof.codegen.Constants.SIG_getConnection;
22import static sf.qof.codegen.Constants.SIG_setConnection;
23import static sf.qof.codegen.Constants.TYPE_RuntimeException;
24import net.sf.cglib.core.ClassEmitter;
25import net.sf.cglib.core.CodeEmitter;
26import net.sf.cglib.core.Constants;
27import net.sf.cglib.core.Signature;
28 
29import org.objectweb.asm.Type;
30 
31import sf.qof.session.UseSessionContext;
32 
33/**
34 * Provides the implementation of a ConnectionFactoryCustomizer to use the
35 * SessionContextFactory.
36 * 
37 * This customizer implements <code>getConnection()</code> and
38 * <code>setConnection()</code> methods. It delegates calls to
39 * <code>getConnection()</code> to
40 * <code>SessionContextFactory.getContext().getConnection()</code>. Calls to
41 * <code>setConnection()</code> throws a RuntimeException.
42 * 
43 * The <code>UseSessionContext</code> annotation indicates that this
44 * customizer should be used and allows to specify a session context name.
45 * 
46 * @see sf.qof.session.SessionContextFactory
47 * @see sf.qof.session.UseSessionContext
48 */
49public class SessionContextConnectionFactoryCustomizer implements ConnectionFactoryCustomizer {
50 
51  private static final Type TYPE_SessionContextFactory = Type.getType("Lsf/qof/session/SessionContextFactory;");
52  private static final Type TYPE_SessionContext = Type.getType("Lsf/qof/session/SessionContext;");
53  private static final Signature SIG_getContext = new Signature("getContext", "()Lsf/qof/session/SessionContext;");
54  private static final Signature SIG_getContextWithName = new Signature("getContext", "(Ljava/lang/String;)Lsf/qof/session/SessionContext;");
55 
56  public void emitFields(Class<?> queryDefinitionClass, Class<?> superClass, ClassEmitter ce) {
57    // no fields needed
58  }
59 
60  public void emitGetConnection(Class<?> queryDefinitionClass, Class<?> superClass, ClassEmitter ce) {
61    CodeEmitter co = ce.begin_method(Constants.ACC_PUBLIC, SIG_getConnection, null, null);
62    if (queryDefinitionClass.isAnnotationPresent(UseSessionContext.class)) {
63      UseSessionContext sessionContextAnnotation = queryDefinitionClass.getAnnotation(UseSessionContext.class);
64      co.push(sessionContextAnnotation.name());
65      co.invoke_static(TYPE_SessionContextFactory, SIG_getContextWithName);
66    } else {
67      co.invoke_static(TYPE_SessionContextFactory, SIG_getContext);
68    }
69    co.invoke_interface(TYPE_SessionContext, SIG_getConnection);
70    co.return_value();
71    co.end_method();
72  }
73 
74  public void emitSetConnection(Class<?> queryDefinitionClass, Class<?> superClass, ClassEmitter ce) {
75    CodeEmitter co = ce.begin_method(Constants.ACC_PUBLIC, SIG_setConnection, null, null);
76    co.throw_exception(TYPE_RuntimeException, "Connection cannot be set");
77    co.end_method();
78  }
79 
80}

[all classes][sf.qof.customizer]
EMMA 2.0.5312 (C) Vladimir Roubtsov