[#1473] Add IdentityDefinition to jooq-meta
This commit is contained in:
parent
7af364eda9
commit
bd72bc41af
@ -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 <code>" + schema.getOutputName() + "</code> schema");
|
||||
printClassJavadoc(out,
|
||||
"A class modelling foreign key relationships between tables of the <code>" + schema.getOutputName() + "</code> 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(" */");
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<Definition> getDefinitionPath() {
|
||||
return getColumn().getDefinitionPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColumnDefinition getColumn() {
|
||||
return column;
|
||||
}
|
||||
}
|
||||
@ -144,7 +144,7 @@ public class DefaultMasterDataTableDefinition extends AbstractDefinition impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColumnDefinition getIdentity() {
|
||||
public IdentityDefinition getIdentity() {
|
||||
return delegate.getIdentity();
|
||||
}
|
||||
|
||||
|
||||
@ -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 <code>IDENTITY</code> column
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface IdentityDefinition extends Definition {
|
||||
|
||||
/**
|
||||
* The <code>IDENTITY</code> column
|
||||
*/
|
||||
ColumnDefinition getColumn();
|
||||
}
|
||||
@ -87,7 +87,7 @@ public interface TableDefinition extends Definition {
|
||||
* Get the <code>IDENTITY</code> column of this table, or <code>null</code>,
|
||||
* if no such column exists.
|
||||
*/
|
||||
ColumnDefinition getIdentity();
|
||||
IdentityDefinition getIdentity();
|
||||
|
||||
/**
|
||||
* This TableDefinition as a {@link Table}
|
||||
|
||||
@ -8,7 +8,12 @@ package org.jooq.test.h2.generatedclasses;
|
||||
*
|
||||
* A class modelling foreign key relationships between tables of the <code>PUBLIC</code>
|
||||
* 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 {
|
||||
|
||||
|
||||
@ -8,7 +8,12 @@ package org.jooq.test.hsqldb.generatedclasses;
|
||||
*
|
||||
* A class modelling foreign key relationships between tables of the <code>PUBLIC</code>
|
||||
* 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 {
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user