Java Code Examples for org.springframework.data.repository.core.RepositoryMetadata#getDomainType()

The following examples show how to use org.springframework.data.repository.core.RepositoryMetadata#getDomainType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSpringAuditableRepositoryAspect.java    From javers with Apache License 2.0 6 votes vote down vote up
void handleDelete(RepositoryMetadata repositoryMetadata, Object domainObjectOrId) {
        if (isIdClass(repositoryMetadata, domainObjectOrId)) {
            Class<?> domainType = repositoryMetadata.getDomainType();
            if (javers.findSnapshots(QueryBuilder.byInstanceId(domainObjectOrId, domainType).limit(1).build()).size() == 0) {
                return;
            }
            javersCommitAdvice.commitShallowDeleteById(domainObjectOrId, domainType);
        } else if (isDomainClass(repositoryMetadata, domainObjectOrId)) {
            if (javers.findSnapshots(QueryBuilder.byInstance(domainObjectOrId).limit(1).build()).size() == 0) {
                return;
            }
            javersCommitAdvice.commitShallowDelete(domainObjectOrId);
        } else {
            throw new IllegalArgumentException("Domain object or object id expected");
        }
}
 
Example 2
Source File: AclJpaRepositoryFactoryBean.java    From strategy-spring-security-acl with Apache License 2.0 5 votes vote down vote up
private RepositoryQuery wrapQuery(Method method, RepositoryMetadata metadata,
      RepositoryQuery query) {
  if (method.getDeclaredAnnotation(NoAcl.class) != null) {
    // no acl applied here
    return query;
  }
  if (query instanceof PartTreeJpaQuery) {
    query = new AclJpaQuery(method, query, metadata.getDomainType(), em, jpaSpecProvider);
  } else {
    logger.warn(
        "Unsupported query type for method '{}' > ACL Jpa Specification not installed: {}",
        method, query.getClass());
  }
  return query;
}
 
Example 3
Source File: IgniteRepositoryQuery.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param metadata Metadata.
 * @param qry Query.
 * @param mtd Method.
 * @param factory Factory.
 * @param cache Cache.
 */
public IgniteRepositoryQuery(RepositoryMetadata metadata, IgniteQuery qry,
    Method mtd, ProjectionFactory factory, IgniteCache cache) {
    type = metadata.getDomainType();
    this.qry = qry;
    this.cache = cache;
    this.metadata = metadata;
    this.mtd = mtd;
    this.factory = factory;

    returnStgy = calcReturnType(mtd, qry.isFieldQuery());
}
 
Example 4
Source File: IgniteQueryGenerator.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param mtd Method.
 * @param metadata Metadata.
 */
@NotNull public static IgniteQuery generateSql(Method mtd, RepositoryMetadata metadata) {
    PartTree parts = new PartTree(mtd.getName(), metadata.getDomainType());

    StringBuilder sql = new StringBuilder();

    if (parts.isDelete())
        throw new UnsupportedOperationException("DELETE clause is not supported now.");
    else {
        sql.append("SELECT ");

        if (parts.isDistinct())
            throw new UnsupportedOperationException("DISTINCT clause in not supported.");

        if (parts.isCountProjection())
            sql.append("COUNT(1) ");
        else
            sql.append(" * ");
    }

    sql.append("FROM ").append(metadata.getDomainType().getSimpleName());

    if (parts.iterator().hasNext()) {
        sql.append(" WHERE ");

        for (PartTree.OrPart orPart : parts) {
            sql.append("(");
            for (Part part : orPart) {
                handleQueryPart(sql, part);
                sql.append(" AND ");
            }

            sql.delete(sql.length() - 5, sql.length());

            sql.append(") OR ");
        }

        sql.delete(sql.length() - 4, sql.length());
    }

    addSorting(sql, parts.getSort());

    if (parts.isLimiting()) {
        sql.append(" LIMIT ");
        sql.append(parts.getMaxResults().intValue());
    }

    return new IgniteQuery(sql.toString(), parts.isCountProjection(), getOptions(mtd));
}
 
Example 5
Source File: IgniteQueryGenerator.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param mtd      Method.
 * @param metadata Metadata.
 * @return Generated ignite query.
 */
