Added hashCode(), equals(), toString() in various places. Fixed delete logic.

Added some missing bean references.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5513 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2007-04-19 17:27:58 +00:00
parent bdae23b768
commit 8eb616f446
28 changed files with 337 additions and 3 deletions

View File

@@ -19,12 +19,18 @@
<property name="sessionFactory"> <property name="sessionFactory">
<ref bean="sessionFactory"/> <ref bean="sessionFactory"/>
</property> </property>
<property name="mapEntryDao">
<ref bean="mapEntryDAO"/>
</property>
</bean> </bean>
<bean id="globalAttributeEntryDAO" class="org.alfresco.repo.attributes.hibernate.GlobalAttributeEntryDAOHibernate"> <bean id="globalAttributeEntryDAO" class="org.alfresco.repo.attributes.hibernate.GlobalAttributeEntryDAOHibernate">
<property name="sessionFactory"> <property name="sessionFactory">
<ref bean="sessionFactory"/> <ref bean="sessionFactory"/>
</property> </property>
<property name="attributeDao">
<ref bean="attributeDAO"/>
</property>
</bean> </bean>
<bean id="mapEntryDAO" class="org.alfresco.repo.attributes.hibernate.MapEntryDAOHibernate"> <bean id="mapEntryDAO" class="org.alfresco.repo.attributes.hibernate.MapEntryDAOHibernate">

View File

@@ -288,4 +288,30 @@ public abstract class AttributeImpl implements Attribute
{ {
throw new AttributeMethodNotImplemented("Not ShortValue"); throw new AttributeMethodNotImplemented("Not ShortValue");
} }
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (!(obj instanceof AttributeImpl))
{
return false;
}
return fID == ((AttributeImpl)obj).fID;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode()
{
return (int)fID;
}
} }

View File

@@ -227,4 +227,43 @@ public class AttributeServiceImpl implements AttributeService
} }
current.put(name, toSave); current.put(name, toSave);
} }
/* (non-Javadoc)
* @see org.alfresco.service.cmr.attributes.AttributeService#getKeys(java.lang.String)
*/
public List<String> getKeys(String path)
{
if (path == null)
{
throw new AVMBadArgumentException("Null Attribute Path.");
}
List<String> keys = parsePath(path);
if (keys.size() == 0)
{
return fGlobalAttributeEntryDAO.getKeys();
}
GlobalAttributeEntry entry = fGlobalAttributeEntryDAO.get(keys.get(0));
if (entry == null)
{
throw new AVMNotFoundException("Attribute Not Found: " + keys.get(0));
}
Attribute current = entry.getAttribute();
if (current.getType() != Type.MAP)
{
throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(0));
}
for (int i = 1; i < keys.size(); i++)
{
current = current.get(keys.get(i));
if (current == null)
{
throw new AVMNotFoundException("Attribute Not Found: " + keys.get(i));
}
if (current.getType() != Type.MAP)
{
throw new AVMWrongTypeException("Attribute Not Map: " + keys.get(i));
}
}
return new ArrayList<String>(current.keySet());
}
} }

View File

@@ -25,6 +25,8 @@
package org.alfresco.repo.attributes; package org.alfresco.repo.attributes;
import java.util.List;
import org.alfresco.service.cmr.attributes.AttributeService; import org.alfresco.service.cmr.attributes.AttributeService;
import org.springframework.context.support.FileSystemXmlApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext;
@@ -59,6 +61,11 @@ public class AttributeServiceTest extends TestCase
@Override @Override
protected void tearDown() throws Exception protected void tearDown() throws Exception
{ {
List<String> globalKeys = fService.getKeys("");
for (String key : globalKeys)
{
fService.removeAttribute("", key);
}
fContext.close(); fContext.close();
fContext = null; fContext = null;
} }
@@ -87,8 +94,13 @@ public class AttributeServiceTest extends TestCase
assertNotNull(fService.getAttribute("boolean")); assertNotNull(fService.getAttribute("boolean"));
assertEquals(42, (int)fService.getAttribute("short").getShortValue()); assertEquals(42, (int)fService.getAttribute("short").getShortValue());
assertEquals("I sneeze.", fService.getAttribute("map/funky").getStringValue()); assertEquals("I sneeze.", fService.getAttribute("map/funky").getStringValue());
Attribute found = fService.getAttribute("map"); assertEquals(10, fService.getKeys("").size());
System.out.println(found); assertEquals(5, fService.getKeys("map").size());
List<String> keys = fService.getKeys("");
for (String key : keys)
{
System.out.println(key + " => " + fService.getAttribute(key));
}
} }
catch (Exception e) catch (Exception e)
{ {

View File

@@ -79,4 +79,13 @@ public class BooleanAttributeImpl extends AttributeImpl implements
{ {
return Type.BOOLEAN; return Type.BOOLEAN;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return fValue ? "true" : "false";
}
} }

View File

@@ -71,4 +71,13 @@ public class BooleanAttributeValue extends AttributeValue implements
{ {
fData = value; fData = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return fData ? "true" : "false";
}
} }

