Search in sources :

Example 1 with Dialect

use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.

the class StoredProcedureTest method configure.

@Override
protected void configure(Configuration configuration) {
    super.configure(configuration);
    configuration.addAuxiliaryDatabaseObject(new AuxiliaryDatabaseObject() {

        @Override
        public String getExportIdentifier() {
            return "function:findOneUser";
        }

        @Override
        public boolean appliesToDialect(Dialect dialect) {
            return H2Dialect.class.isInstance(dialect);
        }

        @Override
        public boolean beforeTablesOnCreation() {
            return false;
        }

        @Override
        public String[] sqlCreateStrings(Dialect dialect) {
            return new String[] { "CREATE ALIAS findOneUser AS $$\n" + "import org.h2.tools.SimpleResultSet;\n" + "import java.sql.*;\n" + "@CODE\n" + "ResultSet findOneUser() {\n" + "    SimpleResultSet rs = new SimpleResultSet();\n" + "    rs.addColumn(\"ID\", Types.INTEGER, 10, 0);\n" + "    rs.addColumn(\"NAME\", Types.VARCHAR, 255, 0);\n" + "    rs.addRow(1, \"Steve\");\n" + "    return rs;\n" + "}\n" + "$$" };
        }

        @Override
        public String[] sqlDropStrings(Dialect dialect) {
            return new String[] { "DROP ALIAS findUser IF EXISTS" };
        }
    });
    configuration.addAuxiliaryDatabaseObject(new AuxiliaryDatabaseObject() {

        @Override
        public String getExportIdentifier() {
            return "function:findUsers";
        }

        @Override
        public boolean appliesToDialect(Dialect dialect) {
            return H2Dialect.class.isInstance(dialect);
        }

        @Override
        public boolean beforeTablesOnCreation() {
            return false;
        }

        @Override
        public String[] sqlCreateStrings(Dialect dialect) {
            return new String[] { "CREATE ALIAS findUsers AS $$\n" + "import org.h2.tools.SimpleResultSet;\n" + "import java.sql.*;\n" + "@CODE\n" + "ResultSet findUsers() {\n" + "    SimpleResultSet rs = new SimpleResultSet();\n" + "    rs.addColumn(\"ID\", Types.INTEGER, 10, 0);\n" + "    rs.addColumn(\"NAME\", Types.VARCHAR, 255, 0);\n" + "    rs.addRow(1, \"Steve\");\n" + "    rs.addRow(2, \"John\");\n" + "    rs.addRow(3, \"Jane\");\n" + "    return rs;\n" + "}\n" + "$$" };
        }

        @Override
        public String[] sqlDropStrings(Dialect dialect) {
            return new String[] { "DROP ALIAS findUser IF EXISTS" };
        }
    });
    configuration.addAuxiliaryDatabaseObject(new AuxiliaryDatabaseObject() {

        @Override
        public String getExportIdentifier() {
            return "function:findUserRange";
        }

        @Override
        public boolean appliesToDialect(Dialect dialect) {
            return H2Dialect.class.isInstance(dialect);
        }

        @Override
        public boolean beforeTablesOnCreation() {
            return false;
        }

        @Override
        public String[] sqlCreateStrings(Dialect dialect) {
            return new String[] { "CREATE ALIAS findUserRange AS $$\n" + "import org.h2.tools.SimpleResultSet;\n" + "import java.sql.*;\n" + "@CODE\n" + "ResultSet findUserRange(int start, int end) {\n" + "    SimpleResultSet rs = new SimpleResultSet();\n" + "    rs.addColumn(\"ID\", Types.INTEGER, 10, 0);\n" + "    rs.addColumn(\"NAME\", Types.VARCHAR, 255, 0);\n" + "    for ( int i = start; i < end; i++ ) {\n" + "        rs.addRow(1, \"User \" + i );\n" + "    }\n" + "    return rs;\n" + "}\n" + "$$" };
        }

        @Override
        public String[] sqlDropStrings(Dialect dialect) {
            return new String[] { "DROP ALIAS findUserRange IF EXISTS" };
        }
    });
}
Also used : H2Dialect(org.hibernate.dialect.H2Dialect) H2Dialect(org.hibernate.dialect.H2Dialect) RequiresDialect(org.hibernate.testing.RequiresDialect) Dialect(org.hibernate.dialect.Dialect) AuxiliaryDatabaseObject(org.hibernate.boot.model.relational.AuxiliaryDatabaseObject)

Example 2 with Dialect

use of org.hibernate.dialect.Dialect in project uPortal by Jasig.

the class DelayedValidationQueryResolverImpl method getValidationQuery.

protected String getValidationQuery(DataSource dataSource) {
    final Dialect dialect = this.resolveDialect(dataSource);
    if (dialect == null) {
        return null;
    }
    final Class<? extends Dialect> dialectType = dialect.getClass();
    return resolveValidationQuery(dialectType);
}
Also used : Dialect(org.hibernate.dialect.Dialect)

Example 3 with Dialect

use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.

the class InFlightMetadataCollectorImpl method processExportableProducers.

