Refine search
@Test public void testProperCallbacks() { PersistentClassVisitorValidator vv = new PersistentClassVisitorValidator(); new RootClass( metadataBuildingContext ).accept( vv ); new Subclass( new RootClass( metadataBuildingContext ), metadataBuildingContext ).accept( vv ); new JoinedSubclass( new RootClass( metadataBuildingContext ), metadataBuildingContext ).accept( vv ); new SingleTableSubclass( new RootClass( metadataBuildingContext ), metadataBuildingContext ).accept( vv ); new UnionSubclass( new RootClass( metadataBuildingContext ), metadataBuildingContext ).accept( vv ); }
final IdentifierSourceSimple idSource = (IdentifierSourceSimple) hierarchySource.getIdentifierSource(); final SimpleValue idValue = new SimpleValue( sourceDocument, rootEntityDescriptor.getTable() ); rootEntityDescriptor.setIdentifier( idValue ); if ( propertyName == null || !rootEntityDescriptor.hasPojoRepresentation() ) { if ( !idValue.isTypeSpecified() ) { throw new MappingException( "must specify an identifier type: " + rootEntityDescriptor.getEntityName(), sourceDocument.getOrigin() ); idValue.setTypeUsingReflection( rootEntityDescriptor.getClassName(), propertyName ); Property prop = new Property(); prop.setValue( idValue ); bindProperty( sourceDocument, prop ); rootEntityDescriptor.setIdentifierProperty( prop ); rootEntityDescriptor.setDeclaredIdentifierProperty( prop );
rootEntityDescriptor.setIdentifier( cid ); cid, idClassName, rootEntityDescriptor.getClassName(), null, idClassName == null, identifierSource.getEmbeddableSource(), mapper, rootEntityDescriptor.getClassName(), null, null, ); rootEntityDescriptor.setIdentifierMapper(mapper); Property property = new Property(); property.setName( PropertyPath.IDENTIFIER_MAPPER_PROPERTY ); property.setUpdateable( false ); property.setInsertable( false ); property.setValue( mapper ); property.setPropertyAccessorName( "embedded" ); rootEntityDescriptor.addProperty( property );
@Override public void validate(Mapping mapping) throws MappingException { super.validate( mapping ); if ( !getIdentifier().isValid( mapping ) ) { throw new MappingException( "identifier mapping has wrong number of columns: " + getEntityName() + " type: " + getIdentifier().getType().getName() ); } checkCompositeIdentifier(); }
private static void bindDiscriminatorColumnToRootPersistentClass( RootClass rootClass, Ejb3DiscriminatorColumn discriminatorColumn, Map<String, Join> secondaryTables, PropertyHolder propertyHolder, MetadataBuildingContext context) { if ( rootClass.getDiscriminator() == null ) { if ( discriminatorColumn == null ) { throw new AssertionFailure( "discriminator column should have been built" ); } discriminatorColumn.setJoins( secondaryTables ); discriminatorColumn.setPropertyHolder( propertyHolder ); SimpleValue discriminatorColumnBinding = new SimpleValue( context, rootClass.getTable() ); rootClass.setDiscriminator( discriminatorColumnBinding ); discriminatorColumn.linkWithValue( discriminatorColumnBinding ); discriminatorColumnBinding.setTypeName( discriminatorColumn.getDiscriminatorTypeName() ); rootClass.setPolymorphic( true ); if ( LOG.isTraceEnabled() ) { LOG.tracev( "Setting discriminator for entity {0}", rootClass.getEntityName() ); } } }
Component identifier = (Component) rootClass.getIdentifier(); if (identifier == null) { identifier = AnnotationBinder.createComponent( buildingContext ); rootClass.setIdentifier( identifier ); identifier.setNullValue( "undefined" ); rootClass.setEmbeddedIdentifier( true ); rootClass.setIdentifierMapper( identifier ); rootClass.setIdentifier( ( KeyValue ) getValue() ); if (embedded) { rootClass.setEmbeddedIdentifier( true ); rootClass.setIdentifierProperty( prop ); final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull( declaringClass, rootClass.setDeclaredIdentifierProperty( prop );
this.sessionFactory = sessionFactory; name = persistentClass.getEntityName(); rootName = persistentClass.getRootClass().getEntityName(); ); versioned = persistentClass.isVersioned(); if ( persistentClass.hasPojoRepresentation() ) { if ( prop.isNaturalIdentifier() ) { naturalIdNumbers.add( i ); if ( prop.isUpdateable() ) { foundUpdateableNaturalIdProperty = true; if ( "id".equals( prop.getName() ) ) { foundNonIdentifierPropertyNamedId = true;
public void bindEntity() { persistentClass.setAbstract( annotatedClass.isAbstract() ); persistentClass.setClassName( annotatedClass.getName() ); persistentClass.setJpaEntityName(name); persistentClass.setEntityName( annotatedClass.getName() ); rootClass.setMutable( mutable ); rootClass.setExplicitPolymorphism( isExplicitPolymorphism( polymorphismType ) ); rootClass.setWhere( where ); rootClass.setCacheConcurrencyStrategy( cacheConcurrentStrategy ); rootClass.setCacheRegionName( cacheRegion ); rootClass.setLazyPropertiesCacheable( cacheLazyProperty ); rootClass.setNaturalIdCacheRegionName( naturalIdCacheRegion ); : forceDiscriminator; rootClass.setForceDiscriminator( forceDiscriminatorInSelects ); rootClass.setDiscriminatorInsertable( insertableDiscriminator );
RootClass rc = new RootClass(mdbc); TableIdentifier tableIdentifier = TableIdentifier.create(table); String className = revengStrategy.tableToClassName( tableIdentifier ); log.debug("Building entity " + className + " based on " + tableIdentifier); rc.setEntityName( className ); rc.setJpaEntityName( StringHelper.unqualify( className ) ); rc.setClassName( className ); rc.setProxyInterfaceName( rc.getEntityName() ); // TODO: configurable ? rc.setLazy(true); rc.setMetaAttributes( BinderUtils.safeMap( RevEngUtils.getTableToMetaAttributesInRevengStrategy( rc.setDiscriminatorValue( rc.getEntityName() ); rc.setTable(table); try { metadataCollector.addEntityBinding(rc); Table table2 = class1.getTable(); throw new JDBCBinderException("Duplicate class name '" + rc.getEntityName() + "' generated for '" + table + "'. Same name where generated for '" + table2 + "'"); metadataCollector.addImport( rc.getEntityName(), rc.getEntityName() ); bindOutgoingForeignKeys(table, rc, processed); bindColumnsToProperties(table, rc, processed, mapping); List<ForeignKey> incomingForeignKeys = manyToOneCandidates.get( rc.getEntityName() ); bindIncomingForeignKeys(rc, processed, incomingForeignKeys, mapping); updatePrimaryKey(rc, pki);
public void bindEntity() { persistentClass.setAbstract( annotatedClass.isAbstract() ); persistentClass.setClassName( annotatedClass.getName() ); persistentClass.setNodeName( name ); persistentClass.setEntityName( annotatedClass.getName() ); rootClass.setMutable( mutable ); rootClass.setExplicitPolymorphism( isExplicitPolymorphism( polymorphismType ) ); if ( StringHelper.isNotEmpty( where ) ) rootClass.setWhere( where ); if ( cacheConcurrentStrategy != null ) { rootClass.setCacheConcurrencyStrategy( cacheConcurrentStrategy ); rootClass.setCacheRegionName( cacheRegion ); rootClass.setLazyPropertiesCacheable( cacheLazyProperty ); rootClass.setForceDiscriminator( annotatedClass.isAnnotationPresent( ForceDiscriminator.class ) );
Property prop = propertyBinder.makePropertyValueAndBind(); setVersionInformation( property, propertyBinder ); rootClass.setVersion( prop ); rootClass.setDeclaredVersion( prop ); SimpleValue simpleValue = ( SimpleValue ) prop.getValue(); simpleValue.setNullValue( "undefined" ); rootClass.setOptimisticLockStyle( OptimisticLockStyle.VERSION ); if ( traceEnabled ) { LOG.tracev( "Version name: {0}, unsavedValue: {1}", rootClass.getVersion().getName(), ( (SimpleValue) rootClass.getVersion().getValue() ).getNullValue() ); Join join = propertyHolder.addJoin( assocTable, false ); for ( Ejb3JoinColumn joinColumn : joinColumns ) { joinColumn.setExplicitTableName( join.getTable().getName() ); Join join = propertyHolder.addJoin( assocTable, false ); for ( Ejb3JoinColumn joinColumn : joinColumns ) { joinColumn.setExplicitTableName( join.getTable().getName() ); Join join = propertyHolder.addJoin( assocTable, false ); for ( Ejb3JoinColumn joinColumn : joinColumns ) { joinColumn.setExplicitTableName( join.getTable().getName() );
tab.setPrimaryKey(primaryKey); id.setIdentifierGeneratorStrategy("assigned"); id.setNullValue("undefined"); tab.getPrimaryKey().addColumn(col); clazz.addProperty(prop); prop.setPropertyAccessorName(mappings.getDefaultAccess()); prop.setInsertable(false); prop.setUpdateable(false); tab.setIdentifierValue(id); clazz.setIdentifier(id); clazz.setIdentifierProperty(prop); clazz.setDiscriminatorValue(mdTable.getQualifiedName());
@Override protected void afterMetadataBuilt(Metadata metadata) { if (addVersions) { for (PersistentClass clazz : metadata.getEntityBindings()) { if (clazz.getVersion() != null) { continue; } try { clazz.getMappedClass().getMethod("getVersion"); clazz.getMappedClass().getMethod("setVersion", long.class); } catch (NoSuchMethodException e) { continue; } RootClass rootClazz = clazz.getRootClass(); Property versionProperty = new Property(); versionProperty.setName("version"); SimpleValue value = new SimpleValue((MetadataImplementor) metadata, rootClazz.getTable()); value.setTypeName("long"); Column column = new Column(); column.setValue(value); column.setName("version"); value.addColumn(column); rootClazz.getTable().addColumn(column); versionProperty.setValue(value); rootClazz.setVersion(versionProperty); rootClazz.addProperty(versionProperty); } } }
SimpleValue id = new SimpleValue(mappings, entity.getTable()); entity.setIdentifier(id); id.setIdentifierGeneratorStrategy("native"); } else { id.setIdentifierGeneratorStrategy(mappedId.getGenerator()); params.putAll(mappedId.getParams()); if ("assigned".equals(mappedId.getGenerator())) { Property prop = new Property(); prop.setValue(id); entity.setIdentifierProperty(prop); id.getTable().setIdentifierValue(id);
private static void bindVersioningProperty(Table table, Element subnode, Mappings mappings, String name, RootClass entity, java.util.Map inheritedMetas) { String propertyName = subnode.attributeValue( "name" ); SimpleValue val = new SimpleValue( table ); bindSimpleValue( subnode, val, false, propertyName, mappings ); if ( !val.isTypeSpecified() ) { val.setTypeName( "version".equals( name ) ? "integer" : "timestamp" ); } Property prop = new Property(); prop.setValue( val ); bindProperty( subnode, prop, mappings, inheritedMetas ); makeVersion( subnode, val ); entity.setVersion( prop ); entity.addProperty( prop ); }
protected void bindVersion(PersistentProperty version, RootClass entity, Mappings mappings, String sessionFactoryBeanName) { if(version != null) { SimpleValue val = new SimpleValue(mappings, entity.getTable()); bindSimpleValue(version, null, val, EMPTY_PATH, mappings, sessionFactoryBeanName); if (val.isTypeSpecified()) { if (!(val.getType() instanceof IntegerType || val.getType() instanceof LongType || val.getType() instanceof TimestampType)) { LOG.warn("Invalid version class specified in " + version.getOwner().getName() + "; must be one of [int, Integer, long, Long, Timestamp, Date]. Not mapping the version."); return; } } else { val.setTypeName("version".equals(version.getName()) ? "integer" : "timestamp"); } Property prop = new Property(); prop.setValue(val); bindProperty(version, prop, mappings); val.setNullValue("undefined"); entity.setVersion(prop); entity.setOptimisticLockMode(0); // 0 is to use version column entity.addProperty(prop); } }
); rootEntityDescriptor.setTable( primaryTable ); if ( log.isDebugEnabled() ) { log.debugf( "Mapping class: %s -> %s", rootEntityDescriptor.getEntityName(), primaryTable.getName() ); rootEntityDescriptor.setOptimisticLockStyle( hierarchySource.getOptimisticLockStyle() ); rootEntityDescriptor.setMutable( hierarchySource.isMutable() ); rootEntityDescriptor.setWhere( hierarchySource.getWhere() ); rootEntityDescriptor.setExplicitPolymorphism( hierarchySource.isExplicitPolymorphism() ); rootEntityDescriptor.createPrimaryKey(); rootEntityDescriptor.setNaturalIdCacheRegionName( hierarchySource.getNaturalIdCaching().getRegion() );
final VersionAttributeSource versionAttributeSource = hierarchySource.getVersionAttributeSource(); final SimpleValue versionValue = new SimpleValue( sourceDocument, rootEntityDescriptor.getTable() ); versionValue.makeVersion(); Property prop = new Property(); prop.setValue( versionValue ); bindProperty( sourceDocument, if ( prop.getValueGenerationStrategy() != null ) { if ( prop.getValueGenerationStrategy().getGenerationTiming() == GenerationTiming.INSERT ) { throw new MappingException( versionValue.setNullValue( versionAttributeSource.getUnsavedValue() ); rootEntityDescriptor.setVersion( prop ); rootEntityDescriptor.setDeclaredVersion( prop ); rootEntityDescriptor.addProperty( prop );
Mapping m = getMapping(entity.getMappedClass()); SimpleValue d = new SimpleValue(mappings, table); entity.setDiscriminator(d); entity.setDiscriminatorValue(m != null && m.getDiscriminator() != null ? m.getDiscriminator() : entity.getClassName()); entity.setDiscriminatorInsertable((Boolean)m.getDiscriminatorMap().get("insert")); d.setTypeName((String)m.getDiscriminatorMap().get("type")); Formula formula = new Formula(); formula.setFormula((String)m.getDiscriminatorMap().get("formula")); d.addFormula(formula); entity.setPolymorphic(true);
private static void bindCompositeId(Element idNode, RootClass entity, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { String propertyName = idNode.attributeValue( "name" ); Component id = new Component( mappings, entity ); entity.setIdentifier( id ); bindCompositeId( idNode, id, entity, propertyName, mappings, inheritedMetas ); if ( propertyName == null ) { entity.setEmbeddedIdentifier( id.isEmbedded() ); if ( id.isEmbedded() ) { // todo : what is the implication of this? id.setDynamic( !entity.hasPojoRepresentation() ); /* * Property prop = new Property(); prop.setName("id"); * prop.setPropertyAccessorName("embedded"); prop.setValue(id); * entity.setIdentifierProperty(prop); */ } } else { Property prop = new Property(); prop.setValue( id ); bindProperty( idNode, prop, mappings, inheritedMetas ); entity.setIdentifierProperty( prop ); } makeIdentifier( idNode, id, mappings ); }