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

org.jadira.usertype.spi.shared.AbstractParameterizedMultiColumnUserType Maven / Gradle / Ivy

package org.jadira.usertype.spi.shared;

import java.util.Properties;

import org.hibernate.SessionFactory;
import org.hibernate.usertype.ParameterizedType;

public abstract class AbstractParameterizedMultiColumnUserType extends AbstractMultiColumnUserType implements ParameterizedType, IntegratorConfiguredType {

	private static final long serialVersionUID = -5378286101759906332L;

	private Properties parameterValues;
    
    @Override
    public void setParameterValues(Properties parameters) {
    	this.parameterValues = parameters;
    }
    
    protected Properties getParameterValues() {
    	return parameterValues;
    }

	@Override
	public void applyConfiguration(SessionFactory sessionFactory) {
		doApplyConfiguration();
    }
    
	private  void doApplyConfiguration() {
    	
		if (DatabaseZoneConfigured.class.isAssignableFrom(this.getClass())) {
			
			@SuppressWarnings("unchecked")
			DatabaseZoneConfigured next = (DatabaseZoneConfigured)this;			
			performDatabaseZoneConfiguration(next);
		}
		if (JavaZoneConfigured.class.isAssignableFrom(this.getClass())) {
			
			@SuppressWarnings("unchecked")
			JavaZoneConfigured next = (JavaZoneConfigured)this;			
			performJavaZoneConfiguration(next);
		}
		
		for (int i = 0; i < getColumnMappers().length; i++) {
			
			if (DatabaseZoneConfigured.class.isAssignableFrom(getColumnMappers()[i].getClass())) {
	
				@SuppressWarnings("unchecked")
				DatabaseZoneConfigured next = (DatabaseZoneConfigured)getColumnMappers()[i];
				
		        performDatabaseZoneConfiguration(next);
			}
			
			if (JavaZoneConfigured.class.isAssignableFrom(getColumnMappers()[i].getClass())) {
				
				@SuppressWarnings("unchecked")
				JavaZoneConfigured next = (JavaZoneConfigured)getColumnMappers()[i];

				performJavaZoneConfiguration(next);				
			}
		}
    }
	
	private  void performDatabaseZoneConfiguration(DatabaseZoneConfigured next) {
		
        String databaseZone = null;
        if (getParameterValues() != null) {
        	databaseZone = getParameterValues().getProperty("databaseZone");
        }
		if (databaseZone == null) {
			databaseZone = ConfigurationHelper.getProperty("databaseZone");
		}
		
        if (databaseZone != null) {
            if ("jvm".equals(databaseZone)) {
                next.setDatabaseZone(null);
            } else {
            	next.setDatabaseZone(next.parseZone(databaseZone));
            }
        }
	}
	
	private  void performJavaZoneConfiguration(JavaZoneConfigured next) {
		
		String javaZone = null;
        if (getParameterValues() != null) {
        	javaZone = getParameterValues().getProperty("javaZone");
        }
		if (javaZone == null) {
			javaZone = ConfigurationHelper.getProperty("javaZone");
		}
		
        if (javaZone != null) {
            if ("jvm".equals(javaZone)) {
                next.setJavaZone(null);
            } else {
            	next.setJavaZone(next.parseZone(javaZone));
            }
        }
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy