Package org.hibernate.type

Examples of org.hibernate.type.Type


    final AssociationType[] ownerAssociationTypes = getOwnerAssociationTypes();
    if ( ownerAssociationTypes != null && ownerAssociationTypes[i] != null ) {
      String ukName = ownerAssociationTypes[i].getRHSUniqueKeyPropertyName();
      if ( ukName != null ) {
        final int index = ( (UniqueKeyLoadable) persister ).getPropertyIndex( ukName );
        final Type type = persister.getPropertyTypes()[index];

        // polymorphism not really handled completely correctly,
        // perhaps...well, actually its ok, assuming that the
        // entity name used in the lookup is the same as the
        // the one used here, which it will be

        EntityUniqueKey euk = new EntityUniqueKey(
            rootPersister.getEntityName(), //polymorphism comment above
            ukName,
            type.semiResolve( values[index], session, object ),
            type,
            persister.getEntityMode(),
            session.getFactory()
          );
        session.getPersistenceContext().addEntity( euk, object );
View Full Code Here


   * @param propertyIndex index of the property of interest
   * @return the meta-data of the inverse side of the specified association or {@code null} if no such meta-data
   * exists
   */
  public static AssociationKeyMetadata getInverseAssociationKeyMetadata(OgmEntityPersister mainSidePersister, int propertyIndex) {
    Type propertyType = mainSidePersister.getPropertyTypes()[propertyIndex];
    SessionFactoryImplementor factory = mainSidePersister.getFactory();

    // property represents no association, so no inverse meta-data can exist
    if ( !propertyType.isAssociationType() ) {
      return null;
    }

    Joinable mainSideJoinable = ( (AssociationType) propertyType ).getAssociatedJoinable( factory );
    OgmEntityPersister inverseSidePersister = null;

    // to-many association
    if ( mainSideJoinable.isCollection() ) {
      inverseSidePersister = (OgmEntityPersister) ( (OgmCollectionPersister) mainSideJoinable ).getElementPersister();
    }
    // to-one
    else {
      inverseSidePersister = (OgmEntityPersister) mainSideJoinable;
      mainSideJoinable = mainSidePersister;
    }

    String mainSideProperty = mainSidePersister.getPropertyNames()[propertyIndex];

    // property is a one-to-one association (a many-to-one cannot be on the inverse side) -> get the meta-data
    // straight from the main-side persister
    AssociationKeyMetadata inverseOneToOneMetadata = mainSidePersister.getInverseOneToOneAssociationKeyMetadata( mainSideProperty );
    if ( inverseOneToOneMetadata != null ) {
      return inverseOneToOneMetadata;
    }

    // process properties of inverse side and try to find association back to main side
    for ( String candidateProperty : inverseSidePersister.getPropertyNames() ) {
      Type type = inverseSidePersister.getPropertyType( candidateProperty );

      // candidate is a *-to-many association
      if ( type.isCollectionType() ) {
        OgmCollectionPersister inverseCollectionPersister = getPersister( factory, (CollectionType) type );
        if ( isCollectionMatching( mainSideJoinable, inverseCollectionPersister ) ) {
          return inverseCollectionPersister.getAssociationKeyMetadata();
        }
      }
View Full Code Here

    Loadable mainSidePersister = (Loadable) collectionPersister.getElementPersister();

    for ( int i = 0; i < mainSidePersister.getPropertyNames().length; i++ ) {
      String candidateProperty = mainSidePersister.getPropertyNames()[i];
      Type type = mainSidePersister.getPropertyType( candidateProperty );

      // candidate is to-one association
      if ( type.isEntityType() ) {
        if ( Arrays.equals( collectionPersister.getKeyColumnNames(), mainSidePersister.getPropertyColumnNames( i ) ) ) {
          return candidateProperty;
        }
      }
      // candidate is to-many association
      else if ( type.isCollectionType() ) {
        OgmCollectionPersister mainSideCollectionPersister = getPersister( collectionPersister.getFactory(), (CollectionType) type );
        if ( isCollectionMatching( mainSideCollectionPersister, collectionPersister ) ) {
          return candidateProperty;
        }
      }
View Full Code Here

    this.entityNames = entityNames;
  }

  @Override
  public Object convertToPropertyType(String entityType, List<String> propertyPath, String value) {
    Type propertyType = getPropertyType( entityType, propertyPath );

    if ( propertyType.isEntityType() ) {
      throw new UnsupportedOperationException( "Queries on associated entities are not supported yet." );
    }

    if ( propertyType instanceof AbstractStandardBasicType ) {
      return ( (AbstractStandardBasicType<?>) propertyType ).fromString( value );
View Full Code Here

  }

  private Type getPropertyType(String entityType, List<String> propertyPath) {
    OgmEntityPersister persister = getPersister( entityType );
    String propertyName = propertyPath.get( 0 );
    Type propertyType = persister.getPropertyType( propertyName );
    if ( propertyPath.size() == 1 ) {
      return propertyType;
    }
    else if ( propertyType.isComponentType() ) {
      return embeddedPropertyType( propertyPath, (ComponentType) propertyType );
    }
    throw new UnsupportedOperationException( "Queries on associated entities are not supported yet." );
  }
View Full Code Here

    }
    throw new UnsupportedOperationException( "Queries on associated entities are not supported yet." );
  }

  private Type embeddedPropertyType(List<String> propertyPath, ComponentType propertyType) {
    Type subType = propertyType;
    for ( int i = 1; i < propertyPath.size(); i++ ) {
      ComponentType componentType = (ComponentType) subType;
      String name = propertyPath.get( i );
      int propertyIndex = componentType.getPropertyIndex( name );
      subType = componentType.getSubtypes()[propertyIndex];
      if ( subType.isAnyType() || subType.isAssociationType() || subType.isEntityType() ) {
        throw new UnsupportedOperationException( "Queries on associated entities are not supported yet." );
      }
    }
    return subType;
  }
View Full Code Here

  }

  public boolean isEmbedddedProperty(String targetTypeName, PropertyPath propertyPath) {
    List<String> namesWithoutAlias = propertyPath.getNodeNamesWithoutAlias();
    OgmEntityPersister persister = getPersister( targetTypeName );
    Type propertyType = persister.getPropertyType( namesWithoutAlias.get( 0 ) );
    return propertyType.isComponentType() && !propertyType.isAssociationType();
  }
View Full Code Here

      if ( !customQuery.getCustomQueryReturns().isEmpty() ) {
        entry = new Object[customQuery.getCustomQueryReturns().size()];
        int i = 0;
        for ( Return queryReturn : customQuery.getCustomQueryReturns() ) {
          ScalarReturn scalarReturn = (ScalarReturn) queryReturn;
          Type type = scalarReturn.getType();

          if ( type != null ) {
            GridType gridType = typeTranslator.getType( type );
            entry[i++] = gridType.nullSafeGet( tuple, scalarReturn.getColumnAlias(), session, null );
          }
View Full Code Here

    // copied from the superclass constructor
    isInverse = collection.isInverse();
    oneToMany = collection.isOneToMany();
    if ( collection.isOneToMany() && getElementPersister() != null && getElementType().isEntityType() ) {
      associationType = AssociationType.EMBEDDED_FK_TO_ENTITY;
      final Type identifierOrUniqueKeyType = ( (EntityType) getElementType() )
          .getIdentifierOrUniqueKeyType( factory );
      gridTypeOfAssociatedId = typeTranslator.getType( identifierOrUniqueKeyType );
    }
    else if ( collection.isOneToMany() ) {
      // one to many but not what we expected
      throw new AssertionFailure( "Association marked as one to many but has no ManyToOneType: " + collection.getRole() );
    }
    else if ( getElementType().isAssociationType() && getElementType().isEntityType() ) {
      associationType = AssociationType.ASSOCIATION_TABLE_TO_ENTITY;
      final Type identifierOrUniqueKeyType = ( (EntityType) getElementType() ).getIdentifierOrUniqueKeyType( factory );
      gridTypeOfAssociatedId = typeTranslator.getType( identifierOrUniqueKeyType );
    }
    else {
      gridTypeOfAssociatedId = null;
      associationType = AssociationType.OTHER;
View Full Code Here

   */
  private static class JsonDotNodeResolver implements DotNodeResolver {

    @Override
    public Statement resolve(DotNode dotNode) {
      final Type dataType = dotNode.getDataType();
      Class<?> requestedType = dataType.getReturnedClass();

      if (dataType.isComponentType()) {
        throw new UnsupportedOperationException("Can't resolve " + dotNode.getText() + ": Components are not implemented yet in JPQL expressions");
      }
      else if (dataType.isEntityType()) {
        // generate this:
        // entityManager.find(Key.fromJson(entityManager, candidate.get(${propertyPath}).isObject(), false), NO_SIDE_EFFECTS);

        // FIXME running a query that uses this in a where clause will be an O(N^2) operation on the number of entities. :-(
        return new TernaryStatement(
            Bool.notEquals(Stmt.loadVariable("candidate").invoke("get", dotNode.getPropertyPath()).invoke("isNull"), null),
            Stmt.loadLiteral(null),
            Stmt.loadVariable("entityManager").invoke("find",
                Stmt.invokeStatic(Key.class, "fromJsonObject",
                    Stmt.loadVariable("entityManager"),
                    Stmt.loadVariable("candidate").invoke("get", dotNode.getPropertyPath()).invoke("isObject"),
                    false),
                Stmt.loadStatic(LongIdGenerator.class, "NO_SIDE_EFFECTS_OPTION")));
      }
      else if (dataType.isCollectionType()) {
        throw new UnsupportedOperationException("Can't resolve " + dotNode.getText() + ": Collections are not implemented yet in JPQL expressions");
      }
      else { // it's a basic type

        // normalize all numbers except longs and chars to double (literals do the same)
View Full Code Here

TOP

Related Classes of org.hibernate.type.Type

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.