Package org.hibernate.dialect

Examples of org.hibernate.dialect.Dialect


  protected final PreparedStatement prepareQueryStatement(
          final QueryParameters queryParameters,
          final boolean scroll,
          final SessionImplementor session) throws SQLException, HibernateException {
    String sql = processFilters( queryParameters, session );
    final Dialect dialect = getFactory().getDialect();
    final RowSelection selection = queryParameters.getRowSelection();
    boolean useLimit = useLimit( selection, dialect );
    boolean hasFirstRow = getFirstRow( selection ) > 0;
    boolean useOffset = hasFirstRow && useLimit && dialect.supportsLimitOffset();
    boolean callable = queryParameters.isCallable();
   
    boolean useScrollableResultSetToSkip = hasFirstRow &&
        !useOffset &&
        getFactory().getSettings().isScrollableResultSetsEnabled();
    ScrollMode scrollMode = scroll ? queryParameters.getScrollMode() : ScrollMode.SCROLL_INSENSITIVE;

    if ( useLimit ) {
      sql = dialect.getLimitString(
          sql.trim(), //use of trim() here is ugly?
          useOffset ? getFirstRow(selection) : 0,
          getMaxOrLimit(selection, dialect)
        );
    }

    sql = preprocessSQL( sql, queryParameters, dialect );
   
    PreparedStatement st = null;
   
    if (callable) {
      st = session.getBatcher()
        .prepareCallableQueryStatement( sql, scroll || useScrollableResultSetToSkip, scrollMode );
    }
    else {
      st = session.getBatcher()
        .prepareQueryStatement( sql, scroll || useScrollableResultSetToSkip, scrollMode );
    }
       

    try {

      int col = 1;
      //TODO: can we limit stored procedures ?!
      if ( useLimit && dialect.bindLimitParametersFirst() ) {
        col += bindLimitParameters( st, col, selection );
      }
      if (callable) {
        col = dialect.registerResultSetOutParameter( (CallableStatement)st, col );
      }

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

      if ( useLimit && !dialect.bindLimitParametersFirst() ) {
        col += bindLimitParameters( st, col, selection );
      }

      if ( !useLimit ) {
        setMaxRows( st, selection );
View Full Code Here


   */
  private int bindLimitParameters(
      final PreparedStatement statement,
      final int index,
      final RowSelection selection) throws SQLException {
    Dialect dialect = getFactory().getDialect();
    if ( !dialect.supportsVariableLimit() ) {
      return 0;
    }
    if ( !hasMaxRows( selection ) ) {
      throw new AssertionFailure( "no max results set" );
    }
    int firstRow = getFirstRow( selection );
    int lastRow = getMaxOrLimit( selection, dialect );
    boolean hasFirstRow = dialect.supportsLimitOffset() && ( firstRow > 0 || dialect.forceLimitUsage() );
    boolean reverse = dialect.bindLimitParametersInReverseOrder();
    if ( hasFirstRow ) {
      statement.setInt( index + ( reverse ? 1 : 0 ), firstRow );
    }
    statement.setInt( index + ( reverse || !hasFirstRow ? 0 : 1 ), lastRow );
    return hasFirstRow ? 2 : 1;
View Full Code Here

          final SessionImplementor session)
  throws SQLException, HibernateException {
 
    ResultSet rs = null;
    try {
      Dialect dialect = getFactory().getDialect();
      if (callable) {
        rs = session.getBatcher().getResultSet( (CallableStatement) st, dialect );
      }
      else {
        rs = session.getBatcher().getResultSet( st );
      }
      rs = wrapResultSetIfEnabled( rs , session );
     
      if ( !dialect.supportsLimitOffset() || !useLimit( selection, dialect ) ) {
        advance( rs, selection );
      }
     
      if ( autodiscovertypes ) {
        autoDiscoverTypes( rs );
View Full Code Here

    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 HashSet();
    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() );
      }
    }

    StringBuffer buf = new StringBuffer()
      .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.getName() );
          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

      return getCurrentTimestamp( session );
    }
  }

  private Timestamp getCurrentTimestamp(SessionImplementor session) {
    Dialect dialect = session.getFactory().getDialect();
    String timestampSelectString = dialect.getCurrentTimestampSelectString();
    if ( dialect.isCurrentTimestampSelectStringCallable() ) {
      return useCallableStatement( timestampSelectString, session );
    }
    else {
      return usePreparedStatement( timestampSelectString, session );
    }
View Full Code Here

    if ( type == null ) {
      throw new QueryException( QueryTranslator.ERROR_CANNOT_DETERMINE_TYPE + node.getText() );
    }
    try {
      LiteralType literalType = ( LiteralType ) type;
      Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
      node.setText( literalType.objectToSQLString( value, dialect ) );
    }
    catch ( Exception e ) {
      throw new QueryException( QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + node.getText(), e );
    }
View Full Code Here

    if ( replacement != null ) {
      constant.setText( replacement );
    }
    else {
      boolean bool = "true".equals( constant.getText().toLowerCase() );
      Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
      constant.setText( dialect.toBooleanValueString(bool) );
    }
  }
