Java Code Examples for org.jooq.meta.jaxb.Configuration

The following examples show how to use org.jooq.meta.jaxb.Configuration. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop-ozone   Source File: JooqCodeGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Generate entity and DAO classes.
 */
private void generateSourceCode(String outputDir) throws Exception {
  Configuration configuration =
      new Configuration()
          .withJdbc(new Jdbc()
              .withDriver(DERBY_DRIVER_CLASS)
              .withUrl(JDBC_URL))
          .withGenerator(new Generator()
              .withDatabase(new Database()
                  .withName("org.jooq.meta.derby.DerbyDatabase")
                  .withOutputSchemaToDefault(true)
                  .withIncludeTables(true)
                  .withIncludePrimaryKeys(true)
                  .withInputSchema(RECON_SCHEMA_NAME))
              .withGenerate(new Generate()
                  .withDaos(true)
                  .withEmptyCatalogs(true))
              .withStrategy(new Strategy().withName(
                  "org.hadoop.ozone.recon.codegen.TableNamingStrategy"))
              .withTarget(new Target()
                  .withPackageName("org.hadoop.ozone.recon.schema")
                  .withClean(true)
                  .withDirectory(outputDir)))
              .withLogging(Logging.WARN);
  GenerationTool.generate(configuration);
}
 
Example 2
Source Project: vertx-jooq   Source File: PostgresConfigurationProvider.java    License: MIT License 6 votes vote down vote up
@Override
public Configuration createGeneratorConfig(String generatorName, String packageName, Class<? extends VertxGeneratorStrategy> generatorStrategy){
    Jdbc jdbcConfig = new Jdbc();
    jdbcConfig.setDriver("org.postgresql.Driver");
    jdbcConfig.setUrl("jdbc:postgresql://127.0.0.1:5432/postgres");
    jdbcConfig.setUser(Credentials.POSTGRES.getUser());
    jdbcConfig.setPassword(Credentials.POSTGRES.getPassword());
    Configuration generatorConfig = createGeneratorConfig(generatorName, packageName, generatorStrategy, jdbcConfig, PostgresDatabase.class.getName());
    ForcedType customJsonMapping = new ForcedType();
    customJsonMapping.setUserType(SomeJsonPojo.class.getName());
    customJsonMapping.setConverter(SomeJsonPojoConverter.class.getName());
    customJsonMapping.setExpression("someCustomJsonObject");
    customJsonMapping.setTypes(".*");
    List<ForcedType> forcedTypes = new ArrayList<>(generatorConfig.getGenerator().getDatabase().getForcedTypes());
    forcedTypes.add(customJsonMapping);
    generatorConfig.getGenerator().getDatabase().setForcedTypes(forcedTypes);
    return generatorConfig;
}
 
Example 3
Source Project: StubbornJava   Source File: CMSMigrations.java    License: MIT License 5 votes vote down vote up
public static void codegen() throws Exception {
    List<ForcedType> forcedTypes = JooqConfig.defaultForcedTypes();

    HikariDataSource ds = CMSConnectionPools.processing();

    Configuration configuration = new Configuration()
        .withJdbc(new Jdbc()
            .withDriver(Driver.class.getName())
            .withUrl(ds.getJdbcUrl())
            .withUser(ds.getUsername())
            .withPassword(ds.getPassword()))
        .withGenerator(new Generator()
            .withDatabase(new Database()
                .withName(MySQLDatabase.class.getName())
                .withIncludes(".*")
                .withExcludes("")
                .withIncludeExcludeColumns(true)
                .withForcedTypes(forcedTypes)
                .withInputSchema("sj_cms"))
            .withGenerate(new Generate()
                .withJavaTimeTypes(true))
            .withStrategy(new Strategy()
                .withName(CustomGeneratorStrategy.class.getName()))
            .withTarget(new Target()
                .withPackageName("com.stubbornjava.cms.server.generated")
                .withDirectory("src/generated/java")));

    GenerationTool.generate(configuration);
}
 
Example 4
Source Project: StubbornJava   Source File: CMSMigrations.java    License: MIT License 5 votes vote down vote up
public static void codegen() throws Exception {
    List<ForcedType> forcedTypes = JooqConfig.defaultForcedTypes();

    HikariDataSource ds = CMSConnectionPools.processing();

    Configuration configuration = new Configuration()
        .withJdbc(new Jdbc()
            .withDriver(Driver.class.getName())
            .withUrl(ds.getJdbcUrl())
            .withUser(ds.getUsername())
            .withPassword(ds.getPassword()))
        .withGenerator(new Generator()
            .withDatabase(new Database()
                .withName(MySQLDatabase.class.getName())
                .withIncludes(".*")
                .withExcludes("")
                .withIncludeExcludeColumns(true)
                .withForcedTypes(forcedTypes)
                .withInputSchema("sj_cms"))
            .withGenerate(new Generate()
                .withJavaTimeTypes(true))
            .withStrategy(new Strategy()
                .withName(CustomGeneratorStrategy.class.getName()))
            .withTarget(new Target()
                .withPackageName("com.stubbornjava.cms.server.generated")
                .withDirectory("src/generated/java")));

    GenerationTool.generate(configuration);
}
 
