You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Abe White <aw...@bea.com> on 2007/01/03 18:51:03 UTC

Re: svn commit: r492225 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/ openjpa-persistence-jdb...

I don't agree with this implementation.  It doesn't leave any room  
for customization through MappingDefaults, it ties the ClassMapping  
to the XMLSchemaParser (?!), and it's totally different than our  
mapping of indexes, foreign keys, and primary keys, the other  
supported constraint types.

> +        mapUniqueConstraints();
> +    }
> +
> +    /**
> +     * Adds unique constraints to the mapped table.
> +     *
> +     */
> +    void mapUniqueConstraints() {
> +        Log log = getRepository().getLog();
> +        Collection uniqueInfos = _info.getUniqueConstraints();
> +        if (uniqueInfos == null || uniqueInfos.isEmpty())
> +            return;
> +        Iterator iter = uniqueInfos.iterator();
> +        Table table = getTable();
> +        int i = 1;
> +        while (iter.hasNext()) {
> +            XMLSchemaParser.UniqueInfo uniqueInfo =
> +                (XMLSchemaParser.UniqueInfo)iter.next();
> +            if (uniqueInfo.cols == null || uniqueInfo.cols.isEmpty())
> +                continue;
> +            String constraintName = table.getName() + "_UNIQUE_" + i;
> +            i++;
> +            Unique uniqueConstraint = table.addUnique 
> (constraintName);
> +            Iterator uniqueColumnNames = uniqueInfo.cols.iterator();
> +            while (uniqueColumnNames.hasNext()) {
> +                String uniqueColumnName = (String) 
> uniqueColumnNames.next();
> +                Column uniqueColumn = table.getColumn 
> (uniqueColumnName);
> +                if (uniqueColumn != null) {
> +                    uniqueConstraint.addColumn(uniqueColumn);
> +                } else {
> +                    table.removeUnique(uniqueConstraint);
> +                    if (log.isWarnEnabled())
> +                        log.warn(_loc.get("missing-unique-column",  
> this,
> +                            table.getName(), uniqueColumnName));
> +                    break;
> +                }
>              }
>          }
>      }
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.