Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import org.hibernate.proxy.EntityNotFoundDelegate;

/**
* Standard non-JPA implementation of EntityNotFoundDelegate, throwing the
* Hibernate-specific {@link ObjectNotFoundException}.
* Standard non-JPA implementation of {@link EntityNotFoundDelegate},
* throwing the Hibernate-specific {@link ObjectNotFoundException}.
*
* @author Steve Ebersole
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.annotations.usertype;

import org.hibernate.testing.orm.junit.DomainModel;
Expand All @@ -9,9 +13,9 @@
@DomainModel(annotatedClasses = MyEntity.class)
public class EnhancedUserTypeTest {

@Test
void test(SessionFactoryScope scope) {
scope.inTransaction(session -> session.persist(new MyEntity(new MyId("x1"), "hello world")));
}
@Test
void test(SessionFactoryScope scope) {
scope.inTransaction(session -> session.persist(new MyEntity(new MyId("x1"), "hello world")));
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.annotations.usertype;

import jakarta.persistence.Entity;
Expand All @@ -6,17 +10,17 @@

@Entity
class MyEntity {
@Id
@Type(MyType.class)
MyId id;
@Id
@Type(MyType.class)
MyId id;

String content;
String content;

MyEntity(MyId id, String content) {
this.id = id;
this.content = content;
}
MyEntity(MyId id, String content) {
this.id = id;
this.content = content;
}

MyEntity() {
}
MyEntity() {
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.annotations.usertype;

class MyId {
final String text;
final String text;

MyId(String text) {
this.text = text;
}
MyId(String text) {
this.text = text;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.annotations.usertype;

import org.hibernate.HibernateException;
Expand All @@ -11,70 +15,70 @@
import java.sql.SQLException;

class MyType implements EnhancedUserType<MyId> {
@Override
public String toSqlLiteral(MyId value) {
return "'" + value.text.replace("'", "''") + "'";
}
@Override
public String toSqlLiteral(MyId value) {
return "'" + value.text.replace("'", "''") + "'";
}

@Override
public String toString(MyId value) throws HibernateException {
return value.text;
}
@Override
public String toString(MyId value) throws HibernateException {
return value.text;
}

@Override
public MyId fromStringValue(CharSequence sequence) throws HibernateException {
return new MyId(sequence.toString());
}
@Override
public MyId fromStringValue(CharSequence sequence) throws HibernateException {
return new MyId(sequence.toString());
}

@Override
public int getSqlType() {
return SqlTypes.VARCHAR;
}
@Override
public int getSqlType() {
return SqlTypes.VARCHAR;
}

@Override
public Class<MyId> returnedClass() {
return MyId.class;
}
@Override
public Class<MyId> returnedClass() {
return MyId.class;
}

@Override
public boolean equals(MyId x, MyId y) {
return x != null && y != null && x.text.equals(y.text);
}
@Override
public boolean equals(MyId x, MyId y) {
return x != null && y != null && x.text.equals(y.text);
}

@Override
public int hashCode(MyId x) {
return x.text.hashCode();
}
@Override
public int hashCode(MyId x) {
return x.text.hashCode();
}

@Override
public MyId nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner)
throws SQLException {
return new MyId(rs.getString(position));
}
@Override
public MyId nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner)
throws SQLException {
return new MyId(rs.getString(position));
}

@Override
public void nullSafeSet(PreparedStatement st, MyId value, int index, SharedSessionContractImplementor session)
throws SQLException {
st.setString(index, value.text);
}
@Override
public void nullSafeSet(PreparedStatement st, MyId value, int index, SharedSessionContractImplementor session)
throws SQLException {
st.setString(index, value.text);
}

@Override
public MyId deepCopy(MyId value) {
return value;
}
@Override
public MyId deepCopy(MyId value) {
return value;
}

@Override
public boolean isMutable() {
return false;
}
@Override
public boolean isMutable() {
return false;
}

@Override
public Serializable disassemble(MyId value) {
return value.text;
}
@Override
public Serializable disassemble(MyId value) {
return value.text;
}

@Override
public MyId assemble(Serializable cached, Object owner) {
return new MyId((String) cached);
}
@Override
public MyId assemble(Serializable cached, Object owner) {
return new MyId((String) cached);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,13 @@ public interface BookAuthorRepository {

@Query("")
List<Author> withNoOrder2(PageRequest pageRequest);

@Query("update Author set name = :name where ssn = :id")
void updateAuthorAddress1(String id, String name);

@Query("update Author set name = :name where ssn = :id")
int updateAuthorAddress2(String id, String name);

@Query("update Author set name = :name where ssn = :id")
boolean updateAuthorAddress3(String id, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,13 @@ record BookWithAuthor(Book book, Author author) {}

@Find
Uni<List<Author>> authorsByCityAndPostcode(String address_city, String address_postcode);

@Query("update Author set address = :address where ssn = :id")
Uni<Void> updateAuthorAddress1(String id, Address address);

@Query("update Author set address = :address where ssn = :id")
Uni<Integer> updateAuthorAddress2(String id, Address address);

@Query("update Author set address = :address where ssn = :id")
Uni<Boolean> updateAuthorAddress3(String id, Address address);
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public final class Context {
private AccessType persistenceUnitDefaultAccessType;
private boolean generateJakartaDataStaticMetamodel;
private boolean quarkusInjection;
private boolean dataEventPackageAvailable;

// keep track of all classes for which model have been generated
private final Set<Metamodel> generatedModelClasses = new HashSet<>();
Expand Down Expand Up @@ -224,6 +225,14 @@ public void setQuarkusInjection(boolean quarkusInjection) {
this.quarkusInjection = quarkusInjection;
}

public boolean isDataEventPackageAvailable() {
return dataEventPackageAvailable;
}

public void setDataEventPackageAvailable(boolean dataEventPackageAvailable) {
this.dataEventPackageAvailable = dataEventPackageAvailable;
}

public Elements getElementUtils() {
return processingEnvironment.getElementUtils();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ private boolean handleSettings(ProcessingEnvironment environment) {
final PackageElement quarkusOrmPackage =
context.getProcessingEnvironment().getElementUtils()
.getPackageElement( "io.quarkus.hibernate.orm" );
final PackageElement dataEventPackage =
context.getProcessingEnvironment().getElementUtils()
.getPackageElement( "jakarta.data.event" );

PackageElement quarkusOrmPanachePackage =
context.getProcessingEnvironment().getElementUtils()
Expand All @@ -265,6 +268,7 @@ && packagePresent(quarkusOrmPanachePackage) ) {
context.setAddGeneratedAnnotation( packagePresent(jakartaAnnotationPackage) );
context.setAddDependentAnnotation( packagePresent(jakartaContextPackage) );
context.setAddTransactionScopedAnnotation( packagePresent(jakartaTransactionsPackage) );
context.setDataEventPackageAvailable( packagePresent(dataEventPackage) );
context.setQuarkusInjection( packagePresent(quarkusOrmPackage) );
context.setUsesQuarkusOrm( packagePresent(quarkusOrmPanachePackage) );
context.setUsesQuarkusReactive( packagePresent(quarkusReactivePanachePackage) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected void handle(StringBuilder declaration, String handled, String rethrown
declaration.append( "\n\t\t\t.onFailure(" )
.append( annotationMetaEntity.importType( handled ) )
.append( ".class)\n" )
.append( "\t\t\t\t\t.transform((_ex) -> new " )
.append( "\t\t\t\t\t.transform(_ex -> new " )
.append( annotationMetaEntity.importType( rethrown ) )
.append( "(_ex.getMessage(), _ex))" );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,24 @@ else if ( element.getKind() == ElementKind.INTERFACE
if ( needsDefaultConstructor() ) {
addDefaultConstructor();
}
if ( needsEventBus() ) {
addEventBus();
}
}
}

private boolean needsEventBus() {
return jakartaDataRepository
&& !usingReactiveSession( sessionType ) // non-reactive
&& context.isDataEventPackageAvailable() // events
&& context.addInjectAnnotation() // @nject
&& context.addDependentAnnotation(); // CDI
}

void addEventBus() {
putMember("_event", new EventField(this) );
}

/**
* For usage with CDI, but outside Quarkus, Jakarta Data
* repositories use {@code @PersistenceUnit} to obtain an
Expand Down Expand Up @@ -685,6 +700,11 @@ boolean needsDefaultConstructor() {
return null;
}

@Override
public boolean isReactive() {
return usingReactiveSession(sessionType);
}

private boolean isPanacheType(TypeElement type) {
return context.usesQuarkusOrm() && isOrmPanacheType( type )
|| context.usesQuarkusReactive() && isReactivePanacheType( type );
Expand Down Expand Up @@ -1377,6 +1397,7 @@ else if ( returnArgument
new LifecycleMethod(
this, method,
entity,
typeAsString(lifecycleParameterArgument(parameterType)),
methodName,
parameter.getSimpleName().toString(),
getSessionVariableName(),
Expand Down Expand Up @@ -1419,6 +1440,23 @@ private static LifecycleMethod.ParameterKind lifecycleParameterKind(TypeMirror p
}
}

private TypeMirror lifecycleParameterArgument(TypeMirror parameterType) {
switch (parameterType.getKind()) {
case ARRAY:
final ArrayType arrayType = (ArrayType) parameterType;
return arrayType.getComponentType();
case DECLARED:
final DeclaredType declaredType = (DeclaredType) parameterType;
final TypeElement typeElement = (TypeElement) declaredType.asElement();
return typeElement.getQualifiedName().contentEquals(LIST)
&& !declaredType.getTypeArguments().isEmpty()
? declaredType.getTypeArguments().get(0)
: context.getElementUtils().getTypeElement(JAVA_OBJECT).asType();
default:
return parameterType;
}
}

private static boolean isVoid(TypeMirror returnType) {
switch (returnType.getKind()) {
case VOID:
Expand Down
Loading
Loading