Skip Headers

# Using Java

Previous

Next

To configure named queries in Java, use a descriptor amendment method (see "Configuring Amendment Methods"). Example: Creating a Named Query with an Amendment Method illustrates an amendment method that creates a named query and adds it to the `DescriptorQueryManager`.

Creating a Named Query with an Amendment Method

    public class EmployeeAmmendmentMethodClass {
    ....
        // Create named query with Employee as its reference class
        public static void createEmployeeQuery(ClassDescriptor descriptor) {
            ReadObjectQuery query = new ReadObjectQuery(Employee.class);
            ExpressionBuilder emp = query.getExpressionBuilder();
            Expression firstNameExpression =             emp.get("firstName").equal(emp.getParameter("firstName"));
            query.setSelectionCriteria(firstNameExpression);
            query.addArgument("firstName");

            descriptor.getQueryManager().addQuery(
                "employeeReadByFirstName", query);
        }
    }