public static IgniteQuery generateSql(Method mtd, RepositoryMetadata metadata) {
    PartTree parts = new PartTree(mtd.getName(), metadata.getDomainType());

    boolean isCountOrFieldQuery = parts.isCountProjection();

    StringBuilder sql = new StringBuilder();

    if (parts.isDelete()) {
        sql.append("DELETE ");

        // For the DML queries aside from SELECT *, they should run over SqlFieldQuery
        isCountOrFieldQuery = true;
    }
    else {
        sql.append("SELECT ");

        if (parts.isDistinct())
            throw new UnsupportedOperationException("DISTINCT clause in not supported.");

        if (isCountOrFieldQuery)
            sql.append("COUNT(1) ");
        else
            sql.append("* ");
    }

    sql.append("FROM ").append(metadata.getDomainType().getSimpleName());

    if (parts.iterator().hasNext()) {
        sql.append(" WHERE ");

        for (PartTree.OrPart orPart : parts) {
            sql.append("(");

            for (Part part : orPart) {
                handleQueryPart(sql, part);
                sql.append(" AND ");
            }

            sql.delete(sql.length() - 5, sql.length());

            sql.append(") OR ");
        }

        sql.delete(sql.length() - 4, sql.length());
    }

    addSorting(sql, parts.getSort());

    if (parts.isLimiting()) {
        sql.append(" LIMIT ");
        sql.append(parts.getMaxResults().intValue());
    }

    return new IgniteQuery(sql.toString(), isCountOrFieldQuery, false, true, getOptions(mtd));
}
 
Example 6
Source File: IgniteRepositoryQuery.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Instantiates a new Ignite repository query.
 *
 * @param ignite                               the ignite
 * @param metadata                             Metadata.
 * @param staticQuery                          Query.
 * @param mtd                                  Method.
 * @param factory                              Factory.
 * @param cache                                Cache.
 * @param staticQueryConfiguration             the query configuration
 * @param queryMethodEvaluationContextProvider the query method evaluation context provider
 */
public IgniteRepositoryQuery(Ignite ignite,
    RepositoryMetadata metadata,
    @Nullable IgniteQuery staticQuery,
    Method mtd,
    ProjectionFactory factory,
    IgniteCache cache,
    @Nullable DynamicQueryConfig staticQueryConfiguration,
    EvaluationContextProvider queryMethodEvaluationContextProvider) {
    this.metadata = metadata;
    this.mtd = mtd;
    this.factory = factory;
    type = metadata.getDomainType();

    this.cache = cache;
    this.ignite = ignite;

    this.staticQueryConfiguration = staticQueryConfiguration;
    this.staticQuery = staticQuery;

    if (this.staticQuery != null)
        staticReturnStgy = calcReturnType(mtd, this.staticQuery.isFieldQuery());
    else
        staticReturnStgy = null;

    expressionParser = new SpelExpressionParser();
    this.queryMethodEvaluationContextProvider = queryMethodEvaluationContextProvider;

    qMethod = getQueryMethod();

    // control projection
    hasDynamicProjection = getQueryMethod().getParameters().hasDynamicProjection();
    hasProjection = hasDynamicProjection || getQueryMethod().getResultProcessor().getReturnedType()
        .isProjecting();

    dynamicProjectionIndex = qMethod.getParameters().getDynamicProjectionIndex();

    returnedDomainClass = getQueryMethod().getReturnedObjectType();

    dynamicQueryConfigurationIndex = getDynamicQueryConfigurationIndex(qMethod);

    // ensure dynamic query configuration param exists if dynamicQuery = true
    if (dynamicQueryConfigurationIndex == -1 && this.staticQuery == null) {
        throw new IllegalStateException(
            "When passing dynamicQuery = true via org.apache.ignite.springdata.repository.config.Query "
                + "annotation, you must provide a non null method parameter of type DynamicQueryConfig");
    }
    // ensure domain class is registered on marshaller to transform row to entity
    registerClassOnMarshaller(((IgniteEx)ignite).context(), type);
}
 
