Package org.apache.openjpa.jdbc.schema

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


    }
   
    void addUniqueConstraints(String table, MetaDataContext ctx,
        MappingInfo info, UniqueConstraint...uniqueConstraints) {
      for (UniqueConstraint anno : uniqueConstraints) {
        Unique unique = createUniqueConstraint(ctx, anno);
        unique.setTableName(table);
        if (info instanceof ClassMappingInfo)
          ((ClassMappingInfo)info).addUnique(table, unique);
        else if (info instanceof FieldMappingInfo)
          ((FieldMappingInfo)info).addJoinTableUnique(unique);
        else
View Full Code Here


                    Arrays.toString(table.getColumnNames())}));
              }
              Column uniqueColumn = table.getColumn(columnName);
              uniqueColumns[i] = uniqueColumn;
            }
            Unique unique = createUnique(cm, "unique", template, 
                uniqueColumns, adapt);
            if (unique != null)
              result.add(unique);
          }
        }
View Full Code Here

                    Arrays.toString(table.getColumnNames())}));
              }
              Column uniqueColumn = table.getColumn(columnName);
              uniqueColumns[i] = uniqueColumn;
            }
            Unique unique = createUnique(cm, "unique", template, 
                uniqueColumns, adapt);
            if (unique != null)
              result.add(unique);
          }
        }
View Full Code Here

        _seqColumn.setType(dict.getPreferredType(Types.BIGINT));
        _seqColumn.setJavaType(JavaTypes.LONG);
       
        if (_uniqueColumnNames != null) {
        String uniqueName = dict.getValidUniqueName("UNQ", table);
        Unique u = table.addUnique(uniqueName);
        for (String columnName : _uniqueColumnNames) {
          if (!table.containsColumn(columnName))
            throw new UserException(_loc.get("unique-missing-column",
              columnName, table.getName(), table.getColumnNames()));
          Column col = table.getColumn(columnName);
          u.addColumn(col);
        }
        }
       
    }
View Full Code Here

       
        Iterator uniqueConstraints = _uniques.iterator();
        Table table = cm.getTable();
        Collection result = new ArrayList();
        while (uniqueConstraints.hasNext()) {
            Unique template = (Unique) uniqueConstraints.next();
            Column[] templateColumns = template.getColumns();
            Column[] uniqueColumns = new Column[templateColumns.length];
            boolean missingColumn = true;
            for (int i=0; i<uniqueColumns.length; i++) {
                String columnName = templateColumns[i].getName();
                Column uniqueColumn = table.getColumn(columnName);
                missingColumn = (uniqueColumn == null);
                if (missingColumn) {
                    throw new UserException(_loc.get("missing-unique-column",
                        cm, table, columnName));
                }
                uniqueColumns[i] = uniqueColumn;
            }
            Unique unique = super.createUnique(cm, "unique", template,
                uniqueColumns, adapt);
            if (unique != null)
                result.add(unique);
        }
        return (Unique[]) result.toArray(new Unique[result.size()]);
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

    private boolean endName() {
        String name = this.currentText();
        if (StringUtils.isNotEmpty(name)) {
            Object current = currentElement();
            if (current instanceof Unique) {
                Unique unq = (Unique)current;
                unq.setIdentifier(DBIdentifier.newConstraint(name, delimit()));
            }
        }
           
        return true;
    }
View Full Code Here

    private void setUnique(FieldMapping fm, EnumSet<UniqueFlag> unique) {
        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

     * table.
     * Pushes the Unique element in the stack.
     */
    private boolean startUniqueConstraint(Attributes attrs)
        throws SAXException {
        Unique unique = new Unique();

        DBIdentifier name = DBIdentifier.newConstraint(attrs.getValue("name"), delimit());
        if (!DBIdentifier.isEmpty(name)) {
            unique.setIdentifier(name);
        }

        pushElement(unique);
        return true;
    }
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.