List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object From source file:org.gridgain.grid.gridify.aop.aspectj.GridifyAspectJAspect.java
License:GNU General Public License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes.//from www. j a v a 2s. c om * * @param joinPoint Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass", "unchecked" }) @Around("execution(@org.gridgain.grid.gridify.Gridify * *(..)) && !cflow(call(* org.gridgain.grid.GridJob.*(..)))") public Object gridify(ProceedingJoinPoint joinPoint) throws Throwable { Method mtd = ((MethodSignature) joinPoint.getSignature()).getMethod(); Gridify ann = mtd.getAnnotation(Gridify.class); assert ann != null : "Intercepted method does not have gridify annotation."; // Since annotations in Java don't allow 'null' as default value // we have accept an empty string and convert it here. // NOTE: there's unintended behavior when user specifies an empty // string as intended grid name. // NOTE: the 'ann.gridName() == null' check is added to mitigate // annotation bugs in some scripting languages (e.g. Groovy). String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); if (G.state(gridName) != STARTED) { throw new GridException("Grid is not locally started: " + gridName); } // Initialize defaults. GridifyArgument arg = new GridifyArgumentAdapter(mtd.getDeclaringClass(), mtd.getName(), mtd.getParameterTypes(), joinPoint.getArgs(), joinPoint.getTarget()); if (!ann.interceptor().equals(GridifyInterceptor.class)) { // Check interceptor first. if (!ann.interceptor().newInstance().isGridify(ann, arg)) { return joinPoint.proceed(); } } if (!ann.taskClass().equals(GridifyDefaultTask.class) && ann.taskName().length() > 0) { throw new GridException("Gridify annotation must specify either Gridify.taskName() or " + "Gridify.taskClass(), but not both: " + ann); } try { Grid grid = G.grid(gridName); // If task class was specified. if (!ann.taskClass().equals(GridifyDefaultTask.class)) { return grid.execute((Class<? extends GridTask<GridifyArgument, Object>>) ann.taskClass(), arg, ann.timeout()).get(); } // If task name was not specified. if (ann.taskName().length() == 0) { return grid.execute(new GridifyDefaultTask(joinPoint.getSignature().getDeclaringType()), arg, ann.timeout()).get(); } // If task name was specified. return grid.execute(ann.taskName(), arg, ann.timeout()).get(); } catch (Throwable e) { for (Class<?> ex : ((MethodSignature) joinPoint.getSignature()).getMethod().getExceptionTypes()) { // Descend all levels down. Throwable cause = e.getCause(); while (cause != null) { if (ex.isAssignableFrom(cause.getClass())) { throw cause; } cause = cause.getCause(); } if (ex.isAssignableFrom(e.getClass())) { throw e; } } throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); } }
From source file:org.gridgain.grid.gridify.aop.aspectj.GridifySetToSetAspectJAspect.java
License:GNU General Public License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes.//from w ww. ja v a 2 s.co m * * @param joinPoint Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass" }) @Around("execution(@org.gridgain.grid.gridify.GridifySetToSet * *(..)) && !cflow(call(* org.gridgain.grid.GridJob.*(..)))") public Object gridify(ProceedingJoinPoint joinPoint) throws Throwable { Method mtd = ((MethodSignature) joinPoint.getSignature()).getMethod(); GridifySetToSet ann = mtd.getAnnotation(GridifySetToSet.class); assert ann != null : "Intercepted method does not have gridify annotation."; // Since annotations in Java don't allow 'null' as default value // we have accept an empty string and convert it here. // NOTE: there's unintended behavior when user specifies an empty // string as intended grid name. // NOTE: the 'ann.gridName() == null' check is added to mitigate // annotation bugs in some scripting languages (e.g. Groovy). String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); if (G.state(gridName) != STARTED) throw new GridException("Grid is not locally started: " + gridName); GridifyNodeFilter nodeFilter = null; if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) nodeFilter = ann.nodeFilter().newInstance(); // Check method return type. checkMethodSignature(mtd); GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); // Creates task argument. GridifyRangeArgument arg = argBuilder.createTaskArgument(mtd.getDeclaringClass(), mtd.getName(), mtd.getReturnType(), mtd.getParameterTypes(), mtd.getParameterAnnotations(), joinPoint.getArgs(), joinPoint.getTarget()); if (!ann.interceptor().equals(GridifyInterceptor.class)) { // Check interceptor first. if (!ann.interceptor().newInstance().isGridify(ann, arg)) return joinPoint.proceed(); } // Proceed locally for negative threshold parameter. if (ann.threshold() < 0) return joinPoint.proceed(); // Analyse where to execute method (remotely or locally). if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) return joinPoint.proceed(); // Check is split to jobs allowed for input method argument with declared splitSize. checkIsSplitToJobsAllowed(arg, ann); try { Grid grid = G.grid(gridName); return execute(grid, joinPoint.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(), ann.splitSize(), ann.timeout()); } catch (Throwable e) { for (Class<?> ex : ((MethodSignature) joinPoint.getSignature()).getMethod().getExceptionTypes()) { // Descend all levels down. Throwable cause = e.getCause(); while (cause != null) { if (ex.isAssignableFrom(cause.getClass())) throw cause; cause = cause.getCause(); } if (ex.isAssignableFrom(e.getClass())) throw e; } throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); } }
From source file:org.gridgain.grid.gridify.aop.aspectj.GridifySetToValueAspectJAspect.java
License:GNU General Public License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes.//from ww w. j av a 2s . c o m * * @param joinPoint Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass" }) @Around("execution(@org.gridgain.grid.gridify.GridifySetToValue * *(..)) && !cflow(call(* org.gridgain.grid.GridJob.*(..)))") public Object gridify(ProceedingJoinPoint joinPoint) throws Throwable { Method mtd = ((MethodSignature) joinPoint.getSignature()).getMethod(); GridifySetToValue ann = mtd.getAnnotation(GridifySetToValue.class); assert ann != null : "Intercepted method does not have gridify annotation."; // Since annotations in Java don't allow 'null' as default value // we have accept an empty string and convert it here. // NOTE: there's unintended behavior when user specifies an empty // string as intended grid name. // NOTE: the 'ann.gridName() == null' check is added to mitigate // annotation bugs in some scripting languages (e.g. Groovy). String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); if (G.state(gridName) != STARTED) throw new GridException("Grid is not locally started: " + gridName); GridifyNodeFilter nodeFilter = null; if (!ann.nodeFilter().equals(GridifyNodeFilter.class)) nodeFilter = ann.nodeFilter().newInstance(); // Check is method allowed for gridify. checkMethodSignature(mtd); GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder(); // Creates task argument. GridifyRangeArgument arg = argBuilder.createTaskArgument(mtd.getDeclaringClass(), mtd.getName(), mtd.getReturnType(), mtd.getParameterTypes(), mtd.getParameterAnnotations(), joinPoint.getArgs(), joinPoint.getTarget()); if (!ann.interceptor().equals(GridifyInterceptor.class)) { // Check interceptor first. if (!ann.interceptor().newInstance().isGridify(ann, arg)) { return joinPoint.proceed(); } } // Proceed locally for negative threshold parameter. if (ann.threshold() < 0) return joinPoint.proceed(); // Analyse where to execute method (remotely or locally). if (arg.getInputSize() != UNKNOWN_SIZE && arg.getInputSize() <= ann.threshold()) return joinPoint.proceed(); // Check is split to jobs allowed for input method argument with declared splitSize. checkIsSplitToJobsAllowed(arg, ann); try { Grid grid = G.grid(gridName); return execute(mtd, grid, joinPoint.getSignature().getDeclaringType(), arg, nodeFilter, ann.threshold(), ann.splitSize(), ann.timeout()); } catch (Throwable e) { for (Class<?> ex : ((MethodSignature) joinPoint.getSignature()).getMethod().getExceptionTypes()) { // Descend all levels down. Throwable cause = e.getCause(); while (cause != null) { if (ex.isAssignableFrom(cause.getClass())) throw cause; cause = cause.getCause(); } if (ex.isAssignableFrom(e.getClass())) throw e; } throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); } }
From source file:org.gridgain.grid.test.aop.aspectj.GridifyJunitAspectJAspect.java
License:GNU General Public License
/** * Executes JUnit3 tests annotated with {@link GridifyTest @GridifyTest} annotation * on the grid.//from w ww .j a v a 2s .co m * * @param joinPoint Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @Around("execution(static junit.framework.Test+ *.suite(..))") public Object gridifyJunit3(ProceedingJoinPoint joinPoint) throws Throwable { Method mtd = ((MethodSignature) joinPoint.getSignature()).getMethod(); GridifyTest ann = mtd.getAnnotation(GridifyTest.class); if (ann == null) { return joinPoint.proceed(); } Test test = (Test) joinPoint.proceed(); TestSuite suite; if (test instanceof TestSuite) { suite = (TestSuite) test; } else { suite = new TestSuite(); suite.addTest(test); } // Pickup class loader of caller code. This is considered as // entire test suite class loader. ClassLoader clsLdr = joinPoint.getSignature().getDeclaringType().getClassLoader(); GridJunit3TestSuite gridSuite = new GridJunit3TestSuite(suite, clsLdr); Properties props = System.getProperties(); // System property is given priority. if (!props.containsKey(GRIDGAIN_TEST_ROUTER.name())) { gridSuite.setRouterClass(ann.routerClass()); } // System property is given priority. if (!props.containsKey(GRIDGAIN_CONFIG.name())) { gridSuite.setConfigurationPath(ann.configPath()); } // System property is given priority. if (!props.containsKey(GRIDGAIN_DISABLED.name())) { gridSuite.setDisabled(ann.disabled()); } // System property is given priority. if (!props.containsKey(GRIDGAIN_TEST_TIMEOUT.name())) { gridSuite.setTimeout(ann.timeout()); } return gridSuite; }
From source file:org.gridgain.grid.test.aop.aspectj.GridifyJunitAspectJAspect.java
License:GNU General Public License
/** * Executes JUnit4 tests annotated with {@link GridifyTest @GridifyTest} annotation * on the grid.//from w w w .j a v a 2s.co m * * @param joinPoint Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @Around("execution(public void (org.junit.runners.Suite).run(org.junit.runner.notification.RunNotifier))" + "&& !cflow(target(org.gridgain.grid.test.junit4.GridJunit4Suite))") public Object gridifyJunit4(ProceedingJoinPoint joinPoint) throws Throwable { Describable suite = (Describable) joinPoint.getTarget(); // We create class with caller class loader, // thus JUnit 4 task will pick up proper class loader. ClassLoader clsLdr = joinPoint.getSignature().getDeclaringType().getClassLoader(); Class<?> cls = Class.forName(suite.getDescription().getDisplayName(), true, clsLdr); if (cls.getAnnotation(GridifyTest.class) != null) { new GridJunit4Suite(cls, clsLdr).run((RunNotifier) joinPoint.getArgs()[0]); return null; } return joinPoint.proceed(); }
From source file:org.grouter.common.logging.MethodLogger.java
License:Apache License
private Object log(ProceedingJoinPoint joinPoint) throws Throwable { log.info("Starting stopwatch"); StopWatch stopWatch = new StopWatch(); stopWatch.start();/*from w ww . j a v a 2s.c om*/ Object[] args = joinPoint.getArgs(); // E.g. public abstract org.grouter.domain.entities.User org.grouter.domain.service.UserService.findById(java.lang.Long) String name = joinPoint.getSignature().toLongString(); StringBuffer sb = new StringBuffer(name + " called with: ["); for (int i = 0; i < args.length; i++) { Object o = args[i]; sb.append(o); sb.append((i == args.length - 1) ? "]" : ", "); } log.info(sb); Object retVal = joinPoint.proceed(); stopWatch.stop(); log.info(" return: " + retVal + ", time: " + stopWatch.getTime()); return retVal; }
From source file:org.hellojavaer.ddal.spring.scan.EnableDBClusterRouteAnnotation.java
License:Apache License
@Around("@annotation(dbClusterRoute)") public Object around(ProceedingJoinPoint joinPoint, DBClusterRoute dbClusterRoute) throws Throwable { try {//ww w . j a v a 2 s. co m DBClusterRouteContext.pushContext(); Object[] args = joinPoint.getArgs(); MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); Method method = methodSignature.getMethod(); MethodBasedSpelExpression expression = expressionCache.get(method); if (expression == null) { synchronized (expressionCache) { expression = expressionCache.get(method); if (expression == null) { expression = new MethodBasedSpelExpression(dbClusterRoute.clusterName(), method); expressionCache.put(method, expression); } } } String targetClusterName = expression.parse(String.class, args); DBClusterRouteContext.setClusterName(targetClusterName); return joinPoint.proceed(args); } finally { DBClusterRouteContext.popContext(); } }
From source file:org.hellojavaer.ddal.spring.scan.EnableShardRouteAnnotation.java
License:Apache License
@Around("@annotation(shardRoute)") public Object around(ProceedingJoinPoint joinPoint, ShardRoute shardRoute) throws Throwable { try {// w w w .j a va 2s .c o m ShardRouteContext.pushContext(); if (shardRoute.scName() != null && shardRoute.scName().length() > 0 // && shardRoute.sdValue() != null && shardRoute.sdValue().length() > 0) { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); Method method = methodSignature.getMethod(); MethodBasedSpelExpression expression = expressionCache.get(method); Object[] args = joinPoint.getArgs(); if (expression == null) { synchronized (expressionCache) { expression = expressionCache.get(method); if (expression == null) { expression = new MethodBasedSpelExpression(shardRoute.sdValue(), method); expressionCache.put(method, expression); } } } Object val = expression.parse(Object.class, args); String[] scNames = shardRoute.scName().split(","); for (String scName : scNames) { ShardRouteContext.setRouteInfo(scName, val); } } else { if ((shardRoute.scName() == null || shardRoute.scName().length() == 0) && (shardRoute.sdValue() == null || shardRoute.sdValue().length() == 0)) { // ok } else { throw new IllegalArgumentException( "scName and sdValue should either both have a non-empty value or both have a empty value"); } } return joinPoint.proceed(joinPoint.getArgs()); } finally { ShardRouteContext.popContext(); } }
From source file:org.hoteia.qalingo.core.aop.cache.CacheManagementAspect.java
License:Apache License
public Object around(ProceedingJoinPoint joinPoint) throws Throwable { Object returnObject = null;/* w w w . j ava 2 s .c o m*/ try { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Class classTarget = signature.getReturnType(); Object[] args = joinPoint.getArgs(); String suffix = ""; FetchPlan askedFetchPlan = null; FetchPlan loadedFetchPlan = null; String cacheType = CACHE_TYPE_MISC; // TOD : Denis : blind le code pour tester les arg differement entre une method get* et find* et autre if (joinPoint.getSignature().toShortString().contains("ById")) { // FIRST ARG IS A LONG FOR THE GET METHOD : SO THIS A GET BY ID cacheType = CACHE_BY_ID; } else if (joinPoint.getSignature().toShortString().contains("ByCode")) { // FIRST ARG IS A STRING FOR THE GET METHOD : SO THIS A GET BY CODE cacheType = CACHE_BY_CODE; } for (int i = 0; i < args.length; i++) { Object arg = args[i]; if (arg instanceof Object[]) { Object[] objects = (Object[]) arg; for (int j = 0; j < objects.length; j++) { Object object = (Object) objects[j]; if (object instanceof FetchPlan) { FetchPlan fetchPlan = (FetchPlan) object; if (fetchPlan != null && !fetchPlan.getFetchModes().isEmpty()) { askedFetchPlan = fetchPlan; } } } } if (arg instanceof RequestData) { RequestData requestData = (RequestData) arg; if (!suffix.endsWith("_")) { suffix = suffix + "_"; } suffix = suffix + requestData.getMarketPlace().getCode() + "_" + requestData.getMarket().getCode() + "_" + requestData.getMarketArea().getCode() + "_" + requestData.getMarketAreaLocalization().getCode() + "_" + requestData.getMarketAreaRetailer().getCode() + "_" + requestData.getMarketAreaCurrency().getCode(); } else if (arg instanceof AbstractEntity) { AbstractEntity argEntity = (AbstractEntity) arg; if (!suffix.endsWith("_")) { suffix = suffix + "_"; } Method[] methods = argEntity.getClass().getMethods(); for (int j = 0; j < methods.length; j++) { Method methodIt = methods[j]; if (methodIt.getName().equals("getId")) { Long id = (Long) methodIt.invoke(argEntity); suffix = suffix + id; } } } else { if (arg != null && !(arg instanceof java.lang.Object[]) && !(arg instanceof AbstractEntity)) { if (!suffix.endsWith("_")) { suffix = suffix + "_"; } suffix = suffix + arg.toString(); } } } String key = null; String cacheName = DEFAULT_CACHE_NAME; if (classTarget != null) { try { Field cacheField = null; Field[] fields = classTarget.getFields(); for (int i = 0; i < fields.length; i++) { Field fieldIt = fields[i]; if (fieldIt.getName().equals(CACHE_NAME)) { cacheField = fieldIt; } } if (cacheField != null) { cacheName = (String) cacheField.get(CACHE_NAME); } } catch (IllegalAccessException e) { if (logger.isDebugEnabled()) { logger.debug("IllegalAccessException code.", e); } } } // CACHE TYPE if (cacheType.equals(CACHE_TYPE_MISC)) { key = joinPoint.getSignature().toShortString() + suffix; if (!cacheName.contains("_misc")) { cacheName = cacheName + "_misc"; } } else if (cacheType.equals(CACHE_BY_CODE)) { // TODO : Denis : utiliser un cache de type cacheName_link_code_id pour avoir l'id en fonction du code key = classTarget.getName() + suffix; cacheName = cacheName + "_link_code_id"; } else { key = classTarget.getName() + suffix; } Cache cache = getCacheManager() != null && StringUtils.isNotEmpty(cacheName) ? getCacheManager().getCache(cacheName) : null; if (cache != null) { if (cache.isKeyInCache(key)) { Element element = cache.get(key); if (element != null && !element.isExpired()) { // WE TEST IF THE FETCH PLAN ARE EQUALS returnObject = element.getObjectValue(); if (returnObject instanceof AbstractEntity) { AbstractEntity entity = (AbstractEntity) returnObject; if (entity.getFetchPlan() != null) { loadedFetchPlan = entity.getFetchPlan(); } if (cacheType.equals(CACHE_BY_ID)) { // ENTITY : UPDATE THE CACHE LINK ID CODE String cacheNameIdCodeLink = cacheName + "_link_code_id"; Cache cacheLinkIdCode = getCacheManager() != null && StringUtils.isNotEmpty(cacheNameIdCodeLink) ? getCacheManager().getCache(cacheNameIdCodeLink) : null; if (cacheLinkIdCode != null) { String newKey = null; String codeValue = null; try { Method[] methods = classTarget.getMethods(); for (int i = 0; i < methods.length; i++) { Method methodIt = methods[i]; if (methodIt.getName().equals("getId")) { Long id = (Long) methodIt.invoke(returnObject); newKey = classTarget.getName() + "_" + id; } if (methodIt.getName().equals("getCode")) { codeValue = (String) methodIt.invoke(returnObject); } if (newKey != null && codeValue != null) { break; } } } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("IllegalAccessException.", e); } } if (newKey != null) { cacheLinkIdCode.put(new Element(newKey, codeValue)); } } } if (cacheType.equals(CACHE_BY_CODE)) { String cacheNameEntityById = cacheName.replace("_link_code_id", ""); Cache cacheEntityById = getCacheManager() != null && StringUtils.isNotEmpty(cacheNameEntityById) ? getCacheManager().getCache(cacheNameEntityById) : null; String newKey = null; Method[] methods = classTarget.getMethods(); for (int i = 0; i < methods.length; i++) { Method methodIt = methods[i]; if (methodIt.getName().equals("getId")) { Long id = (Long) methodIt.invoke(returnObject); newKey = classTarget.getName() + "_" + id; break; } } if (cacheEntityById != null) { if (cacheEntityById.isKeyInCache(newKey)) { Element elementEntityById = cacheEntityById.get(newKey); if (elementEntityById != null && !elementEntityById.isExpired()) { returnObject = elementEntityById.getObjectValue(); } } } } } else if (returnObject instanceof Long) { if (cacheType.equals(CACHE_BY_CODE)) { String cacheNameEntityById = cacheName.replace("_link_code_id", ""); Cache cacheEntityById = getCacheManager() != null && StringUtils.isNotEmpty(cacheNameEntityById) ? getCacheManager().getCache(cacheNameEntityById) : null; String newKey = classTarget.getName() + "_" + returnObject; if (cacheEntityById.isKeyInCache(newKey)) { Element finalElement = cacheEntityById.get(newKey); if (finalElement != null && !finalElement.isExpired()) { // WE WILL TEST IF THE FETCH PLAN ARE EQUALS returnObject = finalElement.getObjectValue(); } } else { // WE RESET THE returnObject WHICH HAS THE LONG VALUE - THIS WILL TRIGGER THE LOAD BY DAO returnObject = null; } } } } } if (returnObject == null) { if (loadedFetchPlan != null) { args = ArrayUtils.add(args, loadedFetchPlan); returnObject = joinPoint.proceed(args); } else { returnObject = joinPoint.proceed(); } if (returnObject != null && cacheType.equals(CACHE_BY_CODE)) { // PUT IN THE RIGHT ENTITY CACHE String cacheNameEntityById = cacheName.replace("_link_code_id", ""); Cache cacheEntityById = getCacheManager() != null && StringUtils.isNotEmpty(cacheNameEntityById) ? getCacheManager().getCache(cacheNameEntityById) : null; String newKey = null; Method[] methods = classTarget.getMethods(); Long value = null; for (int i = 0; i < methods.length; i++) { Method methodIt = methods[i]; if (methodIt.getName().equals("getId")) { Long id = (Long) methodIt.invoke(returnObject); newKey = classTarget.getName() + "_" + id; value = id; break; } } if (cacheEntityById != null) { cacheEntityById.put(new Element(newKey, returnObject)); } cache.put(new Element(key, value)); } else { cache.put(new Element(key, returnObject)); } } else { if (returnObject instanceof AbstractEntity) { AbstractEntity entity = (AbstractEntity) returnObject; if (entity.getFetchPlan() != null) { loadedFetchPlan = entity.getFetchPlan(); } if (askedFetchPlan != null) { if (loadedFetchPlan != null && !loadedFetchPlan.containAllTargetFetchPlans(askedFetchPlan)) { // ENTITY IS LOAD WITHOUT FETCHPLAN - WE RESET THE returnObject TO TRIGGER THE RELOAD WITH THE FETCHPLAN // WE WILL ADD LOADED FETCH PLAN AND ASKED FETCH PLAN TO THE INVOCATED METHOD returnObject = null; } // for (Iterator<SpecificFetchMode> iterator = askedFetchPlan.iterator(); iterator.hasNext();) { // SpecificFetchMode specificFetchMode = (SpecificFetchMode) iterator.next(); // if(loadedFetchPlan == null){ // // ENTITY IS LOAD WITHOUT FETCHPLAN - WE RESET THE returnObject TO TRIGGER THE RELOAD WITH THE FETCHPLAN // returnObject = null; // break; // } else if (!loadedFetchPlan.contains(specificFetchMode)){ // // ENTITY IS LOAD WITH A DIFF FETCHPLAN - WE RESET THE returnObject TO TRIGGER THE RELOAD // returnObject = null; // break; // } // } if (returnObject == null) { if (loadedFetchPlan != null) { for (int i = 0; i < args.length; i++) { Object arg = args[i]; if (arg instanceof Object[]) { Object[] objects = (Object[]) arg; for (int j = 0; j < objects.length; j++) { Object object = (Object) objects[j]; if (object instanceof FetchPlan) { // WE ARE IN THE FETCHPLAN OBJECT ARRAY objects = ArrayUtils.add(objects, entity.getFetchPlan()); args = ArrayUtils.remove(args, i); args = ArrayUtils.add(args, objects); break; } } } } returnObject = joinPoint.proceed(args); } // else { // returnObject = joinPoint.proceed(); // } if (returnObject != null) { if (cacheType.equals(CACHE_BY_CODE)) { // PUT IN THE RIGHT ENTITY CACHE String cacheNameEntityById = cacheName.replace("_link_code_id", ""); Cache cacheEntityById = getCacheManager() != null && StringUtils.isNotEmpty(cacheNameEntityById) ? getCacheManager().getCache(cacheNameEntityById) : null; String newKey = null; Method[] methods = classTarget.getMethods(); Long value = null; for (int i = 0; i < methods.length; i++) { Method methodIt = methods[i]; if (methodIt.getName().equals("getId")) { Long id = (Long) methodIt.invoke(returnObject); newKey = classTarget.getName() + "_" + id; value = id; break; } } if (cacheEntityById != null) { cacheEntityById.put(new Element(newKey, returnObject)); } cache.put(new Element(key, value)); } else { cache.put(new Element(key, returnObject)); } } } } } } } } catch (Exception e) { logger.error("Failed to load datas with Cache AOP!", e); } return returnObject; }
From source file:org.hsweb.web.core.utils.AopUtils.java
License:Apache License
public static final String getMethodName(ProceedingJoinPoint pjp) { StringBuilder methodName = new StringBuilder(pjp.getSignature().getName()).append("("); MethodSignature signature = (MethodSignature) pjp.getSignature(); String[] names = signature.getParameterNames(); Class[] args = signature.getParameterTypes(); for (int i = 0, len = args.length; i < len; i++) { if (i != 0) methodName.append(","); methodName.append(args[i].getSimpleName()).append(" ").append(names[i]); }/*from w w w . ja va 2 s . co m*/ return methodName.append(")").toString(); }