Package org.hibernate.engine.query.sql

Examples of org.hibernate.engine.query.sql.NativeSQLQueryRootReturn


      if ( queryReturns[i] instanceof NativeSQLQueryScalarReturn ) {
        NativeSQLQueryScalarReturn rtn = ( NativeSQLQueryScalarReturn ) queryReturns[i];
        customReturns.add( new ScalarReturn( rtn.getType(), rtn.getColumnAlias() ) );
      }
      else if ( queryReturns[i] instanceof NativeSQLQueryRootReturn ) {
        NativeSQLQueryRootReturn rtn = ( NativeSQLQueryRootReturn ) queryReturns[i];
        String alias = rtn.getAlias();
        EntityAliases entityAliases;
        if ( queryHadAliases || hasPropertyResultMap( alias ) ) {
          entityAliases = new DefaultEntityAliases(
              ( Map ) entityPropertyResultMaps.get( alias ),
              ( SQLLoadable ) alias2Persister.get( alias ),
              ( String ) alias2Suffix.get( alias )
          );
        }
        else {
          entityAliases = new ColumnEntityAliases(
              ( Map ) entityPropertyResultMaps.get( alias ),
              ( SQLLoadable ) alias2Persister.get( alias ),
              ( String ) alias2Suffix.get( alias )
          );
        }
        RootReturn customReturn = new RootReturn(
            alias,
            rtn.getReturnEntityName(),
            entityAliases,
            rtn.getLockMode()
        );
        customReturns.add( customReturn );
        customReturnsByAlias.put( rtn.getAlias(), customReturn );
      }
      else if ( queryReturns[i] instanceof NativeSQLQueryCollectionReturn ) {
        NativeSQLQueryCollectionReturn rtn = ( NativeSQLQueryCollectionReturn ) queryReturns[i];
        String alias = rtn.getAlias();
        SQLLoadableCollection persister = ( SQLLoadableCollection ) alias2CollectionPersister.get( alias );
        boolean isEntityElements = persister.getElementType().isEntityType();
        CollectionAliases collectionAliases;
        EntityAliases elementEntityAliases = null;
        if ( queryHadAliases || hasPropertyResultMap( alias ) ) {
          collectionAliases = new GeneratedCollectionAliases(
              ( Map ) collectionPropertyResultMaps.get( alias ),
              ( SQLLoadableCollection ) alias2CollectionPersister.get( alias ),
              ( String ) alias2CollectionSuffix.get( alias )
          );
          if ( isEntityElements ) {
            elementEntityAliases = new DefaultEntityAliases(
                ( Map ) entityPropertyResultMaps.get( alias ),
                ( SQLLoadable ) alias2Persister.get( alias ),
                ( String ) alias2Suffix.get( alias )
            );
          }
        }
        else {
          collectionAliases = new ColumnCollectionAliases(
              ( Map ) collectionPropertyResultMaps.get( alias ),
              ( SQLLoadableCollection ) alias2CollectionPersister.get( alias )
          );
          if ( isEntityElements ) {
            elementEntityAliases = new ColumnEntityAliases(
                ( Map ) entityPropertyResultMaps.get( alias ),
                ( SQLLoadable ) alias2Persister.get( alias ),
                ( String ) alias2Suffix.get( alias )
            );
          }
        }
        CollectionReturn customReturn = new CollectionReturn(
            alias,
            rtn.getOwnerEntityName(),
            rtn.getOwnerProperty(),
            collectionAliases,
                elementEntityAliases,
            rtn.getLockMode()
        );
        customReturns.add( customReturn );
        customReturnsByAlias.put( rtn.getAlias(), customReturn );
      }
      else if ( queryReturns[i] instanceof NativeSQLQueryJoinReturn ) {
        NativeSQLQueryJoinReturn rtn = ( NativeSQLQueryJoinReturn ) queryReturns[i];
        String alias = rtn.getAlias();
        FetchReturn customReturn;
        NonScalarReturn ownerCustomReturn = ( NonScalarReturn ) customReturnsByAlias.get( rtn.getOwnerAlias() );
        if ( alias2CollectionPersister.containsKey( alias ) ) {
          SQLLoadableCollection persister = ( SQLLoadableCollection ) alias2CollectionPersister.get( alias );
          boolean isEntityElements = persister.getElementType().isEntityType();
          CollectionAliases collectionAliases;
          EntityAliases elementEntityAliases = null;
          if ( queryHadAliases || hasPropertyResultMap( alias ) ) {
            collectionAliases = new GeneratedCollectionAliases(
                ( Map ) collectionPropertyResultMaps.get( alias ),
                persister,
                ( String ) alias2CollectionSuffix.get( alias )
            );
            if ( isEntityElements ) {
              elementEntityAliases = new DefaultEntityAliases(
                  ( Map ) entityPropertyResultMaps.get( alias ),
                  ( SQLLoadable ) alias2Persister.get( alias ),
                  ( String ) alias2Suffix.get( alias )
              );
            }
          }
          else {
            collectionAliases = new ColumnCollectionAliases(
                ( Map ) collectionPropertyResultMaps.get( alias ),
                persister
            );
            if ( isEntityElements ) {
              elementEntityAliases = new ColumnEntityAliases(
                  ( Map ) entityPropertyResultMaps.get( alias ),
                  ( SQLLoadable ) alias2Persister.get( alias ),
                  ( String ) alias2Suffix.get( alias )
              );
            }
          }
          customReturn = new CollectionFetchReturn(
              alias,
              ownerCustomReturn,
              rtn.getOwnerProperty(),
              collectionAliases,
                  elementEntityAliases,
              rtn.getLockMode()
          );
        }
        else {
          EntityAliases entityAliases;
          if ( queryHadAliases || hasPropertyResultMap( alias ) ) {
            entityAliases = new DefaultEntityAliases(
                ( Map ) entityPropertyResultMaps.get( alias ),
                ( SQLLoadable ) alias2Persister.get( alias ),
                ( String ) alias2Suffix.get( alias )
            );
          }
          else {
            entityAliases = new ColumnEntityAliases(
                ( Map ) entityPropertyResultMaps.get( alias ),
                ( SQLLoadable ) alias2Persister.get( alias ),
                ( String ) alias2Suffix.get( alias )
            );
          }
          customReturn = new EntityFetchReturn(
              alias,
              entityAliases,
              ownerCustomReturn,
              rtn.getOwnerProperty(),
              rtn.getLockMode()
          );
        }
        customReturns.add( customReturn );
        customReturnsByAlias.put( alias, customReturn );
      }
