HHH-5662 - Import the initial work
This commit is contained in:
parent
aec8d1a742
commit
960326510f
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Support for writing {@link Constraint} implementations
|
||||
*
|
||||
* @todo do we need to support defining these on particular schemas/catalogs?
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractConstraint implements Constraint {
|
||||
private final TableSpecification table;
|
||||
private final String name;
|
||||
private List<Column> columns = new ArrayList<Column>();
|
||||
|
||||
protected AbstractConstraint(TableSpecification table, String name) {
|
||||
this.table = table;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public TableSpecification getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<Column> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void addColumn(Column column) {
|
||||
if ( column.getValueContainer() != getTable() ) {
|
||||
throw new IllegalArgumentException( "Unable to add column to constraint; tables did not match" );
|
||||
}
|
||||
columns.add( column );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Basic support for {@link SimpleValue} implementations.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractSimpleValue implements SimpleValue {
|
||||
private static final Logger log = LoggerFactory.getLogger( AbstractSimpleValue.class );
|
||||
|
||||
private final ValueContainer container;
|
||||
private Datatype datatype;
|
||||
|
||||
protected AbstractSimpleValue(ValueContainer container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public ValueContainer getValueContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Datatype getDatatype() {
|
||||
return datatype;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setDatatype(Datatype datatype) {
|
||||
log.debug( "setting datatype for column {} : {}", toLoggableString(), datatype );
|
||||
if ( this.datatype != null && ! this.datatype.equals( datatype ) ) {
|
||||
log.debug( "overriding previous datatype : {}", this.datatype );
|
||||
}
|
||||
this.datatype = datatype;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Convenience base class for implementing the {@link ValueContainer} contract centralizing commonality
|
||||
* between modelling tables views and inline views.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractTableSpecification extends AbstractValueContainer implements TableSpecification {
|
||||
private PrimaryKey primaryKey = new PrimaryKey( this );
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PrimaryKey getPrimaryKey() {
|
||||
return primaryKey;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
/**
|
||||
* Convenience base class for implementing the {@link ValueContainer} contract
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractValueContainer implements ValueContainer {
|
||||
private final LinkedHashSet<Value> values = new LinkedHashSet<Value>();
|
||||
|
||||
@Override
|
||||
public Iterable<Value> iterateValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Column createColumn(String name) {
|
||||
final Column column = new Column( this, name );
|
||||
values.add( column );
|
||||
return column;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DerivedValue createDerivedValue(String fragment) {
|
||||
final DerivedValue value = new DerivedValue( this, fragment );
|
||||
values.add( value );
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tuple createTuple(String name) {
|
||||
final Tuple tuple = new Tuple( this, name );
|
||||
values.add( tuple );
|
||||
return tuple;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Models a physical column
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Column extends AbstractSimpleValue implements SimpleValue {
|
||||
private final String name;
|
||||
private Size size;
|
||||
|
||||
protected Column(ValueContainer table, String name) {
|
||||
super( table );
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Size getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(Size size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toLoggableString() {
|
||||
return getValueContainer().getLoggableValueQualifier() + '.' + getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Models size restrictions/requirements on a column's datatype.
|
||||
* <p/>
|
||||
* IMPL NOTE: since we do not necessarily know the datatype up front, and therefore do not necessarily know
|
||||
* whether length or precision/scale sizing is needed, we simply account for both here. Additionally LOB
|
||||
* definitions, by standard, are allowed a "multiplier" consisting of 'K' (Kb), 'M' (Mb) or 'G' (Gb).
|
||||
*/
|
||||
public static class Size {
|
||||
private static enum LobMultiplier { K, M, G }
|
||||
|
||||
private final int precision;
|
||||
private final int scale;
|
||||
private final long length;
|
||||
private final LobMultiplier lobMultiplier;
|
||||
|
||||
/**
|
||||
* Complete constructor.
|
||||
*
|
||||
* @param precision numeric precision
|
||||
* @param scale numeric scale
|
||||
* @param length type length
|
||||
* @param lobMultiplier LOB length multiplier
|
||||
*/
|
||||
public Size(int precision, int scale, long length, LobMultiplier lobMultiplier) {
|
||||
this.precision = precision;
|
||||
this.scale = scale;
|
||||
this.length = length;
|
||||
this.lobMultiplier = lobMultiplier;
|
||||
}
|
||||
|
||||
public Size(int precision) {
|
||||
this( precision, -1, -1, null );
|
||||
}
|
||||
|
||||
public Size(int precision, int scale) {
|
||||
this( precision, scale, -1, null );
|
||||
}
|
||||
|
||||
public Size(long length) {
|
||||
this( -1, -1, length, null );
|
||||
}
|
||||
|
||||
public Size(long length, LobMultiplier lobMultiplier) {
|
||||
this( -1, -1, length, lobMultiplier );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Basic contract for the types of constraints we fully support as metadata constructs:<ul>
|
||||
* <li>primary key</li>
|
||||
* <li>foreign key</li>
|
||||
* <li>unique constraint</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface Constraint {
|
||||
/**
|
||||
* Obtain the table to which this constraint applies.
|
||||
*
|
||||
* @return The constrained table.
|
||||
*/
|
||||
public TableSpecification getTable();
|
||||
|
||||
/**
|
||||
* Obtain the constraint name.
|
||||
*
|
||||
* @return the name.
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Obtain the columns that are part of this constraint.
|
||||
*
|
||||
* @return The constrained columns.
|
||||
*/
|
||||
public List<Column> getColumns();
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Models a JDBC {@link java.sql.Types DATATYPE}
|
||||
*
|
||||
* @todo Do we somehow link this in with {@link org.hibernate.internal.util.jdbc.TypeInfo} ?
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Datatype {
|
||||
private final int typeCode;
|
||||
private final String typeName;
|
||||
private final Class javaType;
|
||||
private final int hashCode;
|
||||
|
||||
public Datatype(int typeCode, String typeName, Class javaType) {
|
||||
this.typeCode = typeCode;
|
||||
this.typeName = typeName;
|
||||
this.javaType = javaType;
|
||||
this.hashCode = generateHashCode();
|
||||
}
|
||||
|
||||
private int generateHashCode() {
|
||||
int result = typeCode;
|
||||
result = 31 * result + typeName.hashCode();
|
||||
result = 31 * result + javaType.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getTypeCode() {
|
||||
return typeCode;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public Class getJavaType() {
|
||||
return javaType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Datatype datatype = (Datatype) o;
|
||||
|
||||
return typeCode == datatype.typeCode
|
||||
&& javaType.equals( datatype.javaType )
|
||||
&& typeName.equals( datatype.typeName );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + "[code=" + typeCode + ", name=" + typeName + ", javaClass=" + javaType.getName() + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Models a value expression. It is the result of a <tt>formula</tt> mapping.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DerivedValue extends AbstractSimpleValue implements SimpleValue {
|
||||
private final String expression;
|
||||
|
||||
public DerivedValue(ValueContainer table, String expression) {
|
||||
super( table );
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String toLoggableString() {
|
||||
return getValueContainer().toLoggableString() + ".{derived-column}";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Contract for entities (in the ERD sense) which can be exported via {@code CREATE}, {@code ALTER}, etc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface Exportable {
|
||||
/**
|
||||
* Get a unique identifier to make sure we are not exporting the same database structure multiple times.
|
||||
*
|
||||
* @return The exporting identifier.
|
||||
*/
|
||||
public String getExportIdentifier();
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Models the notion of a foreign key.
|
||||
* <p/>
|
||||
* Note that this need not mean a physical foreign key; we just mean a relationship between 2 table
|
||||
* specifications.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ForeignKey extends AbstractConstraint implements Constraint, Exportable {
|
||||
private static final Logger log = LoggerFactory.getLogger( ForeignKey.class );
|
||||
|
||||
private final TableSpecification targetTable;
|
||||
private List<Column> targetColumns;
|
||||
|
||||
public ForeignKey(TableSpecification sourceTable, TableSpecification targetTable, String name) {
|
||||
super( sourceTable, name );
|
||||
this.targetTable = targetTable;
|
||||
}
|
||||
|
||||
public ForeignKey(TableSpecification sourceTable, TableSpecification targetTable) {
|
||||
this( sourceTable, targetTable, null );
|
||||
}
|
||||
|
||||
public TableSpecification getSourceTable() {
|
||||
return getTable();
|
||||
}
|
||||
|
||||
public TableSpecification getTargetTable() {
|
||||
return targetTable;
|
||||
}
|
||||
|
||||
public List<Column> getSourceColumns() {
|
||||
return getColumns();
|
||||
}
|
||||
|
||||
public List<Column> getTargetColumns() {
|
||||
return targetColumns == null
|
||||
? getTargetTable().getPrimaryKey().getColumns()
|
||||
: targetColumns;
|
||||
}
|
||||
|
||||
public void addColumnMapping(Column sourceColumn, Column targetColumn) {
|
||||
if ( targetColumn == null ) {
|
||||
if ( targetColumns != null ) {
|
||||
if ( log.isWarnEnabled() ) {
|
||||
log.warn(
|
||||
"Attempt to map column [" + sourceColumn.toLoggableString()
|
||||
+ "] to no target column after explicit target column(s) named for FK [name="
|
||||
+ getName() + "]"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( targetColumns == null ) {
|
||||
if ( !getSourceColumns().isEmpty() ) {
|
||||
log.warn(
|
||||
"Value mapping mismatch as part of FK [table=" + getTable().toLoggableString()
|
||||
+ ", name=" + getName() + "] while adding source column ["
|
||||
+ sourceColumn.toLoggableString() + "]"
|
||||
);
|
||||
}
|
||||
targetColumns = new ArrayList<Column>();
|
||||
}
|
||||
targetColumns.add( targetColumn );
|
||||
}
|
||||
getSourceColumns().add( sourceColumn );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExportIdentifier() {
|
||||
return getSourceTable().getLoggableValueQualifier() + ".FK-" + getName();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import org.hibernate.util.StringHelper;
|
||||
|
||||
/**
|
||||
* Models an identifier (name).
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Identifier {
|
||||
private final String name;
|
||||
private final boolean isQuoted;
|
||||
|
||||
/**
|
||||
* Means to generate an {@link Identifier} instance from its simple name
|
||||
*
|
||||
* @param name The name
|
||||
* @return
|
||||
*/
|
||||
public static Identifier toIdentifier(String name) {
|
||||
if ( name == null ) {
|
||||
return null;
|
||||
}
|
||||
final String trimmedName = name.trim();
|
||||
if ( isQuoted( trimmedName ) ) {
|
||||
final String bareName = trimmedName.substring( 1, trimmedName.length() - 1 );
|
||||
return new Identifier( bareName, true );
|
||||
}
|
||||
else {
|
||||
return new Identifier( trimmedName, false );
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isQuoted(String name) {
|
||||
return name.startsWith( "`" ) && name.endsWith( "`" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an identifier instance.
|
||||
*
|
||||
* @param name The identifier text.
|
||||
* @param quoted Is this a quoted identifier?
|
||||
*/
|
||||
public Identifier(String name, boolean quoted) {
|
||||
if ( StringHelper.isEmpty( name ) ) {
|
||||
throw new IllegalIdentifierException( "Identifier text cannot be null" );
|
||||
}
|
||||
if ( isQuoted( name ) ) {
|
||||
throw new IllegalIdentifierException( "Identifier text should not contain quote markers (`)" );
|
||||
}
|
||||
this.name = name;
|
||||
this.isQuoted = quoted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the identifiers name (text)
|
||||
*
|
||||
* @return The name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a quoted identifier>
|
||||
*
|
||||
* @return True if this is a quote identifier; false otherwise.
|
||||
*/
|
||||
public boolean isQuoted() {
|
||||
return isQuoted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return isQuoted
|
||||
? '`' + getName() + '`'
|
||||
: getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Identifier that = (Identifier) o;
|
||||
|
||||
return isQuoted == that.isQuoted
|
||||
&& name.equals( that.name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
/**
|
||||
* Indicates an attempted use of a name that was deemed illegal
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class IllegalIdentifierException extends HibernateException {
|
||||
public IllegalIdentifierException(String s) {
|
||||
super( s );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* A <tt>data container</tt> defined by a <tt>SELECT</tt> statement. This translates into an inline view in the
|
||||
* SQL statements: <code>select ... from (select ... from logical_table_table ...) ...</code>
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class InLineView extends AbstractTableSpecification implements ValueContainer {
|
||||
private final String select;
|
||||
private final String uniqueValueQualifier;
|
||||
private Set<ObjectName> synchronizedTableSpaces = java.util.Collections.emptySet();
|
||||
|
||||
public InLineView(String select, String uniqueValueQualifier) {
|
||||
this.select = select;
|
||||
this.uniqueValueQualifier = uniqueValueQualifier;
|
||||
}
|
||||
|
||||
public String getSelect() {
|
||||
return select;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLoggableValueQualifier() {
|
||||
return uniqueValueQualifier;
|
||||
}
|
||||
|
||||
public void addSynchronizedTable(String tableName) {
|
||||
addSynchronizedTable( new ObjectName( null, null, tableName ) );
|
||||
}
|
||||
|
||||
public void addSynchronizedTable(ObjectName tableName) {
|
||||
if ( synchronizedTableSpaces.isEmpty() ) {
|
||||
synchronizedTableSpaces = new HashSet<ObjectName>();
|
||||
}
|
||||
synchronizedTableSpaces.add( tableName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ObjectName> getSpaces() {
|
||||
return synchronizedTableSpaces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toLoggableString() {
|
||||
return "{inline-view}";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Models a SQL <tt>INDEX</tt>
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Index extends AbstractConstraint implements Constraint {
|
||||
protected Index(TableSpecification table, String name) {
|
||||
super( table, name );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Models the qualified name of a database object.
|
||||
* <p/>
|
||||
* Some things to keep in mind wrt catalog/schema:
|
||||
* 1) {@link java.sql.DatabaseMetaData#isCatalogAtStart}
|
||||
* 2) {@link java.sql.DatabaseMetaData#getCatalogSeparator()}
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ObjectName {
|
||||
private final Identifier schema;
|
||||
private final Identifier catalog;
|
||||
private final Identifier name;
|
||||
|
||||
private final String identifier;
|
||||
private final int hashCode;
|
||||
|
||||
public ObjectName(Identifier name) {
|
||||
this( null, null, name );
|
||||
}
|
||||
|
||||
public ObjectName(String schemaName, String catalogName, String name) {
|
||||
this(
|
||||
Identifier.toIdentifier( schemaName ),
|
||||
Identifier.toIdentifier( catalogName ),
|
||||
Identifier.toIdentifier( name )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a qualified name reference.
|
||||
*
|
||||
* @param schema The in which the object is defined (optional)
|
||||
* @param catalog The catalog in which the object is defined (optional)
|
||||
* @param name The name (required)
|
||||
*/
|
||||
public ObjectName(Identifier schema, Identifier catalog, Identifier name) {
|
||||
if ( name == null ) {
|
||||
// Identifier cannot be constructed with an 'empty' name
|
||||
throw new IllegalIdentifierException( "Object name must be specified" );
|
||||
}
|
||||
this.name = name;
|
||||
this.schema = schema;
|
||||
this.catalog = catalog;
|
||||
|
||||
StringBuilder buff = new StringBuilder( name.toString() );
|
||||
if ( catalog != null ) {
|
||||
buff.insert( 0, catalog.toString() + '.' );
|
||||
}
|
||||
if ( schema != null ) {
|
||||
buff.insert( 0, schema.toString() + '.' );
|
||||
}
|
||||
this.identifier = buff.toString();
|
||||
|
||||
int tmpHashCode = schema != null ? schema.hashCode() : 0;
|
||||
tmpHashCode = 31 * tmpHashCode + (catalog != null ? catalog.hashCode() : 0);
|
||||
tmpHashCode = 31 * tmpHashCode + name.hashCode();
|
||||
this.hashCode = tmpHashCode;
|
||||
}
|
||||
|
||||
public Identifier getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
public Identifier getCatalog() {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
public Identifier getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ObjectName that = (ObjectName) o;
|
||||
|
||||
return name.equals( that.name )
|
||||
&& areEqual( catalog, that.catalog )
|
||||
&& areEqual( schema, that.schema );
|
||||
}
|
||||
|
||||
private boolean areEqual(Identifier one, Identifier other) {
|
||||
return one == null
|
||||
? other == null
|
||||
: one.equals( other );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ObjectName{" +
|
||||
"name='" + name + '\'' +
|
||||
", schema='" + schema + '\'' +
|
||||
", catalog='" + catalog + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Models a table's primary key.
|
||||
* <p/>
|
||||
* NOTE : This need not be a physical primary key; we just mean a column or columns which uniquely identify rows in
|
||||
* the table. Of course it is recommended to define proper integrity constraints, including primary keys.
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class PrimaryKey extends AbstractConstraint implements Constraint, Exportable {
|
||||
// IMPL NOTE : I override the name behavior here because:
|
||||
// (1) primary keys are not required to be named.
|
||||
// (2) because a primary key is required for each table, it is easier to allow setting the constraint name
|
||||
// later in terms of building the metamodel
|
||||
private String name;
|
||||
|
||||
public PrimaryKey(TableSpecification table) {
|
||||
super( table, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExportIdentifier() {
|
||||
return getTable().getLoggableValueQualifier() + ".PK";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Models a database {@code SEQUENCE}.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Sequence implements Exportable {
|
||||
private final ObjectName name;
|
||||
private final int initialValue;
|
||||
private final int incrementSize;
|
||||
|
||||
public Sequence(ObjectName name, int initialValue, int incrementSize) {
|
||||
this.name = name;
|
||||
this.initialValue = initialValue;
|
||||
this.incrementSize = incrementSize;
|
||||
}
|
||||
|
||||
public String getExportIdentifier() {
|
||||
return name.getIdentifier();
|
||||
}
|
||||
|
||||
public ObjectName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getInitialValue() {
|
||||
return initialValue;
|
||||
}
|
||||
|
||||
public int getIncrementSize() {
|
||||
return incrementSize;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Models a simple, non-compound value.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface SimpleValue extends Value {
|
||||
/**
|
||||
* Retrieve the datatype of this value.
|
||||
*
|
||||
* @return The value's datatype
|
||||
*/
|
||||
public Datatype getDatatype();
|
||||
|
||||
/**
|
||||
* Set the datatype of this value.
|
||||
*
|
||||
* @param datatype The value's datatype
|
||||
*/
|
||||
public void setDatatype(Datatype datatype);
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Models the concept of a relational <tt>TABLE</tt> (or <tt>VIEW</tt>).
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Table extends AbstractTableSpecification implements ValueContainer, Exportable {
|
||||
private final ObjectName name;
|
||||
private final Set<ObjectName> spaces;
|
||||
|
||||
public Table(ObjectName name) {
|
||||
this.name = name;
|
||||
this.spaces = java.util.Collections.singleton( name );
|
||||
}
|
||||
|
||||
public ObjectName getObjectName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLoggableValueQualifier() {
|
||||
return getObjectName().getIdentifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExportIdentifier() {
|
||||
return getObjectName().getIdentifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ObjectName> getSpaces() {
|
||||
return spaces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toLoggableString() {
|
||||
return getObjectName().getIdentifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Table{" +
|
||||
"name=" + getObjectName().getIdentifier() +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Models what ANSI SQL terms a table specification which is a table or a view or an inline view.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface TableSpecification extends ValueContainer {
|
||||
/**
|
||||
* Get the primary key definition for this table spec.
|
||||
*
|
||||
* @return The PK definition.
|
||||
*/
|
||||
public PrimaryKey getPrimaryKey();
|
||||
|
||||
/**
|
||||
* Get the physical table names modelled here. This is especially important in the case of an inline view.
|
||||
*
|
||||
* @return The spaces.
|
||||
*/
|
||||
public Set<ObjectName> getSpaces();
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Models a compound value (a tuple or row-value-constructor is SQL terms). It is both a {@link Value} and
|
||||
* a {@link ValueContainer} simultaneously.
|
||||
* <p/>
|
||||
* IMPL NOTE : in terms of the tables themselves, SQL has no notion of a tuple/compound-value. We simply model
|
||||
* it this way because:
|
||||
* <ul>
|
||||
* <li>it is a cleaner mapping to the logical model</li>
|
||||
* <li>it allows more meaningful traversals from simple values back up to table through any intermediate tuples
|
||||
* because it gives us a better understanding of the model.</li>
|
||||
* <li>it better conveys intent</li>
|
||||
* <li>it adds richness to the model</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Tuple extends AbstractValueContainer implements Value {
|
||||
private final ValueContainer valueContainer;
|
||||
private final String name;
|
||||
|
||||
public Tuple(ValueContainer valueContainer, String name) {
|
||||
this.name = name;
|
||||
this.valueContainer = valueContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueContainer getValueContainer() {
|
||||
return valueContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLoggableValueQualifier() {
|
||||
return getValueContainer().getLoggableValueQualifier() + '.' + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toLoggableString() {
|
||||
return getLoggableValueQualifier() + "{tuple}";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Models a SQL <tt>INDEX</tt> defined as UNIQUE
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class UniqueKey extends AbstractConstraint implements Constraint {
|
||||
protected UniqueKey(TableSpecification table, String name) {
|
||||
super( table, name );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Models a value within a {@link ValueContainer}. This will generally be either a {@link Column column} or a
|
||||
* {@link DerivedValue derived value}, but we also allow the notion of {@link Tuple} at this level
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface Value {
|
||||
/**
|
||||
* Retrieve the table that owns this value.
|
||||
*
|
||||
* @return The owning table.
|
||||
*/
|
||||
public ValueContainer getValueContainer();
|
||||
|
||||
/**
|
||||
* Obtain the string representation of this value usable in log statements.
|
||||
*
|
||||
* @return The loggable representation
|
||||
*/
|
||||
public String toLoggableString();
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010 by Red Hat Inc and/or its affiliates or by
|
||||
* third-party contributors as indicated by either @author tags or express
|
||||
* copyright attribution statements applied by the authors. All
|
||||
* third-party contributions are distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
/**
|
||||
* Contract for data containers (what the ANSI SQL spec calls "table specifications") to which we can map
|
||||
* entity state. The two flavors here are {@link Table physical table} and {@link InLineView inline view}, but a
|
||||
* {@link Tuple} is a conceptual value container as well.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ValueContainer {
|
||||
/**
|
||||
* Obtain an iterator over this containers current set of value definitions.
|
||||
*
|
||||
* @return Iterator over value definitions.
|
||||
*/
|
||||
public Iterable<Value> iterateValues();
|
||||
|
||||
/**
|
||||
* Get a qualifier which can be used to qualify {@link Value values} belonging to this container in
|
||||
* their logging.
|
||||
*
|
||||
* @return The qualifier
|
||||
*/
|
||||
public String getLoggableValueQualifier();
|
||||
|
||||
/**
|
||||
* Obtain the string representation of this value usable in log statements.
|
||||
*
|
||||
* @return The loggable representation
|
||||
*/
|
||||
public String toLoggableString();
|
||||
|
||||
/**
|
||||
* Factory method for creating a {@link Column} associated with this container.
|
||||
*
|
||||
* @param name The column name
|
||||
*
|
||||
* @return The generated column
|
||||
*/
|
||||
public Column createColumn(String name);
|
||||
|
||||
/**
|
||||
* Factory method for creating a {@link DerivedValue} associated with this container.
|
||||
*
|
||||
* @param fragment The value expression
|
||||
*
|
||||
* @return The generated value.
|
||||
*/
|
||||
public DerivedValue createDerivedValue(String fragment);
|
||||
|
||||
/**
|
||||
* Factory method for creating a {@link Tuple} associated with this container.
|
||||
*
|
||||
* @param name The (logical) tuple name
|
||||
*
|
||||
* @return The generated tuple.
|
||||
*/
|
||||
public Tuple createTuple(String name);
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
~ indicated by the @author tags or express copyright attribution
|
||||
~ statements applied by the authors. All third-party contributions are
|
||||
~ distributed under license by Red Hat Inc.
|
||||
~
|
||||
~ This copyrighted material is made available to anyone wishing to use, modify,
|
||||
~ copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
~ Lesser General Public License, as published by the Free Software Foundation.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
~ for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU Lesser General Public License
|
||||
~ along with this distribution; if not, write to:
|
||||
~ Free Software Foundation, Inc.
|
||||
~ 51 Franklin Street, Fifth Floor
|
||||
~ Boston, MA 02110-1301 USA
|
||||
-->
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<p>
|
||||
This package defines the metamodel of a relational database schema.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue