Package org.jooq.util.jaxb

Examples of org.jooq.util.jaxb.Jdbc


        new GenerationTool().run(configuration);
    }

    @SuppressWarnings("unchecked")
    public void run(Configuration configuration) throws Exception {
        Jdbc j = configuration.getJdbc();
        org.jooq.util.jaxb.Generator g = configuration.getGenerator();
        errorIfNull(g, "The <generator/> tag is mandatory.");

        // Some default values for optional elements to avoid NPE's
        if (g.getStrategy() == null)
            g.setStrategy(new Strategy());
        if (g.getTarget() == null)
            g.setTarget(new Target());

        try {

            // Initialise connection
            // ---------------------
            if (connection == null && j != null) {
                Class<? extends Driver> driver = (Class<? extends Driver>) loadClass(driverClass(j));

                Properties properties = properties(j.getProperties());
                if (!properties.containsKey("user"))
                    properties.put("user", defaultString(j.getUser()));
                if (!properties.containsKey("password"))
                    properties.put("password", defaultString(j.getPassword()));

                connection = driver.newInstance().connect(defaultString(j.getUrl()), properties);
                close = true;
            }
            else {
                j = defaultIfNull(j, new Jdbc());
            }


            // Initialise generator
            // --------------------
            Class<Generator> generatorClass = (Class<Generator>) (!isBlank(g.getName())
                ? loadClass(trim(g.getName()))
                : JavaGenerator.class);
            Generator generator = generatorClass.newInstance();

            GeneratorStrategy strategy;

            Matchers matchers = g.getStrategy().getMatchers();
            if (matchers != null) {
                strategy = new MatcherStrategy(matchers);

                if (g.getStrategy().getName() != null) {
                    log.warn("WARNING: Matchers take precedence over custom strategy. Strategy ignored: " +
                        g.getStrategy().getName());
                }
            }
            else {
                Class<GeneratorStrategy> strategyClass = (Class<GeneratorStrategy>) (!isBlank(g.getStrategy().getName())
                    ? loadClass(trim(g.getStrategy().getName()))
                    : DefaultGeneratorStrategy.class);
                strategy = strategyClass.newInstance();
            }

            generator.setStrategy(strategy);

            org.jooq.util.jaxb.Database d = defaultIfNull(g.getDatabase(), new org.jooq.util.jaxb.Database());
            String databaseName = trim(d.getName());
            Class<? extends Database> databaseClass = isBlank(databaseName)
                ? databaseClass(j)
                : (Class<? extends Database>) loadClass(databaseName);
            Database database = databaseClass.newInstance();
            database.setProperties(properties(d.getProperties()));

            List<Schema> schemata = d.getSchemata();

            // For convenience and backwards-compatibility, the schema configuration can be set also directly
            // in the <database/> element
            if (schemata.isEmpty()) {
                Schema schema = new Schema();
                schema.setInputSchema(trim(d.getInputSchema()));
                schema.setOutputSchema(trim(d.getOutputSchema()));
                schema.setOutputSchemaToDefault(d.isOutputSchemaToDefault());
                schemata.add(schema);
            }
            else {
                if (!StringUtils.isBlank(d.getInputSchema())) {
                    log.warn("WARNING: Cannot combine configuration properties /configuration/generator/database/inputSchema and /configuration/generator/database/schemata");
                }
                if (!StringUtils.isBlank(d.getOutputSchema())) {
                    log.warn("WARNING: Cannot combine configuration properties /configuration/generator/database/outputSchema and /configuration/generator/database/schemata");
                }
            }

            for (Schema schema : schemata) {
                if (StringUtils.isBlank(schema.getInputSchema())) {
                    if (!StringUtils.isBlank(j.getSchema())) {
                        log.warn("WARNING: The configuration property jdbc.Schema is deprecated and will be removed in the future. Use /configuration/generator/database/inputSchema instead");
                    }

                    schema.setInputSchema(trim(j.getSchema()));
                }

                // [#3018] Prior to <outputSchemaToDefault/>, empty <outputSchema/> elements meant that
                // the outputSchema should be the default schema. This is a bit too clever, and doesn't
                // work when Maven parses the XML configurations.
View Full Code Here


            }
        }
  }

  public static void main(Properties properties, String... args) throws Exception {
      Jdbc jdbc = new Jdbc();
      jdbc.setDriver(properties.getProperty("jdbc.Driver"));
      jdbc.setUrl(properties.getProperty("jdbc.URL"));
      jdbc.setUser(properties.getProperty("jdbc.User"));
      jdbc.setPassword(properties.getProperty("jdbc.Password"));
      jdbc.setSchema(properties.getProperty("jdbc.Schema"));

      Strategy strategy = new Strategy();
      strategy.setName(properties.containsKey("generator.strategy") ? properties.getProperty("generator.strategy") : null);

      List<MasterDataTable> masterDataTables = new ArrayList<MasterDataTable>();
View Full Code Here

        }
  }

  @SuppressWarnings("unchecked")
    public static void main(Configuration configuration) throws Exception {
      Jdbc j = configuration.getJdbc();
      org.jooq.util.jaxb.Generator g = configuration.getGenerator();

      // Some default values for optional elements to avoid NPE's
      if (g.getStrategy() == null)
          g.setStrategy(new Strategy());
      if (g.getTarget() == null)
          g.setTarget(new Target());

        Class.forName(j.getDriver());
        Connection connection = null;

        try {

            // Initialise connection
            // ---------------------
            Properties properties = new Properties();
            for (Property p : j.getProperties()) {
                properties.put(p.getKey(), p.getValue());
            }

            if (!properties.containsKey("user"))
                properties.put("user", defaultString(j.getUser()));
            if (!properties.containsKey("password"))
                properties.put("password", defaultString(j.getPassword()));

            connection = DriverManager.getConnection(defaultString(j.getUrl()), properties);

            // Initialise generator
            // --------------------
            Class<Generator> generatorClass = (Class<Generator>) (!isBlank(g.getName())
                ? Class.forName(trim(g.getName()))
                : DefaultGenerator.class);
            Generator generator = generatorClass.newInstance();

            Class<GeneratorStrategy> strategyClass = (Class<GeneratorStrategy>) (!isBlank(g.getStrategy().getName())
                ? Class.forName(trim(g.getStrategy().getName()))
                : DefaultGeneratorStrategy.class);
            GeneratorStrategy strategy = strategyClass.newInstance();

            generator.setStrategy(strategy);

            Class<Database> databaseClass = (Class<Database>) Class.forName(trim(g.getDatabase().getName()));
            Database database = databaseClass.newInstance();

            List<Schema> schemata = g.getDatabase().getSchemata();
            if (schemata.isEmpty()) {
                Schema schema = new Schema();
                schema.setInputSchema(trim(g.getDatabase().getInputSchema()));
                schema.setOutputSchema(trim(g.getDatabase().getOutputSchema()));
                schemata.add(schema);
            }
            else {
                if (!StringUtils.isBlank(g.getDatabase().getInputSchema())) {
                    log.warn("WARNING: Cannot combine configuration properties /configuration/generator/database/inputSchema and /configuration/generator/database/schemata");
                }
                if (!StringUtils.isBlank(g.getDatabase().getOutputSchema())) {
                    log.warn("WARNING: Cannot combine configuration properties /configuration/generator/database/outputSchema and /configuration/generator/database/schemata");
                }
            }

            for (Schema schema : schemata) {
                if (StringUtils.isBlank(schema.getInputSchema())) {
                    if (!StringUtils.isBlank(j.getSchema())) {
                        log.warn("WARNING: The configuration property jdbc.Schema is deprecated and will be removed in the future. Use /configuration/generator/database/inputSchema instead");
                    }

                    schema.setInputSchema(trim(j.getSchema()));
                }

                if (StringUtils.isBlank(schema.getOutputSchema())) {
                    schema.setOutputSchema(trim(schema.getInputSchema()));
                }
View Full Code Here

TOP

Related Classes of org.jooq.util.jaxb.Jdbc

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.