HHH-9466 - Drop metamodel package from source
This commit is contained in:
parent
b943525c80
commit
66ce8b7fb5
|
@ -314,7 +314,7 @@
|
|||
<literal>org.hibernate.boot.registry.selector.StrategyRegistrationProvider</literal> (as of 4.3)
|
||||
</listitem>
|
||||
<listitem>
|
||||
<literal>org.hibernate.metamodel.spi.TypeContributor</literal> (as of 4.3)
|
||||
<literal>org.hibernate.boot.model.TypeContributor</literal> (as of 4.3)
|
||||
</listitem>
|
||||
<listitem>
|
||||
JTA's <literal>javax.transaction.TransactionManager</literal> and
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
|
||||
<bean id="typeContributor"
|
||||
class="org.hibernate.envers.internal.entities.TypeContributorImpl" />
|
||||
<service ref="typeContributor" interface="org.hibernate.metamodel.spi.TypeContributor" />
|
||||
<service ref="typeContributor" interface="org.hibernate.boot.model.TypeContributor" />
|
||||
|
||||
</blueprint>
|
|
@ -33,7 +33,7 @@
|
|||
<service ref="strategyRegistrationProvider" interface="org.hibernate.boot.registry.selector.StrategyRegistrationProvider"/>
|
||||
|
||||
<bean id="typeContributor" class="org.hibernate.osgitest.TestTypeContributor"/>
|
||||
<service ref="typeContributor" interface="org.hibernate.metamodel.spi.TypeContributor"/>
|
||||
<service ref="typeContributor" interface="org.hibernate.boot.model.TypeContributor"/>
|
||||
|
||||
<!-- This bundle makes use of Karaf commands to demonstrate core persistence operations. Feel free to remove it. -->
|
||||
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<service ref="strategyRegistrationProvider" interface="org.hibernate.boot.registry.selector.StrategyRegistrationProvider"/>
|
||||
|
||||
<bean id="typeContributor" class="org.hibernate.osgitest.TestTypeContributor"/>
|
||||
<service ref="typeContributor" interface="org.hibernate.metamodel.spi.TypeContributor"/>
|
||||
<service ref="typeContributor" interface="org.hibernate.boot.model.TypeContributor"/>
|
||||
|
||||
<!-- This bundle makes use of Karaf commands to demonstrate core persistence operations. Feel free to remove it. -->
|
||||
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.spi;
|
||||
package org.hibernate.boot.model;
|
||||
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.usertype.CompositeUserType;
|
|
@ -21,7 +21,7 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.spi;
|
||||
package org.hibernate.boot.model;
|
||||
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
|
@ -28,8 +28,6 @@ import java.util.Comparator;
|
|||
import org.hibernate.cache.spi.CacheDataDescription;
|
||||
import org.hibernate.mapping.Collection;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
import org.hibernate.type.VersionType;
|
||||
|
||||
/**
|
||||
|
@ -88,17 +86,6 @@ public class CacheDataDescriptionImpl implements CacheDataDescription {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a CacheDataDescriptionImpl from the mapping model of an entity class (using the new metamodel code).
|
||||
*
|
||||
* @param model The mapping model.
|
||||
*
|
||||
* @return The constructed CacheDataDescriptionImpl
|
||||
*/
|
||||
public static CacheDataDescriptionImpl decode(EntityBinding model) {
|
||||
return new CacheDataDescriptionImpl( model.isMutable(), model.isVersioned(), getVersionComparator( model ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a CacheDataDescriptionImpl from the mapping model of a collection
|
||||
*
|
||||
|
@ -116,31 +103,4 @@ public class CacheDataDescriptionImpl implements CacheDataDescription {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a CacheDataDescriptionImpl from the mapping model of a collection (using the new metamodel code).
|
||||
*
|
||||
* @param model The mapping model.
|
||||
*
|
||||
* @return The constructed CacheDataDescriptionImpl
|
||||
*/
|
||||
public static CacheDataDescriptionImpl decode(PluralAttributeBinding model) {
|
||||
return new CacheDataDescriptionImpl(
|
||||
model.isMutable(),
|
||||
model.getContainer().seekEntityBinding().isVersioned(),
|
||||
getVersionComparator( model.getContainer().seekEntityBinding() )
|
||||
);
|
||||
}
|
||||
|
||||
private static Comparator getVersionComparator(EntityBinding model ) {
|
||||
if ( model.isVersioned() ) {
|
||||
final VersionType versionType = (VersionType) model.getHierarchyDetails()
|
||||
.getVersioningAttributeBinding()
|
||||
.getHibernateTypeDescriptor()
|
||||
.getResolvedTypeMapping();
|
||||
|
||||
return versionType.getComparator();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.hibernate.event.spi.PostInsertEventListener;
|
|||
import org.hibernate.event.spi.PostUpdateEvent;
|
||||
import org.hibernate.event.spi.PostUpdateEventListener;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
|
@ -65,12 +64,6 @@ public class CollectionCacheInvalidator implements Integrator, PostInsertEventLi
|
|||
integrate( serviceRegistry, sessionFactory );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void integrate(MetadataImplementor metadata, SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry) {
|
||||
integrate( serviceRegistry, sessionFactory );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
}
|
||||
|
|
|
@ -136,8 +136,8 @@ import org.hibernate.mapping.SimpleValue;
|
|||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.mapping.TypeDef;
|
||||
import org.hibernate.mapping.UniqueKey;
|
||||
import org.hibernate.metamodel.spi.TypeContributions;
|
||||
import org.hibernate.metamodel.spi.TypeContributor;
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.boot.model.TypeContributor;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.secure.spi.GrantedPermission;
|
||||
import org.hibernate.secure.spi.JaccPermissionDeclarations;
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.hibernate.cfg.Configuration;
|
|||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
@ -201,15 +200,6 @@ public class BeanValidationIntegrator implements Integrator {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void integrate(
|
||||
MetadataImplementor metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry ) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
|
||||
// nothing to do here afaik
|
||||
|
|
|
@ -79,7 +79,7 @@ import org.hibernate.internal.util.StringHelper;
|
|||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.internal.util.io.StreamCopier;
|
||||
import org.hibernate.mapping.Column;
|
||||
import org.hibernate.metamodel.spi.TypeContributions;
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.persister.entity.Lockable;
|
||||
import org.hibernate.procedure.internal.StandardCallableStatementSupport;
|
||||
import org.hibernate.procedure.spi.CallableStatementSupport;
|
||||
|
|
|
@ -23,9 +23,6 @@ package org.hibernate.dialect.unique;
|
|||
import java.util.Iterator;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.metamodel.relational.Column;
|
||||
import org.hibernate.metamodel.relational.Index;
|
||||
import org.hibernate.metamodel.relational.UniqueKey;
|
||||
|
||||
/**
|
||||
* DB2 does not allow unique constraints on nullable columns. Rather than
|
||||
|
@ -65,22 +62,6 @@ public class DB2UniqueDelegate extends DefaultUniqueDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey) {
|
||||
if ( hasNullable( uniqueKey ) ) {
|
||||
return Index.buildSqlCreateIndexString(
|
||||
dialect,
|
||||
uniqueKey.getName(),
|
||||
uniqueKey.getTable(),
|
||||
uniqueKey.getColumns(),
|
||||
true
|
||||
);
|
||||
}
|
||||
else {
|
||||
return super.getAlterTableToAddUniqueKeyCommand( uniqueKey );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlterTableToDropUniqueKeyCommand(
|
||||
org.hibernate.mapping.UniqueKey uniqueKey,
|
||||
|
@ -102,16 +83,6 @@ public class DB2UniqueDelegate extends DefaultUniqueDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey) {
|
||||
if ( hasNullable( uniqueKey ) ) {
|
||||
return Index.buildSqlDropIndexString( dialect, uniqueKey.getTable(), uniqueKey.getName() );
|
||||
}
|
||||
else {
|
||||
return super.getAlterTableToDropUniqueKeyCommand( uniqueKey );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasNullable(org.hibernate.mapping.UniqueKey uniqueKey) {
|
||||
final Iterator<org.hibernate.mapping.Column> iter = uniqueKey.columnIterator();
|
||||
while ( iter.hasNext() ) {
|
||||
|
@ -121,13 +92,4 @@ public class DB2UniqueDelegate extends DefaultUniqueDelegate {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasNullable(UniqueKey uniqueKey) {
|
||||
for ( Column column : uniqueKey.getColumns() ) {
|
||||
if ( column.isNullable() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,6 @@ package org.hibernate.dialect.unique;
|
|||
import java.util.Iterator;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.metamodel.relational.Column;
|
||||
import org.hibernate.metamodel.relational.Table;
|
||||
import org.hibernate.metamodel.relational.UniqueKey;
|
||||
|
||||
/**
|
||||
* The default UniqueDelegate implementation for most dialects. Uses
|
||||
|
@ -107,53 +104,4 @@ public class DefaultUniqueDelegate implements UniqueDelegate {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
// new model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@Override
|
||||
public String getColumnDefinitionUniquenessFragment(Column column) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableCreationUniqueConstraintsFragment(Table table) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey) {
|
||||
// Do this here, rather than allowing UniqueKey/Constraint to do it.
|
||||
// We need full, simplified control over whether or not it happens.
|
||||
final String tableName = uniqueKey.getTable().getQualifiedName( dialect );
|
||||
final String constraintName = dialect.quote( uniqueKey.getName() );
|
||||
|
||||
return "alter table " + tableName + " add constraint " + constraintName + uniqueConstraintSql( uniqueKey );
|
||||
}
|
||||
|
||||
protected String uniqueConstraintSql( UniqueKey uniqueKey ) {
|
||||
final StringBuilder sb = new StringBuilder( " unique (" );
|
||||
final Iterator columnIterator = uniqueKey.getColumns().iterator();
|
||||
while ( columnIterator.hasNext() ) {
|
||||
final org.hibernate.mapping.Column column = (org.hibernate.mapping.Column) columnIterator.next();
|
||||
sb.append( column.getQuotedName( dialect ) );
|
||||
if ( columnIterator.hasNext() ) {
|
||||
sb.append( ", " );
|
||||
}
|
||||
}
|
||||
|
||||
return sb.append( ')' ).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey) {
|
||||
// Do this here, rather than allowing UniqueKey/Constraint to do it.
|
||||
// We need full, simplified control over whether or not it happens.
|
||||
final String tableName = uniqueKey.getTable().getQualifiedName( dialect );
|
||||
final String constraintName = dialect.quote( uniqueKey.getName() );
|
||||
|
||||
return "alter table " + tableName + " drop constraint " + constraintName;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
package org.hibernate.dialect.unique;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.metamodel.relational.UniqueKey;
|
||||
|
||||
/**
|
||||
* Informix requires the constraint name to come last on the alter table.
|
||||
|
@ -48,15 +47,4 @@ public class InformixUniqueDelegate extends DefaultUniqueDelegate {
|
|||
return "alter table " + tableName + " add constraint " + uniqueConstraintSql( uniqueKey ) + " constraint " + constraintName;
|
||||
}
|
||||
|
||||
// new model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@Override
|
||||
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey) {
|
||||
// Do this here, rather than allowing UniqueKey/Constraint to do it.
|
||||
// We need full, simplified control over whether or not it happens.
|
||||
final String tableName = uniqueKey.getTable().getQualifiedName( dialect );
|
||||
final String constraintName = dialect.quote( uniqueKey.getName() );
|
||||
|
||||
return "alter table " + tableName + " add constraint " + uniqueConstraintSql( uniqueKey ) + " constraint " + constraintName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,6 @@
|
|||
*/
|
||||
package org.hibernate.dialect.unique;
|
||||
|
||||
import org.hibernate.metamodel.relational.Column;
|
||||
import org.hibernate.metamodel.relational.Table;
|
||||
import org.hibernate.metamodel.relational.UniqueKey;
|
||||
|
||||
/**
|
||||
* Dialect-level delegate in charge of applying "uniqueness" to a column. Uniqueness can be defined
|
||||
* in 1 of 3 ways:<ol>
|
||||
|
@ -59,18 +55,6 @@ public interface UniqueDelegate {
|
|||
*/
|
||||
public String getColumnDefinitionUniquenessFragment(org.hibernate.mapping.Column column);
|
||||
|
||||
/**
|
||||
* Get the fragment that can be used to make a column unique as part of its column definition.
|
||||
* <p/>
|
||||
* This is intended for dialects which do not support unique constraints
|
||||
*
|
||||
* @param column The column to which to apply the unique
|
||||
*
|
||||
* @return The fragment (usually "unique"), empty string indicates the uniqueness will be indicated using a
|
||||
* different approach
|
||||
*/
|
||||
public String getColumnDefinitionUniquenessFragment(Column column);
|
||||
|
||||
/**
|
||||
* Get the fragment that can be used to apply unique constraints as part of table creation. The implementation
|
||||
* should iterate over the {@link org.hibernate.mapping.UniqueKey} instances for the given table (see
|
||||
|
@ -85,21 +69,6 @@ public interface UniqueDelegate {
|
|||
* comma is important!
|
||||
*/
|
||||
public String getTableCreationUniqueConstraintsFragment(org.hibernate.mapping.Table table);
|
||||
|
||||
/**
|
||||
* Get the fragment that can be used to apply unique constraints as part of table creation. The implementation
|
||||
* should iterate over the {@link org.hibernate.mapping.UniqueKey} instances for the given table (see
|
||||
* {@link org.hibernate.mapping.Table#getUniqueKeyIterator()} and generate the whole fragment for all
|
||||
* unique keys
|
||||
* <p/>
|
||||
* Intended for Dialects which support unique constraint definitions, but just not in separate ALTER statements.
|
||||
*
|
||||
* @param table The table for which to generate the unique constraints fragment
|
||||
*
|
||||
* @return The fragment, typically in the form {@code ", unique(col1, col2), unique( col20)"}. NOTE: The leading
|
||||
* comma is important!
|
||||
*/
|
||||
public String getTableCreationUniqueConstraintsFragment(Table table);
|
||||
|
||||
/**
|
||||
* Get the SQL ALTER TABLE command to be used to create the given UniqueKey.
|
||||
|
@ -115,16 +84,6 @@ public interface UniqueDelegate {
|
|||
String defaultCatalog,
|
||||
String defaultSchema);
|
||||
|
||||
/**
|
||||
* Get the SQL ALTER TABLE command to be used to create the given UniqueKey.
|
||||
*
|
||||
* @param uniqueKey The UniqueKey instance. Contains all information about the columns, as well as
|
||||
* schema/catalog
|
||||
*
|
||||
* @return The ALTER TABLE command
|
||||
*/
|
||||
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey);
|
||||
|
||||
/**
|
||||
* Get the SQL ALTER TABLE command to be used to drop the given UniqueKey.
|
||||
*
|
||||
|
@ -138,13 +97,4 @@ public interface UniqueDelegate {
|
|||
org.hibernate.mapping.UniqueKey uniqueKey,
|
||||
String defaultCatalog, String defaultSchema);
|
||||
|
||||
/**
|
||||
* Get the SQL ALTER TABLE command to be used to drop the given UniqueKey.
|
||||
*
|
||||
* @param uniqueKey The UniqueKey instance. Contains all information about the columns, as well as
|
||||
* schema/catalog
|
||||
*
|
||||
* @return The ALTER TABLE command
|
||||
*/
|
||||
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
package org.hibernate.engine.jdbc;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -26,7 +26,6 @@ package org.hibernate.engine.query.spi;
|
|||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
|
||||
|
||||
|
@ -47,14 +46,6 @@ public class NativeQueryInterpreterInitiator implements SessionFactoryServiceIni
|
|||
return NativeQueryInterpreterStandardImpl.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQueryInterpreter initiateService(
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
MetadataImplementor metadata,
|
||||
ServiceRegistryImplementor registry) {
|
||||
return NativeQueryInterpreterStandardImpl.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<NativeQueryInterpreter> getServiceInitiated() {
|
||||
return NativeQueryInterpreter.class;
|
||||
|
|
|
@ -25,7 +25,6 @@ package org.hibernate.engine.spi;
|
|||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.internal.CacheImpl;
|
||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
|
||||
|
||||
|
@ -40,11 +39,6 @@ public class CacheInitiator implements SessionFactoryServiceInitiator<CacheImple
|
|||
return new CacheImpl( sessionFactory );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheImplementor initiateService(SessionFactoryImplementor sessionFactory, MetadataImplementor metadata, ServiceRegistryImplementor registry) {
|
||||
return new CacheImpl( sessionFactory );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<CacheImplementor> getServiceInitiated() {
|
||||
return CacheImplementor.class;
|
||||
|
|
|
@ -26,7 +26,6 @@ package org.hibernate.event.service.internal;
|
|||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
|
||||
|
||||
|
@ -50,12 +49,4 @@ public class EventListenerServiceInitiator implements SessionFactoryServiceIniti
|
|||
ServiceRegistryImplementor registry) {
|
||||
return new EventListenerRegistryImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventListenerRegistry initiateService(
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
MetadataImplementor metadata,
|
||||
ServiceRegistryImplementor registry) {
|
||||
return new EventListenerRegistryImpl();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ package org.hibernate.integrator.spi;
|
|||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
|
||||
/**
|
||||
|
@ -60,17 +59,6 @@ public interface Integrator {
|
|||
SessionFactoryServiceRegistry serviceRegistry);
|
||||
|
||||
/**
|
||||
* Perform integration.
|
||||
*
|
||||
* @param metadata The metadata used to create the session factory
|
||||
* @param sessionFactory The session factory being created
|
||||
* @param serviceRegistry The session factory's service registry
|
||||
*/
|
||||
public void integrate( MetadataImplementor metadata,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryServiceRegistry serviceRegistry );
|
||||
|
||||
/**
|
||||
* Tongue-in-cheek name for a shutdown callback.
|
||||
*
|
||||
* @param sessionFactory The session factory being closed.
|
||||
|
|
|
@ -130,9 +130,6 @@ import org.hibernate.mapping.PersistentClass;
|
|||
import org.hibernate.mapping.RootClass;
|
||||
import org.hibernate.metadata.ClassMetadata;
|
||||
import org.hibernate.metadata.CollectionMetadata;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.persister.entity.Loadable;
|
||||
|
@ -674,320 +671,6 @@ public final class SessionFactoryImpl
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings( {"ThrowableResultOfMethodCallIgnored"})
|
||||
public SessionFactoryImpl(
|
||||
MetadataImplementor metadata,
|
||||
SessionFactoryOptions sessionFactoryOptions,
|
||||
SessionFactoryObserver observer) throws HibernateException {
|
||||
|
||||
final boolean traceEnabled = LOG.isTraceEnabled();
|
||||
final boolean debugEnabled = traceEnabled || LOG.isDebugEnabled();
|
||||
if ( debugEnabled ) {
|
||||
LOG.debug( "Building session factory" );
|
||||
}
|
||||
|
||||
this.sessionFactoryOptions = sessionFactoryOptions;
|
||||
|
||||
this.properties = createPropertiesFromMap(
|
||||
metadata.getServiceRegistry().getService( ConfigurationService.class ).getSettings()
|
||||
);
|
||||
|
||||
// TODO: these should be moved into SessionFactoryOptions
|
||||
this.settings = new SettingsFactory().buildSettings(
|
||||
properties,
|
||||
metadata.getServiceRegistry()
|
||||
);
|
||||
|
||||
this.serviceRegistry =
|
||||
sessionFactoryOptions.getServiceRegistry()
|
||||
.getService( SessionFactoryServiceRegistryFactory.class )
|
||||
.buildServiceRegistry( this, metadata );
|
||||
|
||||
this.jdbcServices = this.serviceRegistry.getService( JdbcServices.class );
|
||||
this.dialect = this.jdbcServices.getDialect();
|
||||
this.cacheAccess = this.serviceRegistry.getService( CacheImplementor.class );
|
||||
|
||||
// TODO: get SQL functions from JdbcServices (HHH-6559)
|
||||
//this.sqlFunctionRegistry = new SQLFunctionRegistry( this.jdbcServices.getSqlFunctions() );
|
||||
this.sqlFunctionRegistry = new SQLFunctionRegistry( this.dialect, new HashMap<String, SQLFunction>() );
|
||||
|
||||
// TODO: get SQL functions from a new service
|
||||
// this.sqlFunctionRegistry = new SQLFunctionRegistry( getDialect(), cfg.getSqlFunctions() );
|
||||
|
||||
if ( observer != null ) {
|
||||
this.observer.addObserver( observer );
|
||||
}
|
||||
|
||||
this.typeResolver = metadata.getTypeResolver().scope( this );
|
||||
this.typeHelper = new TypeLocatorImpl( typeResolver );
|
||||
|
||||
this.filters = new HashMap<String, FilterDefinition>();
|
||||
for ( FilterDefinition filterDefinition : metadata.getFilterDefinitions() ) {
|
||||
filters.put( filterDefinition.getFilterName(), filterDefinition );
|
||||
}
|
||||
|
||||
if ( debugEnabled ) {
|
||||
LOG.debugf( "Session factory constructed with filter configurations : %s", filters );
|
||||
LOG.debugf( "Instantiating session factory with properties: %s", properties );
|
||||
}
|
||||
this.queryPlanCache = new QueryPlanCache( this );
|
||||
|
||||
class IntegratorObserver implements SessionFactoryObserver {
|
||||
private ArrayList<Integrator> integrators = new ArrayList<Integrator>();
|
||||
|
||||
@Override
|
||||
public void sessionFactoryCreated(SessionFactory factory) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionFactoryClosed(SessionFactory factory) {
|
||||
for ( Integrator integrator : integrators ) {
|
||||
integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry );
|
||||
}
|
||||
integrators.clear();
|
||||
}
|
||||
}
|
||||
|
||||
final IntegratorObserver integratorObserver = new IntegratorObserver();
|
||||
this.observer.addObserver(integratorObserver);
|
||||
for (Integrator integrator : serviceRegistry.getService(IntegratorService.class).getIntegrators()) {
|
||||
integrator.integrate(metadata, this, this.serviceRegistry);
|
||||
integratorObserver.integrators.add(integrator);
|
||||
}
|
||||
|
||||
|
||||
//Generators:
|
||||
|
||||
identifierGenerators = new HashMap<String,IdentifierGenerator>();
|
||||
for ( EntityBinding entityBinding : metadata.getEntityBindings() ) {
|
||||
if ( entityBinding.isRoot() ) {
|
||||
identifierGenerators.put(
|
||||
entityBinding.getEntity().getName(),
|
||||
entityBinding.getHierarchyDetails().getEntityIdentifier().getIdentifierGenerator()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Prepare persisters and link them up with their cache
|
||||
// region/access-strategy
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if ( settings.getCacheRegionPrefix() != null) {
|
||||
stringBuilder
|
||||
.append( settings.getCacheRegionPrefix() )
|
||||
.append( '.' );
|
||||
}
|
||||
final String cacheRegionPrefix = stringBuilder.toString();
|
||||
|
||||
entityPersisters = new HashMap<String,EntityPersister>();
|
||||
Map<String, RegionAccessStrategy> entityAccessStrategies = new HashMap<String, RegionAccessStrategy>();
|
||||
Map<String,ClassMetadata> classMeta = new HashMap<String,ClassMetadata>();
|
||||
for ( EntityBinding model : metadata.getEntityBindings() ) {
|
||||
// TODO: should temp table prep happen when metadata is being built?
|
||||
//model.prepareTemporaryTables( metadata, getDialect() );
|
||||
// cache region is defined by the root-class in the hierarchy...
|
||||
EntityBinding rootEntityBinding = metadata.getRootEntityBinding( model.getEntity().getName() );
|
||||
EntityRegionAccessStrategy accessStrategy = null;
|
||||
if ( settings.isSecondLevelCacheEnabled() &&
|
||||
rootEntityBinding.getHierarchyDetails().getCaching() != null &&
|
||||
model.getHierarchyDetails().getCaching() != null &&
|
||||
model.getHierarchyDetails().getCaching().getAccessType() != null ) {
|
||||
final String cacheRegionName = cacheRegionPrefix + rootEntityBinding.getHierarchyDetails().getCaching().getRegion();
|
||||
accessStrategy = EntityRegionAccessStrategy.class.cast( entityAccessStrategies.get( cacheRegionName ) );
|
||||
if ( accessStrategy == null ) {
|
||||
final AccessType accessType = model.getHierarchyDetails().getCaching().getAccessType();
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev( "Building cache for entity data [{0}]", model.getEntity().getName() );
|
||||
}
|
||||
EntityRegion entityRegion = settings.getRegionFactory().buildEntityRegion(
|
||||
cacheRegionName, properties, CacheDataDescriptionImpl.decode( model )
|
||||
);
|
||||
accessStrategy = entityRegion.buildAccessStrategy( accessType );
|
||||
entityAccessStrategies.put( cacheRegionName, accessStrategy );
|
||||
cacheAccess.addCacheRegion( cacheRegionName, entityRegion );
|
||||
}
|
||||
}
|
||||
EntityPersister cp = serviceRegistry.getService( PersisterFactory.class ).createEntityPersister(
|
||||
model, accessStrategy, this, metadata
|
||||
);
|
||||
entityPersisters.put( model.getEntity().getName(), cp );
|
||||
classMeta.put( model.getEntity().getName(), cp.getClassMetadata() );
|
||||
}
|
||||
this.classMetadata = Collections.unmodifiableMap(classMeta);
|
||||
|
||||
Map<String,Set<String>> tmpEntityToCollectionRoleMap = new HashMap<String,Set<String>>();
|
||||
collectionPersisters = new HashMap<String,CollectionPersister>();
|
||||
Map<String, CollectionMetadata> tmpCollectionMetadata = new HashMap<String, CollectionMetadata>();
|
||||
for ( PluralAttributeBinding model : metadata.getCollectionBindings() ) {
|
||||
if ( model.getAttribute() == null ) {
|
||||
throw new IllegalStateException( "No attribute defined for a AbstractPluralAttributeBinding: " + model );
|
||||
}
|
||||
if ( model.getAttribute().isSingular() ) {
|
||||
throw new IllegalStateException(
|
||||
"AbstractPluralAttributeBinding has a Singular attribute defined: " + model.getAttribute().getName()
|
||||
);
|
||||
}
|
||||
final String cacheRegionName = cacheRegionPrefix + model.getCaching().getRegion();
|
||||
final AccessType accessType = model.getCaching().getAccessType();
|
||||
CollectionRegionAccessStrategy accessStrategy = null;
|
||||
if ( accessType != null && settings.isSecondLevelCacheEnabled() ) {
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev( "Building cache for collection data [{0}]", model.getAttribute().getRole() );
|
||||
}
|
||||
CollectionRegion collectionRegion = settings.getRegionFactory().buildCollectionRegion(
|
||||
cacheRegionName, properties, CacheDataDescriptionImpl.decode( model )
|
||||
);
|
||||
accessStrategy = collectionRegion.buildAccessStrategy( accessType );
|
||||
entityAccessStrategies.put( cacheRegionName, accessStrategy );
|
||||
cacheAccess.addCacheRegion( cacheRegionName, collectionRegion );
|
||||
}
|
||||
CollectionPersister persister = serviceRegistry
|
||||
.getService( PersisterFactory.class )
|
||||
.createCollectionPersister( metadata, model, accessStrategy, this );
|
||||
collectionPersisters.put( model.getAttribute().getRole(), persister );
|
||||
tmpCollectionMetadata.put( model.getAttribute().getRole(), persister.getCollectionMetadata() );
|
||||
Type indexType = persister.getIndexType();
|
||||
if ( indexType != null && indexType.isAssociationType() && !indexType.isAnyType() ) {
|
||||
String entityName = ( ( AssociationType ) indexType ).getAssociatedEntityName( this );
|
||||
Set<String> roles = tmpEntityToCollectionRoleMap.get( entityName );
|
||||
if ( roles == null ) {
|
||||
roles = new HashSet<String>();
|
||||
tmpEntityToCollectionRoleMap.put( entityName, roles );
|
||||
}
|
||||
roles.add( persister.getRole() );
|
||||
}
|
||||
Type elementType = persister.getElementType();
|
||||
if ( elementType.isAssociationType() && !elementType.isAnyType() ) {
|
||||
String entityName = ( ( AssociationType ) elementType ).getAssociatedEntityName( this );
|
||||
Set<String> roles = tmpEntityToCollectionRoleMap.get( entityName );
|
||||
if ( roles == null ) {
|
||||
roles = new HashSet<String>();
|
||||
tmpEntityToCollectionRoleMap.put( entityName, roles );
|
||||
}
|
||||
roles.add( persister.getRole() );
|
||||
}
|
||||
}
|
||||
collectionMetadata = Collections.unmodifiableMap( tmpCollectionMetadata );
|
||||
for ( Map.Entry<String, Set<String>> entry : tmpEntityToCollectionRoleMap.entrySet() ) {
|
||||
entry.setValue( Collections.unmodifiableSet( entry.getValue() ) );
|
||||
}
|
||||
collectionRolesByEntityParticipant = Collections.unmodifiableMap( tmpEntityToCollectionRoleMap );
|
||||
|
||||
|
||||
//Named Queries:
|
||||
namedQueryRepository = new NamedQueryRepository(
|
||||
metadata.getNamedQueryDefinitions(),
|
||||
metadata.getNamedNativeQueryDefinitions(),
|
||||
metadata.getResultSetMappingDefinitions(),
|
||||
new HashMap<String, ProcedureCallMemento>( )
|
||||
);
|
||||
|
||||
imports = new HashMap<String,String>();
|
||||
for ( Map.Entry<String,String> importEntry : metadata.getImports() ) {
|
||||
imports.put( importEntry.getKey(), importEntry.getValue() );
|
||||
}
|
||||
|
||||
// after *all* persisters and named queries are registered
|
||||
Iterator iter = entityPersisters.values().iterator();
|
||||
while ( iter.hasNext() ) {
|
||||
final EntityPersister persister = ( ( EntityPersister ) iter.next() );
|
||||
persister.postInstantiate();
|
||||
registerEntityNameResolvers( persister );
|
||||
|
||||
}
|
||||
iter = collectionPersisters.values().iterator();
|
||||
while ( iter.hasNext() ) {
|
||||
final CollectionPersister persister = ( ( CollectionPersister ) iter.next() );
|
||||
persister.postInstantiate();
|
||||
}
|
||||
|
||||
//JNDI + Serialization:
|
||||
|
||||
name = settings.getSessionFactoryName();
|
||||
try {
|
||||
uuid = (String) UUID_GENERATOR.generate(null, null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new AssertionFailure("Could not generate UUID");
|
||||
}
|
||||
SessionFactoryRegistry.INSTANCE.addSessionFactory(
|
||||
uuid,
|
||||
name,
|
||||
settings.isSessionFactoryNameAlsoJndiName(),
|
||||
this,
|
||||
serviceRegistry.getService( JndiService.class )
|
||||
);
|
||||
|
||||
if ( debugEnabled ) {
|
||||
LOG.debug("Instantiated session factory");
|
||||
}
|
||||
|
||||
if ( settings.isAutoCreateSchema() ) {
|
||||
new SchemaExport( metadata )
|
||||
.setImportSqlCommandExtractor( serviceRegistry.getService( ImportSqlCommandExtractor.class ) )
|
||||
.create( false, true );
|
||||
}
|
||||
|
||||
if ( settings.isAutoDropSchema() ) {
|
||||
schemaExport = new SchemaExport( metadata )
|
||||
.setImportSqlCommandExtractor( serviceRegistry.getService( ImportSqlCommandExtractor.class ) );
|
||||
}
|
||||
|
||||
currentSessionContext = buildCurrentSessionContext();
|
||||
|
||||
//checking for named queries
|
||||
if ( settings.isNamedQueryStartupCheckingEnabled() ) {
|
||||
final Map<String,HibernateException> errors = checkNamedQueries();
|
||||
if ( ! errors.isEmpty() ) {
|
||||
StringBuilder failingQueries = new StringBuilder( "Errors in named queries: " );
|
||||
String sep = "";
|
||||
for ( Map.Entry<String,HibernateException> entry : errors.entrySet() ) {
|
||||
LOG.namedQueryError( entry.getKey(), entry.getValue() );
|
||||
failingQueries.append( entry.getKey() ).append( sep );
|
||||
sep = ", ";
|
||||
}
|
||||
throw new HibernateException( failingQueries.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
// this needs to happen after persisters are all ready to go...
|
||||
this.fetchProfiles = new HashMap<String,FetchProfile>();
|
||||
for ( org.hibernate.metamodel.binding.FetchProfile mappingProfile : metadata.getFetchProfiles() ) {
|
||||
final FetchProfile fetchProfile = new FetchProfile( mappingProfile.getName() );
|
||||
for ( org.hibernate.metamodel.binding.FetchProfile.Fetch mappingFetch : mappingProfile.getFetches() ) {
|
||||
// resolve the persister owning the fetch
|
||||
final String entityName = getImportedClassName( mappingFetch.getEntity() );
|
||||
final EntityPersister owner = entityName == null ? null : entityPersisters.get( entityName );
|
||||
if ( owner == null ) {
|
||||
throw new HibernateException(
|
||||
"Unable to resolve entity reference [" + mappingFetch.getEntity()
|
||||
+ "] in fetch profile [" + fetchProfile.getName() + "]"
|
||||
);
|
||||
}
|
||||
|
||||
// validate the specified association fetch
|
||||
Type associationType = owner.getPropertyType( mappingFetch.getAssociation() );
|
||||
if ( associationType == null || ! associationType.isAssociationType() ) {
|
||||
throw new HibernateException( "Fetch profile [" + fetchProfile.getName() + "] specified an invalid association" );
|
||||
}
|
||||
|
||||
// resolve the style
|
||||
final Fetch.Style fetchStyle = Fetch.Style.parse( mappingFetch.getStyle() );
|
||||
|
||||
// then construct the fetch instance...
|
||||
fetchProfile.addFetch( new Association( owner, mappingFetch.getAssociation() ), fetchStyle );
|
||||
( ( Loadable ) owner ).registerAffectingFetchProfile( fetchProfile.getName() );
|
||||
}
|
||||
fetchProfiles.put( fetchProfile.getName(), fetchProfile );
|
||||
}
|
||||
|
||||
this.customEntityDirtinessStrategy = determineCustomEntityDirtinessStrategy();
|
||||
this.currentTenantIdentifierResolver = determineCurrentTenantIdentifierResolver( null );
|
||||
this.transactionEnvironment = new TransactionEnvironmentImpl( this );
|
||||
this.observer.sessionFactoryCreated( this );
|
||||
}
|
||||
|
||||
@SuppressWarnings( {"unchecked"} )
|
||||
private static Properties createPropertiesFromMap(Map map) {
|
||||
Properties properties = new Properties();
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.metamodel.source;
|
||||
package org.hibernate.internal.util.xml;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.persistence.SharedCacheMode;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.engine.ResultSetMappingDefinition;
|
||||
import org.hibernate.engine.spi.FilterDefinition;
|
||||
import org.hibernate.engine.spi.NamedQueryDefinition;
|
||||
import org.hibernate.engine.spi.NamedSQLQueryDefinition;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.FetchProfile;
|
||||
import org.hibernate.metamodel.binding.IdGenerator;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.TypeDef;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface Metadata {
|
||||
/**
|
||||
* Exposes the options used to produce a {@link Metadata} instance.
|
||||
*/
|
||||
public static interface Options {
|
||||
public StandardServiceRegistry getServiceRegistry();
|
||||
|
||||
public MetadataSourceProcessingOrder getMetadataSourceProcessingOrder();
|
||||
public NamingStrategy getNamingStrategy();
|
||||
public SharedCacheMode getSharedCacheMode();
|
||||
public AccessType getDefaultAccessType();
|
||||
public boolean useNewIdentifierGenerators();
|
||||
public boolean isGloballyQuotedIdentifiers();
|
||||
public String getDefaultSchemaName();
|
||||
public String getDefaultCatalogName();
|
||||
}
|
||||
|
||||
public Options getOptions();
|
||||
|
||||
public SessionFactoryBuilder getSessionFactoryBuilder();
|
||||
|
||||
public SessionFactory buildSessionFactory();
|
||||
|
||||
public Iterable<EntityBinding> getEntityBindings();
|
||||
|
||||
public EntityBinding getEntityBinding(String entityName);
|
||||
|
||||
/**
|
||||
* Get the "root" entity binding
|
||||
* @param entityName
|
||||
* @return the "root entity binding; simply returns entityBinding if it is the root entity binding
|
||||
*/
|
||||
public EntityBinding getRootEntityBinding(String entityName);
|
||||
|
||||
public Iterable<PluralAttributeBinding> getCollectionBindings();
|
||||
|
||||
public TypeDef getTypeDefinition(String name);
|
||||
|
||||
public Iterable<TypeDef> getTypeDefinitions();
|
||||
|
||||
public Iterable<FilterDefinition> getFilterDefinitions();
|
||||
|
||||
public Iterable<NamedQueryDefinition> getNamedQueryDefinitions();
|
||||
|
||||
public Iterable<NamedSQLQueryDefinition> getNamedNativeQueryDefinitions();
|
||||
|
||||
public Iterable<ResultSetMappingDefinition> getResultSetMappingDefinitions();
|
||||
|
||||
public Iterable<Map.Entry<String, String>> getImports();
|
||||
|
||||
public Iterable<FetchProfile> getFetchProfiles();
|
||||
|
||||
public IdGenerator getIdGenerator(String name);
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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;
|
||||
|
||||
import javax.persistence.SharedCacheMode;
|
||||
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public interface MetadataBuilder {
|
||||
public MetadataBuilder with(NamingStrategy namingStrategy);
|
||||
|
||||
public MetadataBuilder with(MetadataSourceProcessingOrder metadataSourceProcessingOrder);
|
||||
|
||||
public MetadataBuilder with(SharedCacheMode cacheMode);
|
||||
|
||||
public MetadataBuilder with(AccessType accessType);
|
||||
|
||||
public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled);
|
||||
|
||||
public Metadata build();
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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;
|
||||
|
||||
/**
|
||||
* Enumeration of the possible orders for processing metadata sources. The implication is in terms of precedence;
|
||||
* for duplicate information in different sources, whichever is processed first has precedence.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public enum MetadataSourceProcessingOrder {
|
||||
ANNOTATIONS_FIRST,
|
||||
HBM_FIRST
|
||||
}
|
|
@ -1,425 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.cfg.EJB3DTDEntityResolver;
|
||||
import org.hibernate.cfg.EJB3NamingStrategy;
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.internal.jaxb.JaxbRoot;
|
||||
import org.hibernate.internal.jaxb.Origin;
|
||||
import org.hibernate.internal.jaxb.SourceType;
|
||||
import org.hibernate.metamodel.source.MappingException;
|
||||
import org.hibernate.metamodel.source.MappingNotFoundException;
|
||||
import org.hibernate.metamodel.source.internal.JaxbHelper;
|
||||
import org.hibernate.metamodel.source.internal.MetadataBuilderImpl;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.EntityResolver;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class MetadataSources {
|
||||
private static final Logger LOG = Logger.getLogger( MetadataSources.class );
|
||||
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
|
||||
private List<JaxbRoot> jaxbRootList = new ArrayList<JaxbRoot>();
|
||||
private LinkedHashSet<Class<?>> annotatedClasses = new LinkedHashSet<Class<?>>();
|
||||
private LinkedHashSet<String> annotatedPackages = new LinkedHashSet<String>();
|
||||
|
||||
private final JaxbHelper jaxbHelper;
|
||||
|
||||
private final EntityResolver entityResolver;
|
||||
private final NamingStrategy namingStrategy;
|
||||
|
||||
private final MetadataBuilderImpl metadataBuilder;
|
||||
|
||||
public MetadataSources(ServiceRegistry serviceRegistry) {
|
||||
this( serviceRegistry, EJB3DTDEntityResolver.INSTANCE, EJB3NamingStrategy.INSTANCE );
|
||||
}
|
||||
|
||||
public MetadataSources(ServiceRegistry serviceRegistry, EntityResolver entityResolver, NamingStrategy namingStrategy) {
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.entityResolver = entityResolver;
|
||||
this.namingStrategy = namingStrategy;
|
||||
|
||||
this.jaxbHelper = new JaxbHelper( this );
|
||||
this.metadataBuilder = new MetadataBuilderImpl( this );
|
||||
|
||||
// service registry really should be either BootstrapServiceRegistry or StandardServiceRegistry type...
|
||||
if ( ! isExpectedServiceRegistryType( serviceRegistry ) ) {
|
||||
LOG.debugf(
|
||||
"Unexpected ServiceRegistry type [%s] encountered during building of MetadataSources; may cause " +
|
||||
"problems later attempting to construct MetadataBuilder",
|
||||
serviceRegistry.getClass().getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected static boolean isExpectedServiceRegistryType(ServiceRegistry serviceRegistry) {
|
||||
return BootstrapServiceRegistry.class.isInstance( serviceRegistry )
|
||||
|| StandardServiceRegistry.class.isInstance( serviceRegistry );
|
||||
}
|
||||
|
||||
public List<JaxbRoot> getJaxbRootList() {
|
||||
return jaxbRootList;
|
||||
}
|
||||
|
||||
public Iterable<String> getAnnotatedPackages() {
|
||||
return annotatedPackages;
|
||||
}
|
||||
|
||||
public Iterable<Class<?>> getAnnotatedClasses() {
|
||||
return annotatedClasses;
|
||||
}
|
||||
|
||||
public ServiceRegistry getServiceRegistry() {
|
||||
return serviceRegistry;
|
||||
}
|
||||
|
||||
public NamingStrategy getNamingStrategy() {
|
||||
return namingStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a builder for metadata where non-default options can be specified.
|
||||
*
|
||||
* @return The built metadata.
|
||||
*/
|
||||
public MetadataBuilder getMetadataBuilder() {
|
||||
return new MetadataBuilderImpl( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a builder for metadata where non-default options can be specified.
|
||||
*
|
||||
* @return The built metadata.
|
||||
*/
|
||||
public MetadataBuilder getMetadataBuilder(StandardServiceRegistry serviceRegistry) {
|
||||
return new MetadataBuilderImpl( this, serviceRegistry );
|
||||
}
|
||||
|
||||
/**
|
||||
* Short-hand form of calling {@link #getMetadataBuilder()} and using its
|
||||
* {@link org.hibernate.metamodel.MetadataBuilder#build()} method in cases where the application wants
|
||||
* to accept the defaults.
|
||||
*
|
||||
* @return The built metadata.
|
||||
*/
|
||||
public Metadata buildMetadata() {
|
||||
return getMetadataBuilder().build();
|
||||
}
|
||||
|
||||
public Metadata buildMetadata(StandardServiceRegistry serviceRegistry) {
|
||||
return getMetadataBuilder( serviceRegistry ).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read metadata from the annotations attached to the given class.
|
||||
*
|
||||
* @param annotatedClass The class containing annotations
|
||||
*
|
||||
* @return this (for method chaining)
|
||||
*/
|
||||
public MetadataSources addAnnotatedClass(Class annotatedClass) {
|
||||
annotatedClasses.add( annotatedClass );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read package-level metadata.
|
||||
*
|
||||
* @param packageName java package name without trailing '.', cannot be {@code null}
|
||||
*
|
||||
* @return this (for method chaining)
|
||||
*/
|
||||
public MetadataSources addPackage(String packageName) {
|
||||
if ( packageName == null ) {
|
||||
throw new IllegalArgumentException( "The specified package name cannot be null" );
|
||||
}
|
||||
if ( packageName.endsWith( "." ) ) {
|
||||
packageName = packageName.substring( 0, packageName.length() - 1 );
|
||||
}
|
||||
annotatedPackages.add( packageName );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read mappings as a application resourceName (i.e. classpath lookup).
|
||||
*
|
||||
* @param name The resource name
|
||||
*
|
||||
* @return this (for method chaining purposes)
|
||||
*/
|
||||
public MetadataSources addResource(String name) {
|
||||
LOG.tracef( "reading mappings from resource : %s", name );
|
||||
|
||||
final Origin origin = new Origin( SourceType.RESOURCE, name );
|
||||
InputStream resourceInputStream = classLoaderService().locateResourceStream( name );
|
||||
if ( resourceInputStream == null ) {
|
||||
throw new MappingNotFoundException( origin );
|
||||
}
|
||||
add( resourceInputStream, origin, true );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private ClassLoaderService classLoaderService() {
|
||||
return serviceRegistry.getService( ClassLoaderService.class );
|
||||
}
|
||||
|
||||
private JaxbRoot add(InputStream inputStream, Origin origin, boolean close) {
|
||||
try {
|
||||
JaxbRoot jaxbRoot = jaxbHelper.unmarshal( inputStream, origin );
|
||||
jaxbRootList.add( jaxbRoot );
|
||||
return jaxbRoot;
|
||||
}
|
||||
finally {
|
||||
if ( close ) {
|
||||
try {
|
||||
inputStream.close();
|
||||
}
|
||||
catch ( IOException ignore ) {
|
||||
LOG.trace( "Was unable to close input stream" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a mapping as an application resource using the convention that a class named {@code foo.bar.Foo} is
|
||||
* mapped by a file named {@code foo/bar/Foo.hbm.xml} which can be resolved as a classpath resource.
|
||||
*
|
||||
* @param entityClass The mapped class. Cannot be {@code null} null.
|
||||
*
|
||||
* @return this (for method chaining purposes)
|
||||
*/
|
||||
public MetadataSources addClass(Class entityClass) {
|
||||
if ( entityClass == null ) {
|
||||
throw new IllegalArgumentException( "The specified class cannot be null" );
|
||||
}
|
||||
LOG.debugf( "adding resource mappings from class convention : %s", entityClass.getName() );
|
||||
final String mappingResourceName = entityClass.getName().replace( '.', '/' ) + ".hbm.xml";
|
||||
addResource( mappingResourceName );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read mappings from a particular XML file
|
||||
*
|
||||
* @param path The path to a file. Expected to be resolvable by {@link File#File(String)}
|
||||
*
|
||||
* @return this (for method chaining purposes)
|
||||
*
|
||||
* @see #addFile(java.io.File)
|
||||
*/
|
||||
public MetadataSources addFile(String path) {
|
||||
return addFile( new File( path ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Read mappings from a particular XML file
|
||||
*
|
||||
* @param file The reference to the XML file
|
||||
*
|
||||
* @return this (for method chaining purposes)
|
||||
*/
|
||||
public MetadataSources addFile(File file) {
|
||||
final String name = file.getAbsolutePath();
|
||||
LOG.tracef( "reading mappings from file : %s", name );
|
||||
final Origin origin = new Origin( SourceType.FILE, name );
|
||||
try {
|
||||
add( new FileInputStream( file ), origin, true );
|
||||
}
|
||||
catch ( FileNotFoundException e ) {
|
||||
throw new MappingNotFoundException( e, origin );
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link #addCacheableFile(java.io.File)} for description
|
||||
*
|
||||
* @param path The path to a file. Expected to be resolvable by {@link File#File(String)}
|
||||
*
|
||||
* @return this (for method chaining purposes)
|
||||
*
|
||||
* @see #addCacheableFile(java.io.File)
|
||||
*/
|
||||
public MetadataSources addCacheableFile(String path) {
|
||||
return this; // todo : implement method body
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a cached mapping file. A cached file is a serialized representation of the DOM structure of a
|
||||
* particular mapping. It is saved from a previous call as a file with the name {@code {xmlFile}.bin}
|
||||
* where {@code {xmlFile}} is the name of the original mapping file.
|
||||
* </p>
|
||||
* If a cached {@code {xmlFile}.bin} exists and is newer than {@code {xmlFile}}, the {@code {xmlFile}.bin}
|
||||
* file will be read directly. Otherwise {@code {xmlFile}} is read and then serialized to {@code {xmlFile}.bin} for
|
||||
* use the next time.
|
||||
*
|
||||
* @param file The cacheable mapping file to be added, {@code {xmlFile}} in above discussion.
|
||||
*
|
||||
* @return this (for method chaining purposes)
|
||||
*/
|
||||
public MetadataSources addCacheableFile(File file) {
|
||||
return this; // todo : implement method body
|
||||
}
|
||||
|
||||
/**
|
||||
* Read metadata from an {@link InputStream}.
|
||||
*
|
||||
* @param xmlInputStream The input stream containing a DOM.
|
||||
*
|
||||
* @return this (for method chaining purposes)
|
||||
*/
|
||||
public MetadataSources addInputStream(InputStream xmlInputStream) {
|
||||
add( xmlInputStream, new Origin( SourceType.INPUT_STREAM, "<unknown>" ), false );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read mappings from a {@link URL}
|
||||
*
|
||||
* @param url The url for the mapping document to be read.
|
||||
*
|
||||
* @return this (for method chaining purposes)
|
||||
*/
|
||||
public MetadataSources addURL(URL url) {
|
||||
final String urlExternalForm = url.toExternalForm();
|
||||
LOG.debugf( "Reading mapping document from URL : %s", urlExternalForm );
|
||||
|
||||
final Origin origin = new Origin( SourceType.URL, urlExternalForm );
|
||||
try {
|
||||
add( url.openStream(), origin, true );
|
||||
}
|
||||
catch ( IOException e ) {
|
||||
throw new MappingNotFoundException( "Unable to open url stream [" + urlExternalForm + "]", e, origin );
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read mappings from a DOM {@link Document}
|
||||
*
|
||||
* @param document The DOM document
|
||||
*
|
||||
* @return this (for method chaining purposes)
|
||||
*/
|
||||
public MetadataSources addDocument(Document document) {
|
||||
final Origin origin = new Origin( SourceType.DOM, "<unknown>" );
|
||||
JaxbRoot jaxbRoot = jaxbHelper.unmarshal( document, origin );
|
||||
jaxbRootList.add( jaxbRoot );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all mappings from a jar file.
|
||||
* <p/>
|
||||
* Assumes that any file named <tt>*.hbm.xml</tt> is a mapping document.
|
||||
*
|
||||
* @param jar a jar file
|
||||
*
|
||||
* @return this (for method chaining purposes)
|
||||
*/
|
||||
public MetadataSources addJar(File jar) {
|
||||
LOG.debugf( "Seeking mapping documents in jar file : %s", jar.getName() );
|
||||
final Origin origin = new Origin( SourceType.JAR, jar.getAbsolutePath() );
|
||||
try {
|
||||
JarFile jarFile = new JarFile( jar );
|
||||
try {
|
||||
Enumeration jarEntries = jarFile.entries();
|
||||
while ( jarEntries.hasMoreElements() ) {
|
||||
final ZipEntry zipEntry = (ZipEntry) jarEntries.nextElement();
|
||||
if ( zipEntry.getName().endsWith( ".hbm.xml" ) ) {
|
||||
LOG.tracef( "found mapping document : %s", zipEntry.getName() );
|
||||
try {
|
||||
add( jarFile.getInputStream( zipEntry ), origin, true );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
throw new MappingException( "could not read mapping documents", e, origin );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
jarFile.close();
|
||||
}
|
||||
catch ( Exception ignore ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( IOException e ) {
|
||||
throw new MappingNotFoundException( e, origin );
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all mapping documents from a directory tree.
|
||||
* <p/>
|
||||
* Assumes that any file named <tt>*.hbm.xml</tt> is a mapping document.
|
||||
*
|
||||
* @param dir The directory
|
||||
*
|
||||
* @return this (for method chaining purposes)
|
||||
*
|
||||
* @throws org.hibernate.MappingException Indicates problems reading the jar file or
|
||||
* processing the contained mapping documents.
|
||||
*/
|
||||
public MetadataSources addDirectory(File dir) {
|
||||
File[] files = dir.listFiles();
|
||||
for ( File file : files ) {
|
||||
if ( file.isDirectory() ) {
|
||||
addDirectory( file );
|
||||
}
|
||||
else if ( file.getName().endsWith( ".hbm.xml" ) ) {
|
||||
addFile( file );
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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;
|
||||
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public interface SessionFactoryBuilder {
|
||||
public SessionFactoryBuilder with(Interceptor interceptor);
|
||||
|
||||
public SessionFactoryBuilder with(EntityNotFoundDelegate entityNotFoundDelegate);
|
||||
|
||||
/**
|
||||
* After all options have been set, build the SessionFactory.
|
||||
*
|
||||
* @return The built SessionFactory.
|
||||
*/
|
||||
public SessionFactory build();
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
/**
|
||||
* Indicates a problem validating the metamodel.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ValidationException extends HibernateException {
|
||||
public ValidationException(String s) {
|
||||
super( s );
|
||||
}
|
||||
|
||||
public ValidationException(String string, Throwable root) {
|
||||
super( string, root );
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.metamodel.domain.Attribute;
|
||||
import org.hibernate.metamodel.source.MetaAttributeContext;
|
||||
|
||||
/**
|
||||
* Basic support for {@link AttributeBinding} implementors
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractAttributeBinding implements AttributeBinding {
|
||||
private final AttributeBindingContainer container;
|
||||
private final Attribute attribute;
|
||||
|
||||
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||
private final Set<SingularAssociationAttributeBinding> entityReferencingAttributeBindings = new HashSet<SingularAssociationAttributeBinding>();
|
||||
|
||||
private boolean includedInOptimisticLocking;
|
||||
|
||||
private boolean isLazy;
|
||||
private String propertyAccessorName;
|
||||
private boolean isAlternateUniqueKey;
|
||||
|
||||
private MetaAttributeContext metaAttributeContext;
|
||||
|
||||
protected AbstractAttributeBinding(AttributeBindingContainer container, Attribute attribute) {
|
||||
this.container = container;
|
||||
this.attribute = attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeBindingContainer getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attribute getAttribute() {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HibernateTypeDescriptor getHibernateTypeDescriptor() {
|
||||
return hibernateTypeDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBasicPropertyAccessor() {
|
||||
return propertyAccessorName == null || "property".equals( propertyAccessorName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPropertyAccessorName() {
|
||||
return propertyAccessorName;
|
||||
}
|
||||
|
||||
public void setPropertyAccessorName(String propertyAccessorName) {
|
||||
this.propertyAccessorName = propertyAccessorName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludedInOptimisticLocking() {
|
||||
return includedInOptimisticLocking;
|
||||
}
|
||||
|
||||
public void setIncludedInOptimisticLocking(boolean includedInOptimisticLocking) {
|
||||
this.includedInOptimisticLocking = includedInOptimisticLocking;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaAttributeContext getMetaAttributeContext() {
|
||||
return metaAttributeContext;
|
||||
}
|
||||
|
||||
public void setMetaAttributeContext(MetaAttributeContext metaAttributeContext) {
|
||||
this.metaAttributeContext = metaAttributeContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlternateUniqueKey() {
|
||||
return isAlternateUniqueKey;
|
||||
}
|
||||
|
||||
public void setAlternateUniqueKey(boolean alternateUniqueKey) {
|
||||
this.isAlternateUniqueKey = alternateUniqueKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLazy() {
|
||||
return isLazy;
|
||||
}
|
||||
|
||||
public void setLazy(boolean isLazy) {
|
||||
this.isLazy = isLazy;
|
||||
}
|
||||
|
||||
public void addEntityReferencingAttributeBinding(SingularAssociationAttributeBinding referencingAttributeBinding) {
|
||||
entityReferencingAttributeBindings.add( referencingAttributeBinding );
|
||||
}
|
||||
|
||||
public Set<SingularAssociationAttributeBinding> getEntityReferencingAttributeBindings() {
|
||||
return Collections.unmodifiableSet( entityReferencingAttributeBindings );
|
||||
}
|
||||
|
||||
public void validate() {
|
||||
if ( !entityReferencingAttributeBindings.isEmpty() ) {
|
||||
// TODO; validate that this AttributeBinding can be a target of an entity reference
|
||||
// (e.g., this attribute is the primary key or there is a unique-key)
|
||||
// can a unique attribute be used as a target? if so, does it need to be non-null?
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import org.hibernate.metamodel.relational.Value;
|
||||
|
||||
/**
|
||||
* Basic contract describing the commonality between the various types of collection element mappings.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractCollectionElement {
|
||||
private final AbstractPluralAttributeBinding collectionBinding;
|
||||
|
||||
private Value elementValue;
|
||||
|
||||
AbstractCollectionElement(AbstractPluralAttributeBinding collectionBinding) {
|
||||
this.collectionBinding = collectionBinding;
|
||||
}
|
||||
|
||||
public abstract CollectionElementNature getCollectionElementNature();
|
||||
|
||||
public AbstractPluralAttributeBinding getCollectionBinding() {
|
||||
return collectionBinding;
|
||||
}
|
||||
|
||||
public Value getElementValue() {
|
||||
return elementValue;
|
||||
}
|
||||
}
|
|
@ -1,394 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.engine.FetchStyle;
|
||||
import org.hibernate.engine.FetchTiming;
|
||||
import org.hibernate.engine.spi.CascadeStyle;
|
||||
import org.hibernate.engine.spi.CascadeStyles;
|
||||
import org.hibernate.metamodel.domain.PluralAttribute;
|
||||
import org.hibernate.metamodel.relational.Table;
|
||||
import org.hibernate.metamodel.relational.TableSpecification;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBinding implements PluralAttributeBinding {
|
||||
private final CollectionKey collectionKey;
|
||||
private final AbstractCollectionElement collectionElement;
|
||||
|
||||
private Table collectionTable;
|
||||
|
||||
private FetchTiming fetchTiming;
|
||||
private FetchStyle fetchStyle;
|
||||
private int batchSize = -1;
|
||||
|
||||
private CascadeStyle cascadeStyle;
|
||||
private boolean orphanDelete;
|
||||
|
||||
private Caching caching;
|
||||
|
||||
private boolean inverse;
|
||||
private boolean mutable = true;
|
||||
|
||||
private Class<? extends CollectionPersister> collectionPersisterClass;
|
||||
|
||||
private String where;
|
||||
private String orderBy;
|
||||
private boolean sorted;
|
||||
private Comparator comparator;
|
||||
private String comparatorClassName;
|
||||
|
||||
private String customLoaderName;
|
||||
private CustomSQL customSqlInsert;
|
||||
private CustomSQL customSqlUpdate;
|
||||
private CustomSQL customSqlDelete;
|
||||
private CustomSQL customSqlDeleteAll;
|
||||
|
||||
private String referencedPropertyName;
|
||||
|
||||
private final java.util.Map filters = new HashMap();
|
||||
private final java.util.Set<String> synchronizedTables = new HashSet<String>();
|
||||
|
||||
protected AbstractPluralAttributeBinding(
|
||||
AttributeBindingContainer container,
|
||||
PluralAttribute attribute,
|
||||
CollectionElementNature collectionElementNature) {
|
||||
super( container, attribute );
|
||||
this.collectionKey = new CollectionKey( this );
|
||||
this.collectionElement = interpretNature( collectionElementNature );
|
||||
}
|
||||
|
||||
private AbstractCollectionElement interpretNature(CollectionElementNature collectionElementNature) {
|
||||
switch ( collectionElementNature ) {
|
||||
case BASIC: {
|
||||
return new BasicCollectionElement( this );
|
||||
}
|
||||
case COMPOSITE: {
|
||||
return new CompositeCollectionElement( this );
|
||||
}
|
||||
case ONE_TO_MANY: {
|
||||
return new OneToManyCollectionElement( this );
|
||||
}
|
||||
case MANY_TO_MANY: {
|
||||
return new ManyToManyCollectionElement( this );
|
||||
}
|
||||
case MANY_TO_ANY: {
|
||||
return new ManyToAnyCollectionElement( this );
|
||||
}
|
||||
default: {
|
||||
throw new AssertionFailure( "Unknown collection element nature : " + collectionElementNature );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protected void initializeBinding(PluralAttributeBindingState state) {
|
||||
// super.initialize( state );
|
||||
// fetchMode = state.getFetchMode();
|
||||
// extraLazy = state.isExtraLazy();
|
||||
// collectionElement.setNodeName( state.getElementNodeName() );
|
||||
// collectionElement.setTypeName( state.getElementTypeName() );
|
||||
// inverse = state.isInverse();
|
||||
// mutable = state.isMutable();
|
||||
// subselectLoadable = state.isSubselectLoadable();
|
||||
// if ( isSubselectLoadable() ) {
|
||||
// getEntityBinding().setSubselectLoadableCollections( true );
|
||||
// }
|
||||
// cacheConcurrencyStrategy = state.getCacheConcurrencyStrategy();
|
||||
// cacheRegionName = state.getCacheRegionName();
|
||||
// orderBy = state.getOrderBy();
|
||||
// where = state.getWhere();
|
||||
// referencedPropertyName = state.getReferencedPropertyName();
|
||||
// sorted = state.isSorted();
|
||||
// comparator = state.getComparator();
|
||||
// comparatorClassName = state.getComparatorClassName();
|
||||
// orphanDelete = state.isOrphanDelete();
|
||||
// batchSize = state.getBatchSize();
|
||||
// embedded = state.isEmbedded();
|
||||
// optimisticLocked = state.isOptimisticLocked();
|
||||
// collectionPersisterClass = state.getCollectionPersisterClass();
|
||||
// filters.putAll( state.getFilters() );
|
||||
// synchronizedTables.addAll( state.getSynchronizedTables() );
|
||||
// customSQLInsert = state.getCustomSQLInsert();
|
||||
// customSQLUpdate = state.getCustomSQLUpdate();
|
||||
// customSQLDelete = state.getCustomSQLDelete();
|
||||
// customSQLDeleteAll = state.getCustomSQLDeleteAll();
|
||||
// loaderName = state.getLoaderName();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public PluralAttribute getAttribute() {
|
||||
return (PluralAttribute) super.getAttribute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssociation() {
|
||||
return collectionElement.getCollectionElementNature() == CollectionElementNature.MANY_TO_ANY
|
||||
|| collectionElement.getCollectionElementNature() == CollectionElementNature.MANY_TO_MANY
|
||||
|| collectionElement.getCollectionElementNature() == CollectionElementNature.ONE_TO_MANY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableSpecification getCollectionTable() {
|
||||
return collectionTable;
|
||||
}
|
||||
|
||||
public void setCollectionTable(Table collectionTable) {
|
||||
this.collectionTable = collectionTable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionKey getCollectionKey() {
|
||||
return collectionKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractCollectionElement getCollectionElement() {
|
||||
return collectionElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CascadeStyle getCascadeStyle() {
|
||||
return cascadeStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCascadeStyles(Iterable<CascadeStyle> cascadeStyles) {
|
||||
List<CascadeStyle> cascadeStyleList = new ArrayList<CascadeStyle>();
|
||||
for ( CascadeStyle style : cascadeStyles ) {
|
||||
if ( style != CascadeStyles.NONE ) {
|
||||
cascadeStyleList.add( style );
|
||||
}
|
||||
if ( style == CascadeStyles.DELETE_ORPHAN ||
|
||||
style == CascadeStyles.ALL_DELETE_ORPHAN ) {
|
||||
orphanDelete = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( cascadeStyleList.isEmpty() ) {
|
||||
cascadeStyle = CascadeStyles.NONE;
|
||||
}
|
||||
else if ( cascadeStyleList.size() == 1 ) {
|
||||
cascadeStyle = cascadeStyleList.get( 0 );
|
||||
}
|
||||
else {
|
||||
cascadeStyle = new CascadeStyles.MultipleCascadeStyle(
|
||||
cascadeStyleList.toArray( new CascadeStyle[ cascadeStyleList.size() ] )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOrphanDelete() {
|
||||
return orphanDelete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchMode getFetchMode() {
|
||||
if ( getFetchStyle() == FetchStyle.JOIN ) {
|
||||
return FetchMode.JOIN;
|
||||
}
|
||||
else {
|
||||
return FetchMode.SELECT;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchTiming getFetchTiming() {
|
||||
return fetchTiming;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFetchTiming(FetchTiming fetchTiming) {
|
||||
this.fetchTiming = fetchTiming;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchStyle getFetchStyle() {
|
||||
return fetchStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFetchStyle(FetchStyle fetchStyle) {
|
||||
this.fetchStyle = fetchStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomLoaderName() {
|
||||
return customLoaderName;
|
||||
}
|
||||
|
||||
public void setCustomLoaderName(String customLoaderName) {
|
||||
this.customLoaderName = customLoaderName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomSQL getCustomSqlInsert() {
|
||||
return customSqlInsert;
|
||||
}
|
||||
|
||||
public void setCustomSqlInsert(CustomSQL customSqlInsert) {
|
||||
this.customSqlInsert = customSqlInsert;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomSQL getCustomSqlUpdate() {
|
||||
return customSqlUpdate;
|
||||
}
|
||||
|
||||
public void setCustomSqlUpdate(CustomSQL customSqlUpdate) {
|
||||
this.customSqlUpdate = customSqlUpdate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomSQL getCustomSqlDelete() {
|
||||
return customSqlDelete;
|
||||
}
|
||||
|
||||
public void setCustomSqlDelete(CustomSQL customSqlDelete) {
|
||||
this.customSqlDelete = customSqlDelete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomSQL getCustomSqlDeleteAll() {
|
||||
return customSqlDeleteAll;
|
||||
}
|
||||
|
||||
public void setCustomSqlDeleteAll(CustomSQL customSqlDeleteAll) {
|
||||
this.customSqlDeleteAll = customSqlDeleteAll;
|
||||
}
|
||||
|
||||
public Class<? extends CollectionPersister> getCollectionPersisterClass() {
|
||||
return collectionPersisterClass;
|
||||
}
|
||||
|
||||
public void setCollectionPersisterClass(Class<? extends CollectionPersister> collectionPersisterClass) {
|
||||
this.collectionPersisterClass = collectionPersisterClass;
|
||||
}
|
||||
|
||||
public Caching getCaching() {
|
||||
return caching;
|
||||
}
|
||||
|
||||
public void setCaching(Caching caching) {
|
||||
this.caching = caching;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOrderBy() {
|
||||
return orderBy;
|
||||
}
|
||||
|
||||
public void setOrderBy(String orderBy) {
|
||||
this.orderBy = orderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWhere() {
|
||||
return where;
|
||||
}
|
||||
|
||||
public void setWhere(String where) {
|
||||
this.where = where;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInverse() {
|
||||
return inverse;
|
||||
}
|
||||
|
||||
public void setInverse(boolean inverse) {
|
||||
this.inverse = inverse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMutable() {
|
||||
return mutable;
|
||||
}
|
||||
|
||||
public void setMutable(boolean mutable) {
|
||||
this.mutable = mutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
return batchSize;
|
||||
}
|
||||
|
||||
public void setBatchSize(int batchSize) {
|
||||
this.batchSize = batchSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public String getReferencedPropertyName() {
|
||||
return referencedPropertyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSorted() {
|
||||
return sorted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator getComparator() {
|
||||
return comparator;
|
||||
}
|
||||
|
||||
public void setComparator(Comparator comparator) {
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
public String getComparatorClassName() {
|
||||
return comparatorClassName;
|
||||
}
|
||||
|
||||
public void addFilter(String name, String condition) {
|
||||
filters.put( name, condition );
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Map getFilterMap() {
|
||||
return filters;
|
||||
}
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.metamodel.domain.SingularAttribute;
|
||||
import org.hibernate.metamodel.relational.SimpleValue;
|
||||
import org.hibernate.metamodel.relational.Tuple;
|
||||
import org.hibernate.metamodel.relational.Value;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractSingularAttributeBinding
|
||||
extends AbstractAttributeBinding
|
||||
implements SingularAttributeBinding {
|
||||
|
||||
private Value value;
|
||||
private List<SimpleValueBinding> simpleValueBindings = new ArrayList<SimpleValueBinding>();
|
||||
|
||||
private boolean hasDerivedValue;
|
||||
private boolean isNullable = true;
|
||||
|
||||
protected AbstractSingularAttributeBinding(AttributeBindingContainer container, SingularAttribute attribute) {
|
||||
super( container, attribute );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingularAttribute getAttribute() {
|
||||
return (SingularAttribute) super.getAttribute();
|
||||
}
|
||||
|
||||
public Value getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setSimpleValueBindings(Iterable<SimpleValueBinding> simpleValueBindings) {
|
||||
List<SimpleValue> values = new ArrayList<SimpleValue>();
|
||||
for ( SimpleValueBinding simpleValueBinding : simpleValueBindings ) {
|
||||
this.simpleValueBindings.add( simpleValueBinding );
|
||||
values.add( simpleValueBinding.getSimpleValue() );
|
||||
this.hasDerivedValue = this.hasDerivedValue || simpleValueBinding.isDerived();
|
||||
this.isNullable = this.isNullable && simpleValueBinding.isNullable();
|
||||
}
|
||||
if ( values.size() == 1 ) {
|
||||
this.value = values.get( 0 );
|
||||
}
|
||||
else {
|
||||
final Tuple tuple = values.get( 0 ).getTable().createTuple( getRole() );
|
||||
for ( SimpleValue value : values ) {
|
||||
tuple.addValue( value );
|
||||
}
|
||||
this.value = tuple;
|
||||
}
|
||||
}
|
||||
|
||||
private String getRole() {
|
||||
return getContainer().getPathBase() + '.' + getAttribute().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSimpleValueSpan() {
|
||||
checkValueBinding();
|
||||
return simpleValueBindings.size();
|
||||
}
|
||||
|
||||
protected void checkValueBinding() {
|
||||
if ( value == null ) {
|
||||
throw new AssertionFailure( "No values yet bound!" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<SimpleValueBinding> getSimpleValueBindings() {
|
||||
return simpleValueBindings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDerivedValue() {
|
||||
checkValueBinding();
|
||||
return hasDerivedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
checkValueBinding();
|
||||
return isNullable;
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.engine.FetchStyle;
|
||||
import org.hibernate.engine.FetchTiming;
|
||||
import org.hibernate.engine.spi.CascadeStyle;
|
||||
|
||||
/**
|
||||
* Contract describing a binding for attributes which model associations.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface AssociationAttributeBinding extends AttributeBinding {
|
||||
/**
|
||||
* Obtain the cascade style in effect for this association.
|
||||
*
|
||||
* @return The (potentially aggregated) cascade style.
|
||||
*/
|
||||
public CascadeStyle getCascadeStyle();
|
||||
|
||||
/**
|
||||
* Set the cascade styles in effect for this association.
|
||||
*
|
||||
* @param cascadeStyles The cascade styles.
|
||||
*/
|
||||
public void setCascadeStyles(Iterable<CascadeStyle> cascadeStyles);
|
||||
|
||||
public FetchTiming getFetchTiming();
|
||||
public void setFetchTiming(FetchTiming fetchTiming);
|
||||
|
||||
public FetchStyle getFetchStyle();
|
||||
public void setFetchStyle(FetchStyle fetchStyle);
|
||||
|
||||
|
||||
/**
|
||||
* Temporary. Needed for integration with legacy org.hibernate.mapping configuration of persisters.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings( {"JavaDoc"})
|
||||
public FetchMode getFetchMode();
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.metamodel.domain.Attribute;
|
||||
import org.hibernate.metamodel.source.MetaAttributeContext;
|
||||
|
||||
/**
|
||||
* The basic contract for binding a {@link #getAttribute() attribute} from the domain model to the relational model.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface AttributeBinding {
|
||||
/**
|
||||
* Obtain the entity binding to which this attribute binding exists.
|
||||
*
|
||||
* @return The entity binding.
|
||||
*/
|
||||
public AttributeBindingContainer getContainer();
|
||||
|
||||
/**
|
||||
* Obtain the attribute bound.
|
||||
*
|
||||
* @return The attribute.
|
||||
*/
|
||||
public Attribute getAttribute();
|
||||
|
||||
/**
|
||||
* Obtain the descriptor for the Hibernate {@link org.hibernate.type.Type} for this binding.
|
||||
* <p/>
|
||||
* For information about the Java type, query the {@link Attribute} obtained from {@link #getAttribute()}
|
||||
* instead.
|
||||
*
|
||||
* @return The type descriptor
|
||||
*/
|
||||
public HibernateTypeDescriptor getHibernateTypeDescriptor();
|
||||
|
||||
public boolean isAssociation();
|
||||
|
||||
public boolean isBasicPropertyAccessor();
|
||||
|
||||
public String getPropertyAccessorName();
|
||||
|
||||
public void setPropertyAccessorName(String propertyAccessorName);
|
||||
|
||||
public boolean isIncludedInOptimisticLocking();
|
||||
|
||||
public void setIncludedInOptimisticLocking(boolean includedInOptimisticLocking);
|
||||
|
||||
/**
|
||||
* Obtain the meta attributes associated with this binding
|
||||
*
|
||||
* @return The meta attributes
|
||||
*/
|
||||
public MetaAttributeContext getMetaAttributeContext();
|
||||
|
||||
public boolean isAlternateUniqueKey();
|
||||
|
||||
public boolean isLazy();
|
||||
|
||||
public void addEntityReferencingAttributeBinding(SingularAssociationAttributeBinding attributeBinding);
|
||||
|
||||
public Set<SingularAssociationAttributeBinding> getEntityReferencingAttributeBindings();
|
||||
|
||||
public void validate();
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import org.hibernate.metamodel.domain.AttributeContainer;
|
||||
import org.hibernate.metamodel.domain.PluralAttribute;
|
||||
import org.hibernate.metamodel.domain.SingularAttribute;
|
||||
import org.hibernate.metamodel.source.MetaAttributeContext;
|
||||
|
||||
/**
|
||||
* Common contract for {@link EntityBinding} and {@link ComponentAttributeBinding} in so far as they are both
|
||||
* containers for {@link AttributeBinding} descriptors
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface AttributeBindingContainer {
|
||||
/**
|
||||
* Obtain the path base of this container. Intended to help uniquely identify each attribute binding.
|
||||
*
|
||||
* @return The path base for this container.
|
||||
*/
|
||||
public String getPathBase();
|
||||
|
||||
/**
|
||||
* Obtain the underlying domain attribute container.
|
||||
*
|
||||
* @return The attribute container
|
||||
*/
|
||||
public AttributeContainer getAttributeContainer();
|
||||
|
||||
/**
|
||||
* Obtain all attribute bindings
|
||||
*
|
||||
* @return All attribute bindings
|
||||
*/
|
||||
public Iterable<AttributeBinding> attributeBindings();
|
||||
|
||||
/**
|
||||
* Locate a specific attribute binding, by its local name.
|
||||
*
|
||||
* @param name The name of the attribute, local to this container.
|
||||
*
|
||||
* @return The attribute binding.
|
||||
*/
|
||||
public AttributeBinding locateAttributeBinding(String name);
|
||||
|
||||
/**
|
||||
* Factory method for basic attribute bindings.
|
||||
*
|
||||
* @param attribute The attribute for which to make a binding.
|
||||
*
|
||||
* @return The attribute binding instance.
|
||||
*/
|
||||
public BasicAttributeBinding makeBasicAttributeBinding(SingularAttribute attribute);
|
||||
|
||||
/**
|
||||
* Factory method for component attribute bindings.
|
||||
*
|
||||
* @param attribute The attribute for which to make a binding.
|
||||
*
|
||||
* @return The attribute binding instance.
|
||||
*/
|
||||
public ComponentAttributeBinding makeComponentAttributeBinding(SingularAttribute attribute);
|
||||
|
||||
/**
|
||||
* Factory method for many-to-one attribute bindings.
|
||||
*
|
||||
* @param attribute The attribute for which to make a binding.
|
||||
*
|
||||
* @return The attribute binding instance.
|
||||
*/
|
||||
public ManyToOneAttributeBinding makeManyToOneAttributeBinding(SingularAttribute attribute);
|
||||
|
||||
/**
|
||||
* Factory method for bag attribute bindings.
|
||||
*
|
||||
* @param attribute The attribute for which to make a binding.
|
||||
* @param nature The nature of the collection elements.
|
||||
*
|
||||
* @return The attribute binding instance.
|
||||
*/
|
||||
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature);
|
||||
|
||||
/**
|
||||
* Factory method for bag attribute bindings.
|
||||
*
|
||||
* @param attribute The attribute for which to make a binding.
|
||||
* @param nature The nature of the collection elements.
|
||||
*
|
||||
* @return The attribute binding instance.
|
||||
*/
|
||||
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature);
|
||||
|
||||
/**
|
||||
* Seeks out the entity binding that is the root of this component path.
|
||||
*
|
||||
* @return The entity binding
|
||||
*/
|
||||
public EntityBinding seekEntityBinding();
|
||||
|
||||
/**
|
||||
* Obtain the {@link Class} reference for this attribute container. Generally this is used to perform reflection
|
||||
* on the attributes.
|
||||
*
|
||||
* @return The {@link Class} reference
|
||||
*/
|
||||
public Class<?> getClassReference();
|
||||
|
||||
/**
|
||||
* Obtain the meta-attribute context for this container.
|
||||
*
|
||||
* @return The meta-attribute context.
|
||||
*/
|
||||
public MetaAttributeContext getMetaAttributeContext();
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import org.hibernate.metamodel.domain.PluralAttribute;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BagBinding extends AbstractPluralAttributeBinding {
|
||||
protected BagBinding(AttributeBindingContainer container, PluralAttribute attribute, CollectionElementNature nature) {
|
||||
super( container, attribute, nature );
|
||||
}
|
||||
}
|
|
@ -1,197 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.mapping.PropertyGeneration;
|
||||
import org.hibernate.metamodel.domain.SingularAttribute;
|
||||
import org.hibernate.metamodel.relational.Column;
|
||||
import org.hibernate.metamodel.relational.Schema;
|
||||
import org.hibernate.metamodel.relational.SimpleValue;
|
||||
import org.hibernate.metamodel.source.MetaAttributeContext;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BasicAttributeBinding
|
||||
extends AbstractSingularAttributeBinding
|
||||
implements KeyValueBinding {
|
||||
|
||||
private String unsavedValue;
|
||||
private PropertyGeneration generation;
|
||||
private boolean includedInOptimisticLocking;
|
||||
|
||||
private boolean forceNonNullable;
|
||||
private boolean forceUnique;
|
||||
private boolean keyCascadeDeleteEnabled;
|
||||
|
||||
private MetaAttributeContext metaAttributeContext;
|
||||
|
||||
BasicAttributeBinding(
|
||||
AttributeBindingContainer container,
|
||||
SingularAttribute attribute,
|
||||
boolean forceNonNullable,
|
||||
boolean forceUnique) {
|
||||
super( container, attribute );
|
||||
this.forceNonNullable = forceNonNullable;
|
||||
this.forceUnique = forceUnique;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssociation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnsavedValue() {
|
||||
return unsavedValue;
|
||||
}
|
||||
|
||||
public void setUnsavedValue(String unsavedValue) {
|
||||
this.unsavedValue = unsavedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyGeneration getGeneration() {
|
||||
return generation;
|
||||
}
|
||||
|
||||
public void setGeneration(PropertyGeneration generation) {
|
||||
this.generation = generation;
|
||||
}
|
||||
|
||||
public boolean isIncludedInOptimisticLocking() {
|
||||
return includedInOptimisticLocking;
|
||||
}
|
||||
|
||||
public void setIncludedInOptimisticLocking(boolean includedInOptimisticLocking) {
|
||||
this.includedInOptimisticLocking = includedInOptimisticLocking;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isKeyCascadeDeleteEnabled() {
|
||||
return keyCascadeDeleteEnabled;
|
||||
}
|
||||
|
||||
public void setKeyCascadeDeleteEnabled(boolean keyCascadeDeleteEnabled) {
|
||||
this.keyCascadeDeleteEnabled = keyCascadeDeleteEnabled;
|
||||
}
|
||||
|
||||
public boolean forceNonNullable() {
|
||||
return forceNonNullable;
|
||||
}
|
||||
|
||||
public boolean forceUnique() {
|
||||
return forceUnique;
|
||||
}
|
||||
|
||||
public MetaAttributeContext getMetaAttributeContext() {
|
||||
return metaAttributeContext;
|
||||
}
|
||||
|
||||
public void setMetaAttributeContext(MetaAttributeContext metaAttributeContext) {
|
||||
this.metaAttributeContext = metaAttributeContext;
|
||||
}
|
||||
|
||||
IdentifierGenerator createIdentifierGenerator(
|
||||
IdGenerator idGenerator,
|
||||
IdentifierGeneratorFactory identifierGeneratorFactory,
|
||||
Properties properties) {
|
||||
Properties params = new Properties();
|
||||
params.putAll( properties );
|
||||
|
||||
// use the schema/catalog specified by getValue().getTable() - but note that
|
||||
// if the schema/catalog were specified as params, they will already be initialized and
|
||||
//will override the values set here (they are in idGenerator.getParameters().)
|
||||
Schema schema = getValue().getTable().getSchema();
|
||||
if ( schema != null ) {
|
||||
if ( schema.getName().getSchema() != null ) {
|
||||
params.setProperty( PersistentIdentifierGenerator.SCHEMA, schema.getName().getSchema().getName() );
|
||||
}
|
||||
if ( schema.getName().getCatalog() != null ) {
|
||||
params.setProperty( PersistentIdentifierGenerator.CATALOG, schema.getName().getCatalog().getName() );
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: not sure how this works for collection IDs...
|
||||
//pass the entity-name, if not a collection-id
|
||||
//if ( rootClass!=null) {
|
||||
params.setProperty( IdentifierGenerator.ENTITY_NAME, getContainer().seekEntityBinding().getEntity().getName() );
|
||||
//}
|
||||
|
||||
//init the table here instead of earlier, so that we can get a quoted table name
|
||||
//TODO: would it be better to simply pass the qualified table name, instead of
|
||||
// splitting it up into schema/catalog/table names
|
||||
String tableName = getValue().getTable().getQualifiedName( identifierGeneratorFactory.getDialect() );
|
||||
params.setProperty( PersistentIdentifierGenerator.TABLE, tableName );
|
||||
|
||||
//pass the column name (a generated id almost always has a single column)
|
||||
if ( getSimpleValueSpan() > 1 ) {
|
||||
throw new MappingException(
|
||||
"A SimpleAttributeBinding used for an identifier has more than 1 Value: " + getAttribute().getName()
|
||||
);
|
||||
}
|
||||
SimpleValue simpleValue = (SimpleValue) getValue();
|
||||
if ( !Column.class.isInstance( simpleValue ) ) {
|
||||
throw new MappingException(
|
||||
"Cannot create an IdentifierGenerator because the value is not a column: " +
|
||||
simpleValue.toLoggableString()
|
||||
);
|
||||
}
|
||||
params.setProperty(
|
||||
PersistentIdentifierGenerator.PK,
|
||||
( (Column) simpleValue ).getColumnName().encloseInQuotesIfQuoted(
|
||||
identifierGeneratorFactory.getDialect()
|
||||
)
|
||||
);
|
||||
|
||||
// TODO: is this stuff necessary for SimpleValue???
|
||||
//if (rootClass!=null) {
|
||||
// StringBuffer tables = new StringBuffer();
|
||||
// Iterator iter = rootClass.getIdentityTables().iterator();
|
||||
// while ( iter.hasNext() ) {
|
||||
// Table table= (Table) iter.next();
|
||||
// tables.append( table.getQuotedName(dialect) );
|
||||
// if ( iter.hasNext() ) tables.append(", ");
|
||||
// }
|
||||
// params.setProperty( PersistentIdentifierGenerator.TABLES, tables.toString() );
|
||||
//}
|
||||
//else {
|
||||
params.setProperty( PersistentIdentifierGenerator.TABLES, tableName );
|
||||
//}
|
||||
|
||||
params.putAll( idGenerator.getParameters() );
|
||||
|
||||
return identifierGeneratorFactory.createIdentifierGenerator(
|
||||
idGenerator.getStrategy(), getHibernateTypeDescriptor().getResolvedTypeMapping(), params
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class BasicCollectionElement extends AbstractCollectionElement {
|
||||
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||
|
||||
public BasicCollectionElement(AbstractPluralAttributeBinding binding) {
|
||||
super( binding );
|
||||
}
|
||||
|
||||
public CollectionElementNature getCollectionElementNature() {
|
||||
return CollectionElementNature.BASIC;
|
||||
}
|
||||
|
||||
public HibernateTypeDescriptor getHibernateTypeDescriptor() {
|
||||
return hibernateTypeDescriptor;
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
|
||||
/**
|
||||
* Defines the caching settings for an entity.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class Caching {
|
||||
private String region;
|
||||
private AccessType accessType;
|
||||
private boolean cacheLazyProperties;
|
||||
|
||||
public Caching() {
|
||||
}
|
||||
|
||||
public Caching(String region, AccessType accessType, boolean cacheLazyProperties) {
|
||||
this.region = region;
|
||||
this.accessType = accessType;
|
||||
this.cacheLazyProperties = cacheLazyProperties;
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public AccessType getAccessType() {
|
||||
return accessType;
|
||||
}
|
||||
|
||||
public void setAccessType(AccessType accessType) {
|
||||
this.accessType = accessType;
|
||||
}
|
||||
|
||||
public boolean isCacheLazyProperties() {
|
||||
return cacheLazyProperties;
|
||||
}
|
||||
|
||||
public void setCacheLazyProperties(boolean cacheLazyProperties) {
|
||||
this.cacheLazyProperties = cacheLazyProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append( "Caching" );
|
||||
sb.append( "{region='" ).append( region ).append( '\'' );
|
||||
sb.append( ", accessType=" ).append( accessType );
|
||||
sb.append( ", cacheLazyProperties=" ).append( cacheLazyProperties );
|
||||
sb.append( '}' );
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -1,173 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.engine.spi.CascadeStyle;
|
||||
import org.hibernate.engine.spi.CascadeStyles;
|
||||
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
* @todo integrate this w/ org.hibernate.engine.spi.CascadeStyle
|
||||
*/
|
||||
public enum CascadeType {
|
||||
/**
|
||||
* Cascades save, delete, update, evict, lock, replicate, merge, persist
|
||||
*/
|
||||
ALL,
|
||||
|
||||
/**
|
||||
* Cascades save, delete, update, evict, lock, replicate, merge, persist + delete orphans
|
||||
*/
|
||||
ALL_DELETE_ORPHAN,
|
||||
|
||||
/**
|
||||
* Cascades save and update
|
||||
*/
|
||||
UPDATE,
|
||||
|
||||
/**
|
||||
* Cascades persist
|
||||
*/
|
||||
PERSIST,
|
||||
|
||||
/**
|
||||
* Cascades merge
|
||||
*/
|
||||
MERGE,
|
||||
|
||||
/**
|
||||
* Cascades lock
|
||||
*/
|
||||
LOCK,
|
||||
|
||||
/**
|
||||
* Cascades refresh
|
||||
*/
|
||||
REFRESH,
|
||||
|
||||
/**
|
||||
* Cascades replicate
|
||||
*/
|
||||
REPLICATE,
|
||||
|
||||
/**
|
||||
* Cascades evict
|
||||
*/
|
||||
EVICT,
|
||||
|
||||
/**
|
||||
* Cascade delete
|
||||
*/
|
||||
DELETE,
|
||||
|
||||
/**
|
||||
* Cascade delete + delete orphans
|
||||
*/
|
||||
DELETE_ORPHAN,
|
||||
|
||||
/**
|
||||
* No cascading
|
||||
*/
|
||||
NONE;
|
||||
|
||||
private static final Map<String, CascadeType> hbmOptionToCascadeType = new HashMap<String, CascadeType>();
|
||||
|
||||
static {
|
||||
hbmOptionToCascadeType.put( "all", ALL );
|
||||
hbmOptionToCascadeType.put( "all-delete-orphan", ALL_DELETE_ORPHAN );
|
||||
hbmOptionToCascadeType.put( "save-update", UPDATE );
|
||||
hbmOptionToCascadeType.put( "persist", PERSIST );
|
||||
hbmOptionToCascadeType.put( "merge", MERGE );
|
||||
hbmOptionToCascadeType.put( "lock", LOCK );
|
||||
hbmOptionToCascadeType.put( "refresh", REFRESH );
|
||||
hbmOptionToCascadeType.put( "replicate", REPLICATE );
|
||||
hbmOptionToCascadeType.put( "evict", EVICT );
|
||||
hbmOptionToCascadeType.put( "delete", DELETE );
|
||||
hbmOptionToCascadeType.put( "remove", DELETE ); // adds remove as a sort-of alias for delete...
|
||||
hbmOptionToCascadeType.put( "delete-orphan", DELETE_ORPHAN );
|
||||
hbmOptionToCascadeType.put( "none", NONE );
|
||||
}
|
||||
|
||||
private static final Map<javax.persistence.CascadeType, CascadeType> jpaCascadeTypeToHibernateCascadeType = new HashMap<javax.persistence.CascadeType, CascadeType>();
|
||||
|
||||
static {
|
||||
jpaCascadeTypeToHibernateCascadeType.put( javax.persistence.CascadeType.ALL, ALL );
|
||||
jpaCascadeTypeToHibernateCascadeType.put( javax.persistence.CascadeType.PERSIST, PERSIST );
|
||||
jpaCascadeTypeToHibernateCascadeType.put( javax.persistence.CascadeType.MERGE, MERGE );
|
||||
jpaCascadeTypeToHibernateCascadeType.put( javax.persistence.CascadeType.REFRESH, REFRESH );
|
||||
jpaCascadeTypeToHibernateCascadeType.put( javax.persistence.CascadeType.DETACH, EVICT );
|
||||
}
|
||||
|
||||
private static final Map<CascadeType, CascadeStyle> cascadeTypeToCascadeStyle = new HashMap<CascadeType, CascadeStyle>();
|
||||
static {
|
||||
cascadeTypeToCascadeStyle.put( ALL, CascadeStyles.ALL );
|
||||
cascadeTypeToCascadeStyle.put( ALL_DELETE_ORPHAN, CascadeStyles.ALL_DELETE_ORPHAN );
|
||||
cascadeTypeToCascadeStyle.put( UPDATE, CascadeStyles.UPDATE );
|
||||
cascadeTypeToCascadeStyle.put( PERSIST, CascadeStyles.PERSIST );
|
||||
cascadeTypeToCascadeStyle.put( MERGE, CascadeStyles.MERGE );
|
||||
cascadeTypeToCascadeStyle.put( LOCK, CascadeStyles.LOCK );
|
||||
cascadeTypeToCascadeStyle.put( REFRESH, CascadeStyles.REFRESH );
|
||||
cascadeTypeToCascadeStyle.put( REPLICATE, CascadeStyles.REPLICATE );
|
||||
cascadeTypeToCascadeStyle.put( EVICT, CascadeStyles.EVICT );
|
||||
cascadeTypeToCascadeStyle.put( DELETE, CascadeStyles.DELETE );
|
||||
cascadeTypeToCascadeStyle.put( DELETE_ORPHAN, CascadeStyles.DELETE_ORPHAN );
|
||||
cascadeTypeToCascadeStyle.put( NONE, CascadeStyles.NONE );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hbmOptionName the cascading option as specified in the hbm mapping file
|
||||
*
|
||||
* @return Returns the {@code CascadeType} for a given hbm cascading option
|
||||
*/
|
||||
public static CascadeType getCascadeType(String hbmOptionName) {
|
||||
return hbmOptionToCascadeType.get( hbmOptionName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jpaCascade the jpa cascade type
|
||||
*
|
||||
* @return Returns the Hibernate {@code CascadeType} for a given jpa cascade type
|
||||
*/
|
||||
public static CascadeType getCascadeType(javax.persistence.CascadeType jpaCascade) {
|
||||
return jpaCascadeTypeToHibernateCascadeType.get( jpaCascade );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the {@code CascadeStyle} that corresponds to this {@code CascadeType}
|
||||
*
|
||||
* @throws MappingException if there is not corresponding {@code CascadeStyle}
|
||||
*/
|
||||
public CascadeStyle toCascadeStyle() {
|
||||
CascadeStyle cascadeStyle = cascadeTypeToCascadeStyle.get( this );
|
||||
if ( cascadeStyle == null ) {
|
||||
throw new MappingException( "No CascadeStyle that corresponds with CascadeType=" + this.name() );
|
||||
}
|
||||
return cascadeStyle;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
/**
|
||||
* Describes the nature of persistent collection elements.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*
|
||||
* @todo Merge with {@link org.hibernate.metamodel.source.binder.PluralAttributeNature} ? package separation kept me from doing that initially
|
||||
*/
|
||||
public enum CollectionElementNature {
|
||||
BASIC,
|
||||
COMPOSITE,
|
||||
ONE_TO_MANY,
|
||||
MANY_TO_MANY,
|
||||
MANY_TO_ANY
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.metamodel.relational.ForeignKey;
|
||||
import org.hibernate.metamodel.relational.TableSpecification;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class CollectionKey {
|
||||
private final AbstractPluralAttributeBinding pluralAttributeBinding;
|
||||
|
||||
private ForeignKey foreignKey;
|
||||
private boolean inverse;
|
||||
private HibernateTypeDescriptor hibernateTypeDescriptor;
|
||||
|
||||
// todo : this would be nice to have but we do not always know it, especially in HBM case.
|
||||
// private BasicAttributeBinding otherSide;
|
||||
|
||||
public CollectionKey(AbstractPluralAttributeBinding pluralAttributeBinding) {
|
||||
this.pluralAttributeBinding = pluralAttributeBinding;
|
||||
}
|
||||
|
||||
public AbstractPluralAttributeBinding getPluralAttributeBinding() {
|
||||
return pluralAttributeBinding;
|
||||
}
|
||||
|
||||
public void prepareForeignKey(String foreignKeyName, String targetTableName) {
|
||||
if ( foreignKey != null ) {
|
||||
throw new AssertionFailure( "Foreign key already initialized" );
|
||||
}
|
||||
final TableSpecification collectionTable = pluralAttributeBinding.getCollectionTable();
|
||||
if ( collectionTable == null ) {
|
||||
throw new AssertionFailure( "Collection table not yet bound" );
|
||||
}
|
||||
|
||||
final TableSpecification targetTable = pluralAttributeBinding.getContainer()
|
||||
.seekEntityBinding()
|
||||
.locateTable( targetTableName );
|
||||
|
||||
// todo : handle implicit fk names...
|
||||
|
||||
foreignKey = collectionTable.createForeignKey( targetTable, foreignKeyName );
|
||||
}
|
||||
|
||||
public ForeignKey getForeignKey() {
|
||||
return foreignKey;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public enum CollectionLaziness {
|
||||
LAZY,
|
||||
NOT,
|
||||
EXTRA
|
||||
}
|
|
@ -1,164 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.mapping.PropertyGeneration;
|
||||
import org.hibernate.metamodel.domain.AttributeContainer;
|
||||
import org.hibernate.metamodel.domain.Component;
|
||||
import org.hibernate.metamodel.domain.PluralAttribute;
|
||||
import org.hibernate.metamodel.domain.PluralAttributeNature;
|
||||
import org.hibernate.metamodel.domain.SingularAttribute;
|
||||
import org.hibernate.metamodel.source.MetaAttributeContext;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ComponentAttributeBinding extends AbstractSingularAttributeBinding implements AttributeBindingContainer {
|
||||
private final String path;
|
||||
private Map<String, AttributeBinding> attributeBindingMap = new HashMap<String, AttributeBinding>();
|
||||
private SingularAttribute parentReference;
|
||||
private MetaAttributeContext metaAttributeContext;
|
||||
|
||||
public ComponentAttributeBinding(AttributeBindingContainer container, SingularAttribute attribute) {
|
||||
super( container, attribute );
|
||||
this.path = container.getPathBase() + '.' + attribute.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityBinding seekEntityBinding() {
|
||||
return getContainer().seekEntityBinding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPathBase() {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeContainer getAttributeContainer() {
|
||||
return getComponent();
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return (Component) getAttribute().getSingularAttributeType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssociation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaAttributeContext getMetaAttributeContext() {
|
||||
return metaAttributeContext;
|
||||
}
|
||||
|
||||
public void setMetaAttributeContext(MetaAttributeContext metaAttributeContext) {
|
||||
this.metaAttributeContext = metaAttributeContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeBinding locateAttributeBinding(String name) {
|
||||
return attributeBindingMap.get( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<AttributeBinding> attributeBindings() {
|
||||
return attributeBindingMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkValueBinding() {
|
||||
// do nothing here...
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicAttributeBinding makeBasicAttributeBinding(SingularAttribute attribute) {
|
||||
final BasicAttributeBinding binding = new BasicAttributeBinding(
|
||||
this,
|
||||
attribute,
|
||||
isNullable(),
|
||||
isAlternateUniqueKey() // todo : is this accurate?
|
||||
);
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
protected void registerAttributeBinding(String name, AttributeBinding attributeBinding) {
|
||||
// todo : hook this into the EntityBinding notion of "entity referencing attribute bindings"
|
||||
attributeBindingMap.put( name, attributeBinding );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentAttributeBinding makeComponentAttributeBinding(SingularAttribute attribute) {
|
||||
final ComponentAttributeBinding binding = new ComponentAttributeBinding( this, attribute );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManyToOneAttributeBinding makeManyToOneAttributeBinding(SingularAttribute attribute) {
|
||||
final ManyToOneAttributeBinding binding = new ManyToOneAttributeBinding( this, attribute );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
|
||||
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.BAG );
|
||||
final BagBinding binding = new BagBinding( this, attribute, nature );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
|
||||
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET );
|
||||
final SetBinding binding = new SetBinding( this, attribute, nature );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getClassReference() {
|
||||
return getComponent().getClassReference();
|
||||
}
|
||||
|
||||
public SingularAttribute getParentReference() {
|
||||
return parentReference;
|
||||
}
|
||||
|
||||
public void setParentReference(SingularAttribute parentReference) {
|
||||
this.parentReference = parentReference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyGeneration getGeneration() {
|
||||
// todo : not sure the correct thing to return here since it essentially relies on the simple sub-attributes.
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class CompositeCollectionElement extends AbstractCollectionElement {
|
||||
public CompositeCollectionElement(AbstractPluralAttributeBinding binding) {
|
||||
super( binding );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionElementNature getCollectionElementNature() {
|
||||
return CollectionElementNature.COMPOSITE;
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
|
||||
|
||||
/**
|
||||
* Wraps the information for custom SQL execution
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class CustomSQL {
|
||||
private final String sql;
|
||||
private final boolean isCallable;
|
||||
private final ExecuteUpdateResultCheckStyle checkStyle;
|
||||
|
||||
public CustomSQL(String sql, boolean callable, ExecuteUpdateResultCheckStyle checkStyle) {
|
||||
this.sql = sql;
|
||||
isCallable = callable;
|
||||
this.checkStyle = checkStyle;
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
public boolean isCallable() {
|
||||
return isCallable;
|
||||
}
|
||||
|
||||
public ExecuteUpdateResultCheckStyle getCheckStyle() {
|
||||
return checkStyle;
|
||||
}
|
||||
}
|
|
@ -1,605 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.engine.spi.FilterDefinition;
|
||||
import org.hibernate.internal.util.ValueHolder;
|
||||
import org.hibernate.internal.util.collections.JoinedIterable;
|
||||
import org.hibernate.metamodel.domain.AttributeContainer;
|
||||
import org.hibernate.metamodel.domain.Entity;
|
||||
import org.hibernate.metamodel.domain.PluralAttribute;
|
||||
import org.hibernate.metamodel.domain.PluralAttributeNature;
|
||||
import org.hibernate.metamodel.domain.SingularAttribute;
|
||||
import org.hibernate.metamodel.relational.TableSpecification;
|
||||
import org.hibernate.metamodel.source.MetaAttributeContext;
|
||||
import org.hibernate.metamodel.source.binder.JpaCallbackClass;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||
|
||||
/**
|
||||
* Provides the link between the domain and the relational model for an entity.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Hardy Ferentschik
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class EntityBinding implements AttributeBindingContainer {
|
||||
private static final String NULL_DISCRIMINATOR_MATCH_VALUE = "null";
|
||||
private static final String NOT_NULL_DISCRIMINATOR_MATCH_VALUE = "not null";
|
||||
|
||||
private final EntityBinding superEntityBinding;
|
||||
private final List<EntityBinding> subEntityBindings = new ArrayList<EntityBinding>();
|
||||
private final HierarchyDetails hierarchyDetails;
|
||||
|
||||
private Entity entity;
|
||||
private TableSpecification primaryTable;
|
||||
private String primaryTableName;
|
||||
private Map<String, TableSpecification> secondaryTables = new HashMap<String, TableSpecification>();
|
||||
|
||||
private ValueHolder<Class<?>> proxyInterfaceType;
|
||||
|
||||
private String jpaEntityName;
|
||||
|
||||
private Class<? extends EntityPersister> customEntityPersisterClass;
|
||||
private Class<? extends EntityTuplizer> customEntityTuplizerClass;
|
||||
|
||||
private String discriminatorMatchValue;
|
||||
|
||||
private Set<FilterDefinition> filterDefinitions = new HashSet<FilterDefinition>();
|
||||
private Set<SingularAssociationAttributeBinding> entityReferencingAttributeBindings = new HashSet<SingularAssociationAttributeBinding>();
|
||||
|
||||
private MetaAttributeContext metaAttributeContext;
|
||||
|
||||
private boolean lazy;
|
||||
private boolean mutable;
|
||||
private String whereFilter;
|
||||
private String rowId;
|
||||
|
||||
private boolean dynamicUpdate;
|
||||
private boolean dynamicInsert;
|
||||
|
||||
private int batchSize;
|
||||
private boolean selectBeforeUpdate;
|
||||
private boolean hasSubselectLoadableCollections;
|
||||
|
||||
private Boolean isAbstract;
|
||||
|
||||
private String customLoaderName;
|
||||
private CustomSQL customInsert;
|
||||
private CustomSQL customUpdate;
|
||||
private CustomSQL customDelete;
|
||||
|
||||
private Set<String> synchronizedTableNames = new HashSet<String>();
|
||||
private Map<String, AttributeBinding> attributeBindingMap = new HashMap<String, AttributeBinding>();
|
||||
|
||||
private List<JpaCallbackClass> jpaCallbackClasses = new ArrayList<JpaCallbackClass>();
|
||||
|
||||
/**
|
||||
* Used to instantiate the EntityBinding for an entity that is the root of an inheritance hierarchy
|
||||
*
|
||||
* @param inheritanceType The inheritance type for the hierarchy
|
||||
* @param entityMode The entity mode used in this hierarchy.
|
||||
*/
|
||||
public EntityBinding(InheritanceType inheritanceType, EntityMode entityMode) {
|
||||
this.superEntityBinding = null;
|
||||
this.hierarchyDetails = new HierarchyDetails( this, inheritanceType, entityMode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to instantiate the EntityBinding for an entity that is a subclass (sub-entity) in an inheritance hierarchy
|
||||
*
|
||||
* @param superEntityBinding The entity binding of this binding's super
|
||||
*/
|
||||
public EntityBinding(EntityBinding superEntityBinding) {
|
||||
this.superEntityBinding = superEntityBinding;
|
||||
this.superEntityBinding.subEntityBindings.add( this );
|
||||
this.hierarchyDetails = superEntityBinding.getHierarchyDetails();
|
||||
}
|
||||
|
||||
public HierarchyDetails getHierarchyDetails() {
|
||||
return hierarchyDetails;
|
||||
}
|
||||
|
||||
public EntityBinding getSuperEntityBinding() {
|
||||
return superEntityBinding;
|
||||
}
|
||||
|
||||
public boolean isRoot() {
|
||||
return superEntityBinding == null;
|
||||
}
|
||||
|
||||
public boolean isPolymorphic() {
|
||||
return superEntityBinding != null ||
|
||||
hierarchyDetails.getEntityDiscriminator() != null ||
|
||||
! subEntityBindings.isEmpty();
|
||||
}
|
||||
|
||||
public boolean hasSubEntityBindings() {
|
||||
return subEntityBindings.size() > 0;
|
||||
}
|
||||
|
||||
public int getSubEntityBindingClosureSpan() {
|
||||
int n = subEntityBindings.size();
|
||||
for ( EntityBinding subEntityBinding : subEntityBindings ) {
|
||||
n += subEntityBinding.getSubEntityBindingClosureSpan();
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/* used for testing */
|
||||
public Iterable<EntityBinding> getDirectSubEntityBindings() {
|
||||
return subEntityBindings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns sub-EntityBinding objects in a special 'order', most derived subclasses
|
||||
* first. Specifically, the sub-entity bindings follow a depth-first,
|
||||
* post-order traversal
|
||||
*
|
||||
* Note that the returned value excludes this entity binding.
|
||||
*
|
||||
* @return sub-entity bindings ordered by those entity bindings that are most derived.
|
||||
*/
|
||||
public Iterable<EntityBinding> getPostOrderSubEntityBindingClosure() {
|
||||
// TODO: why this order?
|
||||
List<Iterable<EntityBinding>> subclassIterables = new ArrayList<Iterable<EntityBinding>>( subEntityBindings.size() + 1 );
|
||||
for ( EntityBinding subEntityBinding : subEntityBindings ) {
|
||||
Iterable<EntityBinding> subSubEntityBindings = subEntityBinding.getPostOrderSubEntityBindingClosure();
|
||||
if ( subSubEntityBindings.iterator().hasNext() ) {
|
||||
subclassIterables.add( subSubEntityBindings );
|
||||
}
|
||||
}
|
||||
if ( ! subEntityBindings.isEmpty() ) {
|
||||
subclassIterables.add( subEntityBindings );
|
||||
}
|
||||
return new JoinedIterable<EntityBinding>( subclassIterables );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns sub-EntityBinding ordered as a depth-first,
|
||||
* pre-order traversal (a subclass precedes its own subclasses).
|
||||
*
|
||||
* Note that the returned value specifically excludes this entity binding.
|
||||
*
|
||||
* @return sub-entity bindings ordered as a depth-first,
|
||||
* pre-order traversal
|
||||
*/
|
||||
public Iterable<EntityBinding> getPreOrderSubEntityBindingClosure() {
|
||||
return getPreOrderSubEntityBindingClosure( false );
|
||||
}
|
||||
|
||||
private Iterable<EntityBinding> getPreOrderSubEntityBindingClosure(boolean includeThis) {
|
||||
List<Iterable<EntityBinding>> iterables = new ArrayList<Iterable<EntityBinding>>();
|
||||
if ( includeThis ) {
|
||||
iterables.add( java.util.Collections.singletonList( this ) );
|
||||
}
|
||||
for ( EntityBinding subEntityBinding : subEntityBindings ) {
|
||||
Iterable<EntityBinding> subSubEntityBindingClosure = subEntityBinding.getPreOrderSubEntityBindingClosure( true );
|
||||
if ( subSubEntityBindingClosure.iterator().hasNext() ) {
|
||||
iterables.add( subSubEntityBindingClosure );
|
||||
}
|
||||
}
|
||||
return new JoinedIterable<EntityBinding>( iterables );
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void setEntity(Entity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public TableSpecification getPrimaryTable() {
|
||||
return primaryTable;
|
||||
}
|
||||
|
||||
public void setPrimaryTable(TableSpecification primaryTable) {
|
||||
this.primaryTable = primaryTable;
|
||||
}
|
||||
|
||||
public TableSpecification locateTable(String tableName) {
|
||||
if ( tableName == null || tableName.equals( getPrimaryTableName() ) ) {
|
||||
return primaryTable;
|
||||
}
|
||||
TableSpecification tableSpec = secondaryTables.get( tableName );
|
||||
if ( tableSpec == null ) {
|
||||
throw new AssertionFailure(
|
||||
String.format(
|
||||
"Unable to find table %s amongst tables %s",
|
||||
tableName,
|
||||
secondaryTables.keySet()
|
||||
)
|
||||
);
|
||||
}
|
||||
return tableSpec;
|
||||
}
|
||||
public String getPrimaryTableName() {
|
||||
return primaryTableName;
|
||||
}
|
||||
|
||||
public void setPrimaryTableName(String primaryTableName) {
|
||||
this.primaryTableName = primaryTableName;
|
||||
}
|
||||
|
||||
public void addSecondaryTable(String tableName, TableSpecification table) {
|
||||
secondaryTables.put( tableName, table );
|
||||
}
|
||||
|
||||
public boolean isVersioned() {
|
||||
return getHierarchyDetails().getVersioningAttributeBinding() != null;
|
||||
}
|
||||
|
||||
public boolean isDiscriminatorMatchValueNull() {
|
||||
return NULL_DISCRIMINATOR_MATCH_VALUE.equals( discriminatorMatchValue );
|
||||
}
|
||||
|
||||
public boolean isDiscriminatorMatchValueNotNull() {
|
||||
return NOT_NULL_DISCRIMINATOR_MATCH_VALUE.equals( discriminatorMatchValue );
|
||||
}
|
||||
|
||||
public String getDiscriminatorMatchValue() {
|
||||
return discriminatorMatchValue;
|
||||
}
|
||||
|
||||
public void setDiscriminatorMatchValue(String discriminatorMatchValue) {
|
||||
this.discriminatorMatchValue = discriminatorMatchValue;
|
||||
}
|
||||
|
||||
public Iterable<FilterDefinition> getFilterDefinitions() {
|
||||
return filterDefinitions;
|
||||
}
|
||||
|
||||
public void addFilterDefinition(FilterDefinition filterDefinition) {
|
||||
filterDefinitions.add( filterDefinition );
|
||||
}
|
||||
|
||||
public Iterable<SingularAssociationAttributeBinding> getEntityReferencingAttributeBindings() {
|
||||
return entityReferencingAttributeBindings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityBinding seekEntityBinding() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPathBase() {
|
||||
return getEntity().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getClassReference() {
|
||||
return getEntity().getClassReference();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeContainer getAttributeContainer() {
|
||||
return getEntity();
|
||||
}
|
||||
|
||||
protected void registerAttributeBinding(String name, AttributeBinding attributeBinding) {
|
||||
if ( SingularAssociationAttributeBinding.class.isInstance( attributeBinding ) ) {
|
||||
entityReferencingAttributeBindings.add( (SingularAssociationAttributeBinding) attributeBinding );
|
||||
}
|
||||
attributeBindingMap.put( name, attributeBinding );
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaAttributeContext getMetaAttributeContext() {
|
||||
return metaAttributeContext;
|
||||
}
|
||||
|
||||
public void setMetaAttributeContext(MetaAttributeContext metaAttributeContext) {
|
||||
this.metaAttributeContext = metaAttributeContext;
|
||||
}
|
||||
|
||||
public boolean isMutable() {
|
||||
return mutable;
|
||||
}
|
||||
|
||||
public void setMutable(boolean mutable) {
|
||||
this.mutable = mutable;
|
||||
}
|
||||
|
||||
public boolean isLazy() {
|
||||
return lazy;
|
||||
}
|
||||
|
||||
public void setLazy(boolean lazy) {
|
||||
this.lazy = lazy;
|
||||
}
|
||||
|
||||
public ValueHolder<Class<?>> getProxyInterfaceType() {
|
||||
return proxyInterfaceType;
|
||||
}
|
||||
|
||||
public void setProxyInterfaceType(ValueHolder<Class<?>> proxyInterfaceType) {
|
||||
this.proxyInterfaceType = proxyInterfaceType;
|
||||
}
|
||||
|
||||
public String getWhereFilter() {
|
||||
return whereFilter;
|
||||
}
|
||||
|
||||
public void setWhereFilter(String whereFilter) {
|
||||
this.whereFilter = whereFilter;
|
||||
}
|
||||
|
||||
public String getRowId() {
|
||||
return rowId;
|
||||
}
|
||||
|
||||
public void setRowId(String rowId) {
|
||||
this.rowId = rowId;
|
||||
}
|
||||
|
||||
public boolean isDynamicUpdate() {
|
||||
return dynamicUpdate;
|
||||
}
|
||||
|
||||
public void setDynamicUpdate(boolean dynamicUpdate) {
|
||||
this.dynamicUpdate = dynamicUpdate;
|
||||
}
|
||||
|
||||
public boolean isDynamicInsert() {
|
||||
return dynamicInsert;
|
||||
}
|
||||
|
||||
public void setDynamicInsert(boolean dynamicInsert) {
|
||||
this.dynamicInsert = dynamicInsert;
|
||||
}
|
||||
|
||||
public int getBatchSize() {
|
||||
return batchSize;
|
||||
}
|
||||
|
||||
public void setBatchSize(int batchSize) {
|
||||
this.batchSize = batchSize;
|
||||
}
|
||||
|
||||
public boolean isSelectBeforeUpdate() {
|
||||
return selectBeforeUpdate;
|
||||
}
|
||||
|
||||
public void setSelectBeforeUpdate(boolean selectBeforeUpdate) {
|
||||
this.selectBeforeUpdate = selectBeforeUpdate;
|
||||
}
|
||||
|
||||
public boolean hasSubselectLoadableCollections() {
|
||||
return hasSubselectLoadableCollections;
|
||||
}
|
||||
|
||||
/* package-protected */
|
||||
void setSubselectLoadableCollections(boolean hasSubselectLoadableCollections) {
|
||||
this.hasSubselectLoadableCollections = hasSubselectLoadableCollections;
|
||||
}
|
||||
|
||||
public Class<? extends EntityPersister> getCustomEntityPersisterClass() {
|
||||
return customEntityPersisterClass;
|
||||
}
|
||||
|
||||
public void setCustomEntityPersisterClass(Class<? extends EntityPersister> customEntityPersisterClass) {
|
||||
this.customEntityPersisterClass = customEntityPersisterClass;
|
||||
}
|
||||
|
||||
public Class<? extends EntityTuplizer> getCustomEntityTuplizerClass() {
|
||||
return customEntityTuplizerClass;
|
||||
}
|
||||
|
||||
public void setCustomEntityTuplizerClass(Class<? extends EntityTuplizer> customEntityTuplizerClass) {
|
||||
this.customEntityTuplizerClass = customEntityTuplizerClass;
|
||||
}
|
||||
|
||||
public Boolean isAbstract() {
|
||||
return isAbstract;
|
||||
}
|
||||
|
||||
public void setAbstract(Boolean isAbstract) {
|
||||
this.isAbstract = isAbstract;
|
||||
}
|
||||
|
||||
public Set<String> getSynchronizedTableNames() {
|
||||
return synchronizedTableNames;
|
||||
}
|
||||
|
||||
public void addSynchronizedTableNames(java.util.Collection<String> synchronizedTableNames) {
|
||||
this.synchronizedTableNames.addAll( synchronizedTableNames );
|
||||
}
|
||||
|
||||
public String getJpaEntityName() {
|
||||
return jpaEntityName;
|
||||
}
|
||||
|
||||
public void setJpaEntityName(String jpaEntityName) {
|
||||
this.jpaEntityName = jpaEntityName;
|
||||
}
|
||||
|
||||
public String getCustomLoaderName() {
|
||||
return customLoaderName;
|
||||
}
|
||||
|
||||
public void setCustomLoaderName(String customLoaderName) {
|
||||
this.customLoaderName = customLoaderName;
|
||||
}
|
||||
|
||||
public CustomSQL getCustomInsert() {
|
||||
return customInsert;
|
||||
}
|
||||
|
||||
public void setCustomInsert(CustomSQL customInsert) {
|
||||
this.customInsert = customInsert;
|
||||
}
|
||||
|
||||
public CustomSQL getCustomUpdate() {
|
||||
return customUpdate;
|
||||
}
|
||||
|
||||
public void setCustomUpdate(CustomSQL customUpdate) {
|
||||
this.customUpdate = customUpdate;
|
||||
}
|
||||
|
||||
public CustomSQL getCustomDelete() {
|
||||
return customDelete;
|
||||
}
|
||||
|
||||
public void setCustomDelete(CustomSQL customDelete) {
|
||||
this.customDelete = customDelete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append( "EntityBinding" );
|
||||
sb.append( "{entity=" ).append( entity != null ? entity.getName() : "not set" );
|
||||
sb.append( '}' );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicAttributeBinding makeBasicAttributeBinding(SingularAttribute attribute) {
|
||||
return makeSimpleAttributeBinding( attribute, false, false );
|
||||
}
|
||||
|
||||
private BasicAttributeBinding makeSimpleAttributeBinding(SingularAttribute attribute, boolean forceNonNullable, boolean forceUnique) {
|
||||
final BasicAttributeBinding binding = new BasicAttributeBinding(
|
||||
this,
|
||||
attribute,
|
||||
forceNonNullable,
|
||||
forceUnique
|
||||
);
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentAttributeBinding makeComponentAttributeBinding(SingularAttribute attribute) {
|
||||
final ComponentAttributeBinding binding = new ComponentAttributeBinding( this, attribute );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManyToOneAttributeBinding makeManyToOneAttributeBinding(SingularAttribute attribute) {
|
||||
final ManyToOneAttributeBinding binding = new ManyToOneAttributeBinding( this, attribute );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
|
||||
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.BAG );
|
||||
final BagBinding binding = new BagBinding( this, attribute, nature );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
|
||||
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET );
|
||||
final SetBinding binding = new SetBinding( this, attribute, nature );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeBinding locateAttributeBinding(String name) {
|
||||
return attributeBindingMap.get( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<AttributeBinding> attributeBindings() {
|
||||
return attributeBindingMap.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of attribute bindings defined on this class, including the
|
||||
* identifier attribute binding and attribute bindings defined
|
||||
* as part of a join.
|
||||
*
|
||||
* @return The number of attribute bindings
|
||||
*/
|
||||
public int getAttributeBindingClosureSpan() {
|
||||
// TODO: update account for join attribute bindings
|
||||
return superEntityBinding != null ?
|
||||
superEntityBinding.getAttributeBindingClosureSpan() + attributeBindingMap.size() :
|
||||
attributeBindingMap.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attribute bindings defined on this class, including the
|
||||
* identifier attribute binding and attribute bindings defined
|
||||
* as part of a join.
|
||||
*
|
||||
* @return The attribute bindings.
|
||||
*/
|
||||
public Iterable<AttributeBinding> getAttributeBindingClosure() {
|
||||
// TODO: update size to account for joins
|
||||
Iterable<AttributeBinding> iterable;
|
||||
if ( superEntityBinding != null ) {
|
||||
List<Iterable<AttributeBinding>> iterables = new ArrayList<Iterable<AttributeBinding>>( 2 );
|
||||
iterables.add( superEntityBinding.getAttributeBindingClosure() );
|
||||
iterables.add( attributeBindings() );
|
||||
iterable = new JoinedIterable<AttributeBinding>( iterables );
|
||||
}
|
||||
else {
|
||||
iterable = attributeBindings();
|
||||
}
|
||||
return iterable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attribute bindings for this EntityBinding and all of its
|
||||
* sub-EntityBinding, starting from the root of the hierarchy; includes
|
||||
* the identifier and attribute bindings defined as part of a join.
|
||||
* @return
|
||||
*/
|
||||
public Iterable<AttributeBinding> getSubEntityAttributeBindingClosure() {
|
||||
List<Iterable<AttributeBinding>> iterables = new ArrayList<Iterable<AttributeBinding>>();
|
||||
iterables.add( getAttributeBindingClosure() );
|
||||
for ( EntityBinding subEntityBinding : getPreOrderSubEntityBindingClosure() ) {
|
||||
// only add attribute bindings declared for the subEntityBinding
|
||||
iterables.add( subEntityBinding.attributeBindings() );
|
||||
// TODO: if EntityBinding.attributeBindings() excludes joined attributes, then they need to be added here
|
||||
}
|
||||
return new JoinedIterable<AttributeBinding>( iterables );
|
||||
}
|
||||
|
||||
public void setJpaCallbackClasses( List<JpaCallbackClass> jpaCallbackClasses ) {
|
||||
this.jpaCallbackClasses = jpaCallbackClasses;
|
||||
}
|
||||
|
||||
public Iterable<JpaCallbackClass> getJpaCallbackClasses() {
|
||||
return jpaCallbackClasses;
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import org.hibernate.metamodel.relational.SimpleValue;
|
||||
|
||||
/**
|
||||
* Binding of the discriminator in a entity hierarchy
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class EntityDiscriminator {
|
||||
private final HibernateTypeDescriptor explicitHibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||
|
||||
private SimpleValue boundValue;
|
||||
private boolean forced;
|
||||
private boolean inserted = true;
|
||||
|
||||
public EntityDiscriminator() {
|
||||
}
|
||||
|
||||
public SimpleValue getBoundValue() {
|
||||
return boundValue;
|
||||
}
|
||||
|
||||
public void setBoundValue(SimpleValue boundValue) {
|
||||
this.boundValue = boundValue;
|
||||
}
|
||||
|
||||
public HibernateTypeDescriptor getExplicitHibernateTypeDescriptor() {
|
||||
return explicitHibernateTypeDescriptor;
|
||||
}
|
||||
|
||||
public boolean isForced() {
|
||||
return forced;
|
||||
}
|
||||
|
||||
public void setForced(boolean forced) {
|
||||
this.forced = forced;
|
||||
}
|
||||
|
||||
public boolean isInserted() {
|
||||
return inserted;
|
||||
}
|
||||
|
||||
public void setInserted(boolean inserted) {
|
||||
this.inserted = inserted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append( "EntityDiscriminator" );
|
||||
sb.append( "{boundValue=" ).append( boundValue );
|
||||
sb.append( ", forced=" ).append( forced );
|
||||
sb.append( ", inserted=" ).append( inserted );
|
||||
sb.append( '}' );
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
|
||||
/**
|
||||
* Binds the entity identifier.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class EntityIdentifier {
|
||||
private final EntityBinding entityBinding;
|
||||
private BasicAttributeBinding attributeBinding;
|
||||
private IdentifierGenerator identifierGenerator;
|
||||
private IdGenerator idGenerator;
|
||||
private boolean isIdentifierMapper = false;
|
||||
// todo : mappers, etc
|
||||
|
||||
/**
|
||||
* Create an identifier
|
||||
*
|
||||
* @param entityBinding the entity binding for which this instance is the id
|
||||
*/
|
||||
public EntityIdentifier(EntityBinding entityBinding) {
|
||||
this.entityBinding = entityBinding;
|
||||
}
|
||||
|
||||
public BasicAttributeBinding getValueBinding() {
|
||||
return attributeBinding;
|
||||
}
|
||||
|
||||
public void setValueBinding(BasicAttributeBinding attributeBinding) {
|
||||
if ( this.attributeBinding != null ) {
|
||||
throw new AssertionFailure(
|
||||
String.format(
|
||||
"Identifier value binding already existed for %s",
|
||||
entityBinding.getEntity().getName()
|
||||
)
|
||||
);
|
||||
}
|
||||
this.attributeBinding = attributeBinding;
|
||||
}
|
||||
|
||||
public void setIdGenerator(IdGenerator idGenerator) {
|
||||
this.idGenerator = idGenerator;
|
||||
}
|
||||
|
||||
public boolean isEmbedded() {
|
||||
return attributeBinding.getSimpleValueSpan() > 1;
|
||||
}
|
||||
|
||||
public boolean isIdentifierMapper() {
|
||||
return isIdentifierMapper;
|
||||
}
|
||||
|
||||
// todo do we really need this createIdentifierGenerator and how do we make sure the getter is not called too early
|
||||
// maybe some sort of visitor pattern here!? (HF)
|
||||
public IdentifierGenerator createIdentifierGenerator(IdentifierGeneratorFactory factory, Properties properties) {
|
||||
if ( idGenerator != null ) {
|
||||
identifierGenerator = attributeBinding.createIdentifierGenerator( idGenerator, factory, properties );
|
||||
}
|
||||
return identifierGenerator;
|
||||
}
|
||||
|
||||
public IdentifierGenerator getIdentifierGenerator() {
|
||||
return identifierGenerator;
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A fetch profile allows a user to dynamically modify the fetching strategy used for particular associations at runtime, whereas
|
||||
* that information was historically only statically defined in the metadata.
|
||||
* <p/>
|
||||
* This class represent the data as it is defined in their metadata.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @see org.hibernate.engine.profile.FetchProfile
|
||||
*/
|
||||
public class FetchProfile {
|
||||
|
||||
private final String name;
|
||||
private final Set<Fetch> fetches;
|
||||
|
||||
/**
|
||||
* Create a fetch profile representation.
|
||||
*
|
||||
* @param name The name of the fetch profile.
|
||||
* @param fetches
|
||||
*/
|
||||
public FetchProfile( String name,
|
||||
Set<Fetch> fetches ) {
|
||||
this.name = name;
|
||||
this.fetches = fetches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the name of the fetch profile.
|
||||
*
|
||||
* @return The profile name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the fetches associated with this profile
|
||||
*
|
||||
* @return The fetches associated with this profile.
|
||||
*/
|
||||
public Set<Fetch> getFetches() {
|
||||
return Collections.unmodifiableSet(fetches);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a fetch to this profile.
|
||||
*
|
||||
* @param entity The entity which contains the association to be fetched
|
||||
* @param association The association to fetch
|
||||
* @param style The style of fetch t apply
|
||||
*/
|
||||
public void addFetch( String entity,
|
||||
String association,
|
||||
String style ) {
|
||||
fetches.add(new Fetch(entity, association, style));
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines an individual association fetch within the given profile.
|
||||
*/
|
||||
public static class Fetch {
|
||||
private final String entity;
|
||||
private final String association;
|
||||
private final String style;
|
||||
|
||||
public Fetch( String entity,
|
||||
String association,
|
||||
String style ) {
|
||||
this.entity = entity;
|
||||
this.association = association;
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
public String getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public String getAssociation() {
|
||||
return association;
|
||||
}
|
||||
|
||||
public String getStyle() {
|
||||
return style;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.metamodel.domain.PluralAttribute;
|
||||
import org.hibernate.metamodel.domain.PluralAttributeNature;
|
||||
|
||||
/**
|
||||
* Helper utilities specific to the binding package.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Helper {
|
||||
public static void checkPluralAttributeNature(PluralAttribute attribute, PluralAttributeNature expected) {
|
||||
if ( attribute.getNature() != expected ) {
|
||||
throw new AssertionFailure(
|
||||
String.format(
|
||||
"Mismatched collection natures; expecting %s, but found %s",
|
||||
expected.getName(),
|
||||
attribute.getNature().getName()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class HibernateTypeDescriptor {
|
||||
private String explicitTypeName;
|
||||
private String javaTypeName;
|
||||
private boolean isToOne;
|
||||
private Map<String, String> typeParameters = new HashMap<String, String>( );
|
||||
|
||||
private Type resolvedTypeMapping;
|
||||
|
||||
public String getExplicitTypeName() {
|
||||
return explicitTypeName;
|
||||
}
|
||||
|
||||
public void setExplicitTypeName(String explicitTypeName) {
|
||||
this.explicitTypeName = explicitTypeName;
|
||||
}
|
||||
|
||||
public String getJavaTypeName() {
|
||||
return javaTypeName;
|
||||
}
|
||||
|
||||
public void setJavaTypeName(String javaTypeName) {
|
||||
this.javaTypeName = javaTypeName;
|
||||
}
|
||||
|
||||
public boolean isToOne() {
|
||||
return isToOne;
|
||||
}
|
||||
|
||||
public void setToOne(boolean toOne) {
|
||||
isToOne = toOne;
|
||||
}
|
||||
|
||||
public Map<String, String> getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
public void setTypeParameters(Map<String, String> typeParameters) {
|
||||
this.typeParameters = typeParameters;
|
||||
}
|
||||
|
||||
public Type getResolvedTypeMapping() {
|
||||
return resolvedTypeMapping;
|
||||
}
|
||||
|
||||
public void setResolvedTypeMapping(Type resolvedTypeMapping) {
|
||||
this.resolvedTypeMapping = resolvedTypeMapping;
|
||||
}
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.engine.OptimisticLockStyle;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class HierarchyDetails {
|
||||
private final EntityBinding rootEntityBinding;
|
||||
private final InheritanceType inheritanceType;
|
||||
private final EntityMode entityMode;
|
||||
|
||||
private final EntityIdentifier entityIdentifier;
|
||||
|
||||
private EntityDiscriminator entityDiscriminator;
|
||||
|
||||
private OptimisticLockStyle optimisticLockStyle;
|
||||
private BasicAttributeBinding versioningAttributeBinding;
|
||||
|
||||
private Caching caching;
|
||||
|
||||
private boolean explicitPolymorphism;
|
||||
|
||||
public HierarchyDetails(EntityBinding rootEntityBinding, InheritanceType inheritanceType, EntityMode entityMode) {
|
||||
this.rootEntityBinding = rootEntityBinding;
|
||||
this.inheritanceType = inheritanceType;
|
||||
this.entityMode = entityMode;
|
||||
this.entityIdentifier = new EntityIdentifier( rootEntityBinding );
|
||||
}
|
||||
|
||||
public EntityBinding getRootEntityBinding() {
|
||||
return rootEntityBinding;
|
||||
}
|
||||
|
||||
public InheritanceType getInheritanceType() {
|
||||
return inheritanceType;
|
||||
}
|
||||
|
||||
public EntityMode getEntityMode() {
|
||||
return entityMode;
|
||||
}
|
||||
|
||||
public EntityIdentifier getEntityIdentifier() {
|
||||
return entityIdentifier;
|
||||
}
|
||||
|
||||
public EntityDiscriminator getEntityDiscriminator() {
|
||||
return entityDiscriminator;
|
||||
}
|
||||
|
||||
public OptimisticLockStyle getOptimisticLockStyle() {
|
||||
return optimisticLockStyle;
|
||||
}
|
||||
|
||||
public void setOptimisticLockStyle(OptimisticLockStyle optimisticLockStyle) {
|
||||
this.optimisticLockStyle = optimisticLockStyle;
|
||||
}
|
||||
|
||||
public void setEntityDiscriminator(EntityDiscriminator entityDiscriminator) {
|
||||
this.entityDiscriminator = entityDiscriminator;
|
||||
}
|
||||
|
||||
public BasicAttributeBinding getVersioningAttributeBinding() {
|
||||
return versioningAttributeBinding;
|
||||
}
|
||||
|
||||
public void setVersioningAttributeBinding(BasicAttributeBinding versioningAttributeBinding) {
|
||||
this.versioningAttributeBinding = versioningAttributeBinding;
|
||||
}
|
||||
|
||||
public Caching getCaching() {
|
||||
return caching;
|
||||
}
|
||||
|
||||
public void setCaching(Caching caching) {
|
||||
this.caching = caching;
|
||||
}
|
||||
|
||||
public boolean isExplicitPolymorphism() {
|
||||
return explicitPolymorphism;
|
||||
}
|
||||
|
||||
public void setExplicitPolymorphism(boolean explicitPolymorphism) {
|
||||
this.explicitPolymorphism = explicitPolymorphism;
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
|
||||
/**
|
||||
* Identifier generator container, Useful to keep named generator in annotations
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class IdGenerator implements Serializable {
|
||||
private final String name;
|
||||
private final String strategy;
|
||||
private final Map<String, String> parameters;
|
||||
|
||||
public IdGenerator( String name,
|
||||
String strategy,
|
||||
Map<String, String> parameters ) {
|
||||
this.name = name;
|
||||
this.strategy = strategy;
|
||||
if ( CollectionHelper.isEmpty( parameters ) ) {
|
||||
this.parameters = Collections.emptyMap();
|
||||
}
|
||||
else {
|
||||
this.parameters = Collections.unmodifiableMap( parameters );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return identifier generator strategy
|
||||
*/
|
||||
public String getStrategy() {
|
||||
return strategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return generator name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return generator configuration parameters
|
||||
*/
|
||||
public Map<String, String> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.binding;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
|
||||
/**
|
||||
* The inheritance type for a given entity.
|
||||
* <p>
|
||||
* Note, we are not using the JPA enum, because we need the ability to extend the types if we need to.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public enum InheritanceType {
|
||||
JOINED,
|
||||
SINGLE_TABLE,
|
||||
TABLE_PER_CLASS,
|
||||
NO_INHERITANCE;
|
||||
|
||||
/**
|
||||
* @param jpaType The JPA inheritance type
|
||||
*
|
||||
* @return The inheritance type of this class.
|
||||
*/
|
||||
public static InheritanceType get(javax.persistence.InheritanceType jpaType) {
|
||||
switch ( jpaType ) {
|
||||
case SINGLE_TABLE: {
|
||||
return InheritanceType.SINGLE_TABLE;
|
||||
}
|
||||
case JOINED: {
|
||||
return InheritanceType.JOINED;
|
||||
}
|
||||
case TABLE_PER_CLASS: {
|
||||
return InheritanceType.TABLE_PER_CLASS;
|
||||
}
|
||||
default: {
|
||||
throw new MappingException( "Unknown jpa inheritance type:" + jpaType.name() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface KeyValueBinding extends AttributeBinding {
|
||||
public boolean isKeyCascadeDeleteEnabled();
|
||||
|
||||
public String getUnsavedValue();
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class ManyToAnyCollectionElement extends AbstractCollectionElement {
|
||||
ManyToAnyCollectionElement(AbstractPluralAttributeBinding binding) {
|
||||
super( binding );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionElementNature getCollectionElementNature() {
|
||||
return CollectionElementNature.MANY_TO_ANY;
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class ManyToManyCollectionElement extends AbstractCollectionElement {
|
||||
|
||||
private final java.util.Map manyToManyFilters = new HashMap();
|
||||
private String manyToManyWhere;
|
||||
private String manyToManyOrderBy;
|
||||
|
||||
|
||||
ManyToManyCollectionElement(AbstractPluralAttributeBinding binding) {
|
||||
super( binding );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionElementNature getCollectionElementNature() {
|
||||
return CollectionElementNature.MANY_TO_MANY;
|
||||
}
|
||||
|
||||
public void fromHbmXml(Element node){
|
||||
/*
|
||||
<!ELEMENT many-to-many (meta*,(column|formula)*,filter*)>
|
||||
<!ATTLIST many-to-many class CDATA #IMPLIED>
|
||||
<!ATTLIST many-to-many node CDATA #IMPLIED>
|
||||
<!ATTLIST many-to-many embed-xml (true|false) "true">
|
||||
<!ATTLIST many-to-many entity-name CDATA #IMPLIED>
|
||||
<!ATTLIST many-to-many column CDATA #IMPLIED>
|
||||
<!ATTLIST many-to-many formula CDATA #IMPLIED>
|
||||
<!ATTLIST many-to-many not-found (exception|ignore) "exception">
|
||||
<!ATTLIST many-to-many outer-join (true|false|auto) #IMPLIED>
|
||||
<!ATTLIST many-to-many fetch (join|select) #IMPLIED>
|
||||
<!ATTLIST many-to-many lazy (false|proxy) #IMPLIED>
|
||||
<!ATTLIST many-to-many foreign-key CDATA #IMPLIED>
|
||||
<!ATTLIST many-to-many unique (true|false) "false">
|
||||
<!ATTLIST many-to-many where CDATA #IMPLIED>
|
||||
<!ATTLIST many-to-many order-by CDATA #IMPLIED>
|
||||
<!ATTLIST many-to-many property-ref CDATA #IMPLIED>
|
||||
*/
|
||||
}
|
||||
|
||||
public String getManyToManyWhere() {
|
||||
return manyToManyWhere;
|
||||
}
|
||||
|
||||
public void setManyToManyWhere(String manyToManyWhere) {
|
||||
this.manyToManyWhere = manyToManyWhere;
|
||||
}
|
||||
|
||||
public String getManyToManyOrderBy() {
|
||||
return manyToManyOrderBy;
|
||||
}
|
||||
|
||||
public void setManyToManyOrderBy(String manyToManyOrderBy) {
|
||||
this.manyToManyOrderBy = manyToManyOrderBy;
|
||||
}
|
||||
}
|
|
@ -1,241 +0,0 @@
|
|||
/*
|
||||
* 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.binding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.engine.FetchStyle;
|
||||
import org.hibernate.engine.FetchTiming;
|
||||
import org.hibernate.engine.spi.CascadeStyle;
|
||||
import org.hibernate.engine.spi.CascadeStyles;
|
||||
import org.hibernate.metamodel.domain.SingularAttribute;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Gail Badner
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ManyToOneAttributeBinding extends BasicAttributeBinding implements SingularAssociationAttributeBinding {
|
||||
private String referencedEntityName;
|
||||
private String referencedAttributeName;
|
||||
private AttributeBinding referencedAttributeBinding;
|
||||
|
||||
private boolean isLogicalOneToOne;
|
||||
private String foreignKeyName;
|
||||
|
||||
private CascadeStyle cascadeStyle;
|
||||
private FetchTiming fetchTiming;
|
||||
private FetchStyle fetchStyle;
|
||||
|
||||
ManyToOneAttributeBinding(AttributeBindingContainer container, SingularAttribute attribute) {
|
||||
super( container, attribute, false, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssociation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isPropertyReference() {
|
||||
return referencedAttributeName != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getReferencedEntityName() {
|
||||
return referencedEntityName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReferencedEntityName(String referencedEntityName) {
|
||||
this.referencedEntityName = referencedEntityName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getReferencedAttributeName() {
|
||||
return referencedAttributeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReferencedAttributeName(String referencedEntityAttributeName) {
|
||||
this.referencedAttributeName = referencedEntityAttributeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CascadeStyle getCascadeStyle() {
|
||||
return cascadeStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCascadeStyles(Iterable<CascadeStyle> cascadeStyles) {
|
||||
List<CascadeStyle> cascadeStyleList = new ArrayList<CascadeStyle>();
|
||||
for ( CascadeStyle style : cascadeStyles ) {
|
||||
if ( style != CascadeStyles.NONE ) {
|
||||
cascadeStyleList.add( style );
|
||||
}
|
||||
}
|
||||
if ( cascadeStyleList.isEmpty() ) {
|
||||
cascadeStyle = CascadeStyles.NONE;
|
||||
}
|
||||
else if ( cascadeStyleList.size() == 1 ) {
|
||||
cascadeStyle = cascadeStyleList.get( 0 );
|
||||
}
|
||||
else {
|
||||
cascadeStyle = new CascadeStyles.MultipleCascadeStyle(
|
||||
cascadeStyleList.toArray( new CascadeStyle[ cascadeStyleList.size() ] )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchTiming getFetchTiming() {
|
||||
return fetchTiming;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFetchTiming(FetchTiming fetchTiming) {
|
||||
this.fetchTiming = fetchTiming;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchStyle getFetchStyle() {
|
||||
return fetchStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFetchStyle(FetchStyle fetchStyle) {
|
||||
if ( fetchStyle == FetchStyle.SUBSELECT ) {
|
||||
throw new AssertionFailure( "Subselect fetching not yet supported for singular associations" );
|
||||
}
|
||||
this.fetchStyle = fetchStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchMode getFetchMode() {
|
||||
if ( fetchStyle == FetchStyle.JOIN ) {
|
||||
return FetchMode.JOIN;
|
||||
}
|
||||
else if ( fetchStyle == FetchStyle.SELECT ) {
|
||||
return FetchMode.SELECT;
|
||||
}
|
||||
else if ( fetchStyle == FetchStyle.BATCH ) {
|
||||
// we need the subsequent select...
|
||||
return FetchMode.SELECT;
|
||||
}
|
||||
|
||||
throw new AssertionFailure( "Unexpected fetch style : " + fetchStyle.name() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isReferenceResolved() {
|
||||
return referencedAttributeBinding != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void resolveReference(AttributeBinding referencedAttributeBinding) {
|
||||
if ( ! EntityBinding.class.isInstance( referencedAttributeBinding.getContainer() ) ) {
|
||||
throw new AssertionFailure( "Illegal attempt to resolve many-to-one reference based on non-entity attribute" );
|
||||
}
|
||||
final EntityBinding entityBinding = (EntityBinding) referencedAttributeBinding.getContainer();
|
||||
if ( !referencedEntityName.equals( entityBinding.getEntity().getName() ) ) {
|
||||
throw new IllegalStateException(
|
||||
"attempt to set EntityBinding with name: [" +
|
||||
entityBinding.getEntity().getName() +
|
||||
"; entity name should be: " + referencedEntityName
|
||||
);
|
||||
}
|
||||
if ( referencedAttributeName == null ) {
|
||||
referencedAttributeName = referencedAttributeBinding.getAttribute().getName();
|
||||
}
|
||||
else if ( !referencedAttributeName.equals( referencedAttributeBinding.getAttribute().getName() ) ) {
|
||||
throw new IllegalStateException(
|
||||
"Inconsistent attribute name; expected: " + referencedAttributeName +
|
||||
"actual: " + referencedAttributeBinding.getAttribute().getName()
|
||||
);
|
||||
}
|
||||
this.referencedAttributeBinding = referencedAttributeBinding;
|
||||
// buildForeignKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeBinding getReferencedAttributeBinding() {
|
||||
if ( !isReferenceResolved() ) {
|
||||
throw new IllegalStateException( "Referenced AttributeBiding has not been resolved." );
|
||||
}
|
||||
return referencedAttributeBinding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final EntityBinding getReferencedEntityBinding() {
|
||||
return (EntityBinding) referencedAttributeBinding.getContainer();
|
||||
}
|
||||
|
||||
// private void buildForeignKey() {
|
||||
// // TODO: move this stuff to relational model
|
||||
// ForeignKey foreignKey = getValue().getTable()
|
||||
// .createForeignKey( referencedAttributeBinding.getValue().getTable(), foreignKeyName );
|
||||
// Iterator<SimpleValue> referencingValueIterator = getSimpleValues().iterator();
|
||||
// Iterator<SimpleValue> targetValueIterator = referencedAttributeBinding.getSimpleValues().iterator();
|
||||
// while ( referencingValueIterator.hasNext() ) {
|
||||
// if ( !targetValueIterator.hasNext() ) {
|
||||
// // TODO: improve this message
|
||||
// throw new MappingException(
|
||||
// "number of values in many-to-one reference is greater than number of values in target"
|
||||
// );
|
||||
// }
|
||||
// SimpleValue referencingValue = referencingValueIterator.next();
|
||||
// SimpleValue targetValue = targetValueIterator.next();
|
||||
// if ( Column.class.isInstance( referencingValue ) ) {
|
||||
// if ( !Column.class.isInstance( targetValue ) ) {
|
||||
// // TODO improve this message
|
||||
// throw new MappingException( "referencing value is a column, but target is not a column" );
|
||||
// }
|
||||
// foreignKey.addColumnMapping( Column.class.cast( referencingValue ), Column.class.cast( targetValue ) );
|
||||
// }
|
||||
// else if ( Column.class.isInstance( targetValue ) ) {
|
||||
// // TODO: improve this message
|
||||
// throw new MappingException( "referencing value is not a column, but target is a column." );
|
||||
// }
|
||||
// }
|
||||
// if ( targetValueIterator.hasNext() ) {
|
||||
// throw new MappingException( "target value has more simple values than referencing value" );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void validate() {
|
||||
// // can't check this until both the domain and relational states are initialized...
|
||||
// if ( getCascadeTypes().contains( CascadeType.DELETE_ORPHAN ) ) {
|
||||
// if ( !isLogicalOneToOne ) {
|
||||
// throw new MappingException(
|
||||
// "many-to-one attribute [" + locateAttribute().getName() + "] does not support orphan delete as it is not unique"
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// //TODO: validate that the entity reference is resolved
|
||||
// }
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A meta attribute is a named value or values.
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class MetaAttribute implements Serializable {
|
||||
private final String name;
|
||||
private List<String> values = new ArrayList<String>();
|
||||
|
||||
public MetaAttribute(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<String> getValues() {
|
||||
return Collections.unmodifiableList(values);
|
||||
}
|
||||
|
||||
public void addValue(String value) {
|
||||
values.add( value );
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
if ( values.size() != 1 ) {
|
||||
throw new IllegalStateException( "no unique value" );
|
||||
}
|
||||
return values.get( 0 );
|
||||
}
|
||||
|
||||
public boolean isMultiValued() {
|
||||
return values.size()>1;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "[" + name + "=" + values + "]";
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class OneToManyCollectionElement extends AbstractCollectionElement {
|
||||
|
||||
OneToManyCollectionElement(AbstractPluralAttributeBinding binding) {
|
||||
super( binding );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionElementNature getCollectionElementNature() {
|
||||
return CollectionElementNature.ONE_TO_MANY;
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.hibernate.metamodel.domain.PluralAttribute;
|
||||
import org.hibernate.metamodel.relational.TableSpecification;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface PluralAttributeBinding extends AssociationAttributeBinding {
|
||||
// todo : really it is the element (and/or index) that can be associative not the collection itself...
|
||||
|
||||
@Override
|
||||
public PluralAttribute getAttribute();
|
||||
|
||||
public CollectionKey getCollectionKey();
|
||||
|
||||
public AbstractCollectionElement getCollectionElement();
|
||||
|
||||
public TableSpecification getCollectionTable();
|
||||
|
||||
public boolean isMutable();
|
||||
|
||||
public Caching getCaching();
|
||||
|
||||
public Class<? extends CollectionPersister> getCollectionPersisterClass();
|
||||
|
||||
public String getCustomLoaderName();
|
||||
|
||||
public CustomSQL getCustomSqlInsert();
|
||||
|
||||
public CustomSQL getCustomSqlUpdate();
|
||||
|
||||
public CustomSQL getCustomSqlDelete();
|
||||
|
||||
public CustomSQL getCustomSqlDeleteAll();
|
||||
|
||||
public boolean isOrphanDelete();
|
||||
|
||||
String getWhere();
|
||||
|
||||
boolean isSorted();
|
||||
|
||||
Comparator getComparator();
|
||||
|
||||
int getBatchSize();
|
||||
|
||||
java.util.Map getFilterMap();
|
||||
|
||||
boolean isInverse();
|
||||
|
||||
String getOrderBy();
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.hibernate.metamodel.domain.PluralAttribute;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SetBinding extends AbstractPluralAttributeBinding {
|
||||
private Comparator comparator;
|
||||
|
||||
protected SetBinding(
|
||||
AttributeBindingContainer container,
|
||||
PluralAttribute attribute,
|
||||
CollectionElementNature collectionElementNature) {
|
||||
super( container, attribute, collectionElementNature );
|
||||
}
|
||||
|
||||
public Comparator getComparator() {
|
||||
return comparator;
|
||||
}
|
||||
|
||||
public void setComparator(Comparator comparator) {
|
||||
this.comparator = comparator;
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import org.hibernate.metamodel.relational.Column;
|
||||
import org.hibernate.metamodel.relational.DerivedValue;
|
||||
import org.hibernate.metamodel.relational.SimpleValue;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SimpleValueBinding {
|
||||
private SimpleValue simpleValue;
|
||||
private boolean includeInInsert;
|
||||
private boolean includeInUpdate;
|
||||
|
||||
public SimpleValueBinding() {
|
||||
this( true, true );
|
||||
}
|
||||
|
||||
public SimpleValueBinding(SimpleValue simpleValue) {
|
||||
this();
|
||||
setSimpleValue( simpleValue );
|
||||
}
|
||||
|
||||
public SimpleValueBinding(SimpleValue simpleValue, boolean includeInInsert, boolean includeInUpdate) {
|
||||
this( includeInInsert, includeInUpdate );
|
||||
setSimpleValue( simpleValue );
|
||||
}
|
||||
|
||||
public SimpleValueBinding(boolean includeInInsert, boolean includeInUpdate) {
|
||||
this.includeInInsert = includeInInsert;
|
||||
this.includeInUpdate = includeInUpdate;
|
||||
}
|
||||
|
||||
public SimpleValue getSimpleValue() {
|
||||
return simpleValue;
|
||||
}
|
||||
|
||||
public void setSimpleValue(SimpleValue simpleValue) {
|
||||
this.simpleValue = simpleValue;
|
||||
if ( DerivedValue.class.isInstance( simpleValue ) ) {
|
||||
includeInInsert = false;
|
||||
includeInUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDerived() {
|
||||
return DerivedValue.class.isInstance( simpleValue );
|
||||
}
|
||||
|
||||
public boolean isNullable() {
|
||||
return isDerived() || Column.class.cast( simpleValue ).isNullable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the value to be inserted as part of its binding here?
|
||||
* <p/>
|
||||
* <b>NOTE</b> that a column may be bound to multiple attributes. The purpose of this value is to track this
|
||||
* notion of "insertability" for this particular binding.
|
||||
*
|
||||
* @return {@code true} indicates the value should be included; {@code false} indicates it should not
|
||||
*/
|
||||
public boolean isIncludeInInsert() {
|
||||
return includeInInsert;
|
||||
}
|
||||
|
||||
public void setIncludeInInsert(boolean includeInInsert) {
|
||||
this.includeInInsert = includeInInsert;
|
||||
}
|
||||
|
||||
public boolean isIncludeInUpdate() {
|
||||
return includeInUpdate;
|
||||
}
|
||||
|
||||
public void setIncludeInUpdate(boolean includeInUpdate) {
|
||||
this.includeInUpdate = includeInUpdate;
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
/**
|
||||
* Contract describing the attribute binding for singular associations ({@code many-to-one}, {@code one-to-one}).
|
||||
*
|
||||
* @author Gail Badner
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@SuppressWarnings( {"JavaDoc", "UnusedDeclaration"})
|
||||
public interface SingularAssociationAttributeBinding extends SingularAttributeBinding, AssociationAttributeBinding {
|
||||
/**
|
||||
* Is this association based on a property reference (non PK column(s) as target of FK)?
|
||||
* <p/>
|
||||
* Convenience form of checking {@link #getReferencedAttributeName()} for {@code null}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isPropertyReference();
|
||||
|
||||
/**
|
||||
* Obtain the name of the referenced entity.
|
||||
*
|
||||
* @return The referenced entity name
|
||||
*/
|
||||
public String getReferencedEntityName();
|
||||
|
||||
/**
|
||||
* Set the name of the
|
||||
* @param referencedEntityName
|
||||
*/
|
||||
public void setReferencedEntityName(String referencedEntityName);
|
||||
|
||||
public String getReferencedAttributeName();
|
||||
public void setReferencedAttributeName(String referencedAttributeName);
|
||||
|
||||
|
||||
// "resolvable"
|
||||
public void resolveReference(AttributeBinding attributeBinding);
|
||||
public boolean isReferenceResolved();
|
||||
public EntityBinding getReferencedEntityBinding();
|
||||
public AttributeBinding getReferencedAttributeBinding();
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import org.hibernate.mapping.PropertyGeneration;
|
||||
import org.hibernate.metamodel.relational.Value;
|
||||
|
||||
/**
|
||||
* Specialized binding contract for singular (non-collection) attributes
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface SingularAttributeBinding extends AttributeBinding {
|
||||
/**
|
||||
* Obtain the value bound here. This could potentially be a {@link org.hibernate.metamodel.relational.Tuple}
|
||||
* indicating multiple database values are bound, in which case access to the individual values can be achieved by
|
||||
* either casting this return to {@link org.hibernate.metamodel.relational.Tuple} and using its
|
||||
* {@link org.hibernate.metamodel.relational.Tuple#values()} method or using the {@link #getSimpleValueBindings()}
|
||||
* method here and accessing each bindings {@link SimpleValueBinding#getSimpleValue simple value}
|
||||
*
|
||||
* @return The bound value
|
||||
*/
|
||||
public Value getValue();
|
||||
|
||||
/**
|
||||
* Returns the number of {@link SimpleValueBinding} objects that will be returned by
|
||||
* {@link #getSimpleValueBindings()}
|
||||
*
|
||||
* @return the number of {@link SimpleValueBinding simple value bindings}
|
||||
*
|
||||
* @see #getSimpleValueBindings()
|
||||
*/
|
||||
public int getSimpleValueSpan();
|
||||
|
||||
public Iterable<SimpleValueBinding> getSimpleValueBindings();
|
||||
|
||||
public void setSimpleValueBindings(Iterable<SimpleValueBinding> simpleValueBindings);
|
||||
|
||||
/**
|
||||
* Convenience method to determine if any {@link SimpleValueBinding simple value bindings} are derived values
|
||||
* (formula mappings).
|
||||
*
|
||||
* @return {@code true} indicates that the binding contains a derived value; {@code false} indicates it does not.
|
||||
*/
|
||||
public boolean hasDerivedValue();
|
||||
|
||||
/**
|
||||
* Convenience method to determine if all {@link SimpleValueBinding simple value bindings} allow nulls.
|
||||
*
|
||||
* @return {@code true} indicates that all values allow {@code null}; {@code false} indicates one or more do not
|
||||
*/
|
||||
public boolean isNullable();
|
||||
|
||||
/**
|
||||
* Obtain the generation strategy for this attribute/value.
|
||||
*
|
||||
* @return The generation strategy
|
||||
*/
|
||||
public PropertyGeneration getGeneration();
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.binding;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents the metamodel view of a typedef (type definition).
|
||||
*
|
||||
* @author John Verhaeg
|
||||
*/
|
||||
public class TypeDef implements Serializable {
|
||||
private final String name;
|
||||
private final String typeClass;
|
||||
private final Map<String, String> parameters;
|
||||
|
||||
public TypeDef(String name, String typeClass, Map<String, String> parameters) {
|
||||
this.name = name;
|
||||
this.typeClass = typeClass;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getTypeClass() {
|
||||
return typeClass;
|
||||
}
|
||||
|
||||
public Map<String, String> getParameters() {
|
||||
return Collections.unmodifiableMap(parameters);
|
||||
}
|
||||
}
|
|
@ -1,308 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.cfg.NotYetImplementedException;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.ValueHolder;
|
||||
|
||||
/**
|
||||
* 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 String className;
|
||||
private final ValueHolder<Class<?>> classReference;
|
||||
private final Hierarchical superType;
|
||||
private LinkedHashSet<Attribute> attributeSet = new LinkedHashSet<Attribute>();
|
||||
private HashMap<String, Attribute> attributeMap = new HashMap<String, Attribute>();
|
||||
|
||||
public AbstractAttributeContainer(String name, String className, ValueHolder<Class<?>> classReference, Hierarchical superType) {
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
this.classReference = classReference;
|
||||
this.superType = superType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getClassReference() {
|
||||
return classReference.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueHolder<Class<?>> getClassReferenceUnresolved() {
|
||||
return classReference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hierarchical getSuperType() {
|
||||
return superType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Attribute> attributes() {
|
||||
return Collections.unmodifiableSet( attributeSet );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRoleBaseName() {
|
||||
return getClassName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attribute locateAttribute(String name) {
|
||||
return attributeMap.get( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingularAttribute locateSingularAttribute(String name) {
|
||||
return (SingularAttribute) locateAttribute( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingularAttribute createSingularAttribute(String name) {
|
||||
SingularAttribute attribute = new SingularAttributeImpl( name, this );
|
||||
addAttribute( attribute );
|
||||
return attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingularAttribute createVirtualSingularAttribute(String name) {
|
||||
throw new NotYetImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingularAttribute locateComponentAttribute(String name) {
|
||||
return (SingularAttributeImpl) locateAttribute( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingularAttribute createComponentAttribute(String name, Component component) {
|
||||
SingularAttributeImpl attribute = new SingularAttributeImpl( name, this );
|
||||
attribute.resolveType( component );
|
||||
addAttribute( attribute );
|
||||
return attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluralAttribute locatePluralAttribute(String name) {
|
||||
return (PluralAttribute) locateAttribute( name );
|
||||
}
|
||||
|
||||
protected PluralAttribute createPluralAttribute(String name, PluralAttributeNature nature) {
|
||||
PluralAttribute attribute = nature.isIndexed()
|
||||
? new IndexedPluralAttributeImpl( name, nature, this )
|
||||
: new PluralAttributeImpl( name, nature, this );
|
||||
addAttribute( attribute );
|
||||
return attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluralAttribute locateBag(String name) {
|
||||
return locatePluralAttribute( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluralAttribute createBag(String name) {
|
||||
return createPluralAttribute( name, PluralAttributeNature.BAG );
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluralAttribute locateSet(String name) {
|
||||
return locatePluralAttribute( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluralAttribute createSet(String name) {
|
||||
return createPluralAttribute( name, PluralAttributeNature.SET );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexedPluralAttribute locateList(String name) {
|
||||
return (IndexedPluralAttribute) locatePluralAttribute( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexedPluralAttribute createList(String name) {
|
||||
return (IndexedPluralAttribute) createPluralAttribute( name, PluralAttributeNature.LIST );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexedPluralAttribute locateMap(String name) {
|
||||
return (IndexedPluralAttribute) locatePluralAttribute( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexedPluralAttribute createMap(String name) {
|
||||
return (IndexedPluralAttribute) createPluralAttribute( name, PluralAttributeNature.MAP );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append( "AbstractAttributeContainer" );
|
||||
sb.append( "{name='" ).append( name ).append( '\'' );
|
||||
sb.append( ", superType=" ).append( superType );
|
||||
sb.append( '}' );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected void addAttribute(Attribute attribute) {
|
||||
// todo : how to best "secure" this?
|
||||
if ( attributeMap.put( attribute.getName(), attribute ) != null ) {
|
||||
throw new IllegalArgumentException( "Attribute with name [" + attribute.getName() + "] already registered" );
|
||||
}
|
||||
attributeSet.add( attribute );
|
||||
}
|
||||
|
||||
// todo : inner classes for now..
|
||||
|
||||
public static class SingularAttributeImpl implements SingularAttribute {
|
||||
private final AttributeContainer attributeContainer;
|
||||
private final String name;
|
||||
private Type type;
|
||||
|
||||
public SingularAttributeImpl(String name, AttributeContainer attributeContainer) {
|
||||
this.name = name;
|
||||
this.attributeContainer = attributeContainer;
|
||||
}
|
||||
|
||||
public boolean isTypeResolved() {
|
||||
return type != null;
|
||||
}
|
||||
|
||||
public void resolveType(Type type) {
|
||||
if ( type == null ) {
|
||||
throw new IllegalArgumentException( "Attempt to resolve with null type" );
|
||||
}
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getSingularAttributeType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeContainer getAttributeContainer() {
|
||||
return attributeContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingular() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PluralAttributeImpl implements PluralAttribute {
|
||||
private final AttributeContainer attributeContainer;
|
||||
private final PluralAttributeNature nature;
|
||||
private final String name;
|
||||
|
||||
private Type elementType;
|
||||
|
||||
public PluralAttributeImpl(String name, PluralAttributeNature nature, AttributeContainer attributeContainer) {
|
||||
this.name = name;
|
||||
this.nature = nature;
|
||||
this.attributeContainer = attributeContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeContainer getAttributeContainer() {
|
||||
return attributeContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingular() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluralAttributeNature getNature() {
|
||||
return nature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRole() {
|
||||
return StringHelper.qualify( attributeContainer.getRoleBaseName(), name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getElementType() {
|
||||
return elementType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setElementType(Type elementType) {
|
||||
this.elementType = elementType;
|
||||
}
|
||||
}
|
||||
|
||||
public static class IndexedPluralAttributeImpl extends PluralAttributeImpl implements IndexedPluralAttribute {
|
||||
private Type indexType;
|
||||
|
||||
public IndexedPluralAttributeImpl(String name, PluralAttributeNature nature, AttributeContainer attributeContainer) {
|
||||
super( name, nature, attributeContainer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getIndexType() {
|
||||
return indexType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndexType(Type indexType) {
|
||||
this.indexType = indexType;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
/**
|
||||
* Describes 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();
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
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 {
|
||||
/**
|
||||
* Obtain the name of this container in terms of creating attribute role names.
|
||||
* <p/>
|
||||
* NOTE : A role uniquely names each attribute. The role name is the name of the attribute prefixed by the "path"
|
||||
* to its container.
|
||||
*
|
||||
* @return The container base name for role construction.
|
||||
*/
|
||||
public String getRoleBaseName();
|
||||
|
||||
/**
|
||||
* 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 locateAttribute(String name);
|
||||
|
||||
/**
|
||||
* Retrieve the attributes contained in this container.
|
||||
*
|
||||
* @return The contained attributes
|
||||
*/
|
||||
public Set<Attribute> attributes();
|
||||
|
||||
public SingularAttribute locateSingularAttribute(String name);
|
||||
public SingularAttribute createSingularAttribute(String name);
|
||||
public SingularAttribute createVirtualSingularAttribute(String name);
|
||||
|
||||
public SingularAttribute locateComponentAttribute(String name);
|
||||
public SingularAttribute createComponentAttribute(String name, Component component);
|
||||
|
||||
public PluralAttribute locatePluralAttribute(String name);
|
||||
|
||||
public PluralAttribute locateBag(String name);
|
||||
public PluralAttribute createBag(String name);
|
||||
|
||||
public PluralAttribute locateSet(String name);
|
||||
public PluralAttribute createSet(String name);
|
||||
|
||||
public IndexedPluralAttribute locateList(String name);
|
||||
public IndexedPluralAttribute createList(String name);
|
||||
|
||||
public IndexedPluralAttribute locateMap(String name);
|
||||
public IndexedPluralAttribute createMap(String name);
|
||||
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
import org.hibernate.internal.util.ValueHolder;
|
||||
|
||||
/**
|
||||
* Models a basic type.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BasicType implements Type {
|
||||
private final String name;
|
||||
private final ValueHolder<Class<?>> classReference;
|
||||
|
||||
public BasicType(String name, ValueHolder<Class<?>> classReference) {
|
||||
this.name = name;
|
||||
this.classReference = classReference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getClassReference() {
|
||||
return classReference.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueHolder<Class<?>> getClassReferenceUnresolved() {
|
||||
return classReference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssociation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComponent() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
import org.hibernate.internal.util.ValueHolder;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
public Component(String name, String className, ValueHolder<Class<?>> classReference, Hierarchical superType) {
|
||||
super( name, className, classReference, superType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssociation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComponent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRoleBaseName() {
|
||||
// todo : this is not really completely accurate atm
|
||||
// the role base here should really be the role of the component attribute.
|
||||
return getClassName();
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
import org.hibernate.internal.util.ValueHolder;
|
||||
|
||||
/**
|
||||
* Models the notion of an entity
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class Entity extends AbstractAttributeContainer {
|
||||
/**
|
||||
* Constructor for the entity
|
||||
*
|
||||
* @param entityName The name of the entity
|
||||
* @param className The name of this entity's java class
|
||||
* @param classReference The reference to this entity's {@link Class}
|
||||
* @param superType The super type for this entity. If there is not super type {@code null} needs to be passed.
|
||||
*/
|
||||
public Entity(String entityName, String className, ValueHolder<Class<?>> classReference, Hierarchical superType) {
|
||||
super( entityName, className, classReference, superType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssociation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComponent() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface IndexedPluralAttribute extends PluralAttribute {
|
||||
public Type getIndexType();
|
||||
public void setIndexType(Type indexType);
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.domain;
|
||||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.internal.util.ValueHolder;
|
||||
|
||||
/**
|
||||
* Models the naming of a Java type where we may not have access to that type's {@link Class} reference. Generally
|
||||
* speaking this is the case in various hibernate-tools and reverse-engineering use cases.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JavaType {
|
||||
private final String name;
|
||||
private final ValueHolder<Class<?>> classReference;
|
||||
|
||||
public JavaType(final String name, final ClassLoaderService classLoaderService) {
|
||||
this.name = name;
|
||||
this.classReference = new ValueHolder<Class<?>>(
|
||||
new ValueHolder.DeferredInitializer<Class<?>>() {
|
||||
@Override
|
||||
public Class<?> initialize() {
|
||||
return classLoaderService.classForName( name );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public JavaType(Class<?> theClass) {
|
||||
this.name = theClass.getName();
|
||||
this.classReference = new ValueHolder<Class<?>>( theClass );
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Class<?> getClassReference() {
|
||||
return classReference.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder( super.toString() )
|
||||
.append( "[name=" ).append( name ).append( "]" )
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
import org.hibernate.internal.util.ValueHolder;
|
||||
|
||||
/**
|
||||
* Models the concept class in the hierarchy with no persistent attributes.
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class NonEntity extends AbstractAttributeContainer {
|
||||
/**
|
||||
* Constructor for the non-entity
|
||||
*
|
||||
* @param entityName The name of the non-entity
|
||||
* @param className The name of this non-entity's java class
|
||||
* @param classReference The reference to this non-entity's {@link Class}
|
||||
* @param superType The super type for this non-entity. If there is not super type {@code null} needs to be passed.
|
||||
*/
|
||||
public NonEntity(String entityName, String className, ValueHolder<Class<?>> classReference, Hierarchical superType) {
|
||||
super( entityName, className, classReference, superType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssociation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComponent() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface PluralAttribute extends Attribute {
|
||||
public String getRole();
|
||||
public PluralAttributeNature getNature();
|
||||
public Type getElementType();
|
||||
public void setElementType(Type elementType);
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
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 ),
|
||||
IDBAG( "idbag", Collection.class ),
|
||||
SET( "set", Set.class ),
|
||||
LIST( "list", List.class ),
|
||||
MAP( "map", Map.class );
|
||||
|
||||
private final String name;
|
||||
private final Class javaContract;
|
||||
private final boolean indexed;
|
||||
|
||||
PluralAttributeNature(String name, Class javaContract) {
|
||||
this.name = name;
|
||||
this.javaContract = javaContract;
|
||||
this.indexed = Map.class.isAssignableFrom( javaContract ) || List.class.isAssignableFrom( javaContract );
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Class getJavaContract() {
|
||||
return javaContract;
|
||||
}
|
||||
|
||||
public boolean isIndexed() {
|
||||
return indexed;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
public boolean isTypeResolved();
|
||||
|
||||
public void resolveType(Type type);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
import org.hibernate.internal.util.ValueHolder;
|
||||
|
||||
/**
|
||||
* Models the concept of a (intermediate) superclass
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Superclass extends AbstractAttributeContainer {
|
||||
/**
|
||||
* Constructor for the entity
|
||||
*
|
||||
* @param entityName The name of the entity
|
||||
* @param className The name of this entity's java class
|
||||
* @param classReference The reference to this entity's {@link Class}
|
||||
* @param superType The super type for this entity. If there is not super type {@code null} needs to be passed.
|
||||
*/
|
||||
public Superclass(String entityName, String className, ValueHolder<Class<?>> classReference, Hierarchical superType) {
|
||||
super( entityName, className, classReference, superType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssociation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComponent() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.domain;
|
||||
|
||||
import org.hibernate.internal.util.ValueHolder;
|
||||
|
||||
/**
|
||||
* Basic information about a Java type, in regards to its role in particular set of mappings.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface Type {
|
||||
/**
|
||||
* Obtain the name of the type.
|
||||
*
|
||||
* @return The name
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Obtain the java class name for this type.
|
||||
*
|
||||
* @return The class name
|
||||
*/
|
||||
public String getClassName();
|
||||
|
||||
/**
|
||||
* Obtain the java {@link Class} reference for this type
|
||||
*
|
||||
* @return The {@link Class} reference
|
||||
*
|
||||
* @throws org.hibernate.boot.registry.classloading.spi.ClassLoadingException Indicates the class reference
|
||||
* could not be determined. Generally this is the case in reverse-engineering scenarios where the specified
|
||||
* domain model classes do not yet exist.
|
||||
*/
|
||||
public Class<?> getClassReference();
|
||||
|
||||
public ValueHolder<Class<?>> getClassReferenceUnresolved();
|
||||
|
||||
public boolean isAssociation();
|
||||
|
||||
public boolean isComponent();
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* 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.domain;
|
||||
|
||||
/**
|
||||
* Describes the type of a type :/
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public enum TypeNature {
|
||||
BASIC( "basic" ),
|
||||
COMPONENT( "component" ),
|
||||
ENTITY( "entity" ),
|
||||
SUPERCLASS( "superclass" ),
|
||||
NON_ENTITY( "non-entity" );
|
||||
|
||||
private final String name;
|
||||
|
||||
private TypeNature(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + "[" + getName() + "]";
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
<!--
|
||||
~ 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>
|
|
@ -1,36 +0,0 @@
|
|||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ Copyright (c) 2011, 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>
|
||||
<head></head>
|
||||
<body>
|
||||
<p>
|
||||
<i>NOTE: This package is currently unfinished and therefore considered experimental and unsupported.</i>
|
||||
</p>
|
||||
<p>
|
||||
This package defines the new Hibernate metamodel as well as the code used to build that metamodel from user sources
|
||||
(HBM mapping files, annotations, etc).
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
|
||||
/**
|
||||
* Convenience base class for {@link org.hibernate.mapping.AuxiliaryDatabaseObject}s.
|
||||
* <p/>
|
||||
* This implementation performs dialect scoping checks strictly based on
|
||||
* dialect name comparisons. Custom implementations might want to do
|
||||
* instanceof-type checks.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractAuxiliaryDatabaseObject implements AuxiliaryDatabaseObject {
|
||||
// Use a UUID in identifier prefix because this object is not qualified by a schema/catalog
|
||||
// (not sure this matters...)
|
||||
private static final String EXPORT_IDENTIFIER_PREFIX = "auxiliary-object-" + UUID.randomUUID();
|
||||
private static final AtomicInteger counter = new AtomicInteger( 0 );
|
||||
private final String exportIdentifier;
|
||||
private final Set<String> dialectScopes;
|
||||
|
||||
protected AbstractAuxiliaryDatabaseObject(Set<String> dialectScopes) {
|
||||
this.dialectScopes = dialectScopes == null ? new HashSet<String>() : dialectScopes;
|
||||
this.exportIdentifier =
|
||||
new StringBuilder( EXPORT_IDENTIFIER_PREFIX )
|
||||
.append( '.' )
|
||||
.append( counter.getAndIncrement() )
|
||||
.toString();
|
||||
}
|
||||
|
||||
public void addDialectScope(String dialectName) {
|
||||
dialectScopes.add( dialectName );
|
||||
}
|
||||
|
||||
public Iterable<String> getDialectScopes() {
|
||||
return dialectScopes;
|
||||
}
|
||||
|
||||
public boolean appliesToDialect(Dialect dialect) {
|
||||
// empty means no scoping
|
||||
return dialectScopes.isEmpty() || dialectScopes.contains( dialect.getClass().getName() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExportIdentifier() {
|
||||
return exportIdentifier;
|
||||
}
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
/*
|
||||
* 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.hibernate.AssertionFailure;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
|
||||
/**
|
||||
* Support for writing {@link Constraint} implementations
|
||||
*
|
||||
* @todo do we need to support defining these on particular schemas/catalogs?
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
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 int getColumnSpan() {
|
||||
return columns.size();
|
||||
}
|
||||
|
||||
protected List<Column> internalColumnAccess() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void addColumn(Column column) {
|
||||
internalAddColumn( column );
|
||||
}
|
||||
|
||||
protected void internalAddColumn(Column column) {
|
||||
if ( column.getTable() != getTable() ) {
|
||||
throw new AssertionFailure(
|
||||
String.format(
|
||||
"Unable to add column to constraint; tables [%s, %s] did not match",
|
||||
column.getTable().toLoggableString(),
|
||||
getTable().toLoggableString()
|
||||
)
|
||||
);
|
||||
}
|
||||
columns.add( column );
|
||||
}
|
||||
|
||||
protected boolean isCreationVetoed(Dialect dialect) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract String sqlConstraintStringInAlterTable(Dialect dialect);
|
||||
|
||||
public String[] sqlDropStrings(Dialect dialect) {
|
||||
if ( isCreationVetoed( dialect ) ) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return new String[] {
|
||||
new StringBuilder()
|
||||
.append( "alter table " )
|
||||
.append( getTable().getQualifiedName( dialect ) )
|
||||
.append( " drop constraint " )
|
||||
.append( dialect.quote( getName() ) )
|
||||
.toString()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public String[] sqlCreateStrings(Dialect dialect) {
|
||||
if ( isCreationVetoed( dialect ) ) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return new String[] {
|
||||
new StringBuilder( "alter table " )
|
||||
.append( getTable().getQualifiedName( dialect ) )
|
||||
.append( sqlConstraintStringInAlterTable( dialect ) )
|
||||
.toString()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* 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.internal.CoreMessageLogger;
|
||||
import org.hibernate.metamodel.ValidationException;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Basic support for {@link SimpleValue} implementations.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractSimpleValue implements SimpleValue {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, AbstractSimpleValue.class.getName());
|
||||
|
||||
private final TableSpecification table;
|
||||
private final int position;
|
||||
private Datatype datatype;
|
||||
|
||||
protected AbstractSimpleValue(TableSpecification table, int position) {
|
||||
this.table = table;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableSpecification getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Datatype getDatatype() {
|
||||
return datatype;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDatatype(Datatype datatype) {
|
||||
LOG.debugf( "setting datatype for column %s : %s", toLoggableString(), datatype );
|
||||
if ( this.datatype != null && ! this.datatype.equals( datatype ) ) {
|
||||
LOG.debugf( "overriding previous datatype : %s", this.datatype );
|
||||
}
|
||||
this.datatype = datatype;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateJdbcTypes(JdbcCodes typeCodes) {
|
||||
// todo : better compatibility testing...
|
||||
if ( datatype.getTypeCode() != typeCodes.nextJdbcCde() ) {
|
||||
throw new ValidationException( "Mismatched types" );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* 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.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Convenience base class for implementing the {@link ValueContainer} contract centralizing commonality
|
||||
* between modeling tables, views and inline views.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractTableSpecification implements TableSpecification {
|
||||
private final static AtomicInteger tableCounter = new AtomicInteger( 0 );
|
||||
private final int tableNumber;
|
||||
|
||||
private final LinkedHashMap<String, SimpleValue> values = new LinkedHashMap<String, SimpleValue>();
|
||||
|
||||
private final PrimaryKey primaryKey = new PrimaryKey( this );
|
||||
private final List<ForeignKey> foreignKeys = new ArrayList<ForeignKey>();
|
||||
|
||||
public AbstractTableSpecification() {
|
||||
this.tableNumber = tableCounter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTableNumber() {
|
||||
return tableNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<SimpleValue> values() {
|
||||
return values.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Column locateOrCreateColumn(String name) {
|
||||
if(values.containsKey( name )){
|
||||
return (Column) values.get( name );
|
||||
}
|
||||
final Column column = new Column( this, values.size(), name );
|
||||
values.put( name, column );
|
||||
return column;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DerivedValue locateOrCreateDerivedValue(String fragment) {
|
||||
if(values.containsKey( fragment )){
|
||||
return (DerivedValue) values.get( fragment );
|
||||
}
|
||||
final DerivedValue value = new DerivedValue( this, values.size(), fragment );
|
||||
values.put( fragment, value );
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tuple createTuple(String name) {
|
||||
return new Tuple( this, name );
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryKey getPrimaryKey() {
|
||||
return primaryKey;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.io.Serializable;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
|
||||
/**
|
||||
* Auxiliary database objects (i.e., triggers, stored procedures, etc) defined
|
||||
* in the mappings. Allows Hibernate to manage their lifecycle as part of
|
||||
* creating/dropping the schema.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface AuxiliaryDatabaseObject extends Exportable, Serializable {
|
||||
/**
|
||||
* Does this database object apply to the given dialect?
|
||||
*
|
||||
* @param dialect The dialect to check against.
|
||||
* @return True if this database object does apply to the given dialect.
|
||||
*/
|
||||
boolean appliesToDialect(Dialect dialect);
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, 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.util.Set;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class BasicAuxiliaryDatabaseObjectImpl extends AbstractAuxiliaryDatabaseObject {
|
||||
private static final String CATALOG_NAME_PLACEHOLDER = "${catalog}";
|
||||
private static final String SCHEMA_NAME_PLACEHOLDER = "${schema}";
|
||||
private final Schema defaultSchema;
|
||||
private final String createString;
|
||||
private final String dropString;
|
||||
|
||||
public BasicAuxiliaryDatabaseObjectImpl(
|
||||
Schema defaultSchema,
|
||||
String createString,
|
||||
String dropString,
|
||||
Set<String> dialectScopes) {
|
||||
super( dialectScopes );
|
||||
// keep track of the default schema and the raw create/drop strings;
|
||||
// we may want to allow copying into a database with a different default schema in the future;
|
||||
this.defaultSchema = defaultSchema;
|
||||
this.createString = createString;
|
||||
this.dropString = dropString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] sqlCreateStrings(Dialect dialect) {
|
||||
return new String[] { injectCatalogAndSchema( createString, defaultSchema ) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] sqlDropStrings(Dialect dialect) {
|
||||
return new String[] { injectCatalogAndSchema( dropString, defaultSchema ) };
|
||||
}
|
||||
|
||||
private static String injectCatalogAndSchema(String ddlString, Schema schema) {
|
||||
String rtn = StringHelper.replace( ddlString, CATALOG_NAME_PLACEHOLDER, schema.getName().getCatalog().getName() );
|
||||
rtn = StringHelper.replace( rtn, SCHEMA_NAME_PLACEHOLDER, schema.getName().getSchema().getName() );
|
||||
return rtn;
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class CheckConstraint {
|
||||
private final Table table;
|
||||
private String name;
|
||||
private String condition;
|
||||
|
||||
public CheckConstraint(Table table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
public CheckConstraint(Table table, String name, String condition) {
|
||||
this.table = table;
|
||||
this.name = name;
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public void setCondition(String condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the table to which this constraint applies.
|
||||
*
|
||||
* @return The constrained table.
|
||||
*/
|
||||
public Table getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the constraint name.
|
||||
*
|
||||
* @return the name.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -1,195 +0,0 @@
|
|||
/*
|
||||
* 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.MappingException;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.metamodel.relational.state.ColumnRelationalState;
|
||||
|
||||
/**
|
||||
* Models a physical column
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Column extends AbstractSimpleValue {
|
||||
private final Identifier columnName;
|
||||
private boolean nullable;
|
||||
private boolean unique;
|
||||
|
||||
private String defaultValue;
|
||||
private String checkCondition;
|
||||
private String sqlType;
|
||||
|
||||
private String readFragment;
|
||||
private String writeFragment;
|
||||
|
||||
private String comment;
|
||||
|
||||
private Size size = new Size();
|
||||
|
||||
protected Column(TableSpecification table, int position, String name) {
|
||||
this( table, position, Identifier.toIdentifier( name ) );
|
||||
}
|
||||
|
||||
protected Column(TableSpecification table, int position, Identifier name) {
|
||||
super( table, position );
|
||||
this.columnName = name;
|
||||
}
|
||||
|
||||
public void initialize(ColumnRelationalState state, boolean forceNonNullable, boolean forceUnique) {
|
||||
size.initialize( state.getSize() );
|
||||
nullable = ! forceNonNullable && state.isNullable();
|
||||
unique = ! forceUnique && state.isUnique();
|
||||
checkCondition = state.getCheckCondition();
|
||||
defaultValue = state.getDefault();
|
||||
sqlType = state.getSqlType();
|
||||
|
||||
// TODO: this should go into binding instead (I think???)
|
||||
writeFragment = state.getCustomWriteFragment();
|
||||
readFragment = state.getCustomReadFragment();
|
||||
comment = state.getComment();
|
||||
for ( String uniqueKey : state.getUniqueKeys() ) {
|
||||
getTable().getOrCreateUniqueKey( uniqueKey ).addColumn( this );
|
||||
}
|
||||
for ( String index : state.getIndexes() ) {
|
||||
getTable().getOrCreateIndex( index ).addColumn( this );
|
||||
}
|
||||
}
|
||||
|
||||
public Identifier getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public boolean isNullable() {
|
||||
return nullable;
|
||||
}
|
||||
|
||||
public void setNullable(boolean nullable) {
|
||||
this.nullable = nullable;
|
||||
}
|
||||
|
||||
public boolean isUnique() {
|
||||
return unique;
|
||||
}
|
||||
|
||||
public void setUnique(boolean unique) {
|
||||
this.unique = unique;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public String getCheckCondition() {
|
||||
return checkCondition;
|
||||
}
|
||||
|
||||
public void setCheckCondition(String checkCondition) {
|
||||
this.checkCondition = checkCondition;
|
||||
}
|
||||
|
||||
public String getSqlType() {
|
||||
return sqlType;
|
||||
}
|
||||
|
||||
public void setSqlType(String sqlType) {
|
||||
this.sqlType = sqlType;
|
||||
}
|
||||
|
||||
public String getReadFragment() {
|
||||
return readFragment;
|
||||
}
|
||||
|
||||
public void setReadFragment(String readFragment) {
|
||||
this.readFragment = readFragment;
|
||||
}
|
||||
|
||||
public String getWriteFragment() {
|
||||
return writeFragment;
|
||||
}
|
||||
|
||||
public void setWriteFragment(String writeFragment) {
|
||||
this.writeFragment = writeFragment;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public Size getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(Size size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toLoggableString() {
|
||||
return getTable().getLoggableValueQualifier() + '.' + getColumnName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlias(Dialect dialect) {
|
||||
String alias = columnName.getName();
|
||||
int lastLetter = StringHelper.lastIndexOfLetter( columnName.getName() );
|
||||
if ( lastLetter == -1 ) {
|
||||
alias = "column";
|
||||
}
|
||||
boolean useRawName =
|
||||
columnName.getName().equals( alias ) &&
|
||||
alias.length() <= dialect.getMaxAliasLength() &&
|
||||
! columnName.isQuoted() &&
|
||||
! columnName.getName().toLowerCase().equals( "rowid" );
|
||||
if ( ! useRawName ) {
|
||||
String unique =
|
||||
new StringBuilder()
|
||||
.append( getPosition() )
|
||||
.append( '_' )
|
||||
.append( getTable().getTableNumber() )
|
||||
.append( '_' )
|
||||
.toString();
|
||||
if ( unique.length() >= dialect.getMaxAliasLength() ) {
|
||||
throw new MappingException(
|
||||
"Unique suffix [" + unique + "] length must be less than maximum [" + dialect.getMaxAliasLength() + "]"
|
||||
);
|
||||
}
|
||||
if ( alias.length() + unique.length() > dialect.getMaxAliasLength()) {
|
||||
alias = alias.substring( 0, dialect.getMaxAliasLength() - unique.length() );
|
||||
}
|
||||
alias = alias + unique;
|
||||
}
|
||||
return alias;
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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 extends Exportable {
|
||||
/**
|
||||
* 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();
|
||||
}
|
|
@ -1,224 +0,0 @@
|
|||
/*
|
||||
* 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.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.metamodel.Metadata;
|
||||
|
||||
/**
|
||||
* Represents a database and manages the named schema/catalog pairs defined within.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class Database {
|
||||
private final Schema.Name implicitSchemaName;
|
||||
|
||||
private final Map<Schema.Name,Schema> schemaMap = new HashMap<Schema.Name, Schema>();
|
||||
private final List<AuxiliaryDatabaseObject> auxiliaryDatabaseObjects = new ArrayList<AuxiliaryDatabaseObject>();
|
||||
|
||||
public Database(Metadata.Options options) {
|
||||
String schemaName = options.getDefaultSchemaName();
|
||||
String catalogName = options.getDefaultCatalogName();
|
||||
if ( options.isGloballyQuotedIdentifiers() ) {
|
||||
schemaName = StringHelper.quote( schemaName );
|
||||
catalogName = StringHelper.quote( catalogName );
|
||||
}
|
||||
implicitSchemaName = new Schema.Name( schemaName, catalogName );
|
||||
makeSchema( implicitSchemaName );
|
||||
}
|
||||
|
||||
public Schema getDefaultSchema() {
|
||||
return schemaMap.get( implicitSchemaName );
|
||||
}
|
||||
|
||||
public Schema locateSchema(Schema.Name name) {
|
||||
if ( name.getSchema() == null && name.getCatalog() == null ) {
|
||||
return getDefaultSchema();
|
||||
}
|
||||
Schema schema = schemaMap.get( name );
|
||||
if ( schema == null ) {
|
||||
schema = makeSchema( name );
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
|
||||
private Schema makeSchema(Schema.Name name) {
|
||||
Schema schema;
|
||||
schema = new Schema( name );
|
||||
schemaMap.put( name, schema );
|
||||
return schema;
|
||||
}
|
||||
|
||||
public Schema getSchema(Identifier schema, Identifier catalog) {
|
||||
return locateSchema( new Schema.Name( schema, catalog ) );
|
||||
}
|
||||
|
||||
public Schema getSchema(String schema, String catalog) {
|
||||
return locateSchema( new Schema.Name( Identifier.toIdentifier( schema ), Identifier.toIdentifier( catalog ) ) );
|
||||
}
|
||||
|
||||
public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject) {
|
||||
if ( auxiliaryDatabaseObject == null ) {
|
||||
throw new IllegalArgumentException( "Auxiliary database object is null." );
|
||||
}
|
||||
auxiliaryDatabaseObjects.add( auxiliaryDatabaseObject );
|
||||
}
|
||||
|
||||
public Iterable<AuxiliaryDatabaseObject> getAuxiliaryDatabaseObjects() {
|
||||
return auxiliaryDatabaseObjects;
|
||||
}
|
||||
|
||||
public String[] generateSchemaCreationScript(Dialect dialect) {
|
||||
Set<String> exportIdentifiers = new HashSet<String>( 50 );
|
||||
List<String> script = new ArrayList<String>( 50 );
|
||||
|
||||
for ( Schema schema : schemaMap.values() ) {
|
||||
// TODO: create schema/catalog???
|
||||
for ( Table table : schema.getTables() ) {
|
||||
addSqlCreateStrings( dialect, exportIdentifiers, script, table );
|
||||
}
|
||||
}
|
||||
|
||||
for ( Schema schema : schemaMap.values() ) {
|
||||
for ( Table table : schema.getTables() ) {
|
||||
|
||||
for ( UniqueKey uniqueKey : table.getUniqueKeys() ) {
|
||||
addSqlCreateStrings( dialect, exportIdentifiers, script, uniqueKey );
|
||||
}
|
||||
|
||||
for ( Index index : table.getIndexes() ) {
|
||||
addSqlCreateStrings( dialect, exportIdentifiers, script, index );
|
||||
}
|
||||
|
||||
if ( dialect.hasAlterTable() ) {
|
||||
for ( ForeignKey foreignKey : table.getForeignKeys() ) {
|
||||
// only add the foreign key if its target is a physical table
|
||||
if ( Table.class.isInstance( foreignKey.getTargetTable() ) ) {
|
||||
addSqlCreateStrings( dialect, exportIdentifiers, script, foreignKey );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add sql create strings from PersistentIdentifierGenerator.sqlCreateStrings()
|
||||
|
||||
for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : auxiliaryDatabaseObjects ) {
|
||||
if ( auxiliaryDatabaseObject.appliesToDialect( dialect ) ) {
|
||||
addSqlCreateStrings( dialect, exportIdentifiers, script, auxiliaryDatabaseObject );
|
||||
}
|
||||
}
|
||||
|
||||
return ArrayHelper.toStringArray( script );
|
||||
}
|
||||
|
||||
public String[] generateDropSchemaScript(Dialect dialect) {
|
||||
Set<String> exportIdentifiers = new HashSet<String>( 50 );
|
||||
List<String> script = new ArrayList<String>( 50 );
|
||||
|
||||
|
||||
// drop them in reverse order in case db needs it done that way...
|
||||
for ( int i = auxiliaryDatabaseObjects.size() - 1 ; i >= 0 ; i-- ) {
|
||||
AuxiliaryDatabaseObject object = auxiliaryDatabaseObjects.get( i );
|
||||
if ( object.appliesToDialect( dialect ) ) {
|
||||
addSqlDropStrings( dialect, exportIdentifiers, script, object );
|
||||
}
|
||||
}
|
||||
|
||||
if ( dialect.dropConstraints() ) {
|
||||
for ( Schema schema : schemaMap.values() ) {
|
||||
for ( Table table : schema.getTables() ) {
|
||||
for ( ForeignKey foreignKey : table.getForeignKeys() ) {
|
||||
// only include foreign key if the target table is physical
|
||||
if ( foreignKey.getTargetTable() instanceof Table ) {
|
||||
addSqlDropStrings( dialect, exportIdentifiers, script, foreignKey );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( Schema schema : schemaMap.values() ) {
|
||||
for ( Table table : schema.getTables() ) {
|
||||
addSqlDropStrings( dialect, exportIdentifiers, script, table );
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add sql drop strings from PersistentIdentifierGenerator.sqlCreateStrings()
|
||||
|
||||
// TODO: drop schemas/catalogs???
|
||||
|
||||
return ArrayHelper.toStringArray( script );
|
||||
}
|
||||
|
||||
private static void addSqlDropStrings(
|
||||
Dialect dialect,
|
||||
Set<String> exportIdentifiers,
|
||||
List<String> script,
|
||||
Exportable exportable) {
|
||||
addSqlStrings(
|
||||
exportIdentifiers, script, exportable.getExportIdentifier(), exportable.sqlDropStrings( dialect )
|
||||
);
|
||||
}
|
||||
|
||||
private static void addSqlCreateStrings(
|
||||
Dialect dialect,
|
||||
Set<String> exportIdentifiers,
|
||||
List<String> script,
|
||||
Exportable exportable) {
|
||||
addSqlStrings(
|
||||
exportIdentifiers, script, exportable.getExportIdentifier(), exportable.sqlCreateStrings( dialect )
|
||||
);
|
||||
}
|
||||
|
||||
private static void addSqlStrings(
|
||||
Set<String> exportIdentifiers,
|
||||
List<String> script,
|
||||
String exportIdentifier,
|
||||
String[] sqlStrings) {
|
||||
if ( sqlStrings == null ) {
|
||||
return;
|
||||
}
|
||||
if ( exportIdentifiers.contains( exportIdentifier ) ) {
|
||||
throw new MappingException(
|
||||
"SQL strings added more than once for: " + exportIdentifier
|
||||
);
|
||||
}
|
||||
exportIdentifiers.add( exportIdentifier );
|
||||
script.addAll( Arrays.asList( sqlStrings ) );
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
if ( typeName != null ) {
|
||||
result = 31 * result + typeName.hashCode();
|
||||
}
|
||||
if ( javaType != null ) {
|
||||
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() + "]";
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* 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.dialect.Dialect;
|
||||
|
||||
/**
|
||||
* Models a value expression. It is the result of a <tt>formula</tt> mapping.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DerivedValue extends AbstractSimpleValue {
|
||||
private final String expression;
|
||||
|
||||
public DerivedValue(TableSpecification table, int position, String expression) {
|
||||
super( table, position );
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toLoggableString() {
|
||||
return getTable().toLoggableString() + ".{derived-column}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlias(Dialect dialect) {
|
||||
return "formula" + Integer.toString( getPosition() ) + '_';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value expression.
|
||||
* @return the value expression
|
||||
*/
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* 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.dialect.Dialect;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Gets the SQL strings for creating the database object.
|
||||
*
|
||||
* @param dialect The dialect for which to generate the SQL creation strings
|
||||
*
|
||||
* @return the SQL strings for creating the database object.
|
||||
*/
|
||||
public String[] sqlCreateStrings(Dialect dialect);
|
||||
|
||||
/**
|
||||
* Gets the SQL strings for dropping the database object.
|
||||
*
|
||||
* @param dialect The dialect for which to generate the SQL drop strings
|
||||
*
|
||||
* @return the SQL strings for dropping the database object.
|
||||
*/
|
||||
public String[] sqlDropStrings(Dialect dialect);
|
||||
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
/*
|
||||
* 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.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* 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 = Logger.getLogger( ForeignKey.class );
|
||||
|
||||
private static final String ON_DELETE = " on delete ";
|
||||
private static final String ON_UPDATE = " on update ";
|
||||
|
||||
private final TableSpecification targetTable;
|
||||
private List<Column> targetColumns;
|
||||
|
||||
private ReferentialAction deleteRule = ReferentialAction.NO_ACTION;
|
||||
private ReferentialAction updateRule = ReferentialAction.NO_ACTION;
|
||||
|
||||
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 ) {
|
||||
LOG.debugf(
|
||||
"Attempt to map column [%s] to no target column after explicit target column(s) named for FK [name=%s]",
|
||||
sourceColumn.toLoggableString(),
|
||||
getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
checkTargetTable( targetColumn );
|
||||
if ( targetColumns == null ) {
|
||||
if (!internalColumnAccess().isEmpty()) {
|
||||
LOG.debugf(
|
||||
"Value mapping mismatch as part of FK [table=%s, name=%s] while adding source column [%s]",
|
||||
getTable().toLoggableString(),
|
||||
getName(),
|
||||
sourceColumn.toLoggableString()
|
||||
);
|
||||
}
|
||||
targetColumns = new ArrayList<Column>();
|
||||
}
|
||||
targetColumns.add( targetColumn );
|
||||
}
|
||||
internalAddColumn( sourceColumn );
|
||||
}
|
||||
|
||||
private void checkTargetTable(Column targetColumn) {
|
||||
if ( targetColumn.getTable() != getTargetTable() ) {
|
||||
throw new AssertionFailure(
|
||||
String.format(
|
||||
"Unable to add column to constraint; tables [%s, %s] did not match",
|
||||
targetColumn.getTable().toLoggableString(),
|
||||
getTargetTable().toLoggableString()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExportIdentifier() {
|
||||
return getSourceTable().getLoggableValueQualifier() + ".FK-" + getName();
|
||||
}
|
||||
|
||||
public ReferentialAction getDeleteRule() {
|
||||
return deleteRule;
|
||||
}
|
||||
|
||||
public void setDeleteRule(ReferentialAction deleteRule) {
|
||||
this.deleteRule = deleteRule;
|
||||
}
|
||||
|
||||
public ReferentialAction getUpdateRule() {
|
||||
return updateRule;
|
||||
}
|
||||
|
||||
public void setUpdateRule(ReferentialAction updateRule) {
|
||||
this.updateRule = updateRule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] sqlDropStrings(Dialect dialect) {
|
||||
return new String[] {
|
||||
"alter table " +
|
||||
getTable().getQualifiedName( dialect ) +
|
||||
dialect.getDropForeignKeyString() +
|
||||
getName()
|
||||
};
|
||||
}
|
||||
|
||||
public String sqlConstraintStringInAlterTable(Dialect dialect) {
|
||||
String[] columnNames = new String[ getColumnSpan() ];
|
||||
String[] targetColumnNames = new String[ getColumnSpan() ];
|
||||
int i=0;
|
||||
Iterator<Column> itTargetColumn = getTargetColumns().iterator();
|
||||
for ( Column column : getColumns() ) {
|
||||
if ( ! itTargetColumn.hasNext() ) {
|
||||
throw new MappingException( "More constraint columns that foreign key target columns." );
|
||||
}
|
||||
columnNames[i] = column.getColumnName().encloseInQuotesIfQuoted( dialect );
|
||||
targetColumnNames[i] = ( itTargetColumn.next() ).getColumnName().encloseInQuotesIfQuoted( dialect );
|
||||
i++;
|
||||
}
|
||||
if ( itTargetColumn.hasNext() ) {
|
||||
throw new MappingException( "More foreign key target columns than constraint columns." );
|
||||
}
|
||||
StringBuilder sb =
|
||||
new StringBuilder(
|
||||
dialect.getAddForeignKeyConstraintString(
|
||||
getName(),
|
||||
columnNames,
|
||||
targetTable.getQualifiedName( dialect ),
|
||||
targetColumnNames,
|
||||
this.targetColumns == null
|
||||
)
|
||||
);
|
||||
// TODO: If a dialect does not support cascade-delete, can it support other actions? (HHH-6428)
|
||||
// For now, assume not.
|
||||
if ( dialect.supportsCascadeDelete() ) {
|
||||
if ( deleteRule != ReferentialAction.NO_ACTION ) {
|
||||
sb.append( ON_DELETE ).append( deleteRule.getActionString() );
|
||||
}
|
||||
if ( updateRule != ReferentialAction.NO_ACTION ) {
|
||||
sb.append( ON_UPDATE ).append( updateRule.getActionString() );
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static enum ReferentialAction {
|
||||
NO_ACTION( "no action" ),
|
||||
CASCADE( "cascade" ),
|
||||
SET_NULL( "set null" ),
|
||||
SET_DEFAULT( "set default" ),
|
||||
RESTRICT( "restrict" );
|
||||
|
||||
private final String actionString;
|
||||
|
||||
private ReferentialAction(String actionString) {
|
||||
this.actionString = actionString;
|
||||
}
|
||||
|
||||
public String getActionString() {
|
||||
return actionString;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
/*
|
||||
* 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.dialect.Dialect;
|
||||
import org.hibernate.internal.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 The identifier form of the name.
|
||||
*/
|
||||
public static Identifier toIdentifier(String name) {
|
||||
if ( StringHelper.isEmpty( name ) ) {
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this is a quoted identifier, then return the identifier name
|
||||
* enclosed in dialect-specific open- and end-quotes; otherwise,
|
||||
* simply return the identifier name.
|
||||
*
|
||||
* @param dialect The dialect whose dialect-specific quoting should be used.
|
||||
* @return if quoted, identifier name enclosed in dialect-specific open- and end-quotes; otherwise, the
|
||||
* identifier name.
|
||||
*/
|
||||
public String encloseInQuotesIfQuoted(Dialect dialect) {
|
||||
return isQuoted ?
|
||||
new StringBuilder( name.length() + 2 )
|
||||
.append( dialect.openQuote() )
|
||||
.append( name )
|
||||
.append( dialect.closeQuote() )
|
||||
.toString() :
|
||||
name;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue