From bd72bc41afb0adebcf243c594259caa9b76159dc Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Sat, 2 Jun 2012 13:25:49 +0200 Subject: [PATCH] [#1473] Add IdentityDefinition to jooq-meta --- .../java/org/jooq/util/DefaultGenerator.java | 24 +++---- .../jooq/util/AbstractTableDefinition.java | 6 +- .../jooq/util/DefaultIdentityDefinition.java | 64 +++++++++++++++++++ .../DefaultMasterDataTableDefinition.java | 2 +- .../org/jooq/util/IdentityDefinition.java | 49 ++++++++++++++ .../java/org/jooq/util/TableDefinition.java | 2 +- .../jooq/test/h2/generatedclasses/Keys.java | 5 ++ .../test/hsqldb/generatedclasses/Keys.java | 5 ++ 8 files changed, 141 insertions(+), 16 deletions(-) create mode 100644 jOOQ-meta/src/main/java/org/jooq/util/DefaultIdentityDefinition.java create mode 100644 jOOQ-meta/src/main/java/org/jooq/util/IdentityDefinition.java diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/DefaultGenerator.java b/jOOQ-codegen/src/main/java/org/jooq/util/DefaultGenerator.java index ab9c6e7b98..1e1a332df9 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/util/DefaultGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/util/DefaultGenerator.java @@ -560,7 +560,7 @@ public class DefaultGenerator extends AbstractGenerator { // Add primary / unique / foreign key information if (generateRelations()) { - ColumnDefinition identity = table.getIdentity(); + IdentityDefinition identity = table.getIdentity(); // The identity column if (identity != null) { @@ -572,13 +572,13 @@ public class DefaultGenerator extends AbstractGenerator { out.print("<"); out.print(strategy.getFullJavaClassName(table, Mode.RECORD)); out.print(", "); - out.print(getJavaType(table.getIdentity().getType())); + out.print(getJavaType(identity.getColumn().getType())); out.println("> getIdentity() {"); out.print("\t\treturn "); out.print(strategy.getJavaPackageName(schema)); out.print(".Keys.IDENTITY_"); - out.print(strategy.getJavaIdentifier(identity.getContainer())); + out.print(strategy.getJavaIdentifier(identity.getColumn().getContainer())); out.println(";"); out.println("\t}"); @@ -973,7 +973,9 @@ public class DefaultGenerator extends AbstractGenerator { GenerationWriter out = new GenerationWriter(new File(targetSchemaDir, "Keys.java")); printHeader(out, schema); - printClassJavadoc(out, "A class modelling foreign key relationships between tables of the " + schema.getOutputName() + " schema"); + printClassJavadoc(out, + "A class modelling foreign key relationships between tables of the " + schema.getOutputName() + " schema", + "2.4.0 - [#1459] - The Keys.java class's static initialiser can become too large for big databases. Use constraint definitions in table meta classes instead"); out.suppressWarnings("unchecked"); out.print("public class Keys extends "); @@ -984,21 +986,21 @@ public class DefaultGenerator extends AbstractGenerator { for (TableDefinition table : database.getTables(schema)) { try { - ColumnDefinition identity = table.getIdentity(); + IdentityDefinition identity = table.getIdentity(); if (identity != null) { out.print("\tpublic static final "); out.print(Identity.class); out.print("<"); - out.print(strategy.getFullJavaClassName(identity.getContainer(), Mode.RECORD)); + out.print(strategy.getFullJavaClassName(identity.getColumn().getContainer(), Mode.RECORD)); out.print(", "); - out.print(getJavaType(identity.getType())); + out.print(getJavaType(identity.getColumn().getType())); out.print("> IDENTITY_"); - out.print(strategy.getJavaIdentifier(identity.getContainer())); + out.print(strategy.getJavaIdentifier(identity.getColumn().getContainer())); out.print(" = createIdentity("); - out.print(strategy.getFullJavaIdentifier(identity.getContainer())); + out.print(strategy.getFullJavaIdentifier(identity.getColumn().getContainer())); out.print(", "); - out.print(strategy.getFullJavaIdentifier(identity)); + out.print(strategy.getFullJavaIdentifier(identity.getColumn())); out.println(");"); } } @@ -2852,7 +2854,7 @@ public class DefaultGenerator extends AbstractGenerator { if (deprecation != null && deprecation.length() > 0) { out.println(" *"); - out.println(" * @deprecated : " + deprecation); + printJavadocParagraph(out, "@deprecated : " + deprecation, ""); } out.println(" */"); diff --git a/jOOQ-meta/src/main/java/org/jooq/util/AbstractTableDefinition.java b/jOOQ-meta/src/main/java/org/jooq/util/AbstractTableDefinition.java index 2575dd780b..40f8606a35 100644 --- a/jOOQ-meta/src/main/java/org/jooq/util/AbstractTableDefinition.java +++ b/jOOQ-meta/src/main/java/org/jooq/util/AbstractTableDefinition.java @@ -58,7 +58,7 @@ implements TableDefinition { private boolean mainUniqueKeyLoaded; private UniqueKeyDefinition mainUniqueKey; private boolean identityLoaded; - private ColumnDefinition identity; + private IdentityDefinition identity; public AbstractTableDefinition(SchemaDefinition schema, String name, String comment) { super(schema, name, comment); @@ -110,13 +110,13 @@ implements TableDefinition { } @Override - public final ColumnDefinition getIdentity() { + public final IdentityDefinition getIdentity() { if (!identityLoaded) { identityLoaded = true; for (ColumnDefinition column : getColumns()) { if (column.isIdentity()) { - identity = column; + identity = new DefaultIdentityDefinition(column); break; } } diff --git a/jOOQ-meta/src/main/java/org/jooq/util/DefaultIdentityDefinition.java b/jOOQ-meta/src/main/java/org/jooq/util/DefaultIdentityDefinition.java new file mode 100644 index 0000000000..3a74603f1d --- /dev/null +++ b/jOOQ-meta/src/main/java/org/jooq/util/DefaultIdentityDefinition.java @@ -0,0 +1,64 @@ +/** + * 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; + +import java.util.List; + +/** + * A default implementation for {@link IdentityDefinition} + * + * @author Lukas Eder + */ +public class DefaultIdentityDefinition extends AbstractDefinition implements IdentityDefinition { + + private final ColumnDefinition column; + + public DefaultIdentityDefinition(ColumnDefinition column) { + super(column.getDatabase(), column.getSchema(), column.getName()); + + this.column = column; + } + + @Override + public List getDefinitionPath() { + return getColumn().getDefinitionPath(); + } + + @Override + public ColumnDefinition getColumn() { + return column; + } +} diff --git a/jOOQ-meta/src/main/java/org/jooq/util/DefaultMasterDataTableDefinition.java b/jOOQ-meta/src/main/java/org/jooq/util/DefaultMasterDataTableDefinition.java index 8d98c4a452..e9a999bde6 100644 --- a/jOOQ-meta/src/main/java/org/jooq/util/DefaultMasterDataTableDefinition.java +++ b/jOOQ-meta/src/main/java/org/jooq/util/DefaultMasterDataTableDefinition.java @@ -144,7 +144,7 @@ public class DefaultMasterDataTableDefinition extends AbstractDefinition impleme } @Override - public ColumnDefinition getIdentity() { + public IdentityDefinition getIdentity() { return delegate.getIdentity(); } diff --git a/jOOQ-meta/src/main/java/org/jooq/util/IdentityDefinition.java b/jOOQ-meta/src/main/java/org/jooq/util/IdentityDefinition.java new file mode 100644 index 0000000000..886c7ab5d1 --- /dev/null +++ b/jOOQ-meta/src/main/java/org/jooq/util/IdentityDefinition.java @@ -0,0 +1,49 @@ +/** + * 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; + +/** + * An interface defining an IDENTITY column + * + * @author Lukas Eder + */ +public interface IdentityDefinition extends Definition { + + /** + * The IDENTITY column + */ + ColumnDefinition getColumn(); +} diff --git a/jOOQ-meta/src/main/java/org/jooq/util/TableDefinition.java b/jOOQ-meta/src/main/java/org/jooq/util/TableDefinition.java index 3294e4183f..d9a7b717d6 100644 --- a/jOOQ-meta/src/main/java/org/jooq/util/TableDefinition.java +++ b/jOOQ-meta/src/main/java/org/jooq/util/TableDefinition.java @@ -87,7 +87,7 @@ public interface TableDefinition extends Definition { * Get the IDENTITY column of this table, or null, * if no such column exists. */ - ColumnDefinition getIdentity(); + IdentityDefinition getIdentity(); /** * This TableDefinition as a {@link Table} diff --git a/jOOQ-test/src/org/jooq/test/h2/generatedclasses/Keys.java b/jOOQ-test/src/org/jooq/test/h2/generatedclasses/Keys.java index 674bce28c9..935a2f26f3 100644 --- a/jOOQ-test/src/org/jooq/test/h2/generatedclasses/Keys.java +++ b/jOOQ-test/src/org/jooq/test/h2/generatedclasses/Keys.java @@ -8,7 +8,12 @@ package org.jooq.test.h2.generatedclasses; * * A class modelling foreign key relationships between tables of the PUBLIC * schema + * + * @deprecated : 2.4.0 - [#1459] - The Keys.java class's static initialiser + * can become too large for big databases. Use constraint definitions in table + * meta classes instead */ +@Deprecated @SuppressWarnings({"unchecked"}) public class Keys extends org.jooq.impl.AbstractKeys { diff --git a/jOOQ-test/src/org/jooq/test/hsqldb/generatedclasses/Keys.java b/jOOQ-test/src/org/jooq/test/hsqldb/generatedclasses/Keys.java index 94d074b1c0..0030bfa8a0 100644 --- a/jOOQ-test/src/org/jooq/test/hsqldb/generatedclasses/Keys.java +++ b/jOOQ-test/src/org/jooq/test/hsqldb/generatedclasses/Keys.java @@ -8,7 +8,12 @@ package org.jooq.test.hsqldb.generatedclasses; * * A class modelling foreign key relationships between tables of the PUBLIC * schema + * + * @deprecated : 2.4.0 - [#1459] - The Keys.java class's static initialiser + * can become too large for big databases. Use constraint definitions in table + * meta classes instead */ +@Deprecated @SuppressWarnings({"unchecked"}) public class Keys extends org.jooq.impl.AbstractKeys {