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" };
}
});
}
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);
}
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);
}
}
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;
}
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 ?";
}
}
Aggregations