Examples of SelectStatementBuilder


Examples of de.fuberlin.wiwiss.d2rq.sql.SelectStatementBuilder

    requiredProjections.add(downloadMap.getContentDownloadColumn());
    requiredProjections.addAll(mediaTypeValueMaker.projectionSpecs());
    newRelation.project(requiredProjections);
    newRelation.limit(1);
    Relation filteredRelation = newRelation.immutableSnapshot();
    SelectStatementBuilder builder = new SelectStatementBuilder(filteredRelation);
    String sql = builder.getSQLStatement();
    int contentColumn = builder.getColumnSpecs().indexOf(downloadMap.getContentDownloadColumn()) + 1;
      db = filteredRelation.database();
    Connection conn = db.connection();
    try {
      statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      log.debug(sql);

      db.vendor().beforeQuery(conn);
      resultSet = statement.executeQuery(sql);
      db.vendor().afterQuery(conn);
     
      if (!resultSet.next()) {
        close();
        return// 0 results
      }
      int type = resultSet.getMetaData().getColumnType(contentColumn);
      // TODO Handle Oracle BFILE type; there's some code for that already in ResultRowMap
      if (type == Types.BINARY || type == Types.VARBINARY || type == Types.LONGVARBINARY || type == Types.BLOB) {
        resultStream = resultSet.getBinaryStream(contentColumn);
        if (resultSet.wasNull()) {
          resultStream = null;
        }
      } else {
        String s = resultSet.getString(contentColumn);
        if (!resultSet.wasNull()) {
          resultStream = new ByteArrayInputStream(s.getBytes());
        }
      }
      mediaType = mediaTypeValueMaker.makeValue(
          ResultRowMap.fromResultSet(resultSet, builder.getColumnSpecs(), db));
    } catch (SQLException ex) {
      throw new D2RQException(ex);
    }
  }
View Full Code Here

Examples of de.fuberlin.wiwiss.d2rq.sql.SelectStatementBuilder

  private QueryIterTableSQL(Relation relation,
      Collection<BindingMaker> bindingMakers, ExecutionContext execCxt) {
    super(execCxt);
    this.bindingMakers = bindingMakers;
    SelectStatementBuilder builder = new SelectStatementBuilder(relation);
    wrapped = new SQLIterator(
        builder.getSQLStatement(), builder.getColumnSpecs(), relation.database());
  }
View Full Code Here

Examples of org.hibernate.loader.plan.exec.query.internal.SelectStatementBuilder

    //    build the needed SQL.
    //   2) Determine how to read information out of the ResultSet resulting from executing the indicated SQL
    //    (the SQL aliases).  ReaderCollector and friends are where this work happens, ultimately
    //    producing a ResultSetProcessor

    final SelectStatementBuilder select = new SelectStatementBuilder( queryProcessor.getSessionFactory().getDialect() );

    // LoadPlan is broken down into 2 high-level pieces that we need to process here.
    //
    // First is the QuerySpaces, which roughly equates to the SQL FROM-clause.  We'll cycle through
    // those first, generating aliases into the AliasContext in addition to writing SQL FROM-clause information
    // into SelectStatementBuilder.  The AliasContext is populated here and the reused while process the SQL
    // SELECT-clause into the SelectStatementBuilder and then again also to build the ResultSetProcessor

    applyRootReturnTableFragments( select );

    if ( shouldApplyRootReturnFilterBeforeKeyRestriction() ) {
      applyRootReturnFilterRestrictions( select );
      // add restrictions...
      // first, the load key restrictions (which entity(s)/collection(s) do we want to load?)
      applyKeyRestriction(
          select,
          getRootTableAlias(),
          keyColumnNames,
          getQueryBuildingParameters().getBatchSize()
      );
    }
    else {
      // add restrictions...
      // first, the load key restrictions (which entity(s)/collection(s) do we want to load?)
      applyKeyRestriction(
          select,
          getRootTableAlias(),
          keyColumnNames,
          getQueryBuildingParameters().getBatchSize()
      );
      applyRootReturnFilterRestrictions( select );
    }


    applyRootReturnWhereJoinRestrictions( select );

    applyRootReturnOrderByFragments( select );
    // then move on to joins...

    applyRootReturnSelectFragments( select );

    queryProcessor.processQuerySpaceJoins( getRootQuerySpace(), select );

    // Next, we process the Returns and Fetches building the SELECT clause and at the same time building
    // Readers for reading the described results out of a SQL ResultSet

    FetchStats fetchStats = null;
    if ( FetchSource.class.isInstance( rootReturn ) ) {
      fetchStats = queryProcessor.processFetches(
          (FetchSource) rootReturn,
          select,
          getReaderCollector()
      );
    }
    else if ( CollectionReturn.class.isInstance( rootReturn ) ) {
      final CollectionReturn collectionReturn = (CollectionReturn) rootReturn;
      if ( collectionReturn.getElementGraph() != null ) {
        fetchStats = queryProcessor.processFetches(
            collectionReturn.getElementGraph(),
            select,
            getReaderCollector()
        );
      }
      // TODO: what about index???
    }

    LoadPlanTreePrinter.INSTANCE.logTree( loadPlan, queryProcessor.getAliasResolutionContext() );

    this.sqlStatement = select.toStatementString();
    this.resultSetProcessor = new ResultSetProcessorImpl(
        loadPlan,
        getReaderCollector().buildRowReader(),
        fetchStats != null && fetchStats.hasSubselectFetches()
    );
View Full Code Here

Examples of org.hibernate.loader.plan.exec.query.internal.SelectStatementBuilder

    //    build the needed SQL.
    //   2) Determine how to read information out of the ResultSet resulting from executing the indicated SQL
    //    (the SQL aliases).  ReaderCollector and friends are where this work happens, ultimately
    //    producing a ResultSetProcessor

    final SelectStatementBuilder select = new SelectStatementBuilder( queryProcessor.getSessionFactory().getDialect() );

    // LoadPlan is broken down into 2 high-level pieces that we need to process here.
    //
    // First is the QuerySpaces, which roughly equates to the SQL FROM-clause.  We'll cycle through
    // those first, generating aliases into the AliasContext in addition to writing SQL FROM-clause information
    // into SelectStatementBuilder.  The AliasContext is populated here and the reused while process the SQL
    // SELECT-clause into the SelectStatementBuilder and then again also to build the ResultSetProcessor

    applyRootReturnTableFragments( select );

    if ( shouldApplyRootReturnFilterBeforeKeyRestriction() ) {
      applyRootReturnFilterRestrictions( select );
      // add restrictions...
      // first, the load key restrictions (which entity(s)/collection(s) do we want to load?)
      applyKeyRestriction(
          select,
          getRootTableAlias(),
          keyColumnNames,
          getQueryBuildingParameters().getBatchSize()
      );
    }
    else {
      // add restrictions...
      // first, the load key restrictions (which entity(s)/collection(s) do we want to load?)
      applyKeyRestriction(
          select,
          getRootTableAlias(),
          keyColumnNames,
          getQueryBuildingParameters().getBatchSize()
      );
      applyRootReturnFilterRestrictions( select );
    }


    applyRootReturnWhereJoinRestrictions( select );

    applyRootReturnOrderByFragments( select );
    // then move on to joins...

    applyRootReturnSelectFragments( select );

    queryProcessor.processQuerySpaceJoins( getRootQuerySpace(), select );

    // Next, we process the Returns and Fetches building the SELECT clause and at the same time building
    // Readers for reading the described results out of a SQL ResultSet

    FetchStats fetchStats = null;
    if ( FetchSource.class.isInstance( rootReturn ) ) {
      fetchStats = queryProcessor.processFetches(
          (FetchSource) rootReturn,
          select,
          getReaderCollector()
      );
    }
    else if ( CollectionReturn.class.isInstance( rootReturn ) ) {
      final CollectionReturn collectionReturn = (CollectionReturn) rootReturn;
      if ( collectionReturn.getElementGraph() != null ) {
        fetchStats = queryProcessor.processFetches(
            collectionReturn.getElementGraph(),
            select,
            getReaderCollector()
        );
      }
      // TODO: what about index???
    }

    LoadPlanTreePrinter.INSTANCE.logTree( loadPlan, queryProcessor.getAliasResolutionContext() );

    this.sqlStatement = select.toStatementString();
    this.resultSetProcessor = new ResultSetProcessorImpl(
        loadPlan,
        getReaderCollector().buildRowReader(),
        fetchStats != null && fetchStats.hasSubselectFetches()
    );
