Java 类org.hibernate.dialect.SQLServerDialect 实例源码

项目:lams    文件:HibernateJpaVendorAdapter.java   
/**
 * Determine the Hibernate database dialect class for the given target database.
 * @param database the target database
 * @return the Hibernate database dialect class, or {@code null} if none found
 */
@SuppressWarnings("deprecation")
protected Class<?> determineDatabaseDialectClass(Database database) {
    switch (database) {
        case DB2: return DB2Dialect.class;
        case DERBY: return DerbyDialect.class;  // DerbyDialect deprecated in 4.x
        case H2: return H2Dialect.class;
        case HSQL: return HSQLDialect.class;
        case INFORMIX: return InformixDialect.class;
        case MYSQL: return MySQLDialect.class;
        case ORACLE: return Oracle9iDialect.class;
        case POSTGRESQL: return PostgreSQLDialect.class;  // PostgreSQLDialect deprecated in 4.x
        case SQL_SERVER: return SQLServerDialect.class;
        case SYBASE: return org.hibernate.dialect.SybaseDialect.class;  // SybaseDialect deprecated in 3.6 but not 4.x
        default: return null;
    }
}
项目:holon-datastore-jpa    文件:EntityManagerFactoryConfigurator.java   
private static Class<?> hibernateDatabaseDialectClass(DatabasePlatform database) {
    switch (database) {
    case DB2:
        return DB2Dialect.class;
    case DB2_AS400:
        return DB2400Dialect.class;
    case DERBY:
        return DerbyTenSevenDialect.class;
    case H2:
        return H2Dialect.class;
    case HSQL:
        return HSQLDialect.class;
    case INFORMIX:
        return InformixDialect.class;
    case MYSQL:
        return MySQL5Dialect.class;
    case ORACLE:
        return Oracle10gDialect.class;
    case POSTGRESQL:
        return PostgreSQL82Dialect.class;
    case SQL_SERVER:
        return SQLServerDialect.class;
    case MARIADB:
        return MySQL5Dialect.class;
    case HANA:
        return HANARowStoreDialect.class;
    case SQLITE:
    case NONE:
    default:
        break;
    }
    return null;
}
项目:spring4-understanding    文件:HibernateJpaVendorAdapter.java   
/**
 * Determine the Hibernate database dialect class for the given target database.
 * @param database the target database
 * @return the Hibernate database dialect class, or {@code null} if none found
 */
@SuppressWarnings("deprecation")
protected Class<?> determineDatabaseDialectClass(Database database) {
    switch (database) {
        case DB2: return DB2Dialect.class;
        case DERBY: return DerbyDialect.class;  // DerbyDialect deprecated in 4.x
        case H2: return H2Dialect.class;
        case HSQL: return HSQLDialect.class;
        case INFORMIX: return InformixDialect.class;
        case MYSQL: return MySQLDialect.class;
        case ORACLE: return Oracle9iDialect.class;
        case POSTGRESQL: return PostgreSQLDialect.class;  // PostgreSQLDialect deprecated in 4.x
        case SQL_SERVER: return SQLServerDialect.class;
        case SYBASE: return org.hibernate.dialect.SybaseDialect.class;  // SybaseDialect deprecated in 3.6 but not 4.x
        default: return null;
    }
}
项目:invesdwin-context-persistence    文件:HibernateDialectSpecificDelegate.java   
private Class<? extends Dialect> getHibernateDialect(final PersistenceUnitContext context) {
    final ConnectionDialect dialect = context.getConnectionDialect();
    switch (dialect) {
    case MSSQLSERVER:
        return SQLServerDialect.class;
    case MYSQL:
        return MySQL5InnoDBDialect.class;
    case POSTGRESQL:
        return PostgreSQL9Dialect.class;
    case ORACLE:
        return Oracle10gDialect.class;
    case H2:
        return H2Dialect.class;
    default:
        throw UnknownArgumentException.newInstance(ConnectionDialect.class, dialect);
    }
}
项目:class-guard    文件:HibernateJpaVendorAdapter.java   
/**
 * Determine the Hibernate database dialect class for the given target database.
 * @param database the target database
 * @return the Hibernate database dialect class, or {@code null} if none found
 */