Example 5
Source Project: vertx-jooq   Source File: HsqldbConfigurationProvider.java    License: MIT License 5 votes vote down vote up
@Override
public Configuration createGeneratorConfig(String generatorName, String packageName, Class<? extends VertxGeneratorStrategy> generatorStrategy){
    Jdbc jdbcConfig = new Jdbc();
    jdbcConfig.setDriver("org.hsqldb.jdbcDriver");
    jdbcConfig.setUrl("jdbc:hsqldb:mem:test");
    jdbcConfig.setUser(Credentials.HSQLDB.getUser());
    jdbcConfig.setPassword(Credentials.HSQLDB.getPassword());
    return createGeneratorConfig(generatorName, packageName, generatorStrategy, jdbcConfig, HSQLDBDatabase.class.getName());
}
 
Example 6
Source Project: vertx-jooq   Source File: HsqldbConfigurationProvider.java    License: MIT License 5 votes vote down vote up
@Override
public org.jooq.Configuration createDAOConfiguration(){
    org.jooq.Configuration configuration = new DefaultConfiguration();
    configuration.set(SQLDialect.HSQLDB);
    try {
        configuration.set(DriverManager.getConnection("jdbc:hsqldb:mem:test", "test", ""));
    } catch (SQLException e) {
        throw new AssertionError("Failed setting up DB.",e);
    }
    return configuration;
}
 
Example 7
Source Project: vertx-jooq   Source File: MySQLConfigurationProvider.java    License: MIT License 5 votes vote down vote up
@Override
public Configuration createGeneratorConfig(String generatorName, String packageName, Class<? extends VertxGeneratorStrategy> generatorStrategy){
    Jdbc jdbcConfig = new Jdbc();
    jdbcConfig.setDriver("com.mysql.jdbc.Driver");
    jdbcConfig.setUrl("jdbc:mysql://127.0.0.1:3306/");
    jdbcConfig.setUser(Credentials.MYSQL.getUser());
    jdbcConfig.setPassword(Credentials.MYSQL.getPassword());
    jdbcConfig.setSchema("vertx");
    return createGeneratorConfig(generatorName,packageName,generatorStrategy,jdbcConfig, MySQLDatabase.class.getName());
}
 
Example 8
Source Project: vertx-jooq   Source File: AbstractVertxGeneratorTest.java    License: MIT License 5 votes vote down vote up
@Test
public void generateCodeShouldSucceed() throws Exception {
    configurationProvider.setupDatabase();
    Configuration configuration = configurationProvider.createGeneratorConfig(
            generator.getName(), packageLocation, strategy);
    configuration.setOnError(OnError.FAIL);
    configuration.setLogging(Logging.WARN);
    try {
        GenerationTool.generate(configuration);
        Assert.assertTrue(true);
    } catch (Throwable e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
 
Example 9
Source Project: vertx-jooq   Source File: CustomVertxGeneratorTest.java    License: MIT License 5 votes vote down vote up
public CustomVertxGeneratorTest() {
    super(CustomVertxGenerator.class, VertxGeneratorStrategy.class,"classic.jdbc.custom", new HsqldbConfigurationProvider(){
        @Override
        public Configuration createGeneratorConfig(String generatorName, String packageName, Class<? extends VertxGeneratorStrategy> generatorStrategy) {
            org.jooq.meta.jaxb.Configuration conf =  super.createGeneratorConfig(generatorName, packageName, generatorStrategy);
            //see if generator without interfaces produces compilable classes
            conf.getGenerator().getGenerate().setInterfaces(false);
            return conf;
        }
    });
}
 
Example 10
Source Project: vertx-jooq   Source File: MySQLConfigurationProvider.java    License: MIT License 4 votes vote down vote up
@Override
public org.jooq.Configuration createDAOConfiguration() {
    return new DefaultConfiguration().set(SQLDialect.MYSQL);
}
 
Example 11
Source Project: vertx-jooq   Source File: PostgresConfigurationProvider.java    License: MIT License 4 votes vote down vote up
@Override
public org.jooq.Configuration createDAOConfiguration(){
    return new DefaultConfiguration().set(SQLDialect.POSTGRES);
}