Skip Headers

# Using Java

Previous

Next

Create a descriptor amendment method ("Configuring Amendment Methods") to customize the root class descriptor's `InheritancePolicy` using `InheritancePolicy` methods `setOnlyInstancesExpression` and `setWithAllSubclassesExpression`, as required.

Example: Configuring Only-Instances Expressions shows amendment methods for the `Person` and `Student` descriptors based on the class hierarchy shown in Figure: Example Inheritance Hierarchy and the database table shown in Figure: PERSON Table.

Configuring Only-Instances Expressions

    ...
    // Only-instances expression for Person
    public static void addToPersonDescriptor(Descriptor descriptor) {
        ExpressionBuilder builder = new ExpressionBuilder();
        descriptor.getInheritancePolicy().setOnlyInstancesExpression(
            builder.getField("STUDENT_NUMBER").isNull()
        );
    }
    // Only-instances expression for Student
    public static void addToStudentDescriptor(Descriptor descriptor) {
        ExpressionBuilder builder = new ExpressionBuilder();
        descriptor.getInheritancePolicy().setOnlyInstancesExpression(
            builder.getField("STUDENT_NUMBER").notNull()
        );
    }
    ...

Example: Configuring Only-Instances and With-All-Subclasses Expressions shows amendment methods for the `Bicycle` and `NonFueledVehicle` descriptors based on the class hierarchy shown in Figure: Example Inheritance Hierarchy if the vehicle hierarchy stored all of the classes in a single vehicle table, and there was not a class indicator, but a class extraction method instead.

Configuring Only-Instances and With-All-Subclasses Expressions

    // Bicycle amemndment
    public static void addToBicycleDescriptor(Descriptor descriptor) {
        ExpressionBuilder builder = new ExpressionBuilder();
        descriptor.getInheritancePolicy().setOnlyInstancesExpression(
            builder.getField("BICYCLE_DESCR").notNull()
        );
    }

    // NonFueldVehicle ammendment
    public static void addToNonFueledVehicleDescriptor(Descriptor descriptor) {
        ExpressionBuilder builder = new ExpressionBuilder();
        descriptor.getInheritancePolicy().setWithAllSubclassesExpression(
            builder.getField("FUEL_TYPE").isNull()
        );
    }