All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yestech.lib.hibernate.PersistentMoney Maven / Gradle / Ivy

Go to download

A collection of classes that can be used across yestech artifacts/components, but must not be dependant on any yestech component. Most of the code is utility type code. When more than a few classes are found to be in a package or the package start to handle more that a few reposibilities then a new independant component is created and the existing code in yeslib is ported to the new component.

There is a newer version: 1.2.0
Show newest version
/*
 * Copyright LGPL3
 * YES Technology Association
 * http://yestech.org
 *
 * http://www.opensource.org/licenses/lgpl-3.0.html
 */

package org.yestech.lib.hibernate;

import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
import org.yestech.lib.currency.Money;

import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.UUID;

/**
 * @author Artie Copeland
 * @version $Revision: $
 */
public class PersistentMoney implements UserType {

    public final static PersistentMoney INSTANCE = new PersistentMoney();

    public PersistentMoney() {
        throw new UnsupportedOperationException("not yet implemented");
    }

    private static final int[] SQL_TYPES = new int[]
            {
                    Types.NUMERIC, Types.VARCHAR
            };

    @Override
    public int[] sqlTypes() {
        return SQL_TYPES;
    }

    @Override
    public Class returnedClass() {
        return Money.class;
    }

    @Override
    public boolean equals(Object x, Object y) throws HibernateException {
        if (x == y) {
            return true;
        }
        if (x == null || y == null) {
            return false;
        }
        Money uidx = (Money) x;
        Money uidy = (Money) y;

        return uidx.equals(uidy);
    }

    @Override
    public int hashCode(Object object) throws HibernateException {
        return object.hashCode();
    }

    @Override
    public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException {
        throw new UnsupportedOperationException("not yet implemented");
//        Object uuid = Hibernate.STRING.nullSafeGet(resultSet, string);
//        if (uuid == null) {
//            return null;
//        }
//
//        return UUID.fromString((String) uuid);

    }

    @Override
    public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException {
        throw new UnsupportedOperationException("not yet implemented");
    }

    @Override
    public Object deepCopy(Object value) throws HibernateException {
        if (value == null) {
            return null;
        }
        Money existing = (Money) value;
        return new Money(existing.getAmount(),existing.getLocale());
    }

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

    @Override
    public Serializable disassemble(Object value) throws HibernateException {
        return (Serializable) value;
    }

    @Override
    public Object assemble(Serializable cached, Object value) throws HibernateException {
        return cached;
    }

    @Override
    public Object replace(Object original, Object target, Object owner) throws HibernateException {
        return original;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy