Package org.hibernate.mapping

Examples of org.hibernate.mapping.SimpleValue


    validate();
    log.debug( "building SimpleValue for {}", propertyName );
    if ( table == null ) {
      table = columns[0].getTable();
    }
    simpleValue = new SimpleValue( table );

    linkWithValue();

    boolean isInSecondPass = mappings.isInSecondPass();
    SetSimpleValueTypeSecondPass secondPass = new SetSimpleValueTypeSecondPass(this);
View Full Code Here


        log.debug("today's date: " + todaysDate);
    }

    private Column createColumn(Class clazz) {
        Column column = new Column();
        SimpleValue sv = new SimpleValue();
        sv.setTypeName(clazz.getName());
        column.setValue(sv);
        return column;
    }
View Full Code Here

    }

  }

  private void updatePrimaryKey(RootClass rc, PrimaryKeyInfo pki) {
    SimpleValue idValue = (SimpleValue) rc.getIdentifierProperty().getValue();

    Properties defaultStrategyProperties = new Properties();
    Property constrainedOneToOne = getConstrainedOneToOne(rc);
    if(constrainedOneToOne!=null) {
      if(pki.suggestedStrategy==null) {
        idValue.setIdentifierGeneratorStrategy("foreign");
      }

      if(pki.suggestedProperties==null) {
        defaultStrategyProperties.setProperty("property", constrainedOneToOne.getName());
        idValue.setIdentifierGeneratorProperties(defaultStrategyProperties);
      }
    }


View Full Code Here

      referencedKeyValue = (KeyValue) collection.getOwner()
        .getProperty(propRef)
        .getValue();
    }

    SimpleValue keyValue = new DependantValue( collectionTable, referencedKeyValue );
    //keyValue.setForeignKeyName("none"); // Avoid creating the foreignkey
    //key.setCascadeDeleteEnabled( "cascade".equals( subnode.attributeValue("on-delete") ) );
    Iterator columnIterator = foreignKey.getColumnIterator();
    while ( columnIterator.hasNext() ) {
      Column fkcolumn = (Column) columnIterator.next();
      if(fkcolumn.getSqlTypeCode()!=null) { // TODO: user defined foreign ref columns does not have a type set.
        guessAndAlignType(collectionTable, fkcolumn, mapping, false); // needed to ensure foreign key columns has same type as the "property" column.
      }
      keyValue.addColumn( fkcolumn );
    }

    collection.setKey(keyValue);

    mappings.addCollection(collection);
View Full Code Here

      Properties suggestedProperties = null;
    }


  private PrimaryKeyInfo bindPrimaryKeyToProperties(Table table, RootClass rc, Set processed, Mapping mapping, DatabaseCollector collector) {
    SimpleValue id = null;
    String idPropertyname = null;

    PrimaryKeyInfo pki = new PrimaryKeyInfo();

    List keyColumns = null;
    if (table.getPrimaryKey()!=null) {
      keyColumns = table.getPrimaryKey().getColumns();
    }
    else {
      log.debug("No primary key found for " + table + ", using all properties as the identifier.");
      keyColumns = new ArrayList();
      Iterator iter = table.getColumnIterator();
      while (iter.hasNext() ) {
        Column col = (Column) iter.next();
        keyColumns.add(col);
      }
    }

    final TableIdentifier tableIdentifier = TableIdentifier.create(table);

    String tableIdentifierStrategyName = "assigned";

    boolean naturalId;

    if (keyColumns.size()>1) {
      log.debug("id strategy for " + rc.getEntityName() + " since it has a multiple column primary key");
      naturalId = true;

      id = handleCompositeKey(rc, processed, keyColumns, mapping);
      idPropertyname = revengStrategy.tableToIdentifierPropertyName(tableIdentifier);
      if(idPropertyname==null) {
        idPropertyname = "id";
      }
    }
    else {
      pki.suggestedStrategy = revengStrategy.getTableIdentifierStrategyName(tableIdentifier);
      String suggestedStrategy = pki.suggestedStrategy;
      if(suggestedStrategy==null) {
        suggestedStrategy = collector.getSuggestedIdentifierStrategy( tableIdentifier.getCatalog(), tableIdentifier.getSchema(), tableIdentifier.getName() );
        if(suggestedStrategy==null) {
          suggestedStrategy = "assigned";
        }
        tableIdentifierStrategyName = suggestedStrategy;
      } else {
        tableIdentifierStrategyName = suggestedStrategy;
      }

      naturalId = "assigned".equals( tableIdentifierStrategyName );
      Column pkc = (Column) keyColumns.get(0);
      checkColumn(pkc);

      id = bindColumnToSimpleValue(table, pkc, mapping, !naturalId);

      idPropertyname = revengStrategy.tableToIdentifierPropertyName(tableIdentifier);
      if(idPropertyname==null) {
        idPropertyname = revengStrategy.columnToPropertyName(tableIdentifier, pkc.getName() );
      }

      processed.add(pkc);
    }
    id.setIdentifierGeneratorStrategy(tableIdentifierStrategyName);
    pki.suggestedProperties = revengStrategy.getTableIdentifierProperties(tableIdentifier);
    id.setIdentifierGeneratorProperties(pki.suggestedProperties);
    if(naturalId) {
      id.setNullValue("undefined");
    }

    Property property = makeProperty(tableIdentifier, makeUnique(rc,idPropertyname), id, true, true, false, null, null);
    rc.setIdentifierProperty(property);
    rc.setIdentifier(id);
View Full Code Here

  }

  private Property bindBasicProperty(String propertyName, Table table, Column column, Set processedColumns, Mapping mapping) {

    SimpleValue value = bindColumnToSimpleValue( table, column, mapping, false );

    return makeProperty(TableIdentifier.create( table ), propertyName, value, true, true, false, null, null);
  }
