-
Notifications
You must be signed in to change notification settings - Fork 12.9k
/
Copy pathAbstractEnhancedDeserializationProxy.java.html
110 lines (100 loc) · 6.89 KB
/
AbstractEnhancedDeserializationProxy.java.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang=""><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>AbstractEnhancedDeserializationProxy.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">mybatis</a> > <a href="index.source.html" class="el_package">org.apache.ibatis.executor.loader</a> > <span class="el_source">AbstractEnhancedDeserializationProxy.java</span></div><h1>AbstractEnhancedDeserializationProxy.java</h1><pre class="source lang-java linenums">/*
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.executor.loader;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.ibatis.executor.ExecutorException;
import org.apache.ibatis.reflection.ExceptionUtil;
import org.apache.ibatis.reflection.factory.ObjectFactory;
import org.apache.ibatis.reflection.property.PropertyCopier;
import org.apache.ibatis.reflection.property.PropertyNamer;
/**
* @author Clinton Begin
*/
public abstract class AbstractEnhancedDeserializationProxy {
protected static final String FINALIZE_METHOD = "finalize";
protected static final String WRITE_REPLACE_METHOD = "writeReplace";
private final Class<?> type;
private final Map<String, ResultLoaderMap.LoadPair> unloadedProperties;
private final ObjectFactory objectFactory;
private final List<Class<?>> constructorArgTypes;
private final List<Object> constructorArgs;
<span class="fc" id="L42"> private final ReentrantLock lock = new ReentrantLock();</span>
private boolean reloadingProperty;
protected AbstractEnhancedDeserializationProxy(Class<?> type,
Map<String, ResultLoaderMap.LoadPair> unloadedProperties, ObjectFactory objectFactory,
<span class="fc" id="L47"> List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {</span>
<span class="fc" id="L48"> this.type = type;</span>
<span class="fc" id="L49"> this.unloadedProperties = unloadedProperties;</span>
<span class="fc" id="L50"> this.objectFactory = objectFactory;</span>
<span class="fc" id="L51"> this.constructorArgTypes = constructorArgTypes;</span>
<span class="fc" id="L52"> this.constructorArgs = constructorArgs;</span>
<span class="fc" id="L53"> this.reloadingProperty = false;</span>
<span class="fc" id="L54"> }</span>
public final Object invoke(Object enhanced, Method method, Object[] args) throws Throwable {
<span class="fc" id="L57"> final String methodName = method.getName();</span>
try {
<span class="fc bfc" id="L59" title="All 2 branches covered."> if (WRITE_REPLACE_METHOD.equals(methodName)) {</span>
final Object original;
<span class="pc bpc" id="L61" title="1 of 2 branches missed."> if (constructorArgTypes.isEmpty()) {</span>
<span class="fc" id="L62"> original = objectFactory.create(type);</span>
} else {
<span class="nc" id="L64"> original = objectFactory.create(type, constructorArgTypes, constructorArgs);</span>
}
<span class="fc" id="L67"> PropertyCopier.copyBeanProperties(type, enhanced, original);</span>
<span class="fc" id="L68"> return this.newSerialStateHolder(original, unloadedProperties, objectFactory, constructorArgTypes,</span>
constructorArgs);
}
<span class="fc" id="L71"> lock.lock();</span>
try {
<span class="pc bpc" id="L73" title="1 of 6 branches missed."> if (!FINALIZE_METHOD.equals(methodName) && PropertyNamer.isProperty(methodName) && !reloadingProperty) {</span>
<span class="fc" id="L74"> final String property = PropertyNamer.methodToProperty(methodName);</span>
<span class="fc" id="L75"> final String propertyKey = property.toUpperCase(Locale.ENGLISH);</span>
<span class="fc bfc" id="L76" title="All 2 branches covered."> if (unloadedProperties.containsKey(propertyKey)) {</span>
<span class="fc" id="L77"> final ResultLoaderMap.LoadPair loadPair = unloadedProperties.remove(propertyKey);</span>
<span class="fc bfc" id="L78" title="All 2 branches covered."> if (loadPair != null) {</span>
try {
<span class="fc" id="L80"> reloadingProperty = true;</span>
<span class="fc" id="L81"> loadPair.load(enhanced);</span>
} finally {
<span class="fc" id="L83"> reloadingProperty = false;</span>
<span class="fc" id="L84"> }</span>
} else {
/*
* I'm not sure if this case can really happen or is just in tests - we have an unread property but no
* loadPair to load it.
*/
<span class="fc" id="L90"> throw new ExecutorException("An attempt has been made to read a not loaded lazy property '" + property</span>
+ "' of a disconnected object");
}
}
}
<span class="fc" id="L96"> return enhanced;</span>
} finally {
<span class="fc" id="L98"> lock.unlock();</span>
}
<span class="fc" id="L100"> } catch (Throwable t) {</span>
<span class="fc" id="L101"> throw ExceptionUtil.unwrapThrowable(t);</span>
}
}
protected abstract AbstractSerialStateHolder newSerialStateHolder(Object userBean,
Map<String, ResultLoaderMap.LoadPair> unloadedProperties, ObjectFactory objectFactory,
List<Class<?>> constructorArgTypes, List<Object> constructorArgs);
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.12.202403310830</span></div></body></html>