下面列出了怎么用org.hibernate.annotations.Immutable的API类实例代码及写法,或者点击链接到github查看源代码。
@SuppressWarnings("unchecked")
private static <T> MutabilityPlan<T> createMutabilityPlan(final Class<T> type) {
if ( type.isAnnotationPresent( Immutable.class ) ) {
return ImmutableMutabilityPlan.INSTANCE;
}
// MutableMutabilityPlan is the "safest" option, but we do not necessarily know how to deepCopy etc...
return new MutableMutabilityPlan<T>() {
@Override
protected T deepCopyNotNull(T value) {
throw new HibernateException(
"Not known how to deep copy value of type: [" + type
.getName() + "]"
);
}
};
}
private void validateBind() {
if ( property.isAnnotationPresent( Immutable.class ) ) {
throw new AnnotationException(
"@Immutable on property not allowed. " +
"Only allowed on entity level or on a collection."
);
}
if ( !declaringClassSet ) {
throw new AssertionFailure( "declaringClass has not been set before a bind" );
}
}
@SuppressWarnings({ "unchecked" })
private static <T> MutabilityPlan<T> createMutabilityPlan(Class<T> type) {
if ( type.isAnnotationPresent( Immutable.class ) ) {
return ImmutableMutabilityPlan.INSTANCE;
}
return (MutabilityPlan<T>) SerializableMutabilityPlan.INSTANCE;
}