Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More JPA 3.2 features #1942

Merged
merged 7 commits into from
Oct 17, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,41 @@ protected static FieldDefinition createDateColumn(
*/
protected static FieldDefinition createDateColumn(
final String name) {
return createDateColumn(name, 23, true);
return createDateColumn(name, 3, true);
}

/**
* Helper method to create {@link FieldDefinition} instance
* for {@link java.time.LocalTime} column with given name and size and without
* any additional constraints.
* @param name Column name.
* @param size Column date size.
* @param allowNull Allow {@code null} values for column.
* @return Initialized {@link FieldDefinition} instance.
*/
protected static FieldDefinition createTimeColumn(
final String name, final int size, final boolean allowNull) {
final FieldDefinition field = new FieldDefinition();
field.setName(name);
field.setTypeName("TIME");
field.setSize(size);
field.setShouldAllowNull(allowNull);
field.setIsPrimaryKey(false);
field.setUnique(false);
field.setIsIdentity(false);
return field;
}

/**
* Helper method to create {@link FieldDefinition} instance
* for {@link java.time.LocalTime} column with given name size of {@code 23},
* with {@code null} value allowed and without any additional constraints.
* @param name Column name.
* @return Initialized {@link FieldDefinition} instance.
*/
protected static FieldDefinition createTimeColumn(
final String name) {
return createDateColumn(name, 3, true);
}

protected void adjustForeignKeyFieldTypes(DatabaseSession session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
public class BasicTypeHelperImpl {

/** Set of numeric types and its wrapper classes. */
private static Set numericTypes = new HashSet();
private static final Set<Class<?>> numericTypes = new HashSet<>();
/** Set of integral types and its wrapper classes. */
private static Set integralTypes = new HashSet();
private static final Set<Class<?>> integralTypes = new HashSet<>();
/** Set of floating point types and its wrapper classes. */
private static Set floatingPointTypes = new HashSet();
private static final Set<Class<? extends Number>> floatingPointTypes = new HashSet<>();
/** Set of date classes. */
private static Set dateClasses = new HashSet();
private static final Set<Class<?>> dateClasses = new HashSet<>();
/** Set of time classes. */
private static Set timeClasses = new HashSet();
private static final Set<Class<?>> timeClasses = new HashSet<>();
/** Maps primtives types to their wrapper classes. */
private static Map<Class<?>, Class<?>> primitiveToWrapper = new HashMap<>();
private static final Map<Class<?>, Class<?>> primitiveToWrapper = new HashMap<>();
/** Maps wrapper classes to their primitive types. */
private static Map<Class<?>, Class<?>> wrapperToPrimitive = new HashMap<>();
private static final Map<Class<?>, Class<?>> wrapperToPrimitive = new HashMap<>();

static {
// Initialize set of integral types plus their wrapper classes
Expand Down Expand Up @@ -123,135 +123,135 @@ public String getTypeName(Object type) {
public Class<?> getJavaClass(Object type) {
Class<?> clazz = null;
if (type instanceof Class) {
clazz = (Class)type;
clazz = (Class<?>)type;
} else if (type instanceof ClassDescriptor) {
clazz = ((ClassDescriptor)type).getJavaClass();
}
return clazz;
}

/** Returns the Object type representation.*/
public Object getObjectType() {
public Class<?> getObjectType() {
return Object.class;
}

/** Returns the boolean type representation.*/
public Object getBooleanType() {
public Class<?> getBooleanType() {
return boolean.class;
}

/** Returns the Boolean class representation.*/
public Object getBooleanClassType() {
public Class<?> getBooleanClassType() {
return Boolean.class;
}

/** Returns the char type representation.*/
public Object getCharType() {
public Class<?> getCharType() {
return char.class;
}

/** Returns the Date type representation.*/
public Object getSQLDateType() {
public Class<?> getSQLDateType() {
return java.sql.Date.class;
}

/** Returns the Time type representation.*/
public Object getTimeType() {
public Class<?> getTimeType() {
return java.sql.Time.class;
}

/** Returns the timestamp type representation.*/
public Object getTimestampType() {
public Class<?> getTimestampType() {
return java.sql.Timestamp.class;
}

/** Returns the Character class representation.*/
public Object getCharacterClassType() {
public Class<?> getCharacterClassType() {
return Character.class;
}

/** Returns the byte type representation.*/
public Object getByteType() {
public Class<?> getByteType() {
return byte.class;
}

/** Returns the Byte class representation.*/
public Object getByteClassType() {
public Class<?> getByteClassType() {
return Byte.class;
}

/** Returns the short type representation.*/
public Object getShortType() {
public Class<?> getShortType() {
return short.class;
}

/** Returns the Short class representation.*/
public Object getShortClassType() {
public Class<?> getShortClassType() {
return Short.class;
}

/** Returns the int type representation.*/
public Object getIntType() {
public Class<?> getIntType() {
return int.class;
}

/** Returns the Inter class representation.*/
public Object getIntegerClassType() {
public Class<?> getIntegerClassType() {
return Integer.class;
}

/** Returns the long type representation.*/
public Object getLongType() {
public Class<?> getLongType() {
return long.class;
}

/** Returns the type representation of class Long.*/
public Object getLongClassType() {
public Class<?> getLongClassType() {
return Long.class;
}

/** Returns the type representation of class Map.Entry.*/
public Object getMapEntryType(){
public Class<?> getMapEntryType(){
return Map.Entry.class;
}

/** Returns the float type representation.*/
public Object getFloatType() {
public Class<?> getFloatType() {
return float.class;
}

/** Returns the type representation of class Float.*/
public Object getFloatClassType() {
public Class<?> getFloatClassType() {
return Float.class;
}

/** Returns the double type representation.*/
public Object getDoubleType() {
public Class<?> getDoubleType() {
return double.class;
}

/** Returns the type representation of class Double.*/
public Object getDoubleClassType() {
public Class<?> getDoubleClassType() {
return Double.class;
}

/** Returns the String type representation.*/
public Object getStringType() {
public Class<?> getStringType() {
return String.class;
}

/** Returns the BigInteger type representation.*/
public Object getBigIntegerType() {
public Class<?> getBigIntegerType() {
return BigInteger.class;
}

/** Returns the BigDecimal type representation.*/
public Object getBigDecimalType() {
public Class<?> getBigDecimalType() {
return BigDecimal.class;
}

/** Returns the java.util.Date type representation.*/
public Object getDateType() {
public Class<?> getDateType() {
return Date.class;
}

Expand Down Expand Up @@ -327,7 +327,7 @@ public boolean isIntType(Object type) {
/**
* Returns true if type is the int primitive type or the Integer wrapper class
*/
public boolean isIntegerType(Object type) {
public boolean isIntegerType(Class<?> type) {
return isIntType(type);
}

Expand Down Expand Up @@ -477,6 +477,12 @@ public Object extendedBinaryNumericPromotion(Object left, Object right) {
return promoted;
}

// extendedBinaryNumericPromotion with class cast, shortcut for CriteriaBuilderImpl
@SuppressWarnings("unchecked")
public <T> Class<T> extendedBinaryNumericPromotionClass(Class<?> left, Class<?> right) {
return (Class<T>) extendedBinaryNumericPromotion(left, right);
}

// Helper methods

/** Returns the primitive for the specified wrapper class. */
Expand All @@ -494,7 +500,7 @@ protected Object binaryNumericPromotion(Object left, Object right) {
if ((left == null) || (right == null)) {
return null;
}
Object type = null;
Class<?> type = null;

if (left == getDoubleType() || right == getDoubleType()) {
type = getDoubleType();
Expand All @@ -507,5 +513,6 @@ protected Object binaryNumericPromotion(Object left, Object right) {
}
return type;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class ExceptionLocalizationResource extends ListResourceBundle {
{ "missing_toplink_bean_definition_for", "Missing TopLink bean definition for {0}" },
{ "argument_collection_was_null", "Argument collection was null" },
{ "entity_manager_with_connection_failed", "Execution of user code failed: {0}"},
{ "custom_pu_name_conflict", "Cannot create custom persistence unit with name {0}. This name was found in xml configuration."},
{ "configured_pu_name_conflict", "Cannot create configured persistence unit with name {0}. This name was found in custom persistence units."},
{ "no_entities_retrieved_for_get_single_result", "getSingleResult() did not retrieve any entities." },
{ "no_entities_retrieved_for_get_reference", "Could not find Entity for id: {0}" },
{ "too_many_results_for_get_single_result", "More than one result was returned from Query.getSingleResult()" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public Persistence32TableCreator() {
addTableDefinition(buildTypeTable());
addTableDefinition(buildPokemonTable());
addTableDefinition(buildPokemonTypeTable());
addTableDefinition(buildSyntaxEntityTable());
}

public static TableDefinition buildTypeTable() {
Expand All @@ -48,4 +49,16 @@ public static TableDefinition buildPokemonTypeTable() {
return table;
}

public static TableDefinition buildSyntaxEntityTable() {
TableDefinition table = new TableDefinition();
table.setName("PERSISTENCE32_SYNTAX_ENTITY");
table.addField(createNumericPk("ID"));
table.addField(createStringColumn("STR_VAL_1", 128, true));
table.addField(createStringColumn("STR_VAL_2", 128, true));
table.addField(createNumericColumn("INT_VAL", 15, true));
table.addField(createTimeColumn("TIME_VAL", 3, true));
table.addField(createDateColumn("DATE_VAL", 3, true));
return table;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
import java.util.Objects;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.NamedNativeQuery;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.Table;

@Entity
@Table(name="PERSISTENCE32_POKEMON")
@NamedQuery(name="Pokemon.get", query="SELECT p FROM Pokemon p WHERE p.id = :id")
@NamedNativeQuery(name="Pokemon.deleteAllTypes", query="DELETE FROM PERSISTENCE32_POKEMON_TYPE")
@NamedNativeQuery(name="Pokemon.deleteAll", query="DELETE FROM PERSISTENCE32_POKEMON")
public class Pokemon {

// ID is assigned in tests to avoid collisions
Expand Down
Loading
Loading