mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ContentData
- The default locale if one is not specified - Client code must still handle null locales for backwards compatibility NodeService - Moved support methods for instrinsic properties Locale - The Alfresco String representation of a Locale is x_y_z, even if x, y or z are "" - This makes the SQL like function more accurate for searches against locale properties git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4618 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -134,12 +134,7 @@ public class PropertyValue implements Cloneable, Serializable
|
||||
@Override
|
||||
Serializable convert(Serializable value)
|
||||
{
|
||||
String str = DefaultTypeConverter.INSTANCE.convert(String.class, value);
|
||||
if (value instanceof Locale && str.length() < 6)
|
||||
{
|
||||
str += "_";
|
||||
}
|
||||
return str;
|
||||
return DefaultTypeConverter.INSTANCE.convert(String.class, value);
|
||||
}
|
||||
},
|
||||
DATE
|
||||
|
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.repo.domain.hibernate;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.usertype.UserType;
|
||||
|
||||
/**
|
||||
* Custom type to hide the persistence of {@link java.util.Locale locale} instances.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class LocaleUserType implements UserType
|
||||
{
|
||||
private static int[] SQL_TYPES = new int[] {Types.VARCHAR};
|
||||
|
||||
public Class returnedClass()
|
||||
{
|
||||
return Locale.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #SQL_TYPES
|
||||
*/
|
||||
public int[] sqlTypes()
|
||||
{
|
||||
return SQL_TYPES;
|
||||
}
|
||||
|
||||
public boolean isMutable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object x, Object y) throws HibernateException
|
||||
{
|
||||
return EqualsHelper.nullSafeEquals(x, y);
|
||||
}
|
||||
|
||||
public int hashCode(Object x) throws HibernateException
|
||||
{
|
||||
return x.hashCode();
|
||||
}
|
||||
|
||||
public Object deepCopy(Object value) throws HibernateException
|
||||
{
|
||||
// the qname is immutable
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException
|
||||
{
|
||||
String localeStr = rs.getString(names[0]);
|
||||
if (localeStr == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Locale locale = DefaultTypeConverter.INSTANCE.convert(Locale.class, localeStr);
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
|
||||
public void nullSafeSet(PreparedStatement stmt, Object value, int index) throws HibernateException, SQLException
|
||||
{
|
||||
// we want to ensure that the value is consistent w.r.t. the use of '_'
|
||||
if (value == null)
|
||||
{
|
||||
stmt.setNull(index, Types.VARCHAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
String localeStr = value.toString();
|
||||
if (localeStr.length() < 6)
|
||||
{
|
||||
localeStr += "_";
|
||||
}
|
||||
stmt.setString(index, localeStr);
|
||||
}
|
||||
}
|
||||
|
||||
public Object replace(Object original, Object target, Object owner) throws HibernateException
|
||||
{
|
||||
// qname is immutable
|
||||
return original;
|
||||
}
|
||||
|
||||
public Object assemble(Serializable cached, Object owner) throws HibernateException
|
||||
{
|
||||
// qname is serializable
|
||||
return cached;
|
||||
}
|
||||
|
||||
public Serializable disassemble(Object value) throws HibernateException
|
||||
{
|
||||
// locale is serializable
|
||||
return (Locale) value;
|
||||
}
|
||||
}
|
@@ -7,6 +7,7 @@
|
||||
<hibernate-mapping>
|
||||
|
||||
<typedef class="org.alfresco.repo.domain.hibernate.QNameUserType" name="QName" />
|
||||
<typedef class="org.alfresco.repo.domain.hibernate.LocaleUserType" name="Locale" />
|
||||
|
||||
<class
|
||||
name="org.alfresco.repo.domain.hibernate.NodeImpl"
|
||||
|
Reference in New Issue
Block a user