Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…Blazebit#503] Introduced entity collection management API and made use of it for cascading deletes in entity views. Ironed out many inverse mapping issues
  • Loading branch information
beikov committed Jan 26, 2018
1 parent 8329058 commit cc71717
Show file tree
Hide file tree
Showing 236 changed files with 9,975 additions and 1,417 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<property name="max" value="250"/>
</module>
<module name="ParameterNumber">
<property name="max" value="16"/>
<property name="max" value="20"/>
</module>

<!-- Checks for blocks. You know, those {}'s -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,33 @@ public interface CriteriaBuilderFactory extends ServiceProvider, ConfigurationSo
*/
public <T> DeleteCriteriaBuilder<T> delete(EntityManager entityManager, Class<T> deleteClass, String alias);

/**
* Like {@link CriteriaBuilderFactory#deleteCollection(javax.persistence.EntityManager, java.lang.Class, java.lang.String, java.lang.String)} but with the alias
* equivalent to the camel cased result of what {@link Class#getSimpleName()} of the delete owner class returns.
*
* @param entityManager The entity manager to use for the delete criteria builder
* @param deleteOwnerClass The entity class owning the collection for the delete criteria
* @param collectionName The name of the collection contained in the owner entity class
* @param <T> The type of the entity for the delete criteria
* @return A new delete criteria builder
* @since 1.2.0
*/
public <T> DeleteCriteriaBuilder<T> deleteCollection(EntityManager entityManager, Class<T> deleteOwnerClass, String collectionName);

/**
* Creates a new delete criteria builder for the given entity class and collection name to delete elements of the
* entity class's collection.
*
* @param entityManager The entity manager to use for the delete criteria builder
* @param deleteOwnerClass The entity class owning the collection for the delete criteria
* @param alias The alias that should be used for the entity
* @param collectionName The name of the collection contained in the owner entity class
* @param <T> The type of the entity for the delete criteria
* @return A new delete criteria builder
* @since 1.2.0
*/
public <T> DeleteCriteriaBuilder<T> deleteCollection(EntityManager entityManager, Class<T> deleteOwnerClass, String alias, String collectionName);

/**
* Like {@link CriteriaBuilderFactory#update(javax.persistence.EntityManager, java.lang.Class, java.lang.String)} but with the alias
* equivalent to the camel cased result of what {@link Class#getSimpleName()} of the update class returns.
Expand All @@ -124,6 +151,33 @@ public interface CriteriaBuilderFactory extends ServiceProvider, ConfigurationSo
*/
public <T> UpdateCriteriaBuilder<T> update(EntityManager entityManager, Class<T> updateClass, String alias);

/**
* Like {@link CriteriaBuilderFactory#updateCollection(javax.persistence.EntityManager, java.lang.Class, java.lang.String, java.lang.String)} but with the alias
* equivalent to the camel cased result of what {@link Class#getSimpleName()} of the delete owner class returns.
*
* @param entityManager The entity manager to use for the update criteria builder
* @param updateOwnerClass The entity class owning the collection for the update criteria
* @param collectionName The name of the collection contained in the owner entity class
* @param <T> The type of the entity for the update criteria
* @return A new update criteria builder
* @since 1.2.0
*/
public <T> UpdateCriteriaBuilder<T> updateCollection(EntityManager entityManager, Class<T> updateOwnerClass, String collectionName);

/**
* Creates a new update criteria builder for the given entity class and collection name to update elements of the
* entity class's collection.
*
* @param entityManager The entity manager to use for the update criteria builder
* @param updateOwnerClass The entity class owning the collection for the update criteria
* @param alias The alias that should be used for the entity
* @param collectionName The name of the collection contained in the owner entity class
* @param <T> The type of the entity for the update criteria
* @return A new update criteria builder
* @since 1.2.0
*/
public <T> UpdateCriteriaBuilder<T> updateCollection(EntityManager entityManager, Class<T> updateOwnerClass, String alias, String collectionName);

/**
* Creates a new insert criteria builder for the given entity class.
*
Expand All @@ -134,4 +188,17 @@ public interface CriteriaBuilderFactory extends ServiceProvider, ConfigurationSo
* @since 1.1.0
*/
public <T> InsertCriteriaBuilder<T> insert(EntityManager entityManager, Class<T> insertClass);

