<commit_before>/*
 * Copyright 2011 <NAME>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.martido.genny.example.generator;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import de.martido.genny.api.Field;
import de.martido.genny.api.FieldFilter;
import de.martido.genny.api.FieldProvider;
import de.martido.genny.api.Generator;
import de.martido.genny.api.GeneratorDefinition;
import de.martido.genny.api.GennyConfiguration;

/**
 * Properties are read from a Derby database. This is a somewhat stupid example that's probably
 * never gonna happen in the real world. It's there anyway.
 */
public class DbConfiguration implements GennyConfiguration {

  public static void main(String[] args) throws Exception {
    DbUtil.loadDatabaseDriver();
    try {
      List<String> statements = DbUtil.readSQLScript("src/main/resources/example.sql");
      DbUtil.execute(statements);
      new Generator().generateFrom(new DbConfiguration());
    } finally {
      DbUtil.shutdown();
    }
  }

  @Override
  public List<GeneratorDefinition> configure() {
    GeneratorDefinition def = new GeneratorDefinition();
    def.setTargetClass("de.martido.genny.example.generated.DbConfiguration");
    def.setBaseDirectory("src/generated/java");
    def.setFieldProvider(new DbProvider());
    return Arrays.asList(def);
  }

  /**
   * A custom {@link FieldProvider} that reads properties from a database.<commit_msg>Update sandbox example<commit_after>/*
 * Copyright 2011 <NAME>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.martido.genny.example;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import de.martido.genny.Field;
import de.martido.genny.FieldFilter;
import de.martido.genny.FieldProvider;
import de.martido.genny.GeneratorDefinition;
import de.martido.genny.Genny;
import de.martido.genny.GennyConfiguration;
import de.martido.genny.SourceFile;

/**
 * Properties are read from a Derby database. This is a somewhat stupid example that's probably
 * never gonna happen in the real world. It's there anyway.
 */
public class DbConfiguration implements GennyConfiguration {

  public static void main(String[] args) throws Exception {
    DbUtil.loadDatabaseDriver();
    try {
      List<String> statements = DbUtil.readSQLScript("src/main/resources/example.sql");
      DbUtil.execute(statements);
      new Genny().generateFrom(
          new DbConfiguration(),
          Collections.<String> emptyList(),
          new SourceFile("de.martido.genny.example.Db", "src/generated/java"));
    } finally {
      DbUtil.shutdown();
    }
  }

  @Override
  public GeneratorDefinition configure(List<String> inputFiles) {
    return new GeneratorDefinition(inputFiles) {
      @Override
      public FieldProvider getFieldProvider() {
        return new DbProvider();
      }
    };
  }

  /**
   * A custom {@link FieldProvider} that reads properties from a database.
{'fraction_non_alphanumeric': 0.0977427597955707, 'fraction_numerical': 0.0034071550255536627, 'mean_word_length': 4.167216721672167, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1780351', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1284, 'n_words': 408}