mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
This is a checkpoint of metadata work. Nothing works, but it compiles.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5458 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
188
source/java/org/alfresco/service/cmr/attributes/AttrQuery.java
Normal file
188
source/java/org/alfresco/service/cmr/attributes/AttrQuery.java
Normal file
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.attributes;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute;
|
||||
import org.alfresco.repo.attributes.AttributeUnsupportedQueryType;
|
||||
|
||||
/**
|
||||
* Abstract base class for Attribute Query nodes.
|
||||
* @author britt
|
||||
*/
|
||||
public abstract class AttrQuery implements Serializable
|
||||
{
|
||||
protected Attribute fValue;
|
||||
|
||||
protected String fAttrName;
|
||||
|
||||
protected String fEntityName;
|
||||
|
||||
protected AttrQuery(Attribute value)
|
||||
{
|
||||
fValue = value;
|
||||
switch (fValue.getType())
|
||||
{
|
||||
case BOOLEAN :
|
||||
{
|
||||
fAttrName = "booleanValue";
|
||||
fEntityName = "BooleanAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case BYTE :
|
||||
{
|
||||
fAttrName = "byteValue";
|
||||
fEntityName = "ByteAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case SHORT :
|
||||
{
|
||||
fAttrName = "shortValue";
|
||||
fEntityName = "ShortAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case INT :
|
||||
{
|
||||
fAttrName = "intValue";
|
||||
fEntityName = "IntAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case LONG :
|
||||
{
|
||||
fAttrName = "longValue";
|
||||
fEntityName = "LongAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case FLOAT :
|
||||
{
|
||||
fAttrName = "floatValue";
|
||||
fEntityName = "FloatAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case DOUBLE :
|
||||
{
|
||||
fAttrName = "doubleValue";
|
||||
fEntityName = "DoubleAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case STRING :
|
||||
{
|
||||
fAttrName = "stringValue";
|
||||
fEntityName = "StringAttributeImpl";
|
||||
break;
|
||||
}
|
||||
case BLOB :
|
||||
{
|
||||
fAttrName = "blobValue";
|
||||
fEntityName = "BlobValueImpl";
|
||||
break;
|
||||
}
|
||||
case SERIALIZABLE :
|
||||
{
|
||||
fAttrName = "serializableValue";
|
||||
fEntityName = "SerializableValueImpl";
|
||||
break;
|
||||
}
|
||||
case MAP :
|
||||
{
|
||||
fAttrName = "mapValue"; // This doesn't need to make sense.
|
||||
fEntityName = "MapValueImpl"; // Nor does this.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the predicate that goes into a Hibernate query.
|
||||
* @return The predicate.
|
||||
*/
|
||||
public abstract String getPredicate();
|
||||
|
||||
/**
|
||||
* Get the entity that this predicate applies to.
|
||||
* @return The entity name.
|
||||
*/
|
||||
public String getEntity()
|
||||
{
|
||||
return fEntityName;
|
||||
}
|
||||
|
||||
protected String getValue()
|
||||
{
|
||||
switch (fValue.getType())
|
||||
{
|
||||
case BOOLEAN :
|
||||
{
|
||||
return fValue.getBooleanValue() ? "1" : "0";
|
||||
}
|
||||
case BYTE :
|
||||
{
|
||||
return Byte.toString(fValue.getByteValue());
|
||||
}
|
||||
case SHORT :
|
||||
{
|
||||
return Short.toString(fValue.getShortValue());
|
||||
}
|
||||
case INT :
|
||||
{
|
||||
return Integer.toString(fValue.getIntValue());
|
||||
}
|
||||
case LONG :
|
||||
{
|
||||
return Long.toString(fValue.getLongValue());
|
||||
}
|
||||
case FLOAT :
|
||||
{
|
||||
return Float.toString(fValue.getFloatValue());
|
||||
}
|
||||
case DOUBLE :
|
||||
{
|
||||
return Double.toString(fValue.getDoubleValue());
|
||||
}
|
||||
case STRING :
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
char[] chars = fValue.getStringValue().toCharArray();
|
||||
builder.append('\'');
|
||||
for (char c : chars)
|
||||
{
|
||||
if (c == '\'')
|
||||
{
|
||||
builder.append("\\'");
|
||||
continue;
|
||||
}
|
||||
builder.append(c);
|
||||
}
|
||||
builder.append('\'');
|
||||
return builder.toString();
|
||||
}
|
||||
default :
|
||||
{
|
||||
throw new AttributeUnsupportedQueryType(fValue.getType().name());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.attributes;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute;
|
||||
import org.alfresco.repo.attributes.AttributeUnsupportedQueryType;
|
||||
|
||||
/**
|
||||
* The equals predicate.
|
||||
* @author britt
|
||||
*/
|
||||
public class AttrQueryEquals extends AttrQuery
|
||||
{
|
||||
private static final long serialVersionUID = 2180915053803244460L;
|
||||
|
||||
public AttrQueryEquals(Attribute value)
|
||||
{
|
||||
super(value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttrQuery#getPredicate()
|
||||
*/
|
||||
@Override
|
||||
public String getPredicate()
|
||||
{
|
||||
return "ent." + fAttrName + " = " + getValue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.attributes;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute;
|
||||
|
||||
/**
|
||||
* Greater than query.
|
||||
* @author britt
|
||||
*/
|
||||
public class AttrQueryGT extends AttrQuery
|
||||
{
|
||||
private static final long serialVersionUID = 3171792743187950462L;
|
||||
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
public AttrQueryGT(Attribute value)
|
||||
{
|
||||
super(value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttrQuery#getPredicate()
|
||||
*/
|
||||
@Override
|
||||
public String getPredicate()
|
||||
{
|
||||
return "ent." + fAttrName + " > " + getValue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.attributes;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute;
|
||||
|
||||
/**
|
||||
* Greater than or equals predicate.
|
||||
* @author britt
|
||||
*/
|
||||
public class AttrQueryGTE extends AttrQuery
|
||||
{
|
||||
private static final long serialVersionUID = -7957078449719425057L;
|
||||
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
public AttrQueryGTE(Attribute value)
|
||||
{
|
||||
super(value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttrQuery#getPredicate()
|
||||
*/
|
||||
@Override
|
||||
public String getPredicate()
|
||||
{
|
||||
return "ent." + fAttrName + " >= " + getValue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.attributes;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute;
|
||||
|
||||
/**
|
||||
* Query a less than condition.
|
||||
* @author britt
|
||||
*/
|
||||
public class AttrQueryLT extends AttrQuery
|
||||
{
|
||||
private static final long serialVersionUID = -2385160490778425115L;
|
||||
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
public AttrQueryLT(Attribute value)
|
||||
{
|
||||
super(value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttrQuery#getPredicate()
|
||||
*/
|
||||
@Override
|
||||
public String getPredicate()
|
||||
{
|
||||
return "ent." + fAttrName + " < " + getValue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.attributes;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute;
|
||||
|
||||
/**
|
||||
* Less than or equal query
|
||||
* @author britt
|
||||
*/
|
||||
public class AttrQueryLTE extends AttrQuery
|
||||
{
|
||||
private static final long serialVersionUID = -7735611069499505767L;
|
||||
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
public AttrQueryLTE(Attribute value)
|
||||
{
|
||||
super(value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttrQuery#getPredicate()
|
||||
*/
|
||||
@Override
|
||||
public String getPredicate()
|
||||
{
|
||||
return "ent." + fAttrName + " <= " + getValue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.attributes;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute;
|
||||
import org.alfresco.repo.attributes.AttributeUnsupportedQueryType;
|
||||
|
||||
/**
|
||||
* A "like" query.
|
||||
* @author britt
|
||||
*/
|
||||
public class AttrQueryLike extends AttrQuery
|
||||
{
|
||||
private static final long serialVersionUID = -984397014171296687L;
|
||||
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
public AttrQueryLike(Attribute value)
|
||||
{
|
||||
super(value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttrQuery#getPredicate()
|
||||
*/
|
||||
@Override
|
||||
public String getPredicate()
|
||||
{
|
||||
if (fValue.getType() != Attribute.Type.STRING)
|
||||
{
|
||||
throw new AttributeUnsupportedQueryType(fValue.getType().name());
|
||||
}
|
||||
return "ent." + fAttrName + " like " + getValue();
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.service.cmr.attributes;
|
||||
|
||||
import org.alfresco.repo.attributes.Attribute;
|
||||
|
||||
/**
|
||||
* Not equals query.
|
||||
* @author britt
|
||||
*/
|
||||
public class AttrQueryNE extends AttrQuery
|
||||
{
|
||||
private static final long serialVersionUID = 103038173214972590L;
|
||||
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
public AttrQueryNE(Attribute value)
|
||||
{
|
||||
super(value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.attributes.AttrQuery#getPredicate()
|
||||
*/
|
||||
@Override
|
||||
public String getPredicate()
|
||||
{
|
||||
return "ent." + fAttrName + " <> " + getValue();
|
||||
}
|
||||
}
|
@@ -25,6 +25,8 @@
|
||||
|
||||
package org.alfresco.service.cmr.attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This provides services for reading, writing, and querying global attributes.
|
||||
* @author britt
|
||||
@@ -51,6 +53,13 @@ public interface AttributeService
|
||||
* @param name The name of the Attribute.
|
||||
*/
|
||||
public void removeValue(String path);
|
||||
|
||||
// TODO A query interface.
|
||||
|
||||
/**
|
||||
* Query for a list of attributes which are contained in the container
|
||||
* defined by the given path and meet the query criteria.
|
||||
* @param path
|
||||
* @param query
|
||||
* @return A List of matching attributes.
|
||||
*/
|
||||
public List<Object> query(String path, AttrQuery query);
|
||||
}
|
||||
|
Reference in New Issue
Block a user