diff --git a/jOOQ-tools/src/org/jooq/xtend/Generators.xtend b/jOOQ-tools/src/org/jooq/xtend/Generators.xtend new file mode 100644 index 0000000000..d139ceecbc --- /dev/null +++ b/jOOQ-tools/src/org/jooq/xtend/Generators.xtend @@ -0,0 +1,122 @@ +package org.jooq.xtend + +import java.io.File +import java.io.FileWriter +import java.io.IOException + +abstract class Generators { + + def write(String className, CharSequence contents) { + val file = new File("./../jOOQ/src/main/java/" + className.replace(".", "/") + ".java"); + file.getParentFile().mkdirs(); + + try { + System::out.println("Generating " + file); + val fw = new FileWriter(file); + fw.append(contents); + fw.flush(); + fw.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } + + def first(int degree) { + switch degree { + case 1 : "first" + case 2 : "second" + case 3 : "third" + case 4 : "fourth" + case 5 : "fifth" + case 6 : "sixth" + case 7 : "seventh" + case 8 : "eighth" + case 9 : "ninth" + case 10 : "tenth" + case 11 : "eleventh" + case 12 : "twelfth" + case 13 : "thirteenth" + case 14 : "fourteenth" + case 15 : "fifteenth" + case 16 : "sixteenth" + case 17 : "seventeenth" + case 18 : "eighteenth" + case 19 : "ninteenth" + case 20 : "twentieth" + case 21 : "twenty-first" + case 22 : "twenty-second" + case degree % 10 == 1 : degree + "st" + case degree % 10 == 2 : degree + "nd" + case degree % 10 == 3 : degree + "rd" + default : degree + "th" + } + } + + def classHeader() { + ''' + /** + * 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. + */ + ''' + } + + def generatedAnnotation() { + ''' + @Generated("This class was generated using jOOQ-tools") + ''' + } + + def TN(int degree) { + // A comma-separated list of types T1, T2, .., TN + (1..degree).join(", ", [e | "T" + e]) + } + + def tn(int degree) { + // A comma-separated list of types T1, T2, .., TN + (1..degree).join(", ", [e | "t" + e]) + } + + def TN_tn(int degree) { + // A comma-separated list of arguments T1 t1, T2 t2, .., TN tn + (1..degree).join(", ", [e | "T" + e + " t" + e]) + } + + def Field_TN_tn(int degree) { + (1..degree).join(", ", [e | "Field t" + e]) + } + + +} \ No newline at end of file diff --git a/jOOQ-tools/src/org/jooq/xtend/Records.xtend b/jOOQ-tools/src/org/jooq/xtend/Records.xtend new file mode 100644 index 0000000000..699f7b238d --- /dev/null +++ b/jOOQ-tools/src/org/jooq/xtend/Records.xtend @@ -0,0 +1,111 @@ +/** + * 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.xtend + +import org.jooq.Constants + +/** + * @author Lukas Eder + */ +class Records extends Generators { + + def static void main(String[] args) { + val records = new Records(); + records.generateRecordClasses(); + } + + def generateRecordClasses() { + for (degree : (1..Constants::MAX_ROW_DEGREE)) { + val out = new StringBuilder(); + + out.append(''' + «classHeader» + package org.jooq; + + import javax.annotation.Generated; + + /** + * A model type for a records with degree «degree» + * + * @see Row«degree» + * @author Lukas Eder + */ + «generatedAnnotation» + public interface Record«degree»<«TN(degree)»> extends Record { + + // ------------------------------------------------------------------------ + // Row value expressions + // ------------------------------------------------------------------------ + + /** + * Get this record's fields as a {@link Row«degree»} + */ + Row«degree»<«TN(degree)»> fieldsRow(); + + /** + * Get this record's values as a {@link Row«degree»} + */ + Row«degree»<«TN(degree)»> valuesRow(); + + // ------------------------------------------------------------------------ + // Field accessors + // ------------------------------------------------------------------------ + «FOR d : (1..degree)» + + /** + * Get the «first(d)» field + */ + Field field«d»(); + «ENDFOR» + + // ------------------------------------------------------------------------ + // Value accessors + // ------------------------------------------------------------------------ + «FOR d : (1..degree)» + + /** + * Get the «first(d)» value + */ + T«d» value«d»(); + «ENDFOR» + + } + '''); + + write("org.jooq.Record" + degree, out); + } + } +} \ No newline at end of file diff --git a/jOOQ-tools/src/org/jooq/xtend/Rows.xtend b/jOOQ-tools/src/org/jooq/xtend/Rows.xtend index 79460072bc..00760f4550 100644 --- a/jOOQ-tools/src/org/jooq/xtend/Rows.xtend +++ b/jOOQ-tools/src/org/jooq/xtend/Rows.xtend @@ -35,133 +35,19 @@ */ package org.jooq.xtend -import java.io.File -import java.io.FileWriter -import java.io.IOException import org.jooq.Constants /** * @author Lukas Eder */ -class Rows { +class Rows extends Generators { + def static void main(String[] args) { val rows = new Rows(); rows.generateRowClasses(); rows.generateRowImpl(); } - def write(String className, CharSequence contents) { - val file = new File("./../jOOQ/src/main/java/" + className.replace(".", "/") + ".java"); - file.getParentFile().mkdirs(); - - try { - System::out.println("Generating " + file); - val fw = new FileWriter(file); - fw.append(contents); - fw.flush(); - fw.close(); - } - catch (IOException e) { - e.printStackTrace(); - } - } - - def first(int degree) { - switch degree { - case 1 : "first" - case 2 : "second" - case 3 : "third" - case 4 : "fourth" - case 5 : "fifth" - case 6 : "sixth" - case 7 : "seventh" - case 8 : "eighth" - case 9 : "ninth" - case 10 : "tenth" - case 11 : "eleventh" - case 12 : "twelfth" - case 13 : "thirteenth" - case 14 : "fourteenth" - case 15 : "fifteenth" - case 16 : "sixteenth" - case 17 : "seventeenth" - case 18 : "eighteenth" - case 19 : "ninteenth" - case 20 : "twentieth" - case 21 : "twenty-first" - case 22 : "twenty-second" - case degree % 10 == 1 : degree + "st" - case degree % 10 == 2 : degree + "nd" - case degree % 10 == 3 : degree + "rd" - default : degree + "th" - } - } - - def classHeader() { - ''' - /** - * 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. - */ - ''' - } - - def generatedAnnotation() { - ''' - @Generated("This class was generated using jOOQ-tools") - ''' - } - - def TN(int degree) { - // A comma-separated list of types T1, T2, .., TN - (1..degree).join(", ", [e | "T" + e]) - } - - def tn(int degree) { - // A comma-separated list of types T1, T2, .., TN - (1..degree).join(", ", [e | "t" + e]) - } - - def TN_tn(int degree) { - // A comma-separated list of arguments T1 t1, T2 t2, .., TN tn - (1..degree).join(", ", [e | "T" + e + " t" + e]) - } - - def Field_TN_tn(int degree) { - (1..degree).join(", ", [e | "Field t" + e]) - } - def generateRowClasses() { for (degree : (1..Constants::MAX_ROW_DEGREE)) { val out = new StringBuilder(); diff --git a/jOOQ/src/main/java/org/jooq/Record1.java b/jOOQ/src/main/java/org/jooq/Record1.java index fc9925c5ea..7a70985099 100644 --- a/jOOQ/src/main/java/org/jooq/Record1.java +++ b/jOOQ/src/main/java/org/jooq/Record1.java @@ -35,12 +35,15 @@ */ package org.jooq; +import javax.annotation.Generated; + /** * A model type for a records with degree 1 * * @see Row1 * @author Lukas Eder */ +@Generated("This class was generated using jOOQ-tools") public interface Record1 extends Record { // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/Record2.java b/jOOQ/src/main/java/org/jooq/Record2.java index 6f53427a7d..2b2f50f6d4 100644 --- a/jOOQ/src/main/java/org/jooq/Record2.java +++ b/jOOQ/src/main/java/org/jooq/Record2.java @@ -35,12 +35,15 @@ */ package org.jooq; +import javax.annotation.Generated; + /** * A model type for a records with degree 2 * * @see Row2 * @author Lukas Eder */ +@Generated("This class was generated using jOOQ-tools") public interface Record2 extends Record { // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/Record3.java b/jOOQ/src/main/java/org/jooq/Record3.java index b0153758de..1f569389aa 100644 --- a/jOOQ/src/main/java/org/jooq/Record3.java +++ b/jOOQ/src/main/java/org/jooq/Record3.java @@ -35,12 +35,15 @@ */ package org.jooq; +import javax.annotation.Generated; + /** * A model type for a records with degree 3 * * @see Row3 * @author Lukas Eder */ +@Generated("This class was generated using jOOQ-tools") public interface Record3 extends Record { // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/Record4.java b/jOOQ/src/main/java/org/jooq/Record4.java index 0192bd7010..5dbdfc4912 100644 --- a/jOOQ/src/main/java/org/jooq/Record4.java +++ b/jOOQ/src/main/java/org/jooq/Record4.java @@ -35,12 +35,15 @@ */ package org.jooq; +import javax.annotation.Generated; + /** * A model type for a records with degree 4 * * @see Row4 * @author Lukas Eder */ +@Generated("This class was generated using jOOQ-tools") public interface Record4 extends Record { // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/Record5.java b/jOOQ/src/main/java/org/jooq/Record5.java index bf9df1b488..71ba1e3641 100644 --- a/jOOQ/src/main/java/org/jooq/Record5.java +++ b/jOOQ/src/main/java/org/jooq/Record5.java @@ -35,12 +35,15 @@ */ package org.jooq; +import javax.annotation.Generated; + /** * A model type for a records with degree 5 * * @see Row5 * @author Lukas Eder */ +@Generated("This class was generated using jOOQ-tools") public interface Record5 extends Record { // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/Record6.java b/jOOQ/src/main/java/org/jooq/Record6.java index 812fd1306e..04531770c2 100644 --- a/jOOQ/src/main/java/org/jooq/Record6.java +++ b/jOOQ/src/main/java/org/jooq/Record6.java @@ -35,12 +35,15 @@ */ package org.jooq; +import javax.annotation.Generated; + /** * A model type for a records with degree 6 * * @see Row6 * @author Lukas Eder */ +@Generated("This class was generated using jOOQ-tools") public interface Record6 extends Record { // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/Record7.java b/jOOQ/src/main/java/org/jooq/Record7.java index 9214cb24c4..9e3919c793 100644 --- a/jOOQ/src/main/java/org/jooq/Record7.java +++ b/jOOQ/src/main/java/org/jooq/Record7.java @@ -35,12 +35,15 @@ */ package org.jooq; +import javax.annotation.Generated; + /** * A model type for a records with degree 7 * * @see Row7 * @author Lukas Eder */ +@Generated("This class was generated using jOOQ-tools") public interface Record7 extends Record { // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/Record8.java b/jOOQ/src/main/java/org/jooq/Record8.java index 186f656a9e..192ae05855 100644 --- a/jOOQ/src/main/java/org/jooq/Record8.java +++ b/jOOQ/src/main/java/org/jooq/Record8.java @@ -35,12 +35,15 @@ */ package org.jooq; +import javax.annotation.Generated; + /** * A model type for a records with degree 8 * * @see Row8 * @author Lukas Eder */ +@Generated("This class was generated using jOOQ-tools") public interface Record8 extends Record { // ------------------------------------------------------------------------