Beispiel #1
0
  // bind collections.
  private void bindIncomingForeignKeys(
      PersistentClass rc, Set processed, List foreignKeys, Mapping mapping) {
    if (foreignKeys != null) {
      for (Iterator iter = foreignKeys.iterator(); iter.hasNext(); ) {
        ForeignKey foreignKey = (ForeignKey) iter.next();

        if (revengStrategy.excludeForeignKeyAsCollection(
            foreignKey.getName(),
            TableIdentifier.create(foreignKey.getTable()),
            foreignKey.getColumns(),
            TableIdentifier.create(foreignKey.getReferencedTable()),
            foreignKey.getReferencedColumns())) {
          log.debug(
              "Rev.eng excluded one-to-many or one-to-one for foreignkey " + foreignKey.getName());
        } else if (revengStrategy.isOneToOne(foreignKey)) {
          Property property =
              bindOneToOne(rc, foreignKey.getTable(), foreignKey, processed, false, true);
          rc.addProperty(property);
        } else {
          Property property = bindOneToMany(rc, foreignKey, processed, mapping);
          rc.addProperty(property);
        }
      }
    }
  }
  public void /*test*/ AddNewProperty() {
    System.out.println("******************* testAddNewProperty ********************");
    PersistentClass userMapping = HibernateUtil.getClassMapping(User.class);

    Column column = new Column();
    column.setName("MOTTO");
    column.setNullable(false);
    column.setUnique(true);
    column.setSqlType("VARCHAR");
    userMapping.getTable().addColumn(column);

    SimpleValue value = new SimpleValue();
    value.setTable(userMapping.getTable());
    value.addColumn(column);
    value.setTypeName("string");

    Property prop = new Property();
    prop.setValue(value);
    prop.setName("motto");
    prop.setPropertyAccessorName("field");
    prop.setNodeName(prop.getName());
    userMapping.addProperty(prop);

    HibernateUtil.rebuildSessionFactory();

    ClassMetadata metadata = HibernateUtil.getClassMetadata(User.class);
    String[] propNames = metadata.getPropertyNames();
    boolean mottoFound = false;
    for (int i = 0; i < propNames.length; i++) {
      String propName = propNames[i];
      if (propName.equalsIgnoreCase("motto")) {
        mottoFound = true;
        break;
      }
    }

    assertTrue(mottoFound);
  }
Beispiel #3
0
 private void bindIndex(final ExtendedMappings mappings) {
   if (indexColumn.isImplicit() == false) {
     PropertyHolder valueHolder =
         PropertyHolderBuilder.buildPropertyHolder(
             this.collection,
             IndexedCollection.DEFAULT_INDEX_COLUMN_NAME,
             (XClass) null,
             (XProperty) null);
     List list = (List) this.collection;
     if (!list.isOneToMany()) indexColumn.forceNotNull();
     indexColumn.setPropertyHolder(valueHolder);
     SimpleValueBinder value = new SimpleValueBinder();
     value.setColumns(new Ejb3Column[] {indexColumn});
     value.setExplicitType("integer");
     value.setMappings(mappings);
     SimpleValue indexValue = value.make();
     indexColumn.linkWithValue(indexValue);
     list.setIndex(indexValue);
     list.setBaseIndex(indexColumn.getBase());
     if (list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse()) {
       String entityName = ((OneToMany) list.getElement()).getReferencedEntityName();
       PersistentClass referenced = mappings.getClass(entityName);
       IndexBackref ib = new IndexBackref();
       ib.setName('_' + propertyName + "IndexBackref");
       ib.setUpdateable(false);
       ib.setSelectable(false);
       ib.setCollectionRole(list.getRole());
       ib.setEntityName(list.getOwner().getEntityName());
       ib.setValue(list.getIndex());
       referenced.addProperty(ib);
     }
   } else {
     Collection coll = this.collection;
     throw new AnnotationException(
         "List/array has to be annotated with an @IndexColumn: " + coll.getRole());
   }
 }