List of usage examples for org.aspectj.lang ProceedingJoinPoint proceed
public Object proceed() throws Throwable;
From source file:com.newmainsoftech.spray.slingong.datastore.testmodel.book.AuthorAspect.java
License:Apache License
@Around("createNewAuthorPointcut()") public void aroundCreateNewAuthor(ProceedingJoinPoint proceedingJoinPoint) { Object[] argsArray = proceedingJoinPoint.getArgs(); String name = (String) argsArray[0]; if ((name == null) || "".equals(name)) { String message = "".equals(name) ? "Value of name property of Author entity cannot be empty string." : "Value of name property of Author entity cannot be null."; if (logger.isErrorEnabled()) { logger.error(message);//w ww . j av a 2s .c o m } throw new RuntimeException(message); } try { proceedingJoinPoint.proceed(); } catch (Throwable throwable) { Throwable cause = throwable.getCause(); if (cause == null) { cause = throwable; } if (logger.isErrorEnabled()) { logger.error("Failure at Author.createNewAuthor method", cause); } throw new RuntimeException(cause); } }
From source file:com.newtranx.util.mysql.fabric.SpringMybatisSetQueryTablesAspect.java
License:Apache License
@Around("@annotation(com.newtranx.util.mysql.fabric.QueryTables)") public Object setQueryTables(ProceedingJoinPoint pjp) throws Throwable { try {//ww w . j av a 2 s. co m Method method = AspectJUtils.getMethod(pjp); QueryTables qtAnnotation = method.getAnnotation(QueryTables.class); FabricMySQLConnection connection = (FabricMySQLConnection) sqlSession.getConnection(); if ((connection.getQueryTables().isEmpty() && connection.getShardTable() == null) || qtAnnotation.reset()) { connection.clearServerSelectionCriteria(); String[] tables = qtAnnotation.value(); log.debug("Setting queryTables=" + Arrays.toString(tables)); log.debug("Thread=" + Thread.currentThread() + ", conn=" + connection); if (qtAnnotation.useFirst()) { log.debug("Use setShardTable with first query table instead"); connection.setShardTable(tables[0]); log.debug("New shardTable set"); } else { for (String table : tables) connection.addQueryTable(table); log.debug("New queryTables set"); } } else { log.debug("Keep original queryTables"); } log.debug("QueryTables=" + connection.getQueryTables() + ", shardTable=" + connection.getShardTable()); } catch (Exception e) { e.printStackTrace(System.err); throw e; } return pjp.proceed(); }
From source file:com.newtranx.util.mysql.fabric.SpringMybatisSetShardKeyAspect.java
License:Apache License
@Around("@annotation(com.newtranx.util.mysql.fabric.WithShardKey) || @within(com.newtranx.util.mysql.fabric.WithShardKey)") public Object setShardKey(ProceedingJoinPoint pjp) throws Throwable { Method method = AspectJUtils.getMethod(pjp); String key = null;/*from w ww . j av a 2 s. c o m*/ boolean force = method.getAnnotation(WithShardKey.class).force(); int i = 0; for (Parameter p : method.getParameters()) { ShardKey a = p.getAnnotation(ShardKey.class); if (a != null) { if (key != null) throw new RuntimeException("found multiple shardkey"); Object obj = pjp.getArgs()[i]; if (StringUtils.isEmpty(a.property())) key = obj.toString(); else { BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(obj); key = bw.getPropertyValue(a.property()).toString(); } } i++; } if (key == null) throw new RuntimeException("can not find shardkey"); fabricShardKey.set(key, force); return pjp.proceed(); }
From source file:com.newtranx.util.mysql.fabric.SpringQueryAllShardsAspect.java
License:Apache License
@Around("@annotation(com.newtranx.util.mysql.fabric.QueryAllShards)") public Object union(ProceedingJoinPoint pjp) throws Throwable { Method method = AspectJUtils.getMethod(pjp); QueryAllShards annotation = method.getAnnotation(QueryAllShards.class); String table = annotation.table(); log.debug("Table=" + table); Set<String> groups = groupsCache.get(cacheKey); log.debug("ServerGroups=" + groups); List<Object> list; boolean readOnly = annotation.readOnly(); Pattern excludePattern;//w ww .ja va2 s .c om String excludeRegex = annotation.excludeShardsPatternRegex(); if (!StringUtils.isEmpty(excludeRegex)) { excludePattern = Pattern.compile(excludeRegex); } else { excludePattern = null; } Function<Boolean, List<Object>> computeFunction = (par) -> { Stream<String> stream = groups.stream(); if (par) stream = stream.parallel(); return stream.filter(gp -> { boolean exclude = excludePattern != null && excludePattern.matcher(gp).matches(); if (exclude) { log.debug("Skipping group:" + gp); } return !exclude; }).map(gp -> { log.debug("Querying group: " + gp); ds.whenNewConnection().doInit(conn -> conn.setServerGroupName(gp)) .doInit(conn -> conn.setReadOnly(readOnly)); try { return pjp.proceed(); } catch (Throwable t) { throw Exceptions.propagate(t); } finally { ds.clearInitOps(); } }).collect(Collectors.toList()); }; if (StringUtils.isEmpty(annotation.parallelPool())) { list = computeFunction.apply(false); } else { ForkJoinPool pool; if ("!jdkCommon".equals(annotation.parallelPool())) pool = ForkJoinPool.commonPool(); else pool = applicationContext.getBean(annotation.parallelPool(), ForkJoinPool.class); log.debug("Executing queries in parallel, pool=" + pool); list = pool.submit(() -> { return computeFunction.apply(true); }).get(); } Aggregator aggregator; try { aggregator = (Aggregator) annotation.aggregator().getDeclaredMethod("getInstance", EMPTY_PARAM) .invoke(null, EMPTY_ARGS); } catch (Exception e) { log.warn("Can not get singleton for class " + annotation.aggregator().getName() + ", creating new instance"); aggregator = annotation.aggregator().newInstance(); } return aggregator.apply(list); }
From source file:com.ocs.dynamo.aop.AuditAspect.java
License:Apache License
/** * intercept the save method of an auditable entity * /*from w w w . ja v a 2 s.c o m*/ * @param joinPoint * the join point * @param entity * the entity that is being saved * @return * @throws Throwable */ @Around("anySaveMethod() && args(entity)") public Object auditSave(ProceedingJoinPoint joinPoint, AbstractAuditableEntity<?> entity) throws Throwable { setAuditFields(entity); return joinPoint.proceed(); }
From source file:com.onboard.service.activity.impl.ActivityRecorderImpl.java
License:Apache License
/** * // w w w. j a v a 2 s.c o m * * @param item * */ @Override public Object recordUpdateActivity(ProceedingJoinPoint joinpoint) { BaseProjectItem original = (BaseProjectItem) joinpoint.getArgs()[0]; if (original == null) { return null; } ActivityGenerator activityGenerator = activityGenerators.get(original.getType()); if (activityGenerator != null) { original = activityGenerator.enrichModel(original); } try { BaseProjectItem updated = (BaseProjectItem) joinpoint.proceed(); if (activityGenerator != null) { // updated updated = activityGenerator.enrichModel(updated); Activity activity = activityGenerator.generateUpdateActivity(original, updated); if (activity != null) { activity = this.enrichActivity(activity); activityMapper.insert(activity); this.callActivityHook(activity, original, updated); } } return updated; } catch (ActivityRecorderException e) { logger.error("Fail to log activity:", e); } catch (Throwable t) { logger.error("Fail to log activity:", t); } return original; }
From source file:com.onboard.service.activity.impl.ActivityRecorderImpl.java
License:Apache License
@Override public Object deleteActivity(ProceedingJoinPoint joinpoint) { Object returnVal = null;//from w w w .j a v a2s. c o m String modelType = null; Class<?>[] serviceTypes = joinpoint.getTarget().getClass().getInterfaces(); for (Class<?> clazz : serviceTypes) { if (service2ModelMap.get(clazz.getName()) != null) { modelType = service2ModelMap.get(clazz.getName()); break; } } if (modelType != null) { Activity activity = new Activity(); activity.setAttachType(modelType); activity.setAttachId((Integer) joinpoint.getArgs()[0]); activityMapper.deleteByExample(new ActivityExample(activity)); /** * TODO delete notifications which reference the activity */ } try { returnVal = joinpoint.proceed(); } catch (Throwable e) { logger.error("fail to delete item: ", e); } return returnVal; }
From source file:com.onboard.service.activity.impl.test.ActivityRecorderImplTest.java
License:Apache License
private ProceedingJoinPoint getASampleProceedingJoinPoint() throws Throwable { ProceedingJoinPoint p = mock(ProceedingJoinPoint.class); when(p.getArgs()).thenReturn(new Object[] { original }); when(p.proceed()).thenReturn(identifiable); ActivityService object = mock(ActivityService.class); when(p.getTarget()).thenReturn(object); return p;/*from w ww. j a v a2s . c om*/ }
From source file:com.onboard.service.index.impl.IndexAspectImpl.java
License:Apache License
@Override public Object deleteByPrimaryKey(ProceedingJoinPoint joinpoint) { Object returnVal = null;//from w w w . j a v a2 s. com //String modelType = joinpoint.getTarget().getClass().getName(); // TODO: get model type from mapper String modelType = ""; IndexableService indexableService = indexableServices.getIndexableService(modelType); try { returnVal = joinpoint.proceed(); if (indexableService != null) { String documentId = this.getDocumentId(indexableService.modelType(), (Integer) joinpoint.getArgs()[0]); indexServices.getIndexService().deleteIndexById(documentId); } } catch (Throwable e) { // TODO ?Activityaround advice? logger.error("fail to update index: ", e); } return returnVal; }
From source file:com.onboard.service.index.impl.IndexAspectImpl.java
License:Apache License
@Override public Object deleteByExample(ProceedingJoinPoint joinpoint) { Object returnVal = null;/* w ww . ja v a 2s . co m*/ //String modelType = joinpoint.getTarget().getClass().getName(); // TODO: get model type from mapper String modelType = ""; IndexableService indexableService = indexableServices.getIndexableService(modelType); List<String> documentIdList = new ArrayList<String>(); if (indexableService != null) { BaseExample example = (BaseExample) joinpoint.getArgs()[0]; List<Indexable> items = indexableService.getIndexablesByExample(example); documentIdList = new ArrayList<String>(); for (Indexable item : items) { documentIdList.add(this.getDocumentId(item.getType(), item.getId())); } } try { returnVal = joinpoint.proceed(); if (!documentIdList.isEmpty()) { indexServices.getIndexService().deleteIndexByIdList(documentIdList); } } catch (Throwable e) { logger.error("fail to update index: ", e); } return returnVal; }