HHH-17772 map @Save lifecycle annotation to upsert()
This commit is contained in:
parent
83595ea461
commit
9c707dd4e8
|
@ -76,6 +76,7 @@ import static org.hibernate.jpamodelgen.util.Constants.JD_INSERT;
|
|||
import static org.hibernate.jpamodelgen.util.Constants.JD_ORDER;
|
||||
import static org.hibernate.jpamodelgen.util.Constants.JD_QUERY;
|
||||
import static org.hibernate.jpamodelgen.util.Constants.JD_REPOSITORY;
|
||||
import static org.hibernate.jpamodelgen.util.Constants.JD_SAVE;
|
||||
import static org.hibernate.jpamodelgen.util.Constants.JD_SORT;
|
||||
import static org.hibernate.jpamodelgen.util.Constants.JD_UPDATE;
|
||||
import static org.hibernate.jpamodelgen.util.Constants.MUTINY_SESSION;
|
||||
|
@ -306,7 +307,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
|||
else if ( containsAnnotation( method, HQL, SQL, JD_QUERY, FIND, JD_FIND ) ) {
|
||||
queryMethods.add( method );
|
||||
}
|
||||
else if ( containsAnnotation( method, JD_INSERT, JD_UPDATE, JD_DELETE ) ) {
|
||||
else if ( containsAnnotation( method, JD_INSERT, JD_UPDATE, JD_DELETE, JD_SAVE ) ) {
|
||||
lifecycleMethods.add( method );
|
||||
}
|
||||
}
|
||||
|
@ -487,7 +488,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
|||
private void addLifecycleMethods(List<ExecutableElement> queryMethods) {
|
||||
for ( ExecutableElement method : queryMethods) {
|
||||
if ( method.getModifiers().contains(Modifier.ABSTRACT) ) {
|
||||
if ( hasAnnotation( method, JD_INSERT, JD_UPDATE, JD_DELETE ) ) {
|
||||
if ( hasAnnotation( method, JD_INSERT, JD_UPDATE, JD_DELETE, JD_SAVE ) ) {
|
||||
addLifecycleMethod( method );
|
||||
}
|
||||
}
|
||||
|
@ -641,15 +642,18 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
|||
}
|
||||
|
||||
private static String lifecycleOperation(ExecutableElement method) {
|
||||
if ( hasAnnotation(method, JD_INSERT ) ) {
|
||||
if ( hasAnnotation(method, JD_INSERT) ) {
|
||||
return "insert";
|
||||
}
|
||||
else if ( hasAnnotation(method, JD_UPDATE ) ) {
|
||||
else if ( hasAnnotation(method, JD_UPDATE) ) {
|
||||
return "update";
|
||||
}
|
||||
else if ( hasAnnotation(method, JD_DELETE ) ) {
|
||||
else if ( hasAnnotation(method, JD_DELETE) ) {
|
||||
return "delete";
|
||||
}
|
||||
else if ( hasAnnotation(method, JD_SAVE) ) {
|
||||
return "upsert";
|
||||
}
|
||||
else {
|
||||
throw new AssertionFailure("Unrecognized lifecycle operation");
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ public final class Constants {
|
|||
public static final String JD_INSERT = "jakarta.data.repository.Insert";
|
||||
public static final String JD_UPDATE = "jakarta.data.repository.Update";
|
||||
public static final String JD_DELETE = "jakarta.data.repository.Delete";
|
||||
public static final String JD_SAVE = "jakarta.data.repository.Save";
|
||||
public static final String JD_LIMIT = "jakarta.data.Limit";
|
||||
public static final String JD_SORT = "jakarta.data.Sort";
|
||||
public static final String JD_ORDER = "jakarta.data.Order";
|
||||
|
|
|
@ -11,6 +11,7 @@ import jakarta.data.repository.OrderBy;
|
|||
import jakarta.data.repository.Param;
|
||||
import jakarta.data.repository.Query;
|
||||
import jakarta.data.repository.Repository;
|
||||
import jakarta.data.repository.Save;
|
||||
import jakarta.data.repository.Update;
|
||||
import org.hibernate.StatelessSession;
|
||||
|
||||
|
@ -49,6 +50,9 @@ public interface BookAuthorRepository {
|
|||
@Delete
|
||||
void delete(Book book);
|
||||
|
||||
@Save
|
||||
void createOrUpdate(Book book);
|
||||
|
||||
@Query("from Book where title like :title")
|
||||
List<Book> books0(String title);
|
||||
|
||||
|
|
Loading…
Reference in New Issue