<commit_before>/*
 * Copyright 2013 <NAME>.
 *
 * 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
 *
 *      http://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 es.logongas.ix3.persistencia.impl.hibernate.dao;

import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 *
 * @author <NAME>
 */
public class InvocationHandlerImplDAO implements InvocationHandler {

    Object realObject;

    public InvocationHandlerImplDAO(Object realObject) {
        this.realObject = realObject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Method realMethod = getRealMethod(realObject.getClass(), method);

        return realMethod.invoke(realObject, args);
    }

    private Method getRealMethod(Class realObjectClass, Method method) {
        Method[] methods = realObjectClass.getMethods();

        for (Method realMethod : methods) {
            if (realMethod.getName().equals(method.getName()) == true) {
                return realMethod;
            }
        }

        throw new RuntimeException("No existe ese método:" + method.toGenericString());
    }
}<commit_msg>Al retornar GenericDAOImplHibernate, si existe el interfaz DAO correspondiente que GenericDAOImplHibernate implemente dicho interfaz Comprobar tambien al buscar el método que tengan los mismos parámetros.<commit_after>/*
 * Copyright 2013 <NAME>.
 *
 * 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
 *
 *      http://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 es.logongas.ix3.persistencia.impl.hibernate.dao;

import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Esta clase es una ayuda para crear un Proxy de los interfaces DAO.
 * @author <NAME>
 */
public class InvocationHandlerImplDAO implements InvocationHandler {

    Object realObject;

    public InvocationHandlerImplDAO(Object realObject) {
        this.realObject = realObject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Method realMethod = getRealMethod(realObject.getClass(), method);

        return realMethod.invoke(realObject, args);
    }

    private Method getRealMethod(Class realObjectClass, Method method) {
        Method[] methods = realObjectClass.getMethods();

        for (Method realMethod : methods) {
            if (realMethod.getName().equals(method.getName()) == true) {
                if (equalParameterTypes(realMethod.getParameterTypes(),method.getParameterTypes())) {
                    return realMethod;
                }
            }
        }

        throw new RuntimeException("No existe ese método:" + method.toGenericString());
    }

    private boolean equalParameterTypes(Class[] realParameterTypes,Class[] parameterTypes) {
        if (realParameterTypes.length!=parameterTypes.length) {
            return false;
        }

        for(int i=0;i<realParameterTypes.length;i++) {
            if (realParameterTypes[i].isAssignableFrom(parameterTypes[i])==false) {
                return false;
            }
        }

        return true;
    }

}
{'fraction_non_alphanumeric': 0.08791208791208792, 'fraction_numerical': 0.00463980463980464, 'mean_word_length': 3.201025641025641, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3024220', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1048, 'n_words': 350}