Java Code Examples for javax.jdo.Query#setParameters()

The following examples show how to use javax.jdo.Query#setParameters() . 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: QueryManager.java    From dependency-track with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a List of Finding objects for the specified project.
 * @param project the project to retrieve findings for
 * @return a List of Finding objects
 */
@SuppressWarnings("unchecked")
public List<Finding> getFindings(Project project) {
    final Query query = pm.newQuery(JDOQuery.SQL_QUERY_LANGUAGE, Finding.QUERY);
    query.setParameters(project.getId());
    final List<Object[]> list = query.executeList();
    final List<Finding> findings = new ArrayList<>();
    for (final Object[] o: list) {
        final Finding finding = new Finding(project.getUuid(), o);
        final Component component = getObjectByUuid(Component.class, (String)finding.getComponent().get("uuid"));
        final Vulnerability vulnerability = getObjectByUuid(Vulnerability.class, (String)finding.getVulnerability().get("uuid"));
        final Analysis analysis = getAnalysis(null, component, vulnerability);
        if (analysis == null || !analysis.isSuppressed()) { // do not add globally suppressed findings
            // These are CLOB fields. Handle these here so that database-specific deserialization doesn't need to be performed (in Finding)
            finding.getVulnerability().put("description", vulnerability.getDescription());
            finding.getVulnerability().put("recommendation", vulnerability.getRecommendation());
            findings.add(finding);
        }
    }
    return findings;
}
 
Example 2
Source File: MyApp.java    From tutorials with MIT License 5 votes vote down vote up
public static void queryUsingSQL() {

        Query query = pm.newQuery("javax.jdo.query.SQL", "select * from " + "product_item where price < ? and status = ?");
        query.setClass(ProductItem.class);
        query.setParameters(10, "InStock");
        List<ProductItem> results = query.executeList();

    }
 
Example 3
Source File: MyApp.java    From tutorials with MIT License 3 votes vote down vote up
public static void queryUsingJDOQL() {

        Query query = pm.newQuery("SELECT FROM com.baeldung.libraries.jdo.query.ProductItem " + "WHERE price < threshold PARAMETERS double threshold");
        List<ProductItem> explicitParamResults = (List<ProductItem>) query.execute(10);

        query = pm.newQuery("SELECT FROM " + "com.baeldung.libraries.jdo.query.ProductItem WHERE price < :threshold");
        query.setParameters("double threshold");
        List<ProductItem> explicitParamResults2 = (List<ProductItem>) query.execute(10);

        query = pm.newQuery("SELECT FROM " + "com.baeldung.libraries.jdo.query.ProductItem WHERE price < :threshold");
        List<ProductItem> implicitParamResults = (List<ProductItem>) query.execute(10);

    }