1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright ownership.
5+ * The ASF licenses this file to You under the Apache License, Version 2.0
6+ * (the "License"); you may not use this file except in compliance with
7+ * the License. You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ */
17+
18+ package io .microsphere .hibernate ;
19+
20+ import org .hibernate .CallbackException ;
21+ import org .hibernate .Interceptor ;
22+ import org .hibernate .Transaction ;
23+ import org .hibernate .metamodel .RepresentationMode ;
24+ import org .hibernate .metamodel .spi .EntityRepresentationStrategy ;
25+ import org .hibernate .type .Type ;
26+
27+ import java .io .Serializable ;
28+ import java .util .Iterator ;
29+
30+ /**
31+ * Composite {@link Interceptor}
32+ *
33+ * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
34+ * @see Interceptor
35+ * @since 1.0.0
36+ */
37+ public class CompositeInterceptor implements Interceptor {
38+
39+ private final Iterable <Interceptor > interceptors ;
40+
41+ public CompositeInterceptor (Iterable <Interceptor > interceptors ) {
42+ this .interceptors = interceptors ;
43+ }
44+
45+ @ Override
46+ public boolean onLoad (Object entity , Object id , Object [] state , String [] propertyNames , Type [] types ) throws CallbackException {
47+ for (Interceptor interceptor : interceptors ) {
48+ interceptor .onLoad (entity , id , state , propertyNames , types );
49+ }
50+ return Interceptor .super .onLoad (entity , id , state , propertyNames , types );
51+ }
52+
53+ public boolean onLoad (Object entity , Serializable id , Object [] state , String [] propertyNames , Type [] types ) throws CallbackException {
54+ return Interceptor .super .onLoad (entity , id , state , propertyNames , types );
55+ }
56+
57+ @ Override
58+ public boolean onPersist (Object entity , Object id , Object [] state , String [] propertyNames , Type [] types ) throws CallbackException {
59+ return Interceptor .super .onPersist (entity , id , state , propertyNames , types );
60+ }
61+
62+ @ Override
63+ public void onRemove (Object entity , Object id , Object [] state , String [] propertyNames , Type [] types ) throws CallbackException {
64+ Interceptor .super .onRemove (entity , id , state , propertyNames , types );
65+ }
66+
67+ @ Override
68+ public boolean onFlushDirty (Object entity , Object id , Object [] currentState , Object [] previousState , String [] propertyNames , Type [] types ) throws CallbackException {
69+ return Interceptor .super .onFlushDirty (entity , id , currentState , previousState , propertyNames , types );
70+ }
71+
72+ public boolean onFlushDirty (Object entity , Serializable id , Object [] currentState , Object [] previousState , String [] propertyNames , Type [] types ) throws CallbackException {
73+ return Interceptor .super .onFlushDirty (entity , id , currentState , previousState , propertyNames , types );
74+ }
75+
76+ public boolean onSave (Object entity , Serializable id , Object [] state , String [] propertyNames , Type [] types ) throws CallbackException {
77+ return Interceptor .super .onSave (entity , id , state , propertyNames , types );
78+ }
79+
80+ @ Override
81+ public boolean onSave (Object entity , Object id , Object [] state , String [] propertyNames , Type [] types ) throws CallbackException {
82+ return Interceptor .super .onSave (entity , id , state , propertyNames , types );
83+ }
84+
85+ public void onDelete (Object entity , Serializable id , Object [] state , String [] propertyNames , Type [] types ) throws CallbackException {
86+ Interceptor .super .onDelete (entity , id , state , propertyNames , types );
87+ }
88+
89+ @ Override
90+ public void onDelete (Object entity , Object id , Object [] state , String [] propertyNames , Type [] types ) throws CallbackException {
91+ Interceptor .super .onDelete (entity , id , state , propertyNames , types );
92+ }
93+
94+ public void onCollectionRecreate (Object collection , Serializable key ) throws CallbackException {
95+ Interceptor .super .onCollectionRecreate (collection , key );
96+ }
97+
98+ @ Override
99+ public void onCollectionRecreate (Object collection , Object key ) throws CallbackException {
100+ Interceptor .super .onCollectionRecreate (collection , key );
101+ }
102+
103+ public void onCollectionRemove (Object collection , Serializable key ) throws CallbackException {
104+ Interceptor .super .onCollectionRemove (collection , key );
105+ }
106+
107+ @ Override
108+ public void onCollectionRemove (Object collection , Object key ) throws CallbackException {
109+ Interceptor .super .onCollectionRemove (collection , key );
110+ }
111+
112+ public void onCollectionUpdate (Object collection , Serializable key ) throws CallbackException {
113+ Interceptor .super .onCollectionUpdate (collection , key );
114+ }
115+
116+ @ Override
117+ public void onCollectionUpdate (Object collection , Object key ) throws CallbackException {
118+ Interceptor .super .onCollectionUpdate (collection , key );
119+ }
120+
121+ @ Override
122+ public void preFlush (Iterator <Object > entities ) throws CallbackException {
123+ Interceptor .super .preFlush (entities );
124+ }
125+
126+ @ Override
127+ public void postFlush (Iterator <Object > entities ) throws CallbackException {
128+ Interceptor .super .postFlush (entities );
129+ }
130+
131+ @ Override
132+ public Boolean isTransient (Object entity ) {
133+ return Interceptor .super .isTransient (entity );
134+ }
135+
136+ public int [] findDirty (Object entity , Serializable id , Object [] currentState , Object [] previousState , String [] propertyNames , Type [] types ) {
137+ return Interceptor .super .findDirty (entity , id , currentState , previousState , propertyNames , types );
138+ }
139+
140+ @ Override
141+ public int [] findDirty (Object entity , Object id , Object [] currentState , Object [] previousState , String [] propertyNames , Type [] types ) {
142+ return Interceptor .super .findDirty (entity , id , currentState , previousState , propertyNames , types );
143+ }
144+
145+ @ Override
146+ public Object instantiate (String entityName , EntityRepresentationStrategy representationStrategy , Object id ) throws CallbackException {
147+ return Interceptor .super .instantiate (entityName , representationStrategy , id );
148+ }
149+
150+ @ Override
151+ public Object instantiate (String entityName , RepresentationMode representationMode , Object id ) throws CallbackException {
152+ return Interceptor .super .instantiate (entityName , representationMode , id );
153+ }
154+
155+ @ Override
156+ public String getEntityName (Object object ) throws CallbackException {
157+ return Interceptor .super .getEntityName (object );
158+ }
159+
160+ public Object getEntity (String entityName , Serializable id ) throws CallbackException {
161+ return Interceptor .super .getEntity (entityName , id );
162+ }
163+
164+ @ Override
165+ public Object getEntity (String entityName , Object id ) throws CallbackException {
166+ return Interceptor .super .getEntity (entityName , id );
167+ }
168+
169+ @ Override
170+ public void afterTransactionBegin (Transaction tx ) {
171+ Interceptor .super .afterTransactionBegin (tx );
172+ }
173+
174+ @ Override
175+ public void beforeTransactionCompletion (Transaction tx ) {
176+ Interceptor .super .beforeTransactionCompletion (tx );
177+ }
178+
179+ @ Override
180+ public void afterTransactionCompletion (Transaction tx ) {
181+ Interceptor .super .afterTransactionCompletion (tx );
182+ }
183+
184+ @ Override
185+ public void onInsert (Object entity , Object id , Object [] state , String [] propertyNames , Type [] propertyTypes ) {
186+ Interceptor .super .onInsert (entity , id , state , propertyNames , propertyTypes );
187+ }
188+
189+ @ Override
190+ public void onUpdate (Object entity , Object id , Object [] state , String [] propertyNames , Type [] propertyTypes ) {
191+ Interceptor .super .onUpdate (entity , id , state , propertyNames , propertyTypes );
192+ }
193+
194+ @ Override
195+ public void onUpsert (Object entity , Object id , Object [] state , String [] propertyNames , Type [] propertyTypes ) {
196+ Interceptor .super .onUpsert (entity , id , state , propertyNames , propertyTypes );
197+ }
198+
199+ @ Override
200+ public void onDelete (Object entity , Object id , String [] propertyNames , Type [] propertyTypes ) {
201+ Interceptor .super .onDelete (entity , id , propertyNames , propertyTypes );
202+ }
203+ }
0 commit comments