Search in sources :

Example 1 with AttributeConverter

use of jakarta.persistence.AttributeConverter in project jOOQ by jOOQ.

the class AttributeConverterExtractor method extract.

@SuppressWarnings("unchecked")
final Map<Name, AttributeConverter<?, ?>> extract() {
    Map<Name, AttributeConverter<?, ?>> result = new LinkedHashMap<>();
    initEntityManagerFactory();
    for (PersistentClass persistentClass : meta.getEntityBindings()) {
        Table table = persistentClass.getTable();
        Iterator<Property> propertyIterator = persistentClass.getPropertyIterator();
        propertyLoop: while (propertyIterator.hasNext()) {
            Property property = propertyIterator.next();
            Type type = property.getValue().getType();
            if (type instanceof AttributeConverterTypeAdapter) {
                AttributeConverter<?, ?> converter = ((AttributeConverterTypeAdapter<?>) type).getAttributeConverter().getConverterBean().getBeanInstance();
                Iterator<Column> columnIterator = property.getColumnIterator();
                if (columnIterator.hasNext()) {
                    Column column = columnIterator.next();
                    if (columnIterator.hasNext()) {
                        log.info("AttributeConverter", "Cannot apply AttributeConverter of property " + property + " on several columns.");
                        continue propertyLoop;
                    }
                    result.put(name(table.getCatalog(), table.getSchema(), table.getName(), column.getName()), converter);
                }
            }
        }
    }
    return result;
}
Also used : AttributeConverter(jakarta.persistence.AttributeConverter) Type(org.hibernate.type.Type) Table(org.hibernate.mapping.Table) Column(org.hibernate.mapping.Column) Iterator(java.util.Iterator) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) Property(org.hibernate.mapping.Property) Name(org.jooq.Name) LinkedHashMap(java.util.LinkedHashMap) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

AttributeConverter (jakarta.persistence.AttributeConverter)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Column (org.hibernate.mapping.Column)1 PersistentClass (org.hibernate.mapping.PersistentClass)1 Property (org.hibernate.mapping.Property)1 Table (org.hibernate.mapping.Table)1 Type (org.hibernate.type.Type)1 AttributeConverterTypeAdapter (org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter)1 Name (org.jooq.Name)1