/**
     * @return Query info.
     * @throws GridException In case of error.
     */
    @SuppressWarnings({"unchecked"})
    private GridCacheQueryInfo localQueryInfo() throws GridException {
      GridCacheQueryBean qry = query();

      GridPredicate<GridCacheEntry<Object, Object>> prjPred =
          qry.query().projectionFilter() == null
              ? F.<GridCacheEntry<Object, Object>>alwaysTrue()
              : qry.query().projectionFilter();

      GridMarshaller marsh = cctx.marshaller();

      GridReducer<Object, Object> rdc =
          qry.reducer() != null
              ? marsh.<GridReducer<Object, Object>>unmarshal(marsh.marshal(qry.reducer()), null)
              : null;

      GridClosure<Object, Object> trans =
          qry.transform() != null
              ? marsh.<GridClosure<Object, Object>>unmarshal(marsh.marshal(qry.transform()), null)
              : null;

      return new GridCacheQueryInfo(
          true,
          prjPred,
          trans,
          rdc,
          qry.query(),
          GridCacheLocalQueryFuture.this,
          ctx.localNodeId(),
          cctx.io().nextIoId(),
          qry.query().includeMetadata(),
          true,
          qry.arguments());
    }
  /**
   * Initializes store.
   *
   * @throws GridException If failed to initialize.
   */
  private void init() throws GridException {
    if (initGuard.compareAndSet(false, true)) {
      if (log.isDebugEnabled()) log.debug("Initializing cache store.");

      try {
        if (sesFactory != null)
          // Session factory has been provided - nothing to do.
          return;

        if (!F.isEmpty(hibernateCfgPath)) {
          try {
            URL url = new URL(hibernateCfgPath);

            sesFactory = new Configuration().configure(url).buildSessionFactory();

            if (log.isDebugEnabled()) log.debug("Configured session factory using URL: " + url);

            // Session factory has been successfully initialized.
            return;
          } catch (MalformedURLException e) {
            if (log.isDebugEnabled())
              log.debug("Caught malformed URL exception: " + e.getMessage());
          }

          // Provided path is not a valid URL. File?
          File cfgFile = new File(hibernateCfgPath);

          if (cfgFile.exists()) {
            sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();

            if (log.isDebugEnabled())
              log.debug("Configured session factory using file: " + hibernateCfgPath);

            // Session factory has been successfully initialized.
            return;
          }

          // Provided path is not a file. Classpath resource?
          sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();

          if (log.isDebugEnabled())
            log.debug("Configured session factory using classpath resource: " + hibernateCfgPath);
        } else {
          if (hibernateProps == null) {
            U.warn(
                log, "No Hibernate configuration has been provided for store (will use default).");

            hibernateProps = new Properties();

            hibernateProps.setProperty("hibernate.connection.url", DFLT_CONN_URL);
            hibernateProps.setProperty("hibernate.show_sql", DFLT_SHOW_SQL);
            hibernateProps.setProperty("hibernate.hbm2ddl.auto", DFLT_HBM2DDL_AUTO);
          }

          Configuration cfg = new Configuration();

          cfg.setProperties(hibernateProps);

          assert resourceAvailable(MAPPING_RESOURCE);

          cfg.addResource(MAPPING_RESOURCE);

          sesFactory = cfg.buildSessionFactory();

          if (log.isDebugEnabled())
            log.debug("Configured session factory using properties: " + hibernateProps);
        }
      } catch (HibernateException e) {
        throw new GridException("Failed to initialize store.", e);
      } finally {
        initLatch.countDown();
      }
    } else if (initLatch.getCount() > 0) U.await(initLatch);

    if (sesFactory == null) throw new GridException("Cache store was not properly initialized.");
  }