View File

@@ -78,4 +78,13 @@ public class ByteAttributeImpl extends AttributeImpl implements ByteAttribute
{ {
fValue = value; fValue = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return Byte.toString(fValue);
}
} }

View File

@@ -70,4 +70,13 @@ public class ByteAttributeValue extends AttributeValue implements ByteAttribute
{ {
fData = value; fData = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return Byte.toString(fData);
}
} }

View File

@@ -28,8 +28,8 @@ package org.alfresco.repo.attributes;
import org.alfresco.repo.avm.AVMDAOs; import org.alfresco.repo.avm.AVMDAOs;
/** /**
* Persistent double attribute implementation.
* @author britt * @author britt
*
*/ */
public class DoubleAttributeImpl extends AttributeImpl implements Attribute public class DoubleAttributeImpl extends AttributeImpl implements Attribute
{ {
@@ -78,4 +78,13 @@ public class DoubleAttributeImpl extends AttributeImpl implements Attribute
{ {
fValue = value; fValue = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return Double.toString(fValue);
}
} }

View File

@@ -71,4 +71,13 @@ public class DoubleAttributeValue extends AttributeValue implements
{ {
fData = value; fData = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return Double.toString(fData);
}
} }

View File

@@ -78,4 +78,13 @@ public class FloatAttributeImpl extends AttributeImpl implements FloatAttribute
{ {
fValue = value; fValue = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return Float.toString(fValue);
}
} }

View File

@@ -71,4 +71,13 @@ public class FloatAttributeValue extends AttributeValue implements
{ {
fData = value; fData = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return Float.toString(fData);
}
} }

View File

@@ -1,5 +1,7 @@
package org.alfresco.repo.attributes; package org.alfresco.repo.attributes;
import java.util.List;
/** /**
* Interface for persistence of the top level attribute map. * Interface for persistence of the top level attribute map.
* @author britt * @author britt
@@ -30,4 +32,10 @@ public interface GlobalAttributeEntryDAO
* @return The entry or null. * @return The entry or null.
*/ */
public GlobalAttributeEntry get(String name); public GlobalAttributeEntry get(String name);
/**
* Get all keys for global attributes.
* @return A list of all top level keys.
*/
public List<String> getKeys();
} }

View File

@@ -78,4 +78,13 @@ public class IntAttributeImpl extends AttributeImpl implements IntAttribute
{ {
fValue = value; fValue = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return Integer.toString(fValue);
}
} }

View File

@@ -70,4 +70,13 @@ public class IntAttributeValue extends AttributeValue implements IntAttribute
{ {
fData = value; fData = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return Integer.toString(fData);
}
} }

View File

@@ -78,4 +78,13 @@ public class LongAttributeImpl extends AttributeImpl implements LongAttribute
{ {
fValue = value; fValue = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return Long.toString(fValue);
}
} }

View File

@@ -70,4 +70,13 @@ public class LongAttributeValue extends AttributeValue implements LongAttribute
{ {
fData = value; fData = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return Long.toString(fData);
}
} }

View File

@@ -223,4 +223,23 @@ public class MapAttributeImpl extends AttributeImpl implements MapAttribute
} }
return attrs; return attrs;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
builder.append('{');
for (Map.Entry<String, Attribute> entry : entrySet())
{
builder.append(entry.getKey());
builder.append('=');
builder.append(entry.getValue().toString());
builder.append(' ');
}
builder.append('}');
return builder.toString();
}
} }

View File

@@ -186,4 +186,23 @@ public class MapAttributeValue extends AttributeValue implements MapAttribute
{ {
return fData.values(); return fData.values();
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
builder.append('{');
for (Map.Entry<String, Attribute> entry : fData.entrySet())
{
builder.append(entry.getKey());
builder.append('=');
builder.append(entry.getValue().toString());
builder.append(' ');
}
builder.append('}');
return builder.toString();
}
} }

