package com.mysema.query.sql; import java.util.ArrayList; import java.util.Collection; import java.util.List; import javax.annotation.Nullable; import com.mysema.query.types.Path; import com.mysema.query.types.PathMetadata; import com.mysema.query.types.path.BeanPath; /** * RelationalPathBase is a base class for RelationPath implements * * @author tiwe * * @param entity type */ public class RelationalPathBase extends BeanPath implements RelationalPath { private static final long serialVersionUID = -7031357250283629202L; @Nullable private PrimaryKey primaryKey; @Nullable private Path[] all; private final List> columns = new ArrayList>(); private final List> foreignKeys = new ArrayList>(); private final List> inverseForeignKeys = new ArrayList>(); public RelationalPathBase(Class type, String variable) { super(type, variable); } public RelationalPathBase(Class type, PathMetadata metadata) { super(type, metadata); } protected PrimaryKey createPrimaryKey(Path... columns){ primaryKey = new PrimaryKey(this, columns); return primaryKey; } protected ForeignKey createForeignKey(Path local, String foreign){ ForeignKey foreignKey = new ForeignKey(this, local, foreign); foreignKeys.add(foreignKey); return foreignKey; } protected ForeignKey createForeignKey(List> local, List foreign){ ForeignKey foreignKey = new ForeignKey(this, local, foreign); foreignKeys.add(foreignKey); return foreignKey; } protected ForeignKey createInvForeignKey(Path local, String foreign){ ForeignKey foreignKey = new ForeignKey(this, local, foreign); inverseForeignKeys.add(foreignKey); return foreignKey; } protected ForeignKey createInvForeignKey(List> local, List foreign){ ForeignKey foreignKey = new ForeignKey(this, local, foreign); inverseForeignKeys.add(foreignKey); return foreignKey; } public Path[] all() { if (all == null || all.length != columns.size()){ all = new Path[columns.size()]; columns.toArray(all); } return all; } @Override protected

> P add(P path){ columns.add(path); return path; } @Override public List> getColumns() { return columns; } @Override public Collection> getForeignKeys() { return foreignKeys; } @Override public Collection> getInverseForeignKeys() { return inverseForeignKeys; } @Override public PrimaryKey getPrimaryKey() { return primaryKey; } @Override public String getTableName() { return getType().getAnnotation(Table.class).value(); } }