Search in sources :

Example 1 with DefaultExecuteListenerProvider

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");
}
Also used : DefaultExecuteListener(org.jooq.impl.DefaultExecuteListener) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) FileOutputStream(java.io.FileOutputStream) DSLContext(org.jooq.DSLContext) ExecuteContext(org.jooq.ExecuteContext) ExecuteListener(org.jooq.ExecuteListener) DefaultExecuteListener(org.jooq.impl.DefaultExecuteListener) PersonRecord(com.khartec.waltz.schema.tables.records.PersonRecord) FileInputStream(java.io.FileInputStream)

Example 2 with DefaultExecuteListenerProvider

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);
}
Also used : DefaultConfiguration(org.jooq.impl.DefaultConfiguration) DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) List(java.util.List) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Settings(org.jooq.conf.Settings)

Example 3 with DefaultExecuteListenerProvider

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;
}
Also used : DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) ExceptionTranslator(com.baeldung.jooq.introduction.ExceptionTranslator) DefaultConfiguration(org.jooq.impl.DefaultConfiguration)

Example 4 with DefaultExecuteListenerProvider

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));
    }
}
Also used : DefaultExecuteListener(org.jooq.impl.DefaultExecuteListener) Configuration(org.jooq.Configuration) Query(org.jooq.Query) DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) ExecuteListenerProvider(org.jooq.ExecuteListenerProvider) ExecuteContext(org.jooq.ExecuteContext) Settings(org.jooq.conf.Settings) StopWatch(org.jooq.tools.StopWatch)

Example 5 with DefaultExecuteListenerProvider

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;
}
Also used : DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) SQLDialect(org.jooq.SQLDialect) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) Bean(org.springframework.context.annotation.Bean)

Aggregations

DefaultExecuteListenerProvider (org.jooq.impl.DefaultExecuteListenerProvider)7 DefaultConfiguration (org.jooq.impl.DefaultConfiguration)4 ExecuteContext (org.jooq.ExecuteContext)3 ExecuteListener (org.jooq.ExecuteListener)3 DefaultExecuteListener (org.jooq.impl.DefaultExecuteListener)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 DSLContext (org.jooq.DSLContext)2 SQLDialect (org.jooq.SQLDialect)2 Settings (org.jooq.conf.Settings)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 ExceptionTranslator (com.baeldung.jooq.introduction.ExceptionTranslator)1 PersonRecord (com.khartec.waltz.schema.tables.records.PersonRecord)1 List (java.util.List)1 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)1 ObjectMapper (org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper)1 PersonRecord (org.finos.waltz.schema.tables.records.PersonRecord)1 Configuration (org.jooq.Configuration)1 ExecuteListenerProvider (org.jooq.ExecuteListenerProvider)1 Query (org.jooq.Query)1