| /******************************************************************************* |
| * Copyright (c) 2016 IBM Corporation. All rights reserved. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
| * which accompanies this distribution. |
| * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| * and the Eclipse Distribution License is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * Contributors: |
| * 12/05/2016-2.6 Jody Grassel |
| * - 443546: Converter autoApply does not work for primitive types |
| ******************************************************************************/ |
| |
| package org.eclipse.persistence.jpa.converter.converters; |
| |
| import javax.persistence.AttributeConverter; |
| import javax.persistence.Converter; |
| |
| @Converter(autoApply=true) |
| public class FloatToStringAutoApplyConverter implements AttributeConverter<Float, String> { |
| public static boolean convertToDatabaseTriggered = false; |
| public static boolean convertToEntityTriggered = false; |
| |
| public static Float ctdcVal = null; |
| public static String cteaVal = null; |
| |
| public static void reset() { |
| convertToDatabaseTriggered = false; |
| convertToEntityTriggered = false; |
| ctdcVal = null; |
| cteaVal = null; |
| } |
| |
| @Override |
| public String convertToDatabaseColumn(Float attribute) { |
| convertToDatabaseTriggered = true; |
| ctdcVal = attribute; |
| return Float.toString(attribute); |
| } |
| |
| @Override |
| public Float convertToEntityAttribute(String dbData) { |
| convertToEntityTriggered = true; |
| cteaVal = dbData; |
| return Float.valueOf(dbData); |
| } |
| |
| } |