use of org.jooq.impl.DefaultExecuteListenerProvider in project waltz by khartec.
the class MSSqlImportExportExample method main.
public static void main(String[] args) throws ParseException, IOException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
if (false) {
System.out.println("-- saving");
dsl.selectFrom(PERSON).fetch().formatCSV(new FileOutputStream("person.csv"), ',', "{null}");
}
if (true) {
System.out.println("-- deleting");
dsl.deleteFrom(PERSON).execute();
dsl.transaction(cfg -> {
// insert the identity insert statement
ExecuteListener listener = new DefaultExecuteListener() {
@Override
public void renderEnd(ExecuteContext ctx) {
ctx.sql("SET IDENTITY_INSERT [person] ON " + ctx.sql());
}
};
cfg.set(new DefaultExecuteListenerProvider(listener));
DSLContext tx = DSL.using(cfg);
System.out.println("-- loading");
Loader<PersonRecord> loader = tx.loadInto(PERSON).loadCSV(new FileInputStream("person.csv")).fields(PERSON.fields()).nullString(// treat this from the csv as a database NULL value
"{null}").execute();
System.out.println("processed:" + loader.processed());
System.out.println("stored:" + loader.stored());
System.out.println("ignored:" + loader.ignored());
loader.errors().forEach(e -> System.out.println("error:" + e.exception().getMessage()));
});
}
System.out.println("-- done");
}
use of org.jooq.impl.DefaultExecuteListenerProvider in project unipop by unipop-graph.
the class ContextManager method reloadContexts.
private void reloadContexts() throws IOException {
SQLDialect dialect = SQLDialect.valueOf(this.conf.getString("sqlDialect"));
BasicDataSource ds = new BasicDataSource();
ds.setUrl(new ObjectMapper().readValue(conf.getJSONArray("address").toString(), List.class).get(0).toString());
ds.setDriverClassName(conf.getString("driver"));
String user = conf.optString("user");
String password = conf.optString("password");
if (!user.isEmpty())
ds.setUsername(user);
if (!password.isEmpty())
ds.setPassword(password);
Settings settings = new Settings();
settings.setRenderNameStyle(RenderNameStyle.AS_IS);
Configuration conf = new DefaultConfiguration().set(ds).set(dialect).set(settings).set(new DefaultExecuteListenerProvider(new TimingExecuterListener()));
this.context = DSL.using(conf);
}
use of org.jooq.impl.DefaultExecuteListenerProvider in project tutorials by eugenp.
the class InitialConfiguration method configuration.
public DefaultConfiguration configuration() {
DefaultConfiguration jooqConfiguration = new DefaultConfiguration();
jooqConfiguration.set(connectionProvider());
jooqConfiguration.set(new DefaultExecuteListenerProvider(new ExceptionTranslator()));
return jooqConfiguration;
}
use of org.jooq.impl.DefaultExecuteListenerProvider in project jOOQ by jOOQ.
the class AbstractDatabase method create.
@SuppressWarnings("serial")
protected final DSLContext create(boolean muteExceptions) {
// [#3800] Make sure that faulty queries are logged in a formatted
// way to help users provide us with bug reports
final Configuration configuration = create0().configuration();
if (muteExceptions) {
return DSL.using(configuration);
} else {
final Settings newSettings = SettingsTools.clone(configuration.settings()).withRenderFormatted(true);
final ExecuteListenerProvider[] oldProviders = configuration.executeListenerProviders();
final ExecuteListenerProvider[] newProviders = new ExecuteListenerProvider[oldProviders.length + 1];
System.arraycopy(oldProviders, 0, newProviders, 0, oldProviders.length);
newProviders[oldProviders.length] = new DefaultExecuteListenerProvider(new DefaultExecuteListener() {
class SQLPerformanceWarning extends Exception {
}
@Override
public void start(ExecuteContext ctx) {
// SQLPerformanceWarning.
if (!initialised) {
DSL.using(configuration).selectOne().fetch();
initialised = true;
}
}
@Override
public void executeStart(ExecuteContext ctx) {
ctx.data("org.jooq.util.AbstractDatabase.watch", new StopWatch());
}
@Override
public void executeEnd(ExecuteContext ctx) {
StopWatch watch = (StopWatch) ctx.data("org.jooq.util.AbstractDatabase.watch");
if (watch.split() > TimeUnit.SECONDS.toNanos(5L)) {
watch.splitWarn("Slow SQL");
log.warn("Slow SQL", "jOOQ Meta executed a slow query (slower than 5 seconds)" + "\n\n" + "Please report this bug here: https://github.com/jOOQ/jOOQ/issues/new\n\n" + formatted(ctx.query()), new SQLPerformanceWarning());
}
}
@Override
public void exception(ExecuteContext ctx) {
log.warn("SQL exception", "Exception while executing meta query: " + (ctx.sqlException() != null ? ctx.sqlException().getMessage() : ctx.exception() != null ? ctx.exception().getMessage() : "No exception available") + "\n\n" + "Please report this bug here: https://github.com/jOOQ/jOOQ/issues/new\n\n" + formatted(ctx.query()));
}
private String formatted(Query query) {
return DSL.using(configuration.derive(newSettings)).renderInlined(query);
}
});
return DSL.using(configuration.derive(newProviders));
}
}
use of org.jooq.impl.DefaultExecuteListenerProvider in project tutorials by eugenp.
the class PersistenceContextIntegrationTest method configuration.
@Bean
public DefaultConfiguration configuration() {
DefaultConfiguration jooqConfiguration = new DefaultConfiguration();
jooqConfiguration.set(connectionProvider());
jooqConfiguration.set(new DefaultExecuteListenerProvider(exceptionTransformer()));
String sqlDialectName = environment.getRequiredProperty("jooq.sql.dialect");
SQLDialect dialect = SQLDialect.valueOf(sqlDialectName);
jooqConfiguration.set(dialect);
return jooqConfiguration;
}
Aggregations