--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
final Dialect dialect = serviceRegistry.getService( JdbcServices.class ).getDialect();
dialect.contributeTypes( typeContributions, serviceRegistry );
@Override public void onEvent(RequestEvent event) { if (event.getType() == RequestEvent.Type.RESOURCE_METHOD_START) { this.unitOfWork = this.methodMap.get(event.getUriInfo() .getMatchedResourceMethod().getInvocable().getDefinitionMethod()); if (unitOfWork != null) { this.session = this.sessionFactory.openSession(); setSchema(); //set the schema to the connection try { configureSession(); ManagedSessionContext.bind(this.session); beginTransaction(); } catch (Throwable th) { this.session.close(); this.session = null; ManagedSessionContext.unbind(this.sessionFactory); throw th; } } } else if (event.getType() == RequestEvent.Type.RESOURCE_METHOD_FINISHED) { if (this.session != null) { try { commitTransaction(); } catch (Exception e) { rollbackTransaction(); this.<RuntimeException>rethrow(e); } finally { this.session.close(); this.session = null; ManagedSessionContext.unbind(this.sessionFactory); } } } else if (event.getType() == RequestEvent.Type.ON_EXCEPTION) { if (this.session != null) { try { rollbackTransaction(); } finally { this.session.close(); this.session = null; ManagedSessionContext.unbind(this.sessionFactory); } } } }
private void setSchema() { this.session.doWork(connection -> {
String schemaStatement = null; final String tenantSchema = <YOUR_SCHEMA>; switch (dataSourceFactory.getProperties().get("hibernate.dialect")) { case "org.hibernate.dialect.PostgreSQL9Dialect": schemaStatement = String.format("SET SEARCH_PATH = %s", tenantSchema); break; default: schemaStatement = String.format("SET SCHEMA = %s", tenantSchema); }
PreparedStatement preparedStatement = connection.prepareStatement(schemaStatement); preparedStatement.execute(); }); }