Aliases

Overview

Aliases are code-generated classes the hold the column meta-data for tables. This meta-data is then used for both building Type-Safe Queries and also the meta-data-driven loading/saving of primitives into ResultSets and PreparedStatements.

Example

This is all generated code, but the basic idea is that it statically defines the table meta-data found at build-time:

    public class ChildAlias extends Alias<Child> {

        // The alias keeps a list, columns, of all of its columns
        private final List<AliasColumn<Child, ?, ?>> columns = new ArrayList<AliasColumn<Child, ?, ?>>();

        // Some basic primitive columns
        public final IdAliasColumn<Child> id = new IdAliasColumn<Child>(this, "id", ChildCodegen.Shims.id);
        public final StringAliasColumn<Child> name = new StringAliasColumn<Child>(this, "name", ChildCodegen.Shims.name);
        public final IntAliasColumn<Child> version = new IntAliasColumn<Child>(this, "version", ChildCodegen.Shims.version);

        // The parent foreign key has a specific ForeignKeyAliasColumn column with the "on" join method
        public final ForeignKeyAliasColumn<Child, Parent> parent = new ForeignKeyAliasColumn<Child, Parent>(this, "parent_id", ChildCodegen.Shims.parentId);

        public ChildAlias(String alias) {
            super(Child.class, "child", alias);
            this.columns.add(this.id);
            this.columns.add(this.name);
            this.columns.add(this.version);
            this.columns.add(this.parent);
        }

        // Common Alias columns used by the meta-data mapper
        public List<AliasColumn<Child, ?, ?>> getColumns() {
            return this.columns;
        }

        public IdAliasColumn<Child> getIdColumn() {
            return this.id;
        }

        public IntAliasColumn<Child> getVersionColumn() {
            return this.version;
        }

        public IdAliasColumn<Child> getSubClassIdColumn() {
            return null;
        }

        // To avoid foreign key conflicts, entities are topographically sorted at build-time
        // and given a hardcoded insert order to be used during UoW.flush
        public int getOrder() {
            return 21;
        }

    }