View Full Code Here


      );
    }
    else if ( !void.class.equals( queryAnn.resultClass() ) ) {
      //class mapping usage
      //FIXME should be done in a second pass due to entity name?
      final NativeSQLQueryRootReturn entityQueryReturn =
          new NativeSQLQueryRootReturn( "alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ );
      query = new NamedSQLQueryDefinition(
          queryName,
          new NativeSQLQueryReturn[] { entityQueryReturn },
          null,
          getBoolean( queryName, "org.hibernate.cacheable", hints ),
View Full Code Here

      );
    }
    else if ( !void.class.equals( queryAnn.resultClass() ) ) {
      //class mapping usage
      //FIXME should be done in a second pass due to entity name?
      final NativeSQLQueryRootReturn entityQueryReturn =
          new NativeSQLQueryRootReturn( "alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ );
      query = new NamedSQLQueryDefinition(
          queryAnn.query(),
          new NativeSQLQueryReturn[] { entityQueryReturn },
          null,
          queryAnn.cacheable(),
View Full Code Here

      if ( !BinderHelper.isDefault( entity.discriminatorColumn() ) ) {
        propertyresults.put( "class", new String[] { entity.discriminatorColumn() } );
      }

      propertyresults = propertyresults.isEmpty() ? CollectionHelper.EMPTY_MAP : propertyresults;
      NativeSQLQueryRootReturn result =
          new NativeSQLQueryRootReturn(
              "alias" + entityAliasIndex++, entity.entityClass().getName(), propertyresults, LockMode.READ
          );
      definition.addQueryReturn( result );
    }
View Full Code Here

      if ( queryReturns[i] instanceof NativeSQLQueryScalarReturn ) {
        NativeSQLQueryScalarReturn rtn = ( NativeSQLQueryScalarReturn ) queryReturns[i];
        customReturns.add( new ScalarReturn( rtn.getType(), rtn.getColumnAlias() ) );
      }
      else if ( queryReturns[i] instanceof NativeSQLQueryRootReturn ) {
        NativeSQLQueryRootReturn rtn = ( NativeSQLQueryRootReturn ) queryReturns[i];
        String alias = rtn.getAlias();
        EntityAliases entityAliases;
        if ( queryHadAliases || hasPropertyResultMap( alias ) ) {
          entityAliases = new DefaultEntityAliases(
              ( Map ) entityPropertyResultMaps.get( alias ),
              ( SQLLoadable ) alias2Persister.get( alias ),
              ( String ) alias2Suffix.get( alias )
          );
        }
        else {
          entityAliases = new ColumnEntityAliases(
              ( Map ) entityPropertyResultMaps.get( alias ),
              ( SQLLoadable ) alias2Persister.get( alias ),
              ( String ) alias2Suffix.get( alias )
          );
        }
        RootReturn customReturn = new RootReturn(
            alias,
            rtn.getReturnEntityName(),
            entityAliases,
            rtn.getLockMode()
        );
        customReturns.add( customReturn );
        customReturnsByAlias.put( rtn.getAlias(), customReturn );
      }
      else if ( queryReturns[i] instanceof NativeSQLQueryCollectionReturn ) {
        NativeSQLQueryCollectionReturn rtn = ( NativeSQLQueryCollectionReturn ) queryReturns[i];
        String alias = rtn.getAlias();
        SQLLoadableCollection persister = ( SQLLoadableCollection ) alias2CollectionPersister.get( alias );
        boolean isEntityElements = persister.getElementType().isEntityType();
        CollectionAliases collectionAliases;
        EntityAliases elementEntityAliases = null;
        if ( queryHadAliases || hasPropertyResultMap( alias ) ) {
          collectionAliases = new GeneratedCollectionAliases(
              ( Map ) collectionPropertyResultMaps.get( alias ),
              ( SQLLoadableCollection ) alias2CollectionPersister.get( alias ),
              ( String ) alias2CollectionSuffix.get( alias )
          );
          if ( isEntityElements ) {
            elementEntityAliases = new DefaultEntityAliases(
                ( Map ) entityPropertyResultMaps.get( alias ),
                ( SQLLoadable ) alias2Persister.get( alias ),
                ( String ) alias2Suffix.get( alias )
            );
          }
        }
        else {
          collectionAliases = new ColumnCollectionAliases(
              ( Map ) collectionPropertyResultMaps.get( alias ),
              ( SQLLoadableCollection ) alias2CollectionPersister.get( alias )
          );
          if ( isEntityElements ) {
            elementEntityAliases = new ColumnEntityAliases(
                ( Map ) entityPropertyResultMaps.get( alias ),
                ( SQLLoadable ) alias2Persister.get( alias ),
                ( String ) alias2Suffix.get( alias )
            );
          }
        }
        CollectionReturn customReturn = new CollectionReturn(
            alias,
            rtn.getOwnerEntityName(),
            rtn.getOwnerProperty(),
            collectionAliases,
                elementEntityAliases,
            rtn.getLockMode()
        );
        customReturns.add( customReturn );
        customReturnsByAlias.put( rtn.getAlias(), customReturn );
      }
      else if ( queryReturns[i] instanceof NativeSQLQueryJoinReturn ) {
        NativeSQLQueryJoinReturn rtn = ( NativeSQLQueryJoinReturn ) queryReturns[i];
        String alias = rtn.getAlias();
        FetchReturn customReturn;
        NonScalarReturn ownerCustomReturn = ( NonScalarReturn ) customReturnsByAlias.get( rtn.getOwnerAlias() );
        if ( alias2CollectionPersister.containsKey( alias ) ) {
          SQLLoadableCollection persister = ( SQLLoadableCollection ) alias2CollectionPersister.get( alias );
          boolean isEntityElements = persister.getElementType().isEntityType();
          CollectionAliases collectionAliases;
          EntityAliases elementEntityAliases = null;
          if ( queryHadAliases || hasPropertyResultMap( alias ) ) {
            collectionAliases = new GeneratedCollectionAliases(
                ( Map ) collectionPropertyResultMaps.get( alias ),
                persister,
                ( String ) alias2CollectionSuffix.get( alias )
            );
            if ( isEntityElements ) {
              elementEntityAliases = new DefaultEntityAliases(
                  ( Map ) entityPropertyResultMaps.get( alias ),
                  ( SQLLoadable ) alias2Persister.get( alias ),
                  ( String ) alias2Suffix.get( alias )
              );
            }
          }
          else {
            collectionAliases = new ColumnCollectionAliases(
                ( Map ) collectionPropertyResultMaps.get( alias ),
                persister
            );
            if ( isEntityElements ) {
              elementEntityAliases = new ColumnEntityAliases(
                  ( Map ) entityPropertyResultMaps.get( alias ),
                  ( SQLLoadable ) alias2Persister.get( alias ),
                  ( String ) alias2Suffix.get( alias )
              );
            }
          }
          customReturn = new CollectionFetchReturn(
              alias,
              ownerCustomReturn,
              rtn.getOwnerProperty(),
              collectionAliases,
                  elementEntityAliases,
              rtn.getLockMode()
          );
        }
        else {
          EntityAliases entityAliases;
          if ( queryHadAliases || hasPropertyResultMap( alias ) ) {
            entityAliases = new DefaultEntityAliases(
                ( Map ) entityPropertyResultMaps.get( alias ),
                ( SQLLoadable ) alias2Persister.get( alias ),
                ( String ) alias2Suffix.get( alias )
            );
          }
          else {
            entityAliases = new ColumnEntityAliases(
                ( Map ) entityPropertyResultMaps.get( alias ),
                ( SQLLoadable ) alias2Persister.get( alias ),
                ( String ) alias2Suffix.get( alias )
            );
          }
          customReturn = new EntityFetchReturn(
              alias,
              entityAliases,
              ownerCustomReturn,
              rtn.getOwnerProperty(),
              rtn.getLockMode()
          );
        }
        customReturns.add( customReturn );
        customReturnsByAlias.put( alias, customReturn );
      }
View Full Code Here

      );
    }
    else if ( ! void.class.equals( queryAnn.resultClass() ) ) {
      //class mapping usage
      //FIXME should be done in a second pass due to entity name?
      final NativeSQLQueryRootReturn entityQueryReturn =
          new NativeSQLQueryRootReturn( "alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ );
      query = new NamedSQLQueryDefinition(
          queryName,
          new NativeSQLQueryReturn[]{entityQueryReturn},
          null,
          getBoolean( queryName, "org.hibernate.cacheable", hints ),
View Full Code Here

      );
    }
    else if ( ! void.class.equals( queryAnn.resultClass() ) ) {
      //class mapping usage
      //FIXME should be done in a second pass due to entity name?
      final NativeSQLQueryRootReturn entityQueryReturn =
          new NativeSQLQueryRootReturn( "alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ );
      query = new NamedSQLQueryDefinition(
          queryAnn.query(),
          new NativeSQLQueryReturn[]{entityQueryReturn},
          null,
          queryAnn.cacheable(),
View Full Code Here

      if ( ! BinderHelper.isDefault( entity.discriminatorColumn() ) ) {
        propertyresults.put( "class", new String[]{entity.discriminatorColumn()} );
      }

      propertyresults = propertyresults.isEmpty() ? CollectionHelper.EMPTY_MAP : propertyresults;
      NativeSQLQueryRootReturn result =
          new NativeSQLQueryRootReturn(
              "alias" + entityAliasIndex++, entity.entityClass().getName(), propertyresults, LockMode.READ
          );
      definition.addQueryReturn( result );
    }
View Full Code Here

    check( true, aliasTypeString, new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "string" ) ) );
    check( true, aliasTypeStringClass, new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( String.class.getName() ) ) );
  }

  public void testNativeSQLQueryRootReturn() {
    NativeSQLQueryRootReturn alias = new NativeSQLQueryRootReturn( "abc", null, null);
    NativeSQLQueryRootReturn diffAlias = new NativeSQLQueryRootReturn( "def", null, null);
    NativeSQLQueryRootReturn aliasEntityName = new NativeSQLQueryRootReturn( "abc", "Person", null);
    NativeSQLQueryRootReturn aliasDiffEntityName = new NativeSQLQueryRootReturn( "abc", "Customer", null);
    NativeSQLQueryRootReturn aliasEntityNameLockMode = new NativeSQLQueryRootReturn( "abc", "Person", LockMode.NONE );
//    NativeSQLQueryRootReturn aliasEntityNameDiffLockMode = new NativeSQLQueryRootReturn( "abc", "Person", LockMode.OPTIMISTIC );

    check( false, alias, diffAlias );
    check( false, alias, aliasEntityName );
    check( false, alias, aliasDiffEntityName );
    check( false, alias, aliasEntityNameLockMode );

    check( false, diffAlias, aliasEntityName );
    check( false, diffAlias, aliasDiffEntityName );
    check( false, diffAlias, aliasEntityNameLockMode );

    check( false, aliasEntityName, aliasDiffEntityName );
    check( false, aliasEntityName, aliasEntityNameLockMode );

    check( false, aliasDiffEntityName, aliasEntityNameLockMode );


    check( true, alias, new NativeSQLQueryRootReturn( "abc", null, null) );
    check( true, diffAlias, new NativeSQLQueryRootReturn( "def", null, null) );
    check( true, aliasEntityName, new NativeSQLQueryRootReturn( "abc", "Person", null) );
    check( true, aliasDiffEntityName, new NativeSQLQueryRootReturn( "abc", "Customer", null) );
    check( true, aliasEntityNameLockMode, new NativeSQLQueryRootReturn( "abc", "Person", LockMode.NONE ) );
//    check( true, aliasEntityNameDiffLockMode, new NativeSQLQueryRootReturn( "abc", "Person", LockMode.OPTIMISTIC ) );
  }
View Full Code Here

    check( true, r7, new NativeSQLQueryCollectionReturn( "b", "c", "a", null, LockMode.NONE ) );
  }

  public void testNativeSQLQueryReturnTypes() {
    NativeSQLQueryScalarReturn r1 = new NativeSQLQueryScalarReturn( "a", TypeFactory.basic( "int" ) );
    NativeSQLQueryRootReturn r2 = new NativeSQLQueryRootReturn( "a", "b", LockMode.NONE );
    NativeSQLQueryJoinReturn r3 = new NativeSQLQueryJoinReturn( "a", "b", "c", Collections.singletonMap( "key", "value" ), LockMode.NONE );
    NativeSQLQueryCollectionReturn r4 = new NativeSQLQueryCollectionReturn( "a", "b", "c", Collections.singletonMap( "key", "value" ), LockMode.NONE);

    check( false, r1, r2 );
    check( false, r1, r3 );
View Full Code Here

TOP

Related Classes of org.hibernate.engine.query.sql.NativeSQLQueryRootReturn

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.