View File

@@ -81,4 +81,13 @@ public class SerializableAttributeImpl extends AttributeImpl implements
{ {
fValue = value; fValue = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return fValue.toString();
}
} }

View File

@@ -73,4 +73,13 @@ public class SerializableAttributeValue extends AttributeValue implements
{ {
fData = value; fData = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return fData.toString();
}
} }

View File

@@ -78,4 +78,13 @@ public class ShortAttributeImpl extends AttributeImpl implements ShortAttribute
{ {
return Type.SHORT; return Type.SHORT;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return Short.toString(fValue);
}
} }

View File

@@ -71,4 +71,13 @@ public class ShortAttributeValue extends AttributeValue implements
{ {
fData = value; fData = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return Short.toString(fData);
}
} }

View File

@@ -79,4 +79,13 @@ public class StringAttributeImpl extends AttributeImpl implements
{ {
fValue = value; fValue = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return fValue;
}
} }

View File

@@ -71,4 +71,13 @@ public class StringAttributeValue extends AttributeValue implements
{ {
fData = value; fData = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return fData;
}
} }

View File

@@ -45,6 +45,15 @@ public class AttributeDAOHibernate extends HibernateDaoSupport implements
{ {
private MapEntryDAO fMapEntryDAO; private MapEntryDAO fMapEntryDAO;
public AttributeDAOHibernate()
{
}
public void setMapEntryDao(MapEntryDAO dao)
{
fMapEntryDAO = dao;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.repo.attributes.AttributeDAO#delete(org.alfresco.repo.attributes.Attribute) * @see org.alfresco.repo.attributes.AttributeDAO#delete(org.alfresco.repo.attributes.Attribute)
*/ */

View File

@@ -25,10 +25,14 @@
package org.alfresco.repo.attributes.hibernate; package org.alfresco.repo.attributes.hibernate;
import java.util.List;
import org.alfresco.repo.attributes.Attribute; import org.alfresco.repo.attributes.Attribute;
import org.alfresco.repo.attributes.AttributeDAO;
import org.alfresco.repo.attributes.GlobalAttributeEntry; import org.alfresco.repo.attributes.GlobalAttributeEntry;
import org.alfresco.repo.attributes.GlobalAttributeEntryDAO; import org.alfresco.repo.attributes.GlobalAttributeEntryDAO;
import org.alfresco.repo.attributes.GlobalAttributeEntryImpl; import org.alfresco.repo.attributes.GlobalAttributeEntryImpl;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/** /**
@@ -38,12 +42,25 @@ import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class GlobalAttributeEntryDAOHibernate extends HibernateDaoSupport public class GlobalAttributeEntryDAOHibernate extends HibernateDaoSupport
implements GlobalAttributeEntryDAO implements GlobalAttributeEntryDAO
{ {
private AttributeDAO fAttributeDAO;
public GlobalAttributeEntryDAOHibernate()
{
}
public void setAttributeDao(AttributeDAO dao)
{
fAttributeDAO = dao;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.repo.attributes.GlobalAttributeEntryDAO#delete(org.alfresco.repo.attributes.GlobalAttributeEntry) * @see org.alfresco.repo.attributes.GlobalAttributeEntryDAO#delete(org.alfresco.repo.attributes.GlobalAttributeEntry)
*/ */
public void delete(GlobalAttributeEntry entry) public void delete(GlobalAttributeEntry entry)
{ {
Attribute attr = entry.getAttribute();
getSession().delete(entry); getSession().delete(entry);
fAttributeDAO.delete(attr);
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -69,4 +86,14 @@ public class GlobalAttributeEntryDAOHibernate extends HibernateDaoSupport
{ {
getSession().save(entry); getSession().save(entry);
} }
/* (non-Javadoc)
* @see org.alfresco.repo.attributes.GlobalAttributeEntryDAO#getKeys()
*/
@SuppressWarnings("unchecked")
public List<String> getKeys()
{
Query query = getSession().createQuery("select gae.name from GlobalAttributeEntryImpl gae");
return (List<String>)query.list();
}
} }

View File

@@ -63,4 +63,11 @@ public interface AttributeService
* @return A List of matching attributes. * @return A List of matching attributes.
*/ */
public List<Attribute> query(String path, AttrQuery query); public List<Attribute> query(String path, AttrQuery query);
/**
* Get all the keys for a given attribute path.
* @param path The attribute path.
* @return A list of all keys.
*/
public List<String> getKeys(String path);
} }