protected Class determineDatabaseDialectClass(Database database) {
    switch (database) {
        case DB2: return DB2Dialect.class;
        case DERBY: return DerbyDialect.class;
        case H2: return H2Dialect.class;
        case HSQL: return HSQLDialect.class;
        case INFORMIX: return InformixDialect.class;
        case MYSQL: return MySQLDialect.class;
        case ORACLE: return Oracle9iDialect.class;
        case POSTGRESQL: return PostgreSQLDialect.class;
        case SQL_SERVER: return SQLServerDialect.class;
        case SYBASE: return SybaseDialect.class;
        default: return null;
    }
}
项目:jpa2ddl    文件:EngineDecorator.java   
public static EngineDecorator getEngineDecorator(String dialect) throws ClassNotFoundException {
    Class<?> dialectClass = Class.forName(dialect);
    if (MySQLDialect.class.isAssignableFrom(dialectClass)) {
        return new MySQLDecorator();
    } else if (PostgreSQL81Dialect.class.isAssignableFrom(dialectClass)) {
        return new PostgreSQLDecorator();
    } else if (Oracle8iDialect.class.isAssignableFrom(dialectClass)) {
        return new OracleDecorator();
    } else if (SQLServerDialect.class.isAssignableFrom(dialectClass)) {
        return new SQLServerDecorator();
    }
    return new NoOpDecorator();

}
项目:document-management-system    文件:DatabaseDialectAdapter.java   
/**
 * Adapt "default.sql" to every supported database
 */
