Examples of Dialect


Examples of org.hibernate.dialect.Dialect

    return new int[ getPropertySpan() ];
  }

  protected String generateSubquery(PersistentClass model, Mapping mapping) {

    Dialect dialect = getFactory().getDialect();
    Settings settings = getFactory().getSettings();
   
    if ( !model.hasSubclasses() ) {
      return model.getTable().getQualifiedName(
          dialect,
          settings.getDefaultCatalogName(),
          settings.getDefaultSchemaName()
        );
    }

    HashSet columns = new LinkedHashSet();
    Iterator titer = model.getSubclassTableClosureIterator();
    while ( titer.hasNext() ) {
      Table table = (Table) titer.next();
      if ( !table.isAbstractUnionTable() ) {
        Iterator citer = table.getColumnIterator();
        while ( citer.hasNext() ) columns.add( citer.next() );
      }
    }

    StringBuilder buf = new StringBuilder()
      .append("( ");

    Iterator siter = new JoinedIterator(
      new SingletonIterator(model),
      model.getSubclassIterator()
    );

    while ( siter.hasNext() ) {
      PersistentClass clazz = (PersistentClass) siter.next();
      Table table = clazz.getTable();
      if ( !table.isAbstractUnionTable() ) {
        //TODO: move to .sql package!!
        buf.append("select ");
        Iterator citer = columns.iterator();
        while ( citer.hasNext() ) {
          Column col = (Column) citer.next();
          if ( !table.containsColumn(col) ) {
            int sqlType = col.getSqlTypeCode(mapping);
            buf.append( dialect.getSelectClauseNullString(sqlType) )
              .append(" as ");
          }
          buf.append( col.getQuotedName(dialect) );
          buf.append(", ");
        }
        buf.append( clazz.getSubclassId() )
          .append(" as clazz_");
        buf.append(" from ")
          .append( table.getQualifiedName(
              dialect,
              settings.getDefaultCatalogName(),
              settings.getDefaultSchemaName()
          ) );
        buf.append(" union ");
        if ( dialect.supportsUnionAll() ) {
          buf.append("all ");
        }
      }
    }
   
    if ( buf.length() > 2 ) {
      //chop the last union (all)
      buf.setLength( buf.length() - ( dialect.supportsUnionAll() ? 11 : 7 ) );
    }

    return buf.append(" )").toString();
  }
View Full Code Here

