Skip Headers

# Using Java

Previous

Next

The `DescriptorQueryManager` generates default SQL for the following persistence operations:

- Insert

- Update

- Delete

- Read-object

- Read-all

- Does-exist

Using Java code, you can use the descriptor query manager to provide custom SQL strings to perform these functions on a class-by-class basis.

Use `ClassDescriptor` method `getQueryManager` to acquire the `DescriptorQueryManager`, and then use the `DescriptorQueryManager` methods that Table: Descriptor Query Manager Methods for Configuring Custom SQL lists.

Descriptor Query Manager Methods for Configuring Custom SQL

To Change the Default SQL for ... | Use Descriptor Query Manager Method ...
--- | ---
Insert | `setInsertQuery (InsertObjectQuery query)`
| `setInsertSQLString (String sqlString)`
| `setInsertCall(Call call)`
Update | `setUpdateQuery (UpdateObjectQuery query)`
| `setUpdateSQLString (String sqlString)`
| `setUpdateCall(Call call)`
Delete | `setDeleteQuery (DeleteObjectQuery query)`
| `setDeleteSQLString (String sqlString)`
| `setDeleteCall(Call call)`
Read | `setReadObjectQuery (ReadObjectQuery query)`
| `setReadObjectSQLString (String sqlString)`
| `setReadObjectCall(Call call)`
Read all | `setReadAllQuery (ReadAllQuery query)`
| `setReadAllSQLString (String sqlString)`
| `setReadAllCall(Call call)`
Does exist | `setDoesExistQuery(DoesExistQuery query)`
| `setDoesExistSQLString(String sqlString)`
| `setDoesExistCall(Call call)`

Example: Configuring a Descriptor Query Manager with Custom SQL Strings shows how to implement an amendment method to configure a descriptor query manager to use custom SQL strings. Alternatively, using an `SQLCall`, you can specify more complex SQL strings using features such as in, out, and in-out parameters and parameter types (see "Using SQL Calls").

Configuring a Descriptor Query Manager with Custom SQL Strings

    public static void addToDescriptor(ClassDescriptor descriptor) {

        // Read-object by primary key procedure
        descriptor.getQueryManager().setReadObjectSQLString(
            "select * from EMP where EMP_ID = #EMP_ID"
        );

        // Read-all instances procedure
        descriptor.getQueryManager().setReadAllSQLString(
            "select * from EMP"
        );

        // Insert procedure
        descriptor.getQueryManager().setInsertSQLString(
            "insert into EMP (EMP_ID, F_NAME, L_NAME, MGR_ID) values (#EMP_ID, #F_NAME, #L_NAME, #MGR_ID)"
        );

        // Update procedure
        descriptor.getQueryManager().setUpdateSQLString(
            "update EMP set (F_NAME, L_NAME, MGR_ID) values (#F_NAME, #L_NAME, #MGR_ID) where EMP_ID = #EMP_ID"
        );
    }

Example: Configuring a Descriptor Query Manager with Custom Stored Procedure Calls shows how to implement an amendment method to configure a descriptor query manager to use Oracle stored procedures using a `StoredProcedureCall` (see "Using a StoredProcedureCall"). This example uses output cursors to return the result set (see "Handling Cursor and Stream Query Results").

Configuring a Descriptor Query Manager with Custom Stored Procedure Calls

    public static void addToDescriptor(ClassDescriptor descriptor) {

        // Read-object by primary key procedure
        StoredProcedureCall readCall = new StoredProcedureCall();
        readCall.setProcedureName("READ_EMP");
        readCall.addNamedArgument("P_EMP_ID", "EMP_ID");       readCall.useNamedCursorOutputAsResultSet("RESULT_CURSOR");       descriptor.getQueryManager().setReadObjectCall(readCall);

        // Read-all instances procedure
        StoredProcedureCall readAllCall = new StoredProcedureCall();
        readAllCall.setProcedureName("READ_ALL_EMP");
        readAllCall.useNamedCursorOutputAsResultSet("RESULT_CURSOR");         descriptor.getQueryManager().setReadAllCall(readAllCall );

        // Insert procedure
        StoredProcedureCall insertCall = new StoredProcedureCall();
        insertCall.setProcedureName("INSERT_EMP");
        insertCall.addNamedArgument("P_EMP_ID", "EMP_ID");
        insertCall.addNamedArgument("P_F_NAME", "F_NAME");
        insertCall.addNamedArgument("P_L_NAME", "L_NAME");
        insertCall.addNamedArgument("P_MGR_ID", "MGR_ID");
        descriptor.getQueryManager().setInsertCall(insertCall);

        // Update procedure
        StoredProcedureCall updateCall = new StoredProcedureCall();      updateCall.setProcedureName("UPDATE_EMP");
        updateCall.addNamedArgument("P_EMP_ID", "EMP_ID");
        updateCall.addNamedArgument("P_F_NAME", "F_NAME");
        updateCall.addNamedArgument("P_L_NAME", "L_NAME");
        updateCall.addNamedArgument("P_MGR_ID", "MGR_ID");
        descriptor.getQueryManager().setUpdateCall(updateCall);
    }