Package org.apache.openjpa.jdbc.schema

Examples of org.apache.openjpa.jdbc.schema.Unique


        }

        // look for an existing constraint on these columns
        Table table = cols[0].getTable();
        Unique[] unqs = table.getUniques();
        Unique exist = null;
        for (int i = 0; i < unqs.length; i++) {
            if (unqs[i].columnsMatch(cols)) {
                exist = unqs[i];
                break;
            }
        }

        // remove existing unique?
        if (!_canUnq) {
            if (exist == null)
                return null;
            if (!adapt)
                throw new MetaDataException(_loc.get(prefix
                    + "-unique-exists", context));
            table.removeUnique(exist);
            return null;
        }

        // no defaults; return existing constraint (if any)
        if (tmplate == null && _unq == null)
            return exist;

        MappingRepository repos = (MappingRepository) context.getRepository();
        if (exist != null) {
            if (_unq != null && _unq.isDeferred() && !exist.isDeferred()) {
                Log log = repos.getLog();
                if (log.isWarnEnabled())
                    log.warn(_loc.get(prefix + "-defer-unique", context));
            }
            return exist;
        }

        // dict can't handle unique constraints?
        DBDictionary dict = repos.getDBDictionary();
        if (_unq != null && !dict.supportsUniqueConstraints) {
            Log log = repos.getLog();
            if (log.isWarnEnabled())
                log.warn(_loc.get(prefix + "-unique-support", context));
            return null;
        }

        boolean fill = repos.getMappingDefaults().defaultMissingInfo();
        if (!adapt && !fill && _unq == null)
            return null;

        String name;
        boolean deferred;
        if (_unq != null) {
            name = _unq.getName();
            deferred = _unq.isDeferred();
        } else {
            name = tmplate.getName();
            deferred = tmplate.isDeferred();
        }

        if (deferred && !dict.supportsDeferredConstraints) {
            Log log = repos.getLog();
            if (log.isWarnEnabled())
                log.warn(_loc.get(prefix + "-create-defer-unique",
                    context, dict.platform));
            deferred = false;
        }

        Unique unq = table.addUnique(name);
        unq.setDeferred(deferred);
        unq.setColumns(cols);
        return unq;
    }
View Full Code Here


            _unq = null;
            return;
        }

        _canUnq = true;
        _unq = new Unique();
        _unq.setName(unq.getName());
        _unq.setDeferred(unq.isDeferred());
    }
View Full Code Here

     */
    private void setUnique(FieldMapping fm) {
        if (_unique.size() == 2) // i.e. TRUE & FALSE
            getLog().warn(_loc.get("inconsist-col-attrs", fm));
        else if (_unique.contains(UniqueFlag.TRUE))
            fm.getValueInfo().setUnique(new Unique());
    }
View Full Code Here

     */
    private boolean startUniqueConstraint(Attributes attrs)
        throws SAXException {
        Object current = currentElement();
        if (current instanceof ClassMapping && _secondaryTable == null) {
            Unique unique = new Unique();
            pushElement(unique);
            return true;
        }
        return false;
    }
View Full Code Here

     * within a ClassMapping element and <em>not</em> within a secondary
     * table. The stack is popped and the Unique element is added to the
     * ClassMappingInfo.
     */
    private void endUniqueConstraint() {
        Unique unique = (Unique) popElement();
        Object current = currentElement();
        if (current instanceof ClassMapping && _secondaryTable == null)
            ((ClassMapping) current).getMappingInfo().addUnique(unique);
    }
View Full Code Here

     * the current Unique element that resides in the top of the stack.
     */
    private boolean endColumnName() {
        Object current = currentElement();
        if (current instanceof Unique) {
            Unique unique = (Unique) current;
            Column column = new Column();
            column.setName(this.currentText());
            unique.addColumn(column);
            return true;
        }
        return false;
    }
View Full Code Here

        String tableName = toTableName(table.schema(), table.name());
        if (tableName != null)
            cm.getMappingInfo().setTableName(tableName);

        for (UniqueConstraint uniqueConstraint:table.uniqueConstraints()) {
            Unique unique = newUnique(cm, null, uniqueConstraint.columnNames());
            cm.getMappingInfo().addUnique(unique);
        }
    }
View Full Code Here

   
    private static Unique newUnique(ClassMapping cm, String name,
        String[] columnNames) {
        if (columnNames == null || columnNames.length == 0)
            return null;
        Unique uniqueConstraint = new Unique();
        uniqueConstraint.setName(name);
        for (int i=0; i<columnNames.length; i++) {
            if (StringUtils.isEmpty(columnNames[i]))
                throw new UserException(_loc.get("empty-unique-column",
                    Arrays.toString(columnNames), cm));
            Column column = new Column();
            column.setName(columnNames[i]);
            uniqueConstraint.addColumn(column);
        }
        return uniqueConstraint;
    }
View Full Code Here

            return;

        Index idx = findIndex(fk.getColumns());
        if (idx != null)
            field.setJoinIndex(idx);
        Unique unq = findUnique(fk.getColumns());
        if (unq != null)
            field.setJoinUnique(unq);
    }
View Full Code Here

        Column[] cols = (vm.getForeignKey() != null)
            ? vm.getForeignKey().getColumns() : vm.getColumns();
        Index idx = findIndex(cols);
        if (idx != null)
            vm.setValueIndex(idx);
        Unique unq = findUnique(cols);
        if (unq != null)
            vm.setValueUnique(unq);
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.schema.Unique

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.