org.jadira.usertype.spi.shared.AbstractParameterizedUserType Maven / Gradle / Ivy
/*
* Copyright 2010, 2011, 2012 Christopher Pheby
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jadira.usertype.spi.shared;
import java.util.Properties;
import org.hibernate.SessionFactory;
import org.hibernate.usertype.ParameterizedType;
public abstract class AbstractParameterizedUserType> extends AbstractSingleColumnUserType implements ParameterizedType, IntegratorConfiguredType {
private static final long serialVersionUID = -8038898451426631564L;
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);
}
if (DatabaseZoneConfigured.class.isAssignableFrom(getColumnMapper().getClass())) {
@SuppressWarnings("unchecked")
DatabaseZoneConfigured next = (DatabaseZoneConfigured)getColumnMapper();
performDatabaseZoneConfiguration(next);
}
if (JavaZoneConfigured.class.isAssignableFrom(getColumnMapper().getClass())) {
@SuppressWarnings("unchecked")
JavaZoneConfigured next = (JavaZoneConfigured)getColumnMapper();
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));
}
}
}
}