Example 7
Source File: IgniteQueryGenerator.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param mtd      Method.
 * @param metadata Metadata.
 * @return Generated ignite query.
 */
public static IgniteQuery generateSql(Method mtd, RepositoryMetadata metadata) {
    PartTree parts = new PartTree(mtd.getName(), metadata.getDomainType());

    boolean isCountOrFieldQuery = parts.isCountProjection();

    StringBuilder sql = new StringBuilder();

    if (parts.isDelete()) {
        sql.append("DELETE ");

        // For the DML queries aside from SELECT *, they should run over SqlFieldQuery
        isCountOrFieldQuery = true;
    }
    else {
        sql.append("SELECT ");

        if (parts.isDistinct())
            throw new UnsupportedOperationException("DISTINCT clause in not supported.");

        if (isCountOrFieldQuery)
            sql.append("COUNT(1) ");
        else
            sql.append("* ");
    }

    sql.append("FROM ").append(metadata.getDomainType().getSimpleName());

    if (parts.iterator().hasNext()) {
        sql.append(" WHERE ");

        for (PartTree.OrPart orPart : parts) {
            sql.append("(");

            for (Part part : orPart) {
                handleQueryPart(sql, part);
                sql.append(" AND ");
            }

            sql.delete(sql.length() - 5, sql.length());

            sql.append(") OR ");
        }

        sql.delete(sql.length() - 4, sql.length());
    }

    addSorting(sql, parts.getSort());

    if (parts.isLimiting()) {
        sql.append(" LIMIT ");
        sql.append(parts.getMaxResults().intValue());
    }

    return new IgniteQuery(sql.toString(), isCountOrFieldQuery, false, true, getOptions(mtd));
}
 
Example 8
Source File: IgniteRepositoryQuery.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Instantiates a new Ignite repository query.
 *
 * @param ignite                               the ignite
 * @param metadata                             Metadata.
 * @param staticQuery                          Query.
 * @param mtd                                  Method.
 * @param factory                              Factory.
 * @param cache                                Cache.
 * @param staticQueryConfiguration             the query configuration
 * @param queryMethodEvaluationContextProvider the query method evaluation context provider
 */
public IgniteRepositoryQuery(Ignite ignite,
    RepositoryMetadata metadata,
    @Nullable IgniteQuery staticQuery,
    Method mtd,
    ProjectionFactory factory,
    IgniteCache cache,
    @Nullable DynamicQueryConfig staticQueryConfiguration,
    QueryMethodEvaluationContextProvider queryMethodEvaluationContextProvider) {
    this.metadata = metadata;
    this.mtd = mtd;
    this.factory = factory;
    type = metadata.getDomainType();

    this.cache = cache;
    this.ignite = ignite;

    this.staticQueryConfiguration = staticQueryConfiguration;
    this.staticQuery = staticQuery;

    if (this.staticQuery != null)
        staticReturnStgy = calcReturnType(mtd, this.staticQuery.isFieldQuery());
    else
        staticReturnStgy = null;

    expressionParser = new SpelExpressionParser();
    this.queryMethodEvaluationContextProvider = queryMethodEvaluationContextProvider;

    qMethod = getQueryMethod();

    // control projection
    hasDynamicProjection = getQueryMethod().getParameters().hasDynamicProjection();
    hasProjection = hasDynamicProjection || getQueryMethod().getResultProcessor().getReturnedType()
        .isProjecting();

    dynamicProjectionIndex = qMethod.getParameters().getDynamicProjectionIndex();

    returnedDomainClass = getQueryMethod().getReturnedObjectType();

    dynamicQueryConfigurationIndex = getDynamicQueryConfigurationIndex(qMethod);

    // ensure dynamic query configuration param exists if dynamicQuery = true
    if (dynamicQueryConfigurationIndex == -1 && this.staticQuery == null) {
        throw new IllegalStateException(
            "When passing dynamicQuery = true via org.apache.ignite.springdata.repository.config.Query "
                + "annotation, you must provide a non null method parameter of type DynamicQueryConfig");
    }
    // ensure domain class is registered on marshaller to transform row to entity
    registerClassOnMarshaller(((IgniteEx)ignite).context(), type);
}