View Full Code Here

    return makeProperty(TableIdentifier.create( table ), propertyName, value, true, true, false, null, null);
  }

  private SimpleValue bindColumnToSimpleValue(Table table, Column column, Mapping mapping, boolean generatedIdentifier) {
    SimpleValue value = new SimpleValue(table);
    value.addColumn(column);
    value.setTypeName(guessAndAlignType(table, column, mapping, generatedIdentifier));
    return value;
  }
View Full Code Here

  private static void bindSimpleId(Element idNode, RootClass entity, Mappings mappings,
      java.util.Map inheritedMetas) throws MappingException {
    String propertyName = idNode.attributeValue( "name" );

    SimpleValue id = new SimpleValue( entity.getTable() );
    entity.setIdentifier( id );

    // if ( propertyName == null || entity.getPojoRepresentation() == null ) {
    // bindSimpleValue( idNode, id, false, RootClass.DEFAULT_IDENTIFIER_COLUMN_NAME, mappings );
    // if ( !id.isTypeSpecified() ) {
    // throw new MappingException( "must specify an identifier type: " + entity.getEntityName()
    // );
    // }
    // }
    // else {
    // bindSimpleValue( idNode, id, false, propertyName, mappings );
    // PojoRepresentation pojo = entity.getPojoRepresentation();
    // id.setTypeUsingReflection( pojo.getClassName(), propertyName );
    //
    // Property prop = new Property();
    // prop.setValue( id );
    // bindProperty( idNode, prop, mappings, inheritedMetas );
    // entity.setIdentifierProperty( prop );
    // }

    if ( propertyName == null ) {
      bindSimpleValue( idNode, id, false, RootClass.DEFAULT_IDENTIFIER_COLUMN_NAME, mappings );
    }
    else {
      bindSimpleValue( idNode, id, false, propertyName, mappings );
    }

    if ( propertyName == null || !entity.hasPojoRepresentation() ) {
      if ( !id.isTypeSpecified() ) {
        throw new MappingException( "must specify an identifier type: "
          + entity.getEntityName() );
      }
    }
    else {
      id.setTypeUsingReflection( entity.getClassName(), propertyName );
    }

    if ( propertyName != null ) {
      Property prop = new Property();
      prop.setValue( id );
View Full Code Here

  private static void bindVersioningProperty(Table table, Element subnode, Mappings mappings,
      String name, RootClass entity, java.util.Map inheritedMetas) {

    String propertyName = subnode.attributeValue( "name" );
    SimpleValue val = new SimpleValue( table );
    bindSimpleValue( subnode, val, false, propertyName, mappings );
    if ( !val.isTypeSpecified() ) {
      // this is either a <version/> tag with no type attribute,
      // or a <timestamp/> tag
      if ( "version".equals( name ) ) {
        val.setTypeName( "integer" );
      }
      else {
        if ( "db".equals( subnode.attributeValue( "source" ) ) ) {
          val.setTypeName( "dbtimestamp" );
        }
        else {
          val.setTypeName( "timestamp" );
        }
      }
    }
    Property prop = new Property();
    prop.setValue( val );
View Full Code Here

    entity.addProperty( prop );
  }

  private static void bindDiscriminatorProperty(Table table, RootClass entity, Element subnode,
      Mappings mappings) {
    SimpleValue discrim = new SimpleValue( table );
    entity.setDiscriminator( discrim );
    bindSimpleValue(
        subnode,
        discrim,
        false,
        RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME,
        mappings
      );
    if ( !discrim.isTypeSpecified() ) {
      discrim.setTypeName( "string" );
      // ( (Column) discrim.getColumnIterator().next() ).setType(type);
    }
    entity.setPolymorphic( true );
    if ( "true".equals( subnode.attributeValue( "force" ) ) )
      entity.setForceDiscriminator( true );
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.SimpleValue

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.