Merge branch 'metamodel-import'
This commit is contained in:
commit
1a8aca99db
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.logical;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Convenient base class for {@link AttributeContainer}. Because in our model all
|
||||
* {@link AttributeContainer AttributeContainers} are also {@link Hierarchical} we also implement that here
|
||||
* as well.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractAttributeContainer implements AttributeContainer, Hierarchical {
|
||||
private final String name;
|
||||
private final Hierarchical superType;
|
||||
private LinkedHashSet<Attribute> attributeSet = new LinkedHashSet<Attribute>();
|
||||
private HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>();
|
||||
|
||||
public AbstractAttributeContainer(String name, Hierarchical superType) {
|
||||
this.name = name;
|
||||
this.superType = superType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hierarchical getSuperType() {
|
||||
return superType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Attribute> getAttributes() {
|
||||
return Collections.unmodifiableSet( attributeSet );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attribute getAttribute(String name) {
|
||||
return attributeMap.get( name );
|
||||
}
|
||||
|
||||
public void addAttribute(Attribute attribute) {
|
||||
// todo : how to best "secure" this?
|
||||
if ( attributeMap.put( attribute.getName(), attribute ) != null ) {
|
||||
throw new IllegalArgumentException( "Attrtibute with name [" + attribute.getName() + "] already registered" );
|
||||
}
|
||||
attributeSet.add( attribute );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.logical;
|
||||
|
||||
/**
|
||||
* Desribes an attribute.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface Attribute {
|
||||
/**
|
||||
* Retrieve the attribute name.
|
||||
*
|
||||
* @return The attribute name.
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Retrieve the declaring container for this attribute (entity/component).
|
||||
*
|
||||
* @return The attribute container.
|
||||
*/
|
||||
public AttributeContainer getAttributeContainer();
|
||||
|
||||
/**
|
||||
* An attribute can be either:<ul>
|
||||
* <li>singular - castable to {@link SingularAttribute}</li>
|
||||
* <li>plural - castable to {@link PluralAttribute}
|
||||
* </ul>
|
||||
*
|
||||
* @return True if attribute is singular; false if plural.
|
||||
*/
|
||||
public boolean isSingular();
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.logical;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Basic contract for any container holding attributes. This allows polymorphic handling of both
|
||||
* components and entities in terms of the attributes they hold.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface AttributeContainer extends Type {
|
||||
/**
|
||||
* Retrieve the attributes contained in this container.
|
||||
*
|
||||
* @return The contained attributes
|
||||
*/
|
||||
public Set<Attribute> getAttributes();
|
||||
|
||||
/**
|
||||
* Retrieve an attribute by name.
|
||||
*
|
||||
* @param name The name of the attribute to retrieve.
|
||||
*
|
||||
* @return The attribute matching the given name, or null.
|
||||
*/
|
||||
public Attribute getAttribute(String name);
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.logical;
|
||||
|
||||
/**
|
||||
* Models a basic type, a simple value.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BasicType implements Type {
|
||||
private final String name;
|
||||
|
||||
public BasicType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeNature getNature() {
|
||||
return TypeNature.BASIC;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.logical;
|
||||
|
||||
/**
|
||||
* Models the notion of a component (what JPA calls an Embeddable).
|
||||
* <p/>
|
||||
* NOTE : Components are not currently really hierarchical. But that is a feature I want to add.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Component extends AbstractAttributeContainer implements Hierarchical {
|
||||
public Component(String name, Hierarchical superType) {
|
||||
super( name, superType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeNature getNature() {
|
||||
return TypeNature.COMPONENT;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.logical;
|
||||
|
||||
/**
|
||||
* Models the notion of an entity
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Entity extends AbstractAttributeContainer {
|
||||
public Entity(String name, Hierarchical superType) {
|
||||
super( name, superType );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public TypeNature getNature() {
|
||||
return TypeNature.ENTITY;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.logical;
|
||||
|
||||
/**
|
||||
* Additional contract for things that can occur in an inheritance hierarchy (specifically ones we would
|
||||
* need to traverse).
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface Hierarchical extends AttributeContainer {
|
||||
/**
|
||||
* Retrieve the super type.
|
||||
*
|
||||
* @return The super type, or null if no super type.
|
||||
*/
|
||||
public Hierarchical getSuperType();
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.logical;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Identifies the specific semantic of a plural valued attribute.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public enum PluralAttributeNature {
|
||||
BAG( "bag", Collection.class ),
|
||||
SET( "set", Set.class ),
|
||||
LIST( "list", List.class ),
|
||||
MAP( "map", Map.class );
|
||||
|
||||
private final String name;
|
||||
private final Class javaContract;
|
||||
|
||||
PluralAttributeNature(String name, Class javaContract) {
|
||||
this.name = name;
|
||||
this.javaContract = javaContract;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Class getJavaContract() {
|
||||
return javaContract;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.logical;
|
||||
|
||||
/**
|
||||
* A single valued (non-collection) attribute
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface SingularAttribute extends Attribute {
|
||||
/**
|
||||
* Retrieve the attribute type descriptor.
|
||||
*
|
||||
* @return THe attribute type.
|
||||
*/
|
||||
public Type getSingularAttributeType();
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.logical;
|
||||
|
||||
/**
|
||||
* Models the concept of a (intermediate) superclass
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Superclass extends AbstractAttributeContainer implements Hierarchical {
|
||||
public Superclass(String name, Hierarchical superType) {
|
||||
super( name, superType );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public TypeNature getNature() {
|
||||
return TypeNature.SUPERCLASS;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.logical;
|
||||
|
||||
/**
|
||||
* Basic information about a Java type, in regards to its role in particular set of mappings.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface Type {
|
||||
/**
|
||||
* Get the name of the type.
|
||||
*
|
||||
* @return The name
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Return the persistence type.
|
||||
*
|
||||
* @return persistence type
|
||||
*/
|
||||
public TypeNature getNature();
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.logical;
|
||||
|
||||
/**
|
||||
* Describes the type of a type :/
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public enum TypeNature {
|
||||
BASIC( "basic" ),
|
||||
COMPONENT( "component" ),
|
||||
ENTITY( "entity" ),
|
||||
SUPERCLASS( "superclass" );
|
||||
|
||||
private final String name;
|
||||
|
||||
private TypeNature(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + "[" + getName() + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<!--
|
||||
~ 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 metadata modeling of a logical domain model. Specifically note that
|
||||
this package does not in any way attempt to encapsulate data modeling information such
|
||||
cardinality or associations. Also note that the top-level logical model is represetation (entity-mode)
|
||||
agnostic.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -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 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 Iterable<Column> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
protected List<Column> internalColumnAccess() {
|
||||
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,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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
private List<ForeignKey> foreignKeys = new ArrayList<ForeignKey>();
|
||||
|
||||
@Override
|
||||
public Iterable<ForeignKey> getForeignKeys() {
|
||||
return foreignKeys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForeignKey createForeignKey(TableSpecification targetTable, String name) {
|
||||
ForeignKey fk = new ForeignKey( this, targetTable, name );
|
||||
foreignKeys.add( fk );
|
||||
return fk;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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> values() {
|
||||
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,120 @@
|
|||
/*
|
||||
* 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 static Size precision(int precision) {
|
||||
return new Size( precision, -1, -1, null );
|
||||
}
|
||||
|
||||
public static Size precision(int precision, int scale) {
|
||||
return new Size( precision, scale, -1, null );
|
||||
}
|
||||
|
||||
public static Size length(long length) {
|
||||
return new Size( -1, -1, length, null );
|
||||
}
|
||||
|
||||
public static Size length(long length, LobMultiplier lobMultiplier) {
|
||||
return new Size( -1, -1, length, lobMultiplier );
|
||||
}
|
||||
|
||||
public int getPrecision() {
|
||||
return precision;
|
||||
}
|
||||
|
||||
public int getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public long getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public LobMultiplier getLobMultiplier() {
|
||||
return 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 Iterable<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,117 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
protected ForeignKey(TableSpecification sourceTable, TableSpecification targetTable, String name) {
|
||||
super( sourceTable, name );
|
||||
this.targetTable = targetTable;
|
||||
}
|
||||
|
||||
protected ForeignKey(TableSpecification sourceTable, TableSpecification targetTable) {
|
||||
this( sourceTable, targetTable, null );
|
||||
}
|
||||
|
||||
public TableSpecification getSourceTable() {
|
||||
return getTable();
|
||||
}
|
||||
|
||||
public TableSpecification getTargetTable() {
|
||||
return targetTable;
|
||||
}
|
||||
|
||||
public Iterable<Column> getSourceColumns() {
|
||||
return getColumns();
|
||||
}
|
||||
|
||||
public Iterable<Column> getTargetColumns() {
|
||||
return targetColumns == null
|
||||
? getTargetTable().getPrimaryKey().getColumns()
|
||||
: targetColumns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addColumn(Column column) {
|
||||
addColumnMapping( column, null );
|
||||
}
|
||||
|
||||
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 ( !internalColumnAccess().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 );
|
||||
}
|
||||
internalColumnAccess().add( sourceColumn );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExportIdentifier() {
|
||||
return getSourceTable().getLoggableValueQualifier() + ".FK-" + getName();
|
||||
}
|
||||
|
||||
public void validate() {
|
||||
if ( getSourceTable() == null ) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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(Table 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,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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
//
|
||||
// todo : default name? {TABLE_NAME}_PK maybe?
|
||||
private String name;
|
||||
|
||||
protected 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,96 @@
|
|||
/*
|
||||
* 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 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;
|
||||
|
||||
private List<Index> indexes;
|
||||
private List<UniqueKey> uniqueKeys;
|
||||
|
||||
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 Iterable<ObjectName> getSpaces() {
|
||||
return spaces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toLoggableString() {
|
||||
return getObjectName().getIdentifier();
|
||||
}
|
||||
|
||||
public Index createIndex(String name) {
|
||||
Index index = new Index( this, name );
|
||||
if ( indexes == null ) {
|
||||
indexes = new ArrayList<Index>();
|
||||
}
|
||||
indexes.add( index );
|
||||
return index;
|
||||
}
|
||||
|
||||
public UniqueKey createUniqueKey(String name) {
|
||||
UniqueKey uniqueKey = new UniqueKey( this, name );
|
||||
if ( uniqueKeys == null ) {
|
||||
uniqueKeys = new ArrayList<UniqueKey>();
|
||||
}
|
||||
uniqueKeys.add( uniqueKey );
|
||||
return uniqueKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Table{" +
|
||||
"name=" + getObjectName().getIdentifier() +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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 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();
|
||||
|
||||
public ForeignKey createForeignKey(TableSpecification targetTable, String name);
|
||||
|
||||
public Iterable<ForeignKey> getForeignKeys();
|
||||
|
||||
/**
|
||||
* Get the physical table names modelled here. This is especially important in the case of an inline view.
|
||||
*
|
||||
* @return The spaces.
|
||||
*/
|
||||
public Iterable<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(Table 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> values();
|
||||
|
||||
/**
|
||||
* 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>
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import org.hibernate.testing.junit.UnitTestCase;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ObjectNameTests extends UnitTestCase {
|
||||
public ObjectNameTests(String string) {
|
||||
super( string );
|
||||
}
|
||||
|
||||
public void testMissingName() {
|
||||
try {
|
||||
new ObjectName( (String)null, null, null );
|
||||
fail();
|
||||
}
|
||||
catch ( IllegalIdentifierException ignore ) {
|
||||
}
|
||||
|
||||
try {
|
||||
new ObjectName( "schema", "catalog", null );
|
||||
fail();
|
||||
}
|
||||
catch ( IllegalIdentifierException ignore ) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testIdentifierBuilding() {
|
||||
ObjectName on = new ObjectName( "schema", "catalog", "name" );
|
||||
assertEquals( "schema.catalog.name", on.getIdentifier() );
|
||||
on = new ObjectName( "schema", null, "name" );
|
||||
assertEquals( "schema.name", on.getIdentifier() );
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.testing.junit.UnitTestCase;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TableManipulationTests extends UnitTestCase {
|
||||
public static final Datatype VARCHAR = new Datatype( Types.VARCHAR, "VARCHAR", String.class );
|
||||
public static final Datatype INTEGER = new Datatype( Types.INTEGER, "INTEGER", Long.class );
|
||||
|
||||
public TableManipulationTests(String string) {
|
||||
super( string );
|
||||
}
|
||||
|
||||
public void testTableCreation() {
|
||||
Table table = new Table( new ObjectName( null, null, "my_table" ) );
|
||||
assertNull( table.getObjectName().getSchema() );
|
||||
assertNull( table.getObjectName().getCatalog() );
|
||||
assertEquals( "my_table", table.getObjectName().getName().toString() );
|
||||
assertEquals( "my_table", table.getExportIdentifier() );
|
||||
assertNull( table.getPrimaryKey().getName() );
|
||||
assertFalse( table.values().iterator().hasNext() );
|
||||
|
||||
Column idColumn = table.createColumn( "id" );
|
||||
idColumn.setDatatype( INTEGER );
|
||||
idColumn.setSize( Column.Size.precision( 18, 0 ) );
|
||||
table.getPrimaryKey().addColumn( idColumn );
|
||||
table.getPrimaryKey().setName( "my_table_pk" );
|
||||
assertEquals( "my_table_pk", table.getPrimaryKey().getName() );
|
||||
assertEquals( "my_table.PK", table.getPrimaryKey().getExportIdentifier() );
|
||||
|
||||
Column col_1 = table.createColumn( "col_1" );
|
||||
col_1.setDatatype( VARCHAR );
|
||||
col_1.setSize( Column.Size.length( 512 ) );
|
||||
|
||||
for ( Value value : table.values() ) {
|
||||
assertTrue( Column.class.isInstance( value ) );
|
||||
Column column = ( Column ) value;
|
||||
if ( column.getName().equals( "id" ) ) {
|
||||
assertEquals( INTEGER, column.getDatatype() );
|
||||
assertEquals( 18, column.getSize().getPrecision() );
|
||||
assertEquals( 0, column.getSize().getScale() );
|
||||
assertEquals( -1, column.getSize().getLength() );
|
||||
assertNull( column.getSize().getLobMultiplier() );
|
||||
}
|
||||
else {
|
||||
assertEquals( "col_1", column.getName() );
|
||||
assertEquals( VARCHAR, column.getDatatype() );
|
||||
assertEquals( -1, column.getSize().getPrecision() );
|
||||
assertEquals( -1, column.getSize().getScale() );
|
||||
assertEquals( 512, column.getSize().getLength() );
|
||||
assertNull( column.getSize().getLobMultiplier() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testBasicForeignKeyDefinition() {
|
||||
Table book = new Table( new ObjectName( null, null, "BOOK" ) );
|
||||
|
||||
Column bookId = book.createColumn( "id" );
|
||||
bookId.setDatatype( INTEGER );
|
||||
bookId.setSize( Column.Size.precision( 18, 0 ) );
|
||||
book.getPrimaryKey().addColumn( bookId );
|
||||
book.getPrimaryKey().setName( "BOOK_PK" );
|
||||
|
||||
Table page = new Table( new ObjectName( null, null, "PAGE" ) );
|
||||
|
||||
Column pageId = page.createColumn( "id" );
|
||||
pageId.setDatatype( INTEGER );
|
||||
pageId.setSize( Column.Size.precision( 18, 0 ) );
|
||||
page.getPrimaryKey().addColumn( pageId );
|
||||
page.getPrimaryKey().setName( "PAGE_PK" );
|
||||
|
||||
Column pageBookId = page.createColumn( "BOOK_ID" );
|
||||
pageId.setDatatype( INTEGER );
|
||||
pageId.setSize( Column.Size.precision( 18, 0 ) );
|
||||
ForeignKey pageBookFk = page.createForeignKey( book, "PAGE_BOOK_FK" );
|
||||
pageBookFk.addColumn( pageBookId );
|
||||
|
||||
assertEquals( page, pageBookFk.getSourceTable() );
|
||||
assertEquals( book, pageBookFk.getTargetTable() );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue