Package org.hibernate.dialect

Examples of org.hibernate.dialect.Dialect


    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

    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

    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

    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 developement, 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();
          log.info( "RDBMS: " + meta.getDatabaseProductName() + ", version: " + meta.getDatabaseProductVersion() );
          log.info( "JDBC driver: " + meta.getDriverName() + ", version: " + meta.getDriverVersion() );

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

    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 developement, 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();
          log.info( "RDBMS: " + meta.getDatabaseProductName() + ", version: " + meta.getDatabaseProductVersion() );
          log.info( "JDBC driver: " + meta.getDriverName() + ", version: " + meta.getDriverVersion() );

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

      processedPositionalParameterValues = getPositionalParameterValues();
      processedPositionalParameterTypes = getPositionalParameterTypes();
      processedSQL = sql;
    }
    else {
      final Dialect dialect = factory.getDialect();
      String symbols = new StringBuffer().append( ParserHelper.HQL_SEPARATORS )
          .append( dialect.openQuote() )
          .append( dialect.closeQuote() )
          .toString();
      StringTokenizer tokens = new StringTokenizer( sql, symbols, true );
      StringBuffer result = new StringBuffer();

      List parameters = new ArrayList();
View Full Code Here

  }

  private String resolveToLiteralString(Type type) {
    try {
      LiteralType literalType = ( LiteralType ) type;
      Dialect dialect = factory.getDialect();
      return literalType.objectToSQLString( constantValue, dialect );
    }
    catch ( Throwable t ) {
      throw new QueryException( QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + constantExpression, t );
    }
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

          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

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.