View Full Code Here

    settings.setDataDefinitionImplicitCommit( metaReportsDDLCausesTxnCommit );
    settings.setDataDefinitionInTransactionSupported( metaReportsDDLInTxnSupported );


    //SQL Dialect:
    Dialect dialect = determineDialect( props, databaseName, databaseMajorVersion );
    settings.setDialect(dialect);
   
    //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

          final boolean scroll,
          final SessionImplementor session) throws SQLException, HibernateException {

    queryParameters.processFilters( getSQLString(), session );
    String sql = queryParameters.getFilteredSQL();
    final Dialect dialect = getFactory().getDialect();
    final RowSelection selection = queryParameters.getRowSelection();
    boolean useLimit = useLimit( selection, dialect );
    boolean hasFirstRow = getFirstRow( selection ) > 0;
    boolean useOffset = hasFirstRow && useLimit && dialect.supportsLimitOffset();
    boolean callable = queryParameters.isCallable();
   
    boolean useScrollableResultSetToSkip = hasFirstRow &&
        !useOffset &&
        getFactory().getSettings().isScrollableResultSetsEnabled();
    ScrollMode scrollMode = scroll ? queryParameters.getScrollMode() : ScrollMode.SCROLL_INSENSITIVE;

    if ( useLimit ) {
      sql = dialect.getLimitString(
          sql.trim(), //use of trim() here is ugly?
          useOffset ? getFirstRow(selection) : 0,
          getMaxOrLimit(selection, dialect)
        );
    }

    sql = preprocessSQL( sql, queryParameters, dialect );
   
    PreparedStatement st = null;
   
    if (callable) {
      st = session.getBatcher()
        .prepareCallableQueryStatement( sql, scroll || useScrollableResultSetToSkip, scrollMode );
    }
    else {
      st = session.getBatcher()
        .prepareQueryStatement( sql, scroll || useScrollableResultSetToSkip, scrollMode );
    }
       

    try {

      int col = 1;
      //TODO: can we limit stored procedures ?!
      if ( useLimit && dialect.bindLimitParametersFirst() ) {
        col += bindLimitParameters( st, col, selection );
      }
      if (callable) {
        col = dialect.registerResultSetOutParameter( (CallableStatement)st, col );
      }

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

      if ( useLimit && !dialect.bindLimitParametersFirst() ) {
        col += bindLimitParameters( st, col, selection );
      }

      if ( !useLimit ) {
        setMaxRows( st, selection );
View Full Code Here

   */
  private int bindLimitParameters(
      final PreparedStatement statement,
      final int index,
      final RowSelection selection) throws SQLException {
    Dialect dialect = getFactory().getDialect();
    if ( !dialect.supportsVariableLimit() ) {
      return 0;
    }
    if ( !hasMaxRows( selection ) ) {
      throw new AssertionFailure( "no max results set" );
    }
    int firstRow = interpretFirstRow( getFirstRow( selection ) );
    int lastRow = getMaxOrLimit( selection, dialect );
    boolean hasFirstRow = dialect.supportsLimitOffset() && ( firstRow > 0 || dialect.forceLimitUsage() );
    boolean reverse = dialect.bindLimitParametersInReverseOrder();
    if ( hasFirstRow ) {
      statement.setInt( index + ( reverse ? 1 : 0 ), firstRow );
    }
    statement.setInt( index + ( reverse || !hasFirstRow ? 0 : 1 ), lastRow );
    return hasFirstRow ? 2 : 1;
View Full Code Here

TOP

Related Classes of org.hibernate.dialect.Dialect

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.