Merge pull request #23 from digulla/digulla
Refactoring of DefaultGenerator to make it easier to reuse
This commit is contained in:
commit
218eea19a9
@ -55,7 +55,7 @@ abstract class AbstractGenerator implements Generator {
|
||||
boolean generateJPAAnnotations = false;
|
||||
boolean generateValidationAnnotations = false;
|
||||
|
||||
GeneratorStrategyWrapper strategy;
|
||||
protected GeneratorStrategyWrapper strategy;
|
||||
|
||||
@Override
|
||||
public void setStrategy(GeneratorStrategy strategy) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -113,7 +113,7 @@ class GenerationUtil {
|
||||
* collisions have to be generally reviewed again, when allowing for more
|
||||
* control over generated source code, as of [#408][#911]
|
||||
*/
|
||||
static String convertToJavaIdentifier(String literal) {
|
||||
public static String convertToJavaIdentifier(String literal) {
|
||||
if (JAVA_KEYWORDS.contains(literal)) {
|
||||
return literal + "_";
|
||||
}
|
||||
|
||||
@ -41,11 +41,16 @@ public class GenerationWriter {
|
||||
private final List<String> initialisationStatements;
|
||||
private final Set<Object> alreadyPrinted;
|
||||
|
||||
public GenerationWriter(File file) throws FileNotFoundException {
|
||||
public GenerationWriter(File file) {
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
this.file = file;
|
||||
this.writer = new PrintWriter(file);
|
||||
try {
|
||||
this.writer = new PrintWriter(file);
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
throw new GeneratorException("Error writing "+file.getAbsolutePath());
|
||||
}
|
||||
this.sb = new StringBuilder();
|
||||
this.staticInitialisationStatements = new ArrayList<String>();
|
||||
this.initialisationStatements = new ArrayList<String>();
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
|
||||
package org.jooq.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
|
||||
/**
|
||||
@ -50,7 +48,7 @@ public interface Generator {
|
||||
/**
|
||||
* Do the code generation
|
||||
*/
|
||||
void generate(Database database) throws IOException;
|
||||
void generate(Database database);
|
||||
|
||||
/**
|
||||
* Set a naming strategy to this generator
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed to you under the Apache License, Version 2.0
|
||||
* (the "License"); You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* . Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* . Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* . Neither the name "jOOQ" nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.jooq.util;
|
||||
|
||||
public class GeneratorException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public GeneratorException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public GeneratorException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user