Search in sources :

Example 1 with Table

use of org.eclipse.jpt.jpa.db.Table in project jbosstools-hibernate by jbosstools.

the class NamingStrategyMappingTools method buildDbJoinTableDefaultName.

protected static String buildDbJoinTableDefaultName(Relationship relationshipReference) {
    Table owningTable = relationshipReference.getTypeMapping().getPrimaryDbTable();
    if (owningTable == null) {
        return null;
    }
    RelationshipMapping relationshipMapping = relationshipReference.getMapping();
    if (relationshipMapping == null) {
        return null;
    }
    Entity targetEntity = relationshipMapping.getResolvedTargetEntity();
    if (targetEntity == null) {
        return null;
    }
    Table targetTable = targetEntity.getPrimaryDbTable();
    if (targetTable == null) {
        return null;
    }
    String name = owningTable.getName() + '_' + targetTable.getName();
    return owningTable.getDatabase().convertNameToIdentifier(name);
}
Also used : Entity(org.eclipse.jpt.jpa.core.context.Entity) Table(org.eclipse.jpt.jpa.db.Table) RelationshipMapping(org.eclipse.jpt.jpa.core.context.RelationshipMapping)

Example 2 with Table

use of org.eclipse.jpt.jpa.db.Table in project jbosstools-hibernate by jbosstools.

the class ForeignKeyImpl method validateForeignKeyName.

private void validateForeignKeyName(List<IMessage> messages, String name, TextRange range) {
    if (name == null || name.trim().length() == 0) {
        messages.add(HibernateJpaValidationMessage.buildMessage(IMessage.HIGH_SEVERITY, Messages.NAME_CANT_BE_EMPTY, getResource(), range));
    } else {
        AttributeMapping mapping = (AttributeMapping) getParent();
        Table table = mapping.getTypeMapping().getPrimaryDbTable();
        if (!mapping.validatesAgainstDatabase() || table == null) {
            return;
        }
        Iterator<org.eclipse.jpt.jpa.db.ForeignKey> fks = table.getForeignKeys().iterator();
        while (fks.hasNext()) {
            org.eclipse.jpt.jpa.db.ForeignKey fk = fks.next();
            if (name.equals(fk.getIdentifier())) {
                return;
            }
        }
        messages.add(HibernateJpaValidationMessage.buildMessage(IMessage.HIGH_SEVERITY, Messages.UNRESOLVED_FOREIGN_KEY_NAME, getResource(), range));
    }
}
Also used : Table(org.eclipse.jpt.jpa.db.Table) AttributeMapping(org.eclipse.jpt.jpa.core.context.AttributeMapping) ForeignKey(org.jboss.tools.hibernate.jpt.core.internal.context.ForeignKey)

Aggregations

Table (org.eclipse.jpt.jpa.db.Table)2 AttributeMapping (org.eclipse.jpt.jpa.core.context.AttributeMapping)1 Entity (org.eclipse.jpt.jpa.core.context.Entity)1 RelationshipMapping (org.eclipse.jpt.jpa.core.context.RelationshipMapping)1 ForeignKey (org.jboss.tools.hibernate.jpt.core.internal.context.ForeignKey)1