/**
* Creates a new insert criteria builder for the given entity class and collection name to update elements of the
* entity class's collection.
*
* @param entityManager The entity manager to use for the insert criteria builder
* @param insertOwnerClass The entity class owning the collection for the insert criteria
* @param collectionName The name of the collection contained in the owner entity class
* @param <T> The type of the entity for the insert criteria
* @return A new insert criteria builder
* @since 1.2.0
*/
public <T> InsertCriteriaBuilder<T> insertCollection(EntityManager entityManager, Class<T> insertOwnerClass, String collectionName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@ public interface ReturningModificationCriteriaBuilderFactory<X> {
*/
public <T> ReturningDeleteCriteriaBuilder<T, X> delete(Class<T> deleteClass, String alias);

/**
* Like {@link ReturningModificationCriteriaBuilderFactory#deleteCollection(java.lang.Class, java.lang.String, java.lang.String)} but with the alias
* equivalent to the camel cased result of what {@link Class#getSimpleName()} of the delete owner class returns.
*
* @param deleteOwnerClass The entity class owning the collection for the delete criteria
* @param collectionName The name of the collection contained in the owner entity class
* @param <T> The type of the entity for the delete criteria
* @return A new delete criteria builder
* @since 1.2.0
*/
public <T> ReturningDeleteCriteriaBuilder<T, X> deleteCollection(Class<T> deleteOwnerClass, String collectionName);

/**
* Creates a new delete criteria builder for the given entity class and collection name to delete elements of the
* entity class's collection.
*
* @param deleteOwnerClass The entity class owning the collection for the delete criteria
* @param alias The alias that should be used for the entity
* @param collectionName The name of the collection contained in the owner entity class
* @param <T> The type of the entity for the delete criteria
* @return A new delete criteria builder
* @since 1.2.0
*/
public <T> ReturningDeleteCriteriaBuilder<T, X> deleteCollection(Class<T> deleteOwnerClass, String alias, String collectionName);

/**
* Like {@link ReturningModificationCriteriaBuilderFactory#update(java.lang.Class, java.lang.String)} but with the alias
* equivalent to the camel cased result of what {@link Class#getSimpleName()} of the update class returns.
Expand All @@ -69,6 +94,31 @@ public interface ReturningModificationCriteriaBuilderFactory<X> {
*/
public <T> ReturningUpdateCriteriaBuilder<T, X> update(Class<T> updateClass, String alias);

/**
* Like {@link CriteriaBuilderFactory#updateCollection(javax.persistence.EntityManager, java.lang.Class, java.lang.String, java.lang.String)} but with the alias
* equivalent to the camel cased result of what {@link Class#getSimpleName()} of the delete owner class returns.
*
* @param updateOwnerClass The entity class owning the collection for the update criteria
* @param collectionName The name of the collection contained in the owner entity class
* @param <T> The type of the entity for the update criteria
* @return A new update criteria builder
* @since 1.2.0
*/
public <T> ReturningUpdateCriteriaBuilder<T, X> updateCollection(Class<T> updateOwnerClass, String collectionName);

/**
* Creates a new update criteria builder for the given entity class and collection name to update elements of the
* entity class's collection.
*
* @param updateOwnerClass The entity class owning the collection for the update criteria
* @param alias The alias that should be used for the entity
* @param collectionName The name of the collection contained in the owner entity class
* @param <T> The type of the entity for the update criteria
* @return A new update criteria builder
* @since 1.2.0
*/
public <T> ReturningUpdateCriteriaBuilder<T, X> updateCollection(Class<T> updateOwnerClass, String alias, String collectionName);

/**
* Creates a new insert criteria builder for the given entity class.
*
Expand All @@ -78,4 +128,16 @@ public interface ReturningModificationCriteriaBuilderFactory<X> {
* @since 1.1.0
*/
public <T> ReturningInsertCriteriaBuilder<T, X> insert(Class<T> insertClass);

/**
* Creates a new insert criteria builder for the given entity class and collection name to update elements of the
* entity class's collection.
*
* @param insertOwnerClass The entity class owning the collection for the insert criteria
* @param collectionName The name of the collection contained in the owner entity class
* @param <T> The type of the entity for the insert criteria
* @return A new insert criteria builder
* @since 1.2.0
*/
public <T> ReturningInsertCriteriaBuilder<T, X> insertCollection(Class<T> insertOwnerClass, String collectionName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Copyright 2014 - 2018 Blazebit.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.blazebit.persistence.spi;

import com.blazebit.persistence.JoinType;

import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.EntityType;
import java.util.List;
import java.util.Map;

/**
* This is a wrapper around the JPA {@link javax.persistence.metamodel.Attribute} that allows additionally efficient access to properties of the metamodel.
*
* @param <X> The Java type represented by the managed type owning the attribute
* @param <Y> The Java element type of the attribute
* @author Christian Beikov
* @since 1.2.0
*/
public interface ExtendedAttribute<X, Y> {

/**
* Returns the underlying attribute.
*
* @return The attribute
*/
public Attribute<X, ?> getAttribute();

/**
* Returns the path from the owning entity type to this attribute.
*
* @return The path to the attribute
*/
public List<Attribute<?, ?>> getAttributePath();

/**
* Returns the element type of the attribute.
*
* @return The element type
*/
public Class<Y> getElementClass();

/**
* Returns whether the type of the attribute causes a cascading delete cycle.
*
* @return True if it has a cascading delete cycle, false otherwise
*/
public boolean hasCascadingDeleteCycle();

/**
* Whether the join columns for the attribute are in a foreign table.
*
* @return True if join columns are in a foreign table, false otherwise
*/
public boolean isForeignJoinColumn();

/**
* Whether columns for the attribute are shared between multiple subtypes
* or shared by occupying the same slot in the resulting SQL.
*
* @return True if columns of the attribute are shared, false otherwise
*/
public boolean isColumnShared();

/**
* Whether the attribute is a non-indexed and non-ordered collection a.k.a. a bag.
*
* @return True if it is a bag, false otherwise
*/
public boolean isBag();

/**
* Whether orphan removal is activated for the attribute.
*
* @return True if orphan removal is activated, else false
*/
public boolean isOrphanRemoval();

/**
* Whether delete cascading is activated for the attribute.
*
* @return True if delete cascading is activated, else false
*/
public boolean isDeleteCascaded();

/**
* Returns where to put treat filters for a treat joined association of this attribute.
*
* @param joinType The join type used for the treat join
* @return The constraint type for the treat filter
*/
public JpaProvider.ConstraintType getJoinTypeIndexedRequiresTreatFilter(JoinType joinType);

/**
* If the attribute is <em>insertable = false</em> and <em>updatable = false</em> it returns the writable mappings for the inverse type.
* Otherwise returns null.
*
* @param inverseType The type containing the inverse relation
* @return The writable mappings for the inverse type if the attribute is not insertable or updatable, null otherwise
*/
public Map<String, String> getWritableMappedByMappings(EntityType<?> inverseType);

/**
* If the attribute is an inverse collection, the mapped by attribute name is returned.
* Otherwise returns null.
*
* @return The mapped by attribute name if the attribute is an inverse collection, null otherwise
*/
public String getMappedBy();

/**
* If the attribute is a collection that uses a join table, returns it's descriptor.
* Otherwise returns null.
*
* @return The join table information if the attribute has one, null otherwise
*/
public JoinTable getJoinTable();

/**
* Returns the column names of the attribute.
*
* @return The column names of the attribute
*/
public String[] getColumnNames();

/**
* Returns the SQL column type names of the attribute.
*
* @return The SQL column type names for the attribute
*/
public String[] getColumnTypes();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2014 - 2018 Blazebit.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.blazebit.persistence.spi;

import javax.persistence.metamodel.ManagedType;
import javax.persistence.metamodel.SingularAttribute;
import java.util.Map;

/**
* This is a wrapper around the JPA {@link javax.persistence.metamodel.ManagedType} that allows additionally efficient access to properties of the metamodel.
*
* @param <X> The Java type represented by this managed type
* @author Christian Beikov
* @since 1.2.0
*/
public interface ExtendedManagedType<X> {

/**
* Returns the underlying managed type.
*
* @return The managed type
*/
public ManagedType<X> getType();

/**
* Returns whether the type has a cascading delete cycle.
*
* @return True if it has a cascading delete cycle, false otherwise
*/
public boolean hasCascadingDeleteCycle();

/**
* Returns the id attribute if it has one, otherwise null.
*
* @return The id attribute or null
*/
public SingularAttribute<X, ?> getIdAttribute();

/**
* Returns the extended attributes of the managed type.
*
* @return The extended attributes
*/
public Map<String, ExtendedAttribute<X, ?>> getAttributes();

/**
* Returns the extended attribute of the managed type for the given attribute name.
*
* @param attributeName The attribute name
* @return The extended attributes
* @throws IllegalArgumentException Is thrown when the attribute doesn't exist
*/
public ExtendedAttribute<X, ?> getAttribute(String attributeName);
}

Loading

0 comments on commit cc71717

Please sign in to comment.