Examples of org.hibernate.dialect.Dialect

    this( propertyName, matchMode.toMatchString( value ), escapeChar, ignoreCase );
  }

  @Override
  public String toSqlString(Criteria criteria,CriteriaQuery criteriaQuery) {
    final Dialect dialect = criteriaQuery.getFactory().getDialect();
    final String[] columns = criteriaQuery.findColumns( propertyName, criteria );
    if ( columns.length != 1 ) {
      throw new HibernateException( "Like may only be used with single-column properties" );
    }

    final String escape = escapeChar == null ? "" : " escape \'" + escapeChar + "\'";
    final String column = columns[0];
    if ( ignoreCase ) {
      if ( dialect.supportsCaseInsensitiveLike() ) {
        return column +" " + dialect.getCaseInsensitiveLike() + " ?" + escape;
      }
      else {
        return dialect.getLowercaseFunction() + '(' + column + ')' + " like ?" + escape;
      }
    }
    else {
      return column + " like ?" + escape;
    }
View Full Code Here

Examples of org.hibernate.dialect.Dialect

          String sql,
          final QueryParameters queryParameters,
          final LimitHandler limitHandler,
          final boolean scroll,
          final SessionImplementor session) throws SQLException, HibernateException {
    final Dialect dialect = getFactory().getDialect();
    final RowSelection selection = queryParameters.getRowSelection();
    boolean useLimit = LimitHelper.useLimit( limitHandler, selection );
    boolean hasFirstRow = LimitHelper.hasFirstRow( selection );
    boolean useLimitOffset = hasFirstRow && useLimit && limitHandler.supportsLimitOffset();
    boolean callable = queryParameters.isCallable();
    final ScrollMode scrollMode = getScrollMode( scroll, hasFirstRow, useLimitOffset, queryParameters );
   
    PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareQueryStatement(
        sql,
        callable,
        scrollMode
    );

    try {

      int col = 1;
      //TODO: can we limit stored procedures ?!
      col += limitHandler.bindLimitParametersAtStartOfQuery( st, col );

      if (callable) {
        col = dialect.registerResultSetOutParameter( (CallableStatement)st, col );
      }

      col += bindParameterValues( st, queryParameters, col, session );

      col += limitHandler.bindLimitParametersAtEndOfQuery( st, col );

      limitHandler.setMaxRows( st );

      if ( selection != null ) {
        if ( selection.getTimeout() != null ) {
          st.setQueryTimeout( selection.getTimeout() );
        }
        if ( selection.getFetchSize() != null ) {
          st.setFetchSize( selection.getFetchSize() );
        }
      }

      // handle lock timeout...
      LockOptions lockOptions = queryParameters.getLockOptions();
      if ( lockOptions != null ) {
        if ( lockOptions.getTimeOut() != LockOptions.WAIT_FOREVER ) {
          if ( !dialect.supportsLockTimeouts() ) {
            if ( LOG.isDebugEnabled() ) {
              LOG.debugf(
                  "Lock timeout [%s] requested but dialect reported to not support lock timeouts",
                  lockOptions.getTimeOut()
              );
            }
          }
          else if ( dialect.isLockTimeoutParameterized() ) {
            st.setInt( col++, lockOptions.getTimeOut() );
          }
        }
      }
View Full Code Here

Examples of org.hibernate.dialect.Dialect

      final String sql,
      final QueryParameters queryParameters,
      final LimitHandler limitHandler,
      final boolean scroll,
      final SessionImplementor session) throws SQLException, HibernateException {
    final Dialect dialect = getFactory().getDialect();
    final RowSelection selection = queryParameters.getRowSelection();
    final boolean useLimit = LimitHelper.useLimit( limitHandler, selection );
    final boolean hasFirstRow = LimitHelper.hasFirstRow( selection );
    final boolean useLimitOffset = hasFirstRow && useLimit && limitHandler.supportsLimitOffset();
    final boolean callable = queryParameters.isCallable();
    final ScrollMode scrollMode = getScrollMode( scroll, hasFirstRow, useLimitOffset, queryParameters );

    final PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator()
        .getStatementPreparer().prepareQueryStatement( sql, callable, scrollMode );

    try {

      int col = 1;
      //TODO: can we limit stored procedures ?!
      col += limitHandler.bindLimitParametersAtStartOfQuery( st, col );

      if (callable) {
        col = dialect.registerResultSetOutParameter( (CallableStatement)st, col );
      }

      col += bindParameterValues( st, queryParameters, col, session );

      col += limitHandler.bindLimitParametersAtEndOfQuery( st, col );

      limitHandler.setMaxRows( st );

      if ( selection != null ) {
        if ( selection.getTimeout() != null ) {
          st.setQueryTimeout( selection.getTimeout() );
        }
        if ( selection.getFetchSize() != null ) {
          st.setFetchSize( selection.getFetchSize() );
        }
      }

      // handle lock timeout...
      final LockOptions lockOptions = queryParameters.getLockOptions();
      if ( lockOptions != null ) {
        if ( lockOptions.getTimeOut() != LockOptions.WAIT_FOREVER ) {
          if ( !dialect.supportsLockTimeouts() ) {
            if ( log.isDebugEnabled() ) {
              log.debugf(
                  "Lock timeout [%s] requested but dialect reported to not support lock timeouts",
                  lockOptions.getTimeOut()
              );
            }
          }
          else if ( dialect.isLockTimeoutParameterized() ) {
            st.setInt( col++, lockOptions.getTimeOut() );
          }
        }
      }
View Full Code Here

Examples of org.hibernate.dialect.Dialect

    boolean metaSupportsScrollable = false;
    boolean metaSupportsGetGeneratedKeys = false;
    boolean metaSupportsBatchUpdates = false;
    boolean metaReportsDDLCausesTxnCommit = false;
    boolean metaReportsDDLInTxnSupported = true;
    Dialect dialect = null;
    JdbcSupport jdbcSupport = null;

    // 'hibernate.temp.use_jdbc_metadata_defaults' is a temporary magic value.
    // The need for it is intended to be alleviated with future development, thus it is
    // not defined as an Environment constant...
    //
    // it is used to control whether we should consult the JDBC metadata to determine
    // certain Settings default values; it is useful to *not* do this when the database
    // may not be available (mainly in tools usage).
    boolean useJdbcMetadata = PropertiesHelper.getBoolean( "hibernate.temp.use_jdbc_metadata_defaults", props, true );
    if ( useJdbcMetadata ) {
      try {
        Connection conn = connections.getConnection();
        try {
          DatabaseMetaData meta = conn.getMetaData();

          dialect = DialectFactory.buildDialect( props, conn );
          jdbcSupport = JdbcSupportLoader.loadJdbcSupport( conn );

          metaSupportsScrollable = meta.supportsResultSetType( ResultSet.TYPE_SCROLL_INSENSITIVE );
          metaSupportsBatchUpdates = meta.supportsBatchUpdates();
          metaReportsDDLCausesTxnCommit = meta.dataDefinitionCausesTransactionCommit();
          metaReportsDDLInTxnSupported = !meta.dataDefinitionIgnoredInTransactions();
          metaSupportsGetGeneratedKeys = meta.supportsGetGeneratedKeys();
         
          log.info( "Database ->\n" +
              "       name : " + meta.getDatabaseProductName() + '\n' +
              "    version : " +  meta.getDatabaseProductVersion() + '\n' +
              "      major : " + meta.getDatabaseMajorVersion() + '\n' +
              "      minor : " + meta.getDatabaseMinorVersion()
          );
          log.info( "Driver ->\n" +
              "       name : " + meta.getDriverName() + '\n' +
              "    version : " + meta.getDriverVersion() + '\n' +
              "      major : " + meta.getDriverMajorVersion() + '\n' +
              "      minor : " + meta.getDriverMinorVersion()
          );
        }
        catch ( SQLException sqle ) {
          log.warn( "Could not obtain connection metadata", sqle );
        }
        finally {
          connections.closeConnection( conn );
        }
      }
      catch ( SQLException sqle ) {
        log.warn( "Could not obtain connection to query metadata", sqle );
        dialect = DialectFactory.buildDialect( props );
      }
      catch ( UnsupportedOperationException uoe ) {
        // user supplied JDBC connections
        dialect = DialectFactory.buildDialect( props );
      }
    }
    else {
      dialect = DialectFactory.buildDialect( props );
    }

    settings.setDataDefinitionImplicitCommit( metaReportsDDLCausesTxnCommit );
    settings.setDataDefinitionInTransactionSupported( metaReportsDDLInTxnSupported );
    settings.setDialect( dialect );
    if ( jdbcSupport == null ) {
      jdbcSupport = JdbcSupportLoader.loadJdbcSupport( null );
    }
    settings.setJdbcSupport( jdbcSupport );

    //use dialect default properties
    final Properties properties = new Properties();
    properties.putAll( dialect.getDefaultProperties() );
    properties.putAll( props );

    // Transaction settings:

    TransactionFactory transactionFactory = createTransactionFactory(properties);
View Full Code Here

Examples of org.hibernate.dialect.Dialect

        && ( !hasDynamicFilterParam( sqlFragment ) )
        && ( !( hasCollectionFilterParam( sqlFragment ) ) ) ) {
      return;
    }

    Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
    String symbols = ParserHelper.HQL_SEPARATORS + dialect.openQuote() + dialect.closeQuote();
    StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
    StringBuilder result = new StringBuilder();

    while ( tokens.hasMoreTokens() ) {
      final String token = tokens.nextToken();
View Full Code Here

Examples of org.hibernate.dialect.Dialect

        AvailableSettings.HBM2DDL_IMPORT_FILES,
        configuration.getProperties(),
        DEFAULT_IMPORT_FILE
    );

    final Dialect dialect = serviceRegistry.getService( JdbcServices.class ).getDialect();
    this.dropSQL = configuration.generateDropSchemaScript( dialect );
    this.createSQL = configuration.generateSchemaCreationScript( dialect );
  }
View Full Code Here

Examples of org.hibernate.dialect.Dialect

        AvailableSettings.HBM2DDL_IMPORT_FILES,
        serviceRegistry.getService( ConfigurationService.class ).getSettings(),
        DEFAULT_IMPORT_FILE
    );

    final Dialect dialect = jdbcServices.getDialect();
    this.dropSQL = metadata.getDatabase().generateDropSchemaScript( dialect );
    this.createSQL = metadata.getDatabase().generateSchemaCreationScript( dialect );
  }
View Full Code Here

Examples of org.hibernate.dialect.Dialect

   *
   * @deprecated properties may be specified via the Configuration object
   */
  @Deprecated
    public SchemaExport(Configuration configuration, Properties properties) throws HibernateException {
    final Dialect dialect = Dialect.getDialect( properties );

    Properties props = new Properties();
    props.putAll( dialect.getDefaultProperties() );
    props.putAll( properties );
    this.connectionHelper = new ManagedProviderConnectionHelper( props );

    this.sqlStatementLogger = new SqlStatementLogger( false, true );
    this.formatter = FormatStyle.DDL.getFormatter();
View Full Code Here

Examples of org.hibernate.dialect.Dialect

        AvailableSettings.HBM2DDL_IMPORT_FILES,
        configuration.getProperties(),
        DEFAULT_IMPORT_FILE
    );

    final Dialect dialect = Dialect.getDialect( configuration.getProperties() );
    this.dropSQL = configuration.generateDropSchemaScript( dialect );
    this.createSQL = configuration.generateSchemaCreationScript( dialect );
  }
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.