本文整理了Java中org.bonitasoft.engine.bdm.model.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:org.bonitasoft.engine.bdm.model.Query
类名称:Query
暂无
代码示例来源:origin: bonitasoft/bonita-engine
public BusinessObjectBuilder withQuery(final Query query) {
final Query addQuery = businessObject.addQuery(query.getName(), query.getContent(), query.getReturnType());
for (final QueryParameter qP : query.getQueryParameters()) {
addQuery.addQueryParameter(qP.getName(), qP.getClassName());
}
return this;
}
代码示例来源:origin: bonitasoft/bonita-engine
private Class<? extends Serializable> getQueryReturnType(final Query queryDefinition, final String entityClassName)
throws SBusinessDataRepositoryException {
if (queryDefinition.hasMultipleResults()) {
return loadClass(entityClassName);
}
try {
return (Class<? extends Serializable>) Thread.currentThread().getContextClassLoader().loadClass(queryDefinition.getReturnType());
} catch (final ClassNotFoundException e) {
throw new SBusinessDataRepositoryException("unable to load class " + queryDefinition.getReturnType());
}
}
代码示例来源:origin: bonitasoft/bonita-engine
@Override
public Query createQueryForLazyField(BusinessObject businessObject, RelationField relationField) {
checkObjectIsNotNull(relationField, "relationField cannot be null");
final String name = createQueryNameForLazyField(businessObject, relationField);
final String content = createQueryContentForLazyField(businessObject.getQualifiedName(), relationField);
final Query q = new Query(name, content, relationField.getReference().getQualifiedName());
if (relationField.isCollection()) {
q.setReturnType(List.class.getName());
}
q.addQueryParameter(Field.PERSISTENCE_ID, Long.class.getName());
return q;
}
代码示例来源:origin: bonitasoft/bonita-engine
private Query findRelatedCountQuery(Query baseQuery, List<Query> queryList) {
Query countQuery = null;
Iterator<Query> iterator = queryList.iterator();
while (iterator.hasNext() && countQuery == null) {
Query currentQuery = iterator.next();
if (Long.class.getName().equals(currentQuery.getReturnType())
&& currentQuery.getName().equals(BDMQueryUtil.getCountQueryName(baseQuery.getName()))) {
countQuery = currentQuery;
}
}
return countQuery;
}
代码示例来源:origin: bonitasoft/bonita-engine
protected JMethod createMethodForQuery(final JDefinedClass entity, final JDefinedClass targetClass, final Query query) {
final String methodName = query.getName();
final JMethod queryMethod = createQueryMethod(entity, targetClass, methodName, query.getReturnType());
for (final QueryParameter param : query.getQueryParameters()) {
queryMethod.param(getModel().ref(param.getClassName()), param.getName());
}
addOptionalPaginationParameters(queryMethod, query);
return queryMethod;
}
代码示例来源:origin: bonitasoft/bonita-engine
private static boolean containsQueryWithName(final BusinessObject businessObject, final String queryName) {
for (final Query q : businessObject.getQueries()) {
if (Objects.equals(queryName, q.getName())) {
return true;
}
}
return false;
}
代码示例来源:origin: bonitasoft/bonita-engine
@Override
public ValidationStatus validate(final Query query) {
final ValidationStatus status = new ValidationStatus();
final String name = query.getName();
if (name == null || name.isEmpty()) {
status.addError(StatusCode.QUERY_WITHOUT_NAME, "A query must have name");
return status;
}
if (!SourceVersion.isIdentifier(name)) {
status.addError(StatusCode.INVALID_JAVA_IDENTIFIER_NAME,
String.format("%s is not a valid Java identifier.", name),
Collections.singletonMap(StatusContext.BDM_ARTIFACT_NAME_KEY, name));
}
if (name.length() > MAX_QUERY_NAME_LENGTH) {
status.addError(StatusCode.QUERY_NAME_LENGTH_TO_HIGH,
String.format("%s length must be lower than 150 characters.", name),
Collections.singletonMap(StatusContext.BDM_ARTIFACT_NAME_KEY, name));
}
if (query.getContent() == null || query.getContent().isEmpty()) {
status.addError(StatusCode.QUERY_WITHOUT_CONTENT,
String.format("%s query must have a content defined", name),
Collections.singletonMap(StatusContext.BDM_ARTIFACT_NAME_KEY, name));
}
if (query.getReturnType() == null || query.getReturnType().isEmpty()) {
status.addError(StatusCode.QUERY_WITHOUT_RETURN_TYPE,
String.format("%s query must have a return type defined", name),
Collections.singletonMap(StatusContext.BDM_ARTIFACT_NAME_KEY, name));
}
return status;
}
代码示例来源:origin: bonitasoft/bonita-engine
private Map<String, Serializable> getQueryParameters(final Query queryDefinition, final Map<String, Serializable> parameters)
throws SBusinessDataRepositoryException {
final Set<String> errors = new HashSet<>();
final Map<String, Serializable> queryParameters = new HashMap<>();
for (final QueryParameter queryParameter : queryDefinition.getQueryParameters()) {
if (parameters != null && parameters.containsKey(queryParameter.getName())) {
queryParameters.put(queryParameter.getName(),
convertToType(loadSerializableClass(queryParameter.getClassName()), parameters.get(queryParameter.getName())));
} else {
errors.add(queryParameter.getName());
}
}
if (!errors.isEmpty()) {
final StringBuilder errorMessage = new StringBuilder().append("parameter(s) are missing for query named ").append(queryDefinition.getName())
.append(" : ");
errorMessage.append(StringUtils.join(errors, ","));
throw new SBusinessDataRepositoryException(errorMessage.toString());
}
return queryParameters;
}
代码示例来源:origin: bonitasoft/bonita-engine
private void addQueriesAnnotation(final BusinessObject bo, final JDefinedClass entityClass) {
final JAnnotationUse namedQueriesAnnotation = codeGenerator.addAnnotation(entityClass, NamedQueries.class);
final JAnnotationArrayMember valueArray = namedQueriesAnnotation.paramArray("value");
// Add provided queries
for (final Query providedQuery : BDMQueryUtil.createProvidedQueriesForBusinessObject(bo)) {
addNamedQuery(entityClass, valueArray, providedQuery.getName(), providedQuery.getContent());
}
// Add method for lazy fields
for (final Query query : BDMQueryUtil.createProvidedQueriesForLazyField(bom, bo)) {
addNamedQuery(entityClass, valueArray, query.getName(), query.getContent());
}
// Add custom queries
for (final Query query : bo.getQueries()) {
addNamedQuery(entityClass, valueArray, query.getName(), query.getContent());
}
}
代码示例来源:origin: bonitasoft/bonita-engine
@Override
public Query createQueryForField(BusinessObject businessObject, Field field) {
checkObjectIsNotNull(field, "field cannot be null");
checkFieldIsNotACollection(field);
final Query query = new Query(createQueryNameForField(field),
createQueryContentForField(businessObject.getQualifiedName(), field), getListReturnType());
if (field instanceof SimpleField) {
query.addQueryParameter(field.getName(), ((SimpleField) field).getType().getClazz().getName());
}
return query;
}
代码示例来源:origin: bonitasoft/bonita-engine
/**
* Verifies that the actual Query has no queryParameters.
* @return this assertion object.
* @throws AssertionError if the actual Query's queryParameters is not empty.
*/
public QueryAssert hasNoQueryParameters() {
// check that actual Query we want to make assertions on is not null.
isNotNull();
// we override the default error message with a more explicit one
String assertjErrorMessage = "\nExpected :\n <%s>\nnot to have queryParameters but had :\n <%s>";
// check
if (actual.getQueryParameters().iterator().hasNext()) {
failWithMessage(assertjErrorMessage, actual, actual.getQueryParameters());
}
// return the current assertion for method chaining
return this;
}
代码示例来源:origin: bonitasoft/bonita-engine
/**
* Verifies that the actual Query's returnType is equal to the given one.
* @param returnType the given returnType to compare the actual Query's returnType to.
* @return this assertion object.
* @throws AssertionError - if the actual Query's returnType is not equal to the given one.
*/
public QueryAssert hasReturnType(String returnType) {
// check that actual Query we want to make assertions on is not null.
isNotNull();
// overrides the default error message with a more explicit one
String assertjErrorMessage = "\nExpected returnType of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
// null safe check
String actualReturnType = actual.getReturnType();
if (!Objects.areEqual(actualReturnType, returnType)) {
failWithMessage(assertjErrorMessage, actual, returnType, actualReturnType);
}
// return the current assertion for method chaining
return this;
}
代码示例来源:origin: bonitasoft/bonita-engine
public Query getCountQueryDefinition(BusinessObject businessObject, Query baseQuery) {
if (!baseQuery.hasMultipleResults()) {
return null;
}
List<Query> queries = new ArrayList<>();
queries.addAll(BDMQueryUtil.createCountProvidedQueriesForBusinessObject(businessObject));
queries.addAll(businessObject.getQueries());
return findRelatedCountQuery(baseQuery, queries);
}
代码示例来源:origin: bonitasoft/bonita-engine
public QueryBuilder withQueryParameter(final String name, final String className) {
query.addQueryParameter(name, className);
return this;
}
代码示例来源:origin: bonitasoft/bonita-engine
/**
* Verifies that the actual Query's content is equal to the given one.
* @param content the given content to compare the actual Query's content to.
* @return this assertion object.
* @throws AssertionError - if the actual Query's content is not equal to the given one.
*/
public QueryAssert hasContent(String content) {
// check that actual Query we want to make assertions on is not null.
isNotNull();
// overrides the default error message with a more explicit one
String assertjErrorMessage = "\nExpected content of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
// null safe check
String actualContent = actual.getContent();
if (!Objects.areEqual(actualContent, content)) {
failWithMessage(assertjErrorMessage, actual, content, actualContent);
}
// return the current assertion for method chaining
return this;
}
代码示例来源:origin: bonitasoft/bonita-engine
public QueryBuilder withReturnType(final String className) {
query.setReturnType(className);
return this;
}
代码示例来源:origin: bonitasoft/bonita-engine
public Query addQuery(final String name, final String queryContent, final String returnType) {
final Query query = new Query(name, queryContent, returnType);
queries.add(query);
return query;
}
代码示例来源:origin: bonitasoft/bonita-engine
protected JMethod createMethodForQuery(final JDefinedClass entity, final JDefinedClass targetClass, final Query query) {
final String methodName = query.getName();
final JMethod queryMethod = createQueryMethod(entity, targetClass, methodName, query.getReturnType());
for (final QueryParameter param : query.getQueryParameters()) {
queryMethod.param(getModel().ref(param.getClassName()), param.getName());
}
addOptionalPaginationParameters(queryMethod, query);
return queryMethod;
}
代码示例来源:origin: bonitasoft/bonita-engine
private static boolean containsQueryWithName(final BusinessObject businessObject, final String queryName) {
for (final Query q : businessObject.getQueries()) {
if (Objects.equals(queryName, q.getName())) {
return true;
}
}
return false;
}
代码示例来源:origin: bonitasoft/bonita-engine
@Override
public ValidationStatus validate(final Query query) {
final ValidationStatus status = new ValidationStatus();
final String name = query.getName();
if (name == null || name.isEmpty()) {
status.addError(StatusCode.QUERY_WITHOUT_NAME, "A query must have name");
return status;
}
if (!SourceVersion.isIdentifier(name)) {
status.addError(StatusCode.INVALID_JAVA_IDENTIFIER_NAME,
String.format("%s is not a valid Java identifier.", name),
Collections.singletonMap(StatusContext.BDM_ARTIFACT_NAME_KEY, name));
}
if (name.length() > MAX_QUERY_NAME_LENGTH) {
status.addError(StatusCode.QUERY_NAME_LENGTH_TO_HIGH,
String.format("%s length must be lower than 150 characters.", name),
Collections.singletonMap(StatusContext.BDM_ARTIFACT_NAME_KEY, name));
}
if (query.getContent() == null || query.getContent().isEmpty()) {
status.addError(StatusCode.QUERY_WITHOUT_CONTENT,
String.format("%s query must have a content defined", name),
Collections.singletonMap(StatusContext.BDM_ARTIFACT_NAME_KEY, name));
}
if (query.getReturnType() == null || query.getReturnType().isEmpty()) {
status.addError(StatusCode.QUERY_WITHOUT_RETURN_TYPE,
String.format("%s query must have a return type defined", name),
Collections.singletonMap(StatusContext.BDM_ARTIFACT_NAME_KEY, name));
}
return status;
}
内容来源于网络,如有侵权,请联系作者删除!