public static String dialectAdapter(InputStream is, String dialect) {
    StringBuilder sb = new StringBuilder();
    BufferedReader br = null;
    String line;

    try {
        br = new BufferedReader(new InputStreamReader(is));

        if (Oracle10gDialect.class.getCanonicalName().equals(dialect)) {
            log.info("Generation SQL for Oracle10gDialect...");

            while ((line = br.readLine()) != null) {
                sb.append(oracleAdapter(line)).append("\n");
            }
        } else if (SQLServerDialect.class.getCanonicalName().equals(dialect)) {
            log.info("Generation SQL for SQLServerDialect...");

            while ((line = br.readLine()) != null) {
                sb.append(sqlServerAdapter(line)).append("\n");
            }
        } else {
            log.info("Generation SQL for GeneralDialect...");

            while ((line = br.readLine()) != null) {
                sb.append(line).append("\n");
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(br);
        IOUtils.closeQuietly(is);
    }

    return sb.toString().trim();
}
项目:communote-server    文件:HibernateDatabaseConfigurationFactory.java   
public HibernateDatabaseConfigurationFactory() {
    builtInConfigurations = new HashMap<String, DatabaseConfiguration>();
    builtInConfigurations.put(SQLServerDialect.class.getName(),
            new MSSQLServerDatabaseConfiguration());
    builtInConfigurations.put(Oracle10gDialect.class.getName(),
            new OracleDatabaseConfiguration());
    builtInConfigurations.put(PostgreSQLDialect.class.getName(),
            new PostgreSQLDatabaseConfiguration());
}
项目:cacheonix-core    文件:ASTParserLoadingTest.java   
public void testStr() {
    Session session = openSession();
    Transaction txn = session.beginTransaction();
    Animal an = new Animal();
    an.setBodyWeight(123.45f);
    session.persist(an);
    String str = (String) session.createQuery("select str(an.bodyWeight) from Animal an where str(an.bodyWeight) like '123%' or str(an.bodyWeight) like '1.23%'").uniqueResult();
    if ( getDialect() instanceof DB2Dialect ) {
        assertTrue( str.startsWith("1.234") );
    }
    else if ( getDialect() instanceof SQLServerDialect ) {
        // no assertion as SQLServer always returns nulls here; even trying directly against the
        // database, it seems to have problems with str() in the where clause...
    }
    else {
        assertTrue( str.startsWith("123.4") );
    }
    if ( ! ( getDialect() instanceof SybaseDialect ) ) {
        // In TransactSQL (the variant spoken by Sybase and SQLServer), the str() function
        // is explicitly intended for numeric values only...
        String dateStr1 = (String) session.createQuery("select str(current_date) from Animal").uniqueResult();
        String dateStr2 = (String) session.createQuery("select str(year(current_date))||'-'||str(month(current_date))||'-'||str(day(current_date)) from Animal").uniqueResult();
        System.out.println(dateStr1 + '=' + dateStr2);
        if ( ! ( getDialect() instanceof Oracle9Dialect || getDialect() instanceof Oracle8iDialect ) ) { //Oracle renders the name of the month :(
            String[] dp1 = StringHelper.split("-", dateStr1);
            String[] dp2 = StringHelper.split("-", dateStr2);
            for (int i=0; i<3; i++) {
                if ( dp1[i].startsWith( "0" ) ) {
                    dp1[i] = dp1[i].substring( 1 );
                }
                assertEquals( dp1[i], dp2[i] );
            }
        }
    }
    session.delete(an);
    txn.commit();
    session.close();
}
项目:kuali_rice    文件:DevHibernateJpaVendorAdapter.java   
/**
 * Determine the Hibernate database dialect class for the given target database.
 * @param database the target database
 * @return the Hibernate database dialect class, or <code>null<code> if none found
 */
protected Class determineDatabaseDialectClass(Database database) {
    switch (database) {
        case DB2: return DB2Dialect.class;
        case HSQL: return HSQLDialect.class;
        case INFORMIX: return InformixDialect.class;
        case MYSQL: return MySQLDialect.class;
        case ORACLE: return Oracle9iDialect.class;
        case POSTGRESQL: return PostgreSQLDialect.class;
        case SQL_SERVER: return SQLServerDialect.class;
        case SYBASE: return SybaseASE15Dialect.class;
        default: return null;
    }
}
项目:Equella    文件:ConvertNtextDatabaseMigration.java   
@Override
protected void executeDataMigration(final HibernateMigrationHelper helper, final MigrationResult result,
    Session session)
{
    final Dialect dialect = helper.getFactory().getDialect();

    if( dialect instanceof SQLServerDialect )
    {
        session.doWork(new Work()
        {
            @Override
            public void execute(Connection connection) throws SQLException
            {
                final DatabaseMetaData metaData = connection.getMetaData();
                final String defaultCatalog = helper.getDefaultCatalog();
                final String defaultSchema = helper.getDefaultSchema();

                final ResultSet tableSet = metaData.getTables(defaultCatalog, defaultSchema, null,
                    new String[]{"TABLE"});
                final List<String> tableNames = Lists.newArrayList();
                try
                {
                    while( tableSet.next() )
                    {
                        tableNames.add(tableSet.getString("TABLE_NAME"));
                    }
                }
                finally
                {
                    tableSet.close();
                }

                for( String tableName : tableNames )
                {
                    final List<ColMeta> ntextCols = Lists.newArrayList();
                    final ResultSet columnSet = metaData.getColumns(defaultCatalog, defaultSchema, tableName, null);

                    try
                    {
                        while( columnSet.next() )
                        {
                            final String colName = columnSet.getString("COLUMN_NAME");
                            final String colDbType = columnSet.getString("TYPE_NAME");
                            if( colDbType.equalsIgnoreCase("ntext") )
                            {
                                LOGGER.info("ntext column found: " + tableName + "." + colName);

                                final int nullable = columnSet.getInt("NULLABLE");
                                final ColMeta colMeta = new ColMeta();
                                colMeta.nullable = (nullable != DatabaseMetaData.columnNoNulls);
                                colMeta.name = colName;
                                ntextCols.add(colMeta);
                            }
                        }
                    }
                    finally
                    {
                        columnSet.close();
                    }

                    for( ColMeta ntextCol : ntextCols )
                    {
                        final String sql = "ALTER TABLE " + Table.qualify(defaultCatalog, defaultSchema, tableName)
                            + " ALTER COLUMN " + ntextCol.name + " nvarchar(max)"
                            + (ntextCol.nullable ? "" : " NOT") + " NULL";
                        final PreparedStatement s = connection.prepareStatement(sql);
                        s.execute();
                    }

                    // We don't seem to need to update
                    // http://stackoverflow.com/questions/4708463/converting-ntext-to-nvcharmaxmax-getting-around-size-limitation
                    result.incrementStatus();
                }
            }
        });
    }
}
项目:Equella    文件:ConvertVarcharDatabaseMigration.java   
@Override
protected void executeDataMigration(final HibernateMigrationHelper helper, final MigrationResult result,
    Session session)
{
    final Dialect dialect = helper.getFactory().getDialect();

    if( dialect instanceof SQLServerDialect )
    {
        session.doWork(new Work()
        {
            @Override
            public void execute(Connection connection) throws SQLException
            {
                final DatabaseMetaData metaData = connection.getMetaData();
                final String defaultCatalog = helper.getDefaultCatalog();
                final String defaultSchema = helper.getDefaultSchema();

                final ResultSet tableSet = metaData.getTables(defaultCatalog, defaultSchema, null,
                    new String[]{"TABLE"});
                final List<String> tableNames = Lists.newArrayList();
                try
                {
                    while( tableSet.next() )
                    {
                        tableNames.add(tableSet.getString("TABLE_NAME"));
                    }
                }
                finally
                {
                    tableSet.close();
                }

                for( String tableName : tableNames )
                {
                    final List<ColMeta> ntextCols = Lists.newArrayList();
                    final ResultSet columnSet = metaData.getColumns(defaultCatalog, defaultSchema, tableName, null);

                    try
                    {
                        while( columnSet.next() )
                        {
                            final String colName = columnSet.getString("COLUMN_NAME");
                            final String colDbType = columnSet.getString("TYPE_NAME");
                            if( colDbType.equalsIgnoreCase("varchar") || colDbType.equalsIgnoreCase("text") )
                            {
                                LOGGER.info("varchar column found: " + tableName + "." + colName);

                                final int nullable = columnSet.getInt("NULLABLE");
                                final ColMeta colMeta = new ColMeta();
                                colMeta.size = columnSet.getInt("COLUMN_SIZE");
                                colMeta.nullable = (nullable != DatabaseMetaData.columnNoNulls);
                                colMeta.name = colName;
                                ntextCols.add(colMeta);
                            }
                        }
                    }
                    finally
                    {
                        columnSet.close();
                    }

                    for( ColMeta ntextCol : ntextCols )
                    {
                        String sizeStr = ntextCol.size == Integer.MAX_VALUE ? "max"
                            : Integer.toString(ntextCol.size);
                        final String sql = "ALTER TABLE " + Table.qualify(defaultCatalog, defaultSchema, tableName)
                            + " ALTER COLUMN " + ntextCol.name + " nvarchar(" + sizeStr + ")"
                            + (ntextCol.nullable ? "" : " NOT") + " NULL";
                        final PreparedStatement s = connection.prepareStatement(sql);
                        s.execute();
                    }

                    result.incrementStatus();
                }
            }
        });
    }
}
项目:lams    文件:StrategySelectorBuilder.java   
private void addDialects(StrategySelectorImpl strategySelector) {
    addDialect( strategySelector, Cache71Dialect.class );
    addDialect( strategySelector, CUBRIDDialect.class );
    addDialect( strategySelector, DB2Dialect.class );
    addDialect( strategySelector, DB2390Dialect.class );
    addDialect( strategySelector, DB2400Dialect.class );
    addDialect( strategySelector, DerbyTenFiveDialect.class );
    addDialect( strategySelector, DerbyTenSixDialect.class );
    addDialect( strategySelector, DerbyTenSevenDialect.class );
    addDialect( strategySelector, FirebirdDialect.class );
    addDialect( strategySelector, FrontBaseDialect.class );
    addDialect( strategySelector, H2Dialect.class );
    addDialect( strategySelector, HSQLDialect.class );
    addDialect( strategySelector, InformixDialect.class );
    addDialect( strategySelector, IngresDialect.class );
    addDialect( strategySelector, Ingres9Dialect.class );
    addDialect( strategySelector, Ingres10Dialect.class );
    addDialect( strategySelector, InterbaseDialect.class );
    addDialect( strategySelector, JDataStoreDialect.class );
    addDialect( strategySelector, MckoiDialect.class );
    addDialect( strategySelector, MimerSQLDialect.class );
    addDialect( strategySelector, MySQL5Dialect.class );
    addDialect( strategySelector, MySQL5InnoDBDialect.class );
    addDialect( strategySelector, MySQL5Dialect.class );
    addDialect( strategySelector, MySQL5InnoDBDialect.class );
    addDialect( strategySelector, Oracle8iDialect.class );
    addDialect( strategySelector, Oracle9iDialect.class );
    addDialect( strategySelector, Oracle10gDialect.class );
    addDialect( strategySelector, PointbaseDialect.class );
    addDialect( strategySelector, PostgresPlusDialect.class );
    addDialect( strategySelector, PostgreSQL81Dialect.class );
    addDialect( strategySelector, PostgreSQL82Dialect.class );
    addDialect( strategySelector, PostgreSQL9Dialect.class );
    addDialect( strategySelector, ProgressDialect.class );
    addDialect( strategySelector, SAPDBDialect.class );
    addDialect( strategySelector, SQLServerDialect.class );
    addDialect( strategySelector, SQLServer2005Dialect.class );
    addDialect( strategySelector, SQLServer2008Dialect.class );
    addDialect( strategySelector, Sybase11Dialect.class );
    addDialect( strategySelector, SybaseAnywhereDialect.class );
    addDialect( strategySelector, SybaseASE15Dialect.class );
    addDialect( strategySelector, SybaseASE157Dialect.class );
    addDialect( strategySelector, TeradataDialect.class );
    addDialect( strategySelector, TimesTenDialect.class );
}
项目:FinanceAnalytics    文件:SqlServer2008DbDialect.java   
@Override
protected Dialect createHibernateDialect() {
  return new SQLServerDialect();
}
项目:metaworks_framework    文件:DialectHelper.java   
public boolean isSqlServer() {
    return getHibernateDialect() instanceof SQLServerDialect;
}
项目:cacheonix-core    文件:RepeatableReadTest.java   
public void testStaleVersionedInstanceFoundOnLock() {
    if ( ! readCommittedIsolationMaintained( "repeatable read tests" ) ) {
        return;
    }
    if ( getDialect().doesReadCommittedCauseWritersToBlockReaders()) {
        reportSkip( "lock blocking", "stale versioned instance" );
        return;
    }
    String check = "EJB3 Specification";
    Session s1 = getSessions().openSession();
    Transaction t1 = s1.beginTransaction();
    Item item = new Item( check );
    s1.save(  item );
    t1.commit();
    s1.close();

    Long itemId = item.getId();
    long initialVersion = item.getVersion();

    // Now, open a new Session and re-load the item...
    s1 = getSessions().openSession();
    t1 = s1.beginTransaction();
    item = ( Item ) s1.get( Item.class, itemId );

    // now that the item is associated with the persistence-context of that session,
    // open a new session and modify it "behind the back" of the first session
    Session s2 = getSessions().openSession();
    Transaction t2 = s2.beginTransaction();
    Item item2 = ( Item ) s2.get( Item.class, itemId );
    item2.setName( "EJB3 Persistence Spec" );
    t2.commit();
    s2.close();

    // at this point, s1 now contains stale data, so acquire a READ lock
    // and make sure we get the already associated state (i.e., the old
    // name and the old version)
    s1.lock( item, LockMode.READ );
    item2 = ( Item ) s1.get( Item.class, itemId );
    assertTrue( item == item2 );
    assertEquals( "encountered non-repeatable read", check, item2.getName() );
    assertEquals( "encountered non-repeatable read", initialVersion, item2.getVersion() );

    // attempt to acquire an UPGRADE lock; this should fail
    try {
        s1.lock( item, LockMode.UPGRADE );
        fail( "expected UPGRADE lock failure" );
    }
    catch( StaleObjectStateException expected ) {
        // this is the expected behavior
    }
    catch( SQLGrammarException t ) {
        if ( getDialect() instanceof SQLServerDialect ) {
            // sql-server (using snapshot isolation) reports this as a grammar exception /:)
            //
            // not to mention that it seems to "lose track" of the transaction in this scenario...
            t1.rollback();
            t1 = s1.beginTransaction();
        }
        else {
            throw t;
        }
    }

    t1.commit();
    s1.close();

    // clean up
    s1 = getSessions().openSession();
    t1 = s1.beginTransaction();
    s1.createQuery( "delete Item" ).executeUpdate();
    t1.commit();
    s1.close();
}
项目:SparkCommerce    文件:DialectHelper.java   
public boolean isSqlServer() {
    return getHibernateDialect() instanceof SQLServerDialect;
}
项目:Portofino    文件:JTDSDatabasePlatform.java   
public JTDSDatabasePlatform() {
    super(new SQLServerDialect(), "jdbc:jtds:sqlserver://<server>[:<port>][/<database>][;instance=<instance>]");
}
项目:Portofino    文件:MSSqlServerDatabasePlatform.java   
public MSSqlServerDatabasePlatform() {
    super(new SQLServerDialect(), "jdbc:sqlserver://<host>[:<port>];database=<databaseName>");
}
项目:blcdemo    文件:DialectHelper.java   
public boolean isSqlServer() {
    return getHibernateDialect() instanceof SQLServerDialect;
}
项目:ERDesignerNG    文件:RepositoryIOTest.java   
public void testLoadSaveRepository() throws Exception {

        Connection theConnection = createConnection();

        Class theHibernateDialect = SQLServerDialect.class;

        String theModelResource = "/de/erdesignerng/test/io/repository/examplemodel.mxm";

        String theNewFile = RepositioryHelper.performRepositorySaveAndLoad(theModelResource, theHibernateDialect,
                theConnection);

        String theOriginalFile = IOUtils.toString(getClass().getResourceAsStream(theModelResource));

        assertTrue(compareStrings(theOriginalFile, theNewFile));
    }