View Full Code Here

Examples of org.hibernate.loader.plan.exec.query.internal.SelectStatementBuilder

      boolean shouldUseOptionalEntityInformation,
      QueryBuildingParameters buildingParameters,
      SessionFactoryImplementor factory) {
    this.loadPlan = loadPlan;

    final SelectStatementBuilder select = new SelectStatementBuilder( factory.getDialect() );
    final EntityReturn rootReturn = Helper.INSTANCE.extractRootReturn( loadPlan, EntityReturn.class );
    final AliasResolutionContext aliasResolutionContext = new AliasResolutionContextImpl( factory );
    final ReaderCollectorImpl readerCollector = new ReaderCollectorImpl();

    final String[] keyColumnNamesToUse = keyColumnNames != null
        ? keyColumnNames
        : ( (Queryable) rootReturn.getEntityPersister() ).getIdentifierColumnNames();

    // apply root entity return specifics
    applyRootReturnSpecifics(
        select,
        keyColumnNamesToUse,
        rootReturn,
        factory,
        buildingParameters,
        aliasResolutionContext
    );
    readerCollector.addReader(
        new EntityReturnReader(
            rootReturn,
            aliasResolutionContext.resolveAliases( rootReturn ),
            new EntityIdentifierReaderImpl(
                rootReturn,
                aliasResolutionContext.resolveAliases( rootReturn ),
                Collections.<EntityReferenceReader>emptyList()
            )
        )
    );

    FetchStats fetchStats = LoadQueryBuilderHelper.applyJoinFetches(
        select,
        factory,
        rootReturn,
        buildingParameters,
        aliasResolutionContext,
        readerCollector
    );

    this.sqlStatement = select.toStatementString();
    this.resultSetProcessor = new ResultSetProcessorImpl(
        loadPlan,
        readerCollector.buildRowReader(),
        fetchStats.hasSubselectFetches()
    );
View Full Code Here

Examples of org.hibernate.loader.plan2.exec.query.internal.SelectStatementBuilder

    //    build the needed SQL.
    //   2) Determine how to read information out of the ResultSet resulting from executing the indicated SQL
    //    (the SQL aliases).  ReaderCollector and friends are where this work happens, ultimately
    //    producing a ResultSetProcessor

    final SelectStatementBuilder select = new SelectStatementBuilder( factory.getDialect() );
    final EntityReturn rootReturn = Helper.INSTANCE.extractRootReturn( loadPlan, EntityReturn.class );
    final ReaderCollectorImpl readerCollector = new ReaderCollectorImpl();

    final LoadQueryJoinAndFetchProcessor helper = new LoadQueryJoinAndFetchProcessor( aliasResolutionContext , buildingParameters, factory );

    final String[] keyColumnNamesToUse = keyColumnNames != null
        ? keyColumnNames
        : ( (Queryable) rootReturn.getEntityPersister() ).getIdentifierColumnNames();

    // LoadPlan is broken down into 2 high-level pieces that we need to process here.
    //
    // First is the QuerySpaces, which roughly equates to the SQL FROM-clause.  We'll cycle through
    // those first, generating aliases into the AliasContext in addition to writing SQL FROM-clause information
    // into SelectStatementBuilder.  The AliasContext is populated here and the reused while process the SQL
    // SELECT-clause into the SelectStatementBuilder and then again also to build the ResultSetProcessor

    processQuerySpaces(
        loadPlan.getQuerySpaces(),
        select,
        keyColumnNamesToUse,
        helper,
        aliasResolutionContext,
        buildingParameters,
        factory
    );

    // Next, we process the Returns and Fetches building the SELECT clause and at the same time building
    // Readers for reading the described results out of a SQL ResultSet

    final FetchStats fetchStats = processReturnAndFetches(
        rootReturn,
        select,
        helper,
        readerCollector,
        aliasResolutionContext
    );

    LoadPlanTreePrinter.INSTANCE.logTree( loadPlan, aliasResolutionContext );

    this.sqlStatement = select.toStatementString();
    this.resultSetProcessor = new ResultSetProcessorImpl(
        loadPlan,
        readerCollector.buildRowReader(),
        fetchStats.hasSubselectFetches()
    );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.