private void processExportableProducers(MetadataBuildingContext buildingContext) {
    // for now we only handle id generators as ExportableProducers
    final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect();
    final String defaultCatalog = extractName(getDatabase().getDefaultNamespace().getName().getCatalog(), dialect);
    final String defaultSchema = extractName(getDatabase().getDefaultNamespace().getName().getSchema(), dialect);
    for (PersistentClass entityBinding : entityBindingMap.values()) {
        if (entityBinding.isInherited()) {
            continue;
        }
        handleIdentifierValueBinding(entityBinding.getIdentifier(), dialect, defaultCatalog, defaultSchema, (RootClass) entityBinding);
    }
    for (Collection collection : collectionBindingMap.values()) {
        if (!IdentifierCollection.class.isInstance(collection)) {
            continue;
        }
        handleIdentifierValueBinding(((IdentifierCollection) collection).getIdentifier(), dialect, defaultCatalog, defaultSchema, null);
    }
}
Also used : Dialect(org.hibernate.dialect.Dialect) Collection(org.hibernate.mapping.Collection) IdentifierCollection(org.hibernate.mapping.IdentifierCollection) PersistentClass(org.hibernate.mapping.PersistentClass) IdentifierCollection(org.hibernate.mapping.IdentifierCollection)

Example 4 with Dialect

use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.

the class MetadataBuildingProcess method handleTypes.

//	private static JandexInitManager buildJandexInitializer(
//			MetadataBuildingOptions options,
//			ClassLoaderAccess classLoaderAccess) {
//		final boolean autoIndexMembers = ConfigurationHelper.getBoolean(
//				org.hibernate.cfg.AvailableSettings.ENABLE_AUTO_INDEX_MEMBER_TYPES,
//				options.getServiceRegistry().getService( ConfigurationService.class ).getSettings(),
//				false
//		);
//
//		return new JandexInitManager( options.getJandexView(), classLoaderAccess, autoIndexMembers );
//	}
private static BasicTypeRegistry handleTypes(MetadataBuildingOptions options) {
    final ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);
    // ultimately this needs to change a little bit to account for HHH-7792
    final BasicTypeRegistry basicTypeRegistry = new BasicTypeRegistry();
    final TypeContributions typeContributions = new TypeContributions() {

        @Override
        public void contributeType(org.hibernate.type.BasicType type) {
            basicTypeRegistry.register(type);
        }

        @Override
        public void contributeType(BasicType type, String... keys) {
            basicTypeRegistry.register(type, keys);
        }

        @Override
        public void contributeType(UserType type, String[] keys) {
            basicTypeRegistry.register(type, keys);
        }

        @Override
        public void contributeType(CompositeUserType type, String[] keys) {
            basicTypeRegistry.register(type, keys);
        }
    };
    // add Dialect contributed types
    final Dialect dialect = options.getServiceRegistry().getService(JdbcServices.class).getDialect();
    dialect.contributeTypes(typeContributions, options.getServiceRegistry());
    // add TypeContributor contributed types.
    for (TypeContributor contributor : classLoaderService.loadJavaServices(TypeContributor.class)) {
        contributor.contribute(typeContributions, options.getServiceRegistry());
    }
    // add explicit application registered types
    for (BasicTypeRegistration basicTypeRegistration : options.getBasicTypeRegistrations()) {
        basicTypeRegistry.register(basicTypeRegistration.getBasicType(), basicTypeRegistration.getRegistrationKeys());
    }
    return basicTypeRegistry;
}
Also used : BasicType(org.hibernate.type.BasicType) TypeContributions(org.hibernate.boot.model.TypeContributions) Dialect(org.hibernate.dialect.Dialect) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry) BasicTypeRegistration(org.hibernate.boot.spi.BasicTypeRegistration) CompositeUserType(org.hibernate.usertype.CompositeUserType) UserType(org.hibernate.usertype.UserType) CompositeUserType(org.hibernate.usertype.CompositeUserType) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) TypeContributor(org.hibernate.boot.model.TypeContributor)

Example 5 with Dialect

use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.

the class IlikeExpression method toSqlString.

@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("ilike may only be used with single-column properties");
    }
    if (dialect instanceof PostgreSQLDialect || dialect instanceof PostgreSQL81Dialect) {
        return columns[0] + " ilike ?";
    } else {
        return dialect.getLowercaseFunction() + '(' + columns[0] + ") like ?";
    }
}
Also used : PostgreSQLDialect(org.hibernate.dialect.PostgreSQLDialect) HibernateException(org.hibernate.HibernateException) PostgreSQL81Dialect(org.hibernate.dialect.PostgreSQL81Dialect) Dialect(org.hibernate.dialect.Dialect) PostgreSQLDialect(org.hibernate.dialect.PostgreSQLDialect) PostgreSQL81Dialect(org.hibernate.dialect.PostgreSQL81Dialect)

Aggregations

Dialect (org.hibernate.dialect.Dialect)64 DialectFactory (org.hibernate.engine.jdbc.dialect.spi.DialectFactory)11 HibernateException (org.hibernate.HibernateException)10 Column (org.hibernate.mapping.Column)10 SQLException (java.sql.SQLException)9 DialectResolutionInfo (org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo)8 Configuration (org.hibernate.cfg.Configuration)7 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)7 ServiceRegistry (org.hibernate.service.ServiceRegistry)7 Properties (java.util.Properties)6 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)6 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)6 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)5 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)5 MetaDataDialect (org.hibernate.cfg.reveng.dialect.MetaDataDialect)5 HibernateConsoleRuntimeException (org.hibernate.console.HibernateConsoleRuntimeException)5 DatabaseMetaDataDialectResolutionInfoAdapter (org.hibernate.engine.jdbc.dialect.spi.DatabaseMetaDataDialectResolutionInfoAdapter)5 DialectResolutionInfoSource (org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfoSource)5 SpatialDialect (org.hibernate.spatial.SpatialDialect)5 Type (org.hibernate.type.Type)5