001/**
002 * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
003 * <p>
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 * <p>
008 * http://www.apache.org/licenses/LICENSE-2.0
009 * <p>
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 */
016package com.mybatisflex.core.javassist;
017
018import org.apache.ibatis.javassist.util.proxy.ProxyFactory;
019import org.apache.ibatis.javassist.util.proxy.ProxyObject;
020import org.apache.ibatis.logging.LogFactory;
021
022import java.util.Arrays;
023
024
025public class ModifyAttrsRecordProxyFactory {
026
027    private static ModifyAttrsRecordProxyFactory instance = new ModifyAttrsRecordProxyFactory();
028
029    public static ModifyAttrsRecordProxyFactory getInstance(){
030        return instance;
031    }
032
033    private ModifyAttrsRecordProxyFactory(){}
034
035    public <T> T get(Class<T> target) {
036        ProxyFactory factory = new ProxyFactory();
037        factory.setSuperclass(target);
038
039        Class<?>[] interfaces = Arrays.copyOf(target.getInterfaces(), target.getInterfaces().length + 1);
040        interfaces[interfaces.length - 1] = ModifyAttrsRecord.class;
041        factory.setInterfaces(interfaces);
042
043
044        final Class<?> proxyClass = factory.createClass();
045
046        T proxyObject = null;
047        try {
048            proxyObject = (T) proxyClass.newInstance();
049            ((ProxyObject) proxyObject).setHandler(new ModifyAttrsRecordHandler());
050        } catch (Throwable e) {
051            LogFactory.getLog(ModifyAttrsRecordProxyFactory.class).error(e.toString(),e);
052        }
053
054        return proxyObject;
055    }
056
057
058
059
060}
061
062
063