use of sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl in project RestyPass by darren-fu.
the class DefaultRestyCommand method isAsyncCommand.
/**
* 是否是异步请求
*
* @return 是异步:true, 不是异步请求:false
*/
private boolean isAsyncCommand() {
Type returnType = this.getReturnType();
this.asyncFutureReturn = false;
this.asyncFutureArg = false;
if (returnType instanceof ParameterizedTypeImpl) {
// 返回类型是Future
ParameterizedTypeImpl returnParameterType = (ParameterizedTypeImpl) returnType;
if ((returnParameterType.getRawType() == Future.class || returnParameterType.getRawType() == RestyFuture.class) && returnParameterType.getActualTypeArguments() != null && returnParameterType.getActualTypeArguments().length > 0) {
// 替换return type: Future<User> -> User
this.returnType = returnParameterType.getActualTypeArguments()[0];
this.asyncFutureReturn = true;
return true;
}
}
RestyFuture futureArg = getFutureArg(this);
if (futureArg != null) {
/**
* Future类型出参
* command执行的时候处理此类异步,将执行结果future放入futureArg中
* @see DefaultRestyCommand#start
*/
this.asyncFutureArg = true;
return true;
}
return false;
}
use of sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl in project conductor by Netflix.
the class WorkflowClientTest method testSearch.
@Test
public void testSearch() {
ClientResponse clientResponse = mock(ClientResponse.class);
SearchResult<WorkflowSummary> workflowSearchResult = new SearchResult<>();
workflowSearchResult.setTotalHits(1);
WorkflowSummary workflowSummary = new WorkflowSummary(new Workflow());
workflowSearchResult.setResults(Collections.singletonList(workflowSummary));
when(clientResponse.getEntity(argThat((GenericType<SearchResult<WorkflowSummary>> type) -> ((ParameterizedTypeImpl) type.getType()).getRawType().equals(SearchResult.class) && ((ParameterizedTypeImpl) type.getType()).getActualTypeArguments()[0].equals(WorkflowSummary.class)))).thenReturn(workflowSearchResult);
when(clientHandler.handle(argThat(argument -> argument.getURI().equals(URI.create("http://myuri:8080/workflow/search?query=my_complex_query"))))).thenReturn(clientResponse);
SearchResult<WorkflowSummary> searchResult = workflowClient.search("my_complex_query");
assertEquals(1, searchResult.getTotalHits());
assertEquals(Collections.singletonList(workflowSummary), searchResult.getResults());
}
use of sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl in project cdmlib by cybertaxonomy.
the class AdvancedBeanInitializer method bulkLoadLazyCollections.
/**
* Loads all lazy collections added to the node and empty the lazy collections collection of the node.
* Lazy beans are initialized elsewhere: {@link #bulkLoadLazyBeans(BeanInitNode)}
* @param node the {@link BeanInitNode} to load the lazy beans for
*/
private void bulkLoadLazyCollections(BeanInitNode node) {
for (Class<?> ownerClazz : node.getLazyCollections().keySet()) {
Map<String, Set<Serializable>> lazyParams = node.getLazyCollections().get(ownerClazz);
for (String param : lazyParams.keySet()) {
Set<Serializable> idSet = lazyParams.get(param);
if (idSet != null && !idSet.isEmpty()) {
if (logger.isTraceEnabled()) {
logger.trace("bulk load " + node + " collections ; ownerClass=" + ownerClazz.getSimpleName() + " ; param = " + param);
}
Type collectionEntitiyType = null;
PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(ownerClazz);
for (PropertyDescriptor d : descriptors) {
if (d.getName().equals(param)) {
Method readMethod = d.getReadMethod();
ParameterizedType pt = (ParameterizedType) readMethod.getGenericReturnType();
Type[] actualTypeArguments = pt.getActualTypeArguments();
if (actualTypeArguments.length == 2) {
// this must be a map of <Language, String> (aka LanguageString) there is no other case like this in the cdm
// in case of Maps the returned Collection will be the Collection of the values, so collectionEntitiyType is the
// second typeArgument
collectionEntitiyType = actualTypeArguments[1];
} else {
collectionEntitiyType = actualTypeArguments[0];
}
if (collectionEntitiyType instanceof TypeVariable) {
collectionEntitiyType = ((TypeVariable) collectionEntitiyType).getBounds()[0];
}
}
}
// TODO use entity name ??
// get from repository
List<Object[]> list;
String hql = "SELECT oc " + " FROM %s as oc LEFT JOIN FETCH oc.%s as col %s" + " WHERE oc.id IN (:idSet) ";
if (collectionEntitiyType instanceof ParameterizedTypeImpl) {
collectionEntitiyType = ((ParameterizedTypeImpl) collectionEntitiyType).getRawType();
}
AutoInit autoInit = addAutoinitFetchLoading((Class<?>) collectionEntitiyType, "col");
hql = String.format(hql, ownerClazz.getSimpleName(), param, autoInit.leftJoinFetch);
try {
if (logger.isTraceEnabled()) {
logger.trace(hql);
}
Query query = genericDao.getHqlQuery(hql);
query.setParameterList("idSet", idSet);
list = query.list();
if (logger.isTraceEnabled()) {
logger.trace("size of retrieved list is " + list.size());
}
} catch (HibernateException e) {
e.printStackTrace();
throw e;
}
// getTarget and add to child node
if (logger.isTraceEnabled()) {
logger.trace("initialize bulk loaded " + node + " collections - DONE");
}
for (Object parentBean : list) {
try {
Object propValue = PropertyUtils.getProperty(parentBean, mapFieldToPropertyName(param, parentBean.getClass().getSimpleName()));
if (propValue == null) {
logger.trace("Collection is null");
} else {
if (propValue instanceof PersistentMap) {
propValue = ((PersistentMap) propValue).values();
}
for (Object newBean : (Collection<Object>) propValue) {
if (newBean instanceof HibernateProxy) {
newBean = initializeInstance(newBean);
}
if (HibernateProxyHelper.isInstanceOf(newBean, CdmBase.class)) {
autoinitializeBean((CdmBase) newBean, autoInit);
}
node.addBean(newBean);
}
}
} catch (Exception e) {
// TODO better throw an exception ?
logger.error("error while getting collection property", e);
}
}
if (logger.isTraceEnabled()) {
logger.trace("bulk load " + node + " collections - DONE");
}
}
}
}
for (AbstractPersistentCollection collection : node.getUninitializedCollections()) {
if (!collection.wasInitialized()) {
// should not happen anymore
collection.forceInitialization();
if (logger.isTraceEnabled()) {
logger.trace("forceInitialization of collection " + collection);
}
} else {
if (logger.isTraceEnabled()) {
logger.trace("collection " + collection + " is initialized - OK!");
}
}
}
node.resetLazyCollections();
}
use of sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl in project conductor by Netflix.
the class WorkflowClientTest method testSearchV2.
@Test
public void testSearchV2() {
ClientResponse clientResponse = mock(ClientResponse.class);
SearchResult<Workflow> workflowSearchResult = new SearchResult<>();
workflowSearchResult.setTotalHits(1);
Workflow workflow = new Workflow();
workflowSearchResult.setResults(Collections.singletonList(workflow));
when(clientResponse.getEntity(argThat((GenericType<SearchResult<Workflow>> type) -> ((ParameterizedTypeImpl) type.getType()).getRawType().equals(SearchResult.class) && ((ParameterizedTypeImpl) type.getType()).getActualTypeArguments()[0].equals(Workflow.class)))).thenReturn(workflowSearchResult);
when(clientHandler.handle(argThat(argument -> argument.getURI().equals(URI.create("http://myuri:8080/workflow/search-v2?query=my_complex_query"))))).thenReturn(clientResponse);
SearchResult<Workflow> searchResult = workflowClient.searchV2("my_complex_query");
assertEquals(1, searchResult.getTotalHits());
assertEquals(Collections.singletonList(workflow), searchResult.getResults());
}
use of sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl in project conductor by Netflix.
the class WorkflowClientTest method testSearchWithParams.
@Test
public void testSearchWithParams() {
ClientResponse clientResponse = mock(ClientResponse.class);
SearchResult<WorkflowSummary> workflowSearchResult = new SearchResult<>();
workflowSearchResult.setTotalHits(1);
WorkflowSummary workflowSummary = new WorkflowSummary(new Workflow());
workflowSearchResult.setResults(Collections.singletonList(workflowSummary));
when(clientResponse.getEntity(argThat((GenericType<SearchResult<WorkflowSummary>> type) -> ((ParameterizedTypeImpl) type.getType()).getRawType().equals(SearchResult.class) && ((ParameterizedTypeImpl) type.getType()).getActualTypeArguments()[0].equals(WorkflowSummary.class)))).thenReturn(workflowSearchResult);
when(clientHandler.handle(argThat(argument -> argument.getURI().equals(URI.create("http://myuri:8080/workflow/search?start=0&size=10&sort=sort&freeText=text&query=my_complex_query"))))).thenReturn(clientResponse);
SearchResult<WorkflowSummary> searchResult = workflowClient.search(0, 10, "sort", "text", "my_complex_query");
assertEquals(1, searchResult.getTotalHits());
assertEquals(Collections.singletonList(workflowSummary), searchResult.getResults());
}
Aggregations