added the category reference table and some support code to manage it
This commit is contained in:
74
src/venice-base/com/silverwrist/venice/SearchMode.java
Normal file
74
src/venice-base/com/silverwrist/venice/SearchMode.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (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.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice;
|
||||
|
||||
import java.util.*;
|
||||
import org.apache.commons.lang.enum.*;
|
||||
|
||||
public final class SearchMode extends Enum
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* The actual enumeration values
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static final SearchMode PREFIX = new SearchMode("PREFIX");
|
||||
public static final SearchMode SUBSTRING = new SearchMode("SUBSTRING");
|
||||
public static final SearchMode REGEXP = new SearchMode("REGEXP");
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private SearchMode(String name)
|
||||
{
|
||||
super(name);
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Standard static method implementations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static SearchMode getEnum(String name)
|
||||
{
|
||||
return (SearchMode)getEnum(SearchMode.class,name);
|
||||
|
||||
} // end getEnum
|
||||
|
||||
public static Map getEnumMap()
|
||||
{
|
||||
return getEnumMap(SearchMode.class);
|
||||
|
||||
} // end getEnumMap
|
||||
|
||||
public static List getEnumList()
|
||||
{
|
||||
return getEnumList(SearchMode.class);
|
||||
|
||||
} // end getEnumList
|
||||
|
||||
public static Iterator iterator()
|
||||
{
|
||||
return iterator(SearchMode.class);
|
||||
|
||||
} // end iterator
|
||||
|
||||
} // end class SearchMode
|
||||
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (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.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.community;
|
||||
|
||||
import java.util.*;
|
||||
import com.silverwrist.dynamo.except.*;
|
||||
import com.silverwrist.venice.iface.VeniceCategory;
|
||||
|
||||
class CategoryImpl implements VeniceCategory
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal class for saving category segments
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private static class Segment
|
||||
{
|
||||
/*====================================================================
|
||||
* Attributes
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
private int id; // ID of this category
|
||||
private String name; // name of this segment
|
||||
|
||||
/*====================================================================
|
||||
* Constructor
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
Segment(int id, String name)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*====================================================================
|
||||
* Public getters
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
final int getID()
|
||||
{
|
||||
return id;
|
||||
|
||||
} // end getID
|
||||
|
||||
final String getName()
|
||||
{
|
||||
return name;
|
||||
|
||||
} // end getName
|
||||
|
||||
} // end class Segment
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private CategoryManager m_mgr; // pointer to manager object
|
||||
private LinkedList m_cats; // the actual category segments
|
||||
private int m_symlink = -1; // if our category is actually a symlink
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructors
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
CategoryImpl(CategoryManager mgr)
|
||||
{
|
||||
m_mgr = mgr;
|
||||
m_cats = new LinkedList();
|
||||
|
||||
} // end constructor
|
||||
|
||||
CategoryImpl(CategoryManager mgr, int id, int symlink, String name)
|
||||
{
|
||||
m_mgr = mgr;
|
||||
m_cats = new LinkedList();
|
||||
m_symlink = symlink;
|
||||
m_cats.add(new Segment(id,name));
|
||||
|
||||
} // end constructor
|
||||
|
||||
CategoryImpl(CategoryImpl parent, int id, int symlink, String name)
|
||||
{
|
||||
m_mgr = parent.m_mgr;
|
||||
m_cats = (LinkedList)(parent.m_cats.clone());
|
||||
m_symlink = symlink;
|
||||
m_cats.add(new Segment(id,name));
|
||||
|
||||
} // end constructor
|
||||
|
||||
private CategoryImpl(CategoryImpl other, int copy_levels)
|
||||
{
|
||||
m_mgr = other.m_mgr;
|
||||
m_cats = new LinkedList();
|
||||
m_symlink = ((copy_levels==other.m_cats.size()) ? other.m_symlink : -1);
|
||||
Iterator it = other.m_cats.iterator();
|
||||
for (int i=0; i<copy_levels; i++)
|
||||
m_cats.add(it.next());
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface VeniceCategory
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public int getCategoryID()
|
||||
{
|
||||
if (m_cats.size()>0)
|
||||
return ((Segment)(m_cats.getLast())).getID();
|
||||
else
|
||||
return -1;
|
||||
|
||||
} // end getCategoryID
|
||||
|
||||
public int getNumLevels()
|
||||
{
|
||||
return m_cats.size();
|
||||
|
||||
} // end getNumLevels
|
||||
|
||||
public int getIDAtLevel(int level)
|
||||
{
|
||||
return ((Segment)(m_cats.get(level))).getID();
|
||||
|
||||
} // end getIDAtLevel
|
||||
|
||||
public String getTitleAtLevel(int level)
|
||||
{
|
||||
return ((Segment)(m_cats.get(level))).getName();
|
||||
|
||||
} // end getTitleAtLevel
|
||||
|
||||
public List getSubCategories() throws DatabaseException
|
||||
{
|
||||
return m_mgr.getCategorySublist(this.getLinkedCategoryID());
|
||||
|
||||
} // end getSubCategories
|
||||
|
||||
public VeniceCategory getSuperCategory(int levels)
|
||||
{
|
||||
return m_mgr.canonicalize(new CategoryImpl(this,levels));
|
||||
|
||||
} // end getSuperCategory
|
||||
|
||||
public VeniceCategory getParentCategory()
|
||||
{
|
||||
return m_mgr.canonicalize(new CategoryImpl(this,m_cats.size()-1));
|
||||
|
||||
} // end getParentCategoryID
|
||||
|
||||
public int getLinkedCategoryID()
|
||||
{
|
||||
if (m_symlink>=0)
|
||||
return m_symlink;
|
||||
else
|
||||
return this.getCategoryID();
|
||||
|
||||
} // end getLinkedCategoryID
|
||||
|
||||
public boolean isSymbolicLink()
|
||||
{
|
||||
return (m_symlink>=0);
|
||||
|
||||
} // end isSymbolicLink
|
||||
|
||||
public VeniceCategory getLinkedCategory() throws DatabaseException
|
||||
{
|
||||
if (m_symlink<0)
|
||||
return this;
|
||||
return (VeniceCategory)(m_mgr.lookup(m_symlink));
|
||||
|
||||
} // end getLinkedCategory
|
||||
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj==null)
|
||||
return false;
|
||||
if (obj instanceof VeniceCategory)
|
||||
return (((VeniceCategory)obj).getLinkedCategoryID()==this.getLinkedCategoryID());
|
||||
return this.toString().equals(obj.toString());
|
||||
|
||||
} // end equals
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
return this.getLinkedCategoryID();
|
||||
|
||||
} // end hashCode
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer buf = new StringBuffer();
|
||||
Iterator it = m_cats.iterator();
|
||||
while (it.hasNext())
|
||||
{ // concatenate all the parts together
|
||||
Segment seg = (Segment)(it.next());
|
||||
if (buf.length()>0)
|
||||
buf.append(": ");
|
||||
buf.append(seg.getName());
|
||||
|
||||
} // end while
|
||||
|
||||
return buf.toString();
|
||||
|
||||
} // end toString
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void dispose()
|
||||
{
|
||||
m_mgr = null;
|
||||
m_cats.clear();
|
||||
m_cats = null;
|
||||
|
||||
} // end dispose
|
||||
|
||||
} // end class CategoryImpl
|
||||
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (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.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.community;
|
||||
|
||||
import java.util.*;
|
||||
import org.apache.commons.collections.*;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.w3c.dom.*;
|
||||
import com.silverwrist.util.xml.*;
|
||||
import com.silverwrist.dynamo.except.*;
|
||||
import com.silverwrist.dynamo.iface.*;
|
||||
import com.silverwrist.dynamo.util.*;
|
||||
import com.silverwrist.venice.SearchMode;
|
||||
import com.silverwrist.venice.iface.VeniceCategory;
|
||||
|
||||
public class CategoryManager implements NamedObject, ComponentInitialize, ComponentShutdown, CategoryService
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private static Logger logger = Logger.getLogger(CategoryManager.class);
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private String m_name; // this object's name
|
||||
private CategoryOps m_ops; // database operations
|
||||
private ReferenceMap m_categories; // cached category values
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public CategoryManager()
|
||||
{
|
||||
m_categories = new ReferenceMap(ReferenceMap.HARD,ReferenceMap.SOFT);
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private final List convertList(List base) throws DatabaseException
|
||||
{
|
||||
if (base.isEmpty())
|
||||
return Collections.EMPTY_LIST;
|
||||
|
||||
ArrayList rc = new ArrayList(base.size());
|
||||
synchronized (this)
|
||||
{ // convert the tuples list ont a full category list
|
||||
Iterator it = base.iterator();
|
||||
while (it.hasNext())
|
||||
{ // get the tuple from the list and convert it
|
||||
CategoryTuple tuple = (CategoryTuple)(it.next());
|
||||
Integer key = new Integer(tuple.getCategoryID());
|
||||
VeniceCategory cat = (VeniceCategory)(m_categories.get(key));
|
||||
if (cat==null)
|
||||
{ // need to create a new category object and add it
|
||||
if (tuple.getParentCategoryID()<0)
|
||||
cat = new CategoryImpl(this,tuple.getCategoryID(),tuple.getSymlink(),tuple.getName());
|
||||
else
|
||||
cat = new CategoryImpl(lookup(tuple.getParentCategoryID()),tuple.getCategoryID(),tuple.getSymlink(),
|
||||
tuple.getName());
|
||||
m_categories.put(key,cat);
|
||||
|
||||
} // end if
|
||||
|
||||
rc.add(cat);
|
||||
|
||||
} // end while
|
||||
|
||||
} // end synchronized block
|
||||
|
||||
return Collections.unmodifiableList(rc);
|
||||
|
||||
} // end convertList
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface NamedObject
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return m_name;
|
||||
|
||||
} // end getName
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface ComponentInitialize
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initialize the component.
|
||||
*
|
||||
* @param config_root Pointer to the section of the Dynamo XML configuration file that configures this
|
||||
* particular component. This is to be considered "read-only" by the component.
|
||||
* @param services An implementation of {@link com.silverwrist.dynamo.iface.ServiceProvider ServiceProvider}
|
||||
* which provides initialization services to the component. This will include an implementation
|
||||
* of {@link com.silverwrist.dynamo.iface.ObjectProvider ObjectProvider} which may be used to
|
||||
* get information about other objects previously initialized by the application.
|
||||
* @exception com.silverwrist.dynamo.except.ConfigException If an error is encountered in the component
|
||||
* configuration.
|
||||
*/
|
||||
public void initialize(Element config_root, ServiceProvider services) throws ConfigException
|
||||
{
|
||||
logger.info("CategoryManager initializing");
|
||||
|
||||
XMLLoader loader = XMLLoader.get();
|
||||
String name_pool = null;
|
||||
try
|
||||
{ // verify the right node name
|
||||
loader.verifyNodeName(config_root,"object");
|
||||
|
||||
// get the object's name
|
||||
m_name = loader.getAttribute(config_root,"name");
|
||||
|
||||
// get the name of the database pool
|
||||
DOMElementHelper config_root_h = new DOMElementHelper(config_root);
|
||||
Element foo = loader.getSubElement(config_root_h,"database");
|
||||
name_pool = loader.getAttribute(foo,"connection");
|
||||
|
||||
} // end try
|
||||
catch (XMLLoadException e)
|
||||
{ // error loading XML config data
|
||||
logger.fatal("XML loader exception in StandardContentSupplier",e);
|
||||
throw new ConfigException(e);
|
||||
|
||||
} // end catch
|
||||
|
||||
// Get the database connection pool.
|
||||
DBConnectionPool pool = GetObjectUtils.getDatabaseConnection(services,name_pool);
|
||||
|
||||
// Get the operations object.
|
||||
m_ops = CategoryOps.get(pool);
|
||||
|
||||
} // end initialize
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface ComponentShutdown
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
m_categories.clear();
|
||||
m_ops = null;
|
||||
|
||||
} // end shutdown
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface CategoryService
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public boolean isValidCategoryID(int catid)
|
||||
{
|
||||
if (catid==-1)
|
||||
return true; // valid by definition; it means "Top"
|
||||
if (m_categories.containsKey(new Integer(catid)))
|
||||
return true; // already present in our category map, it must be OK
|
||||
try
|
||||
{ // call down to the database
|
||||
return m_ops.verifyCategoryID(catid);
|
||||
|
||||
} // end try
|
||||
catch (DatabaseException e)
|
||||
{ // don't throw this exception!
|
||||
logger.warn("CategoryManager.isValidCategoryID(): database failure",e);
|
||||
|
||||
} // end catch
|
||||
|
||||
return false; // default return
|
||||
|
||||
} // end isValidCategoryID
|
||||
|
||||
public List getRootCategoryList() throws DatabaseException
|
||||
{
|
||||
return getCategorySublist(-1);
|
||||
|
||||
} // end getRootCategoryList
|
||||
|
||||
public VeniceCategory getCategory(int catid) throws DatabaseException
|
||||
{
|
||||
return (VeniceCategory)lookup(catid);
|
||||
|
||||
} // end getCategory
|
||||
|
||||
public List searchForCategories(SearchMode mode, String term, int offset, int count) throws DatabaseException
|
||||
{
|
||||
return convertList(m_ops.search(mode,term,offset,count));
|
||||
|
||||
} // end searchForCategories
|
||||
|
||||
public int getSearchCategoryCount(SearchMode mode, String term) throws DatabaseException
|
||||
{
|
||||
return m_ops.getSearchCount(mode,term);
|
||||
|
||||
} // end getSearchCategoryCount
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
synchronized CategoryImpl lookup(int catid) throws DatabaseException
|
||||
{
|
||||
Integer key = new Integer(catid);
|
||||
CategoryImpl rc = (CategoryImpl)(m_categories.get(key));
|
||||
if (rc!=null)
|
||||
return rc;
|
||||
|
||||
if (catid<0)
|
||||
{ // for "TOP" category, handle specially
|
||||
rc = new CategoryImpl(this);
|
||||
m_categories.put(key,rc);
|
||||
return rc;
|
||||
|
||||
} // end if
|
||||
|
||||
// look up the tuple for this category
|
||||
CategoryTuple tuple = m_ops.getCategory(catid);
|
||||
if (tuple==null)
|
||||
{ // category not found!
|
||||
DatabaseException de = new DatabaseException(CategoryManager.class,"CommunityMessages","cat.notfound");
|
||||
de.setParameter(0,String.valueOf(catid));
|
||||
throw de;
|
||||
|
||||
} // end if
|
||||
|
||||
if (tuple.getParentCategoryID()<0)
|
||||
rc = new CategoryImpl(this,tuple.getCategoryID(),tuple.getSymlink(),tuple.getName());
|
||||
else // recurse to look up the parent, and so on
|
||||
rc = new CategoryImpl(lookup(tuple.getParentCategoryID()),tuple.getCategoryID(),tuple.getSymlink(),
|
||||
tuple.getName());
|
||||
m_categories.put(key,rc);
|
||||
return rc;
|
||||
|
||||
} // end lookup
|
||||
|
||||
List getCategorySublist(int parentid) throws DatabaseException
|
||||
{
|
||||
return convertList(m_ops.getCategoriesList(parentid));
|
||||
|
||||
} // end getCategorySublist
|
||||
|
||||
synchronized VeniceCategory canonicalize(CategoryImpl obj)
|
||||
{
|
||||
Integer key = new Integer(obj.getCategoryID());
|
||||
VeniceCategory rc = (VeniceCategory)(m_categories.get(key));
|
||||
if (rc==null)
|
||||
{ // it wasn't in our refmap - it is now!
|
||||
m_categories.put(key,obj);
|
||||
rc = obj;
|
||||
|
||||
} // end if
|
||||
else // dispose of the unneeded second copy
|
||||
obj.dispose();
|
||||
return rc;
|
||||
|
||||
} // end canonicalize
|
||||
|
||||
} // end class CategoryManager
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (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.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.community;
|
||||
|
||||
import java.util.*;
|
||||
import com.silverwrist.dynamo.db.OpsBase;
|
||||
import com.silverwrist.dynamo.except.*;
|
||||
import com.silverwrist.dynamo.iface.*;
|
||||
import com.silverwrist.venice.SearchMode;
|
||||
|
||||
abstract class CategoryOps extends OpsBase
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
protected CategoryOps(DBConnectionPool pool)
|
||||
{
|
||||
super(pool);
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Abstract operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
abstract boolean verifyCategoryID(int catid) throws DatabaseException;
|
||||
|
||||
abstract List getCategoriesList(int parent) throws DatabaseException;
|
||||
|
||||
abstract CategoryTuple getCategory(int catid) throws DatabaseException;
|
||||
|
||||
abstract List search(SearchMode mode, String term, int offset, int count) throws DatabaseException;
|
||||
|
||||
abstract int getSearchCount(SearchMode mode, String term) throws DatabaseException;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static CategoryOps get(DBConnectionPool pool) throws ConfigException
|
||||
{
|
||||
return (CategoryOps)get(pool,CategoryOps.class.getClassLoader(),CategoryOps.class.getName() + "_","CategoryOps");
|
||||
|
||||
} // end get
|
||||
|
||||
} // end class CategoryOps
|
||||
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (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.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.community;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import com.silverwrist.util.*;
|
||||
import com.silverwrist.dynamo.except.*;
|
||||
import com.silverwrist.dynamo.iface.*;
|
||||
import com.silverwrist.venice.SearchMode;
|
||||
|
||||
public class CategoryOps_mysql extends CategoryOps
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private DBUtilities m_utils;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public CategoryOps_mysql(DBConnectionPool pool)
|
||||
{
|
||||
super(pool);
|
||||
m_utils = (DBUtilities)(pool.queryService(DBUtilities.class));
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Abstract implementations from class CategoryOps
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
boolean verifyCategoryID(int catid) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// prepare and execute the statement
|
||||
stmt = conn.prepareStatement("SELECT catid FROM refcategory WHERE catid = ? AND dontuse = 0;");
|
||||
stmt.setInt(1,catid);
|
||||
rs = stmt.executeQuery();
|
||||
return rs.next();
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end verifyCategoryID
|
||||
|
||||
List getCategoriesList(int parent) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// create and execute the statement
|
||||
stmt = conn.prepareStatement("SELECT catid, symlink, name FROM refcategory WHERE parent = ? AND dontuse = 0 "
|
||||
+ "ORDER BY name;");
|
||||
stmt.setInt(1,parent);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
// create the return list of CategoryTuple values
|
||||
ArrayList rc = new ArrayList();
|
||||
while (rs.next())
|
||||
rc.add(new CategoryTuple(rs.getInt(1),parent,rs.getInt(2),rs.getString(3)));
|
||||
return rc;
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end getCategoriesList
|
||||
|
||||
CategoryTuple getCategory(int catid) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// create and execute the statement
|
||||
stmt = conn.prepareStatement("SELECT parent, symlink, name FROM refcategory WHERE catid = ? AND dontuse = 0;");
|
||||
stmt.setInt(1,catid);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
return new CategoryTuple(catid,rs.getInt(1),rs.getInt(2),rs.getString(3));
|
||||
else
|
||||
return null;
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end getCategory
|
||||
|
||||
List search(SearchMode mode, String term, int offset, int count) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// build the SQL statement as a string
|
||||
StringBuffer sql = new StringBuffer("SELECT catid, parent, symlink, name FROM refcategory WHERE name ");
|
||||
if (SearchMode.PREFIX.equals(mode))
|
||||
sql.append("LIKE '").append(m_utils.encodeStringWildcards(term)).append("%'");
|
||||
else if (SearchMode.SUBSTRING.equals(mode))
|
||||
sql.append("LIKE '%").append(m_utils.encodeStringWildcards(term)).append("%'");
|
||||
else if (SearchMode.REGEXP.equals(mode))
|
||||
sql.append("REGEXP '").append(m_utils.encodeString(term)).append('\'');
|
||||
sql.append(" AND dontuse = 0 ORDER BY parent, name LIMIT ").append(offset).append(", ").append(count+1);
|
||||
sql.append(';');
|
||||
|
||||
// execute the operation!
|
||||
stmt = conn.createStatement();
|
||||
rs = stmt.executeQuery(sql.toString());
|
||||
|
||||
// create the return list of CategoryTuple values
|
||||
ArrayList rc = new ArrayList(count+1);
|
||||
while (rs.next())
|
||||
rc.add(new CategoryTuple(rs.getInt(1),rs.getInt(2),rs.getInt(3),rs.getString(4)));
|
||||
return rc;
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end searchForCategories
|
||||
|
||||
int getSearchCount(SearchMode mode, String term) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// build the SQL statement as a string
|
||||
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM refcategory WHERE name ");
|
||||
if (SearchMode.PREFIX.equals(mode))
|
||||
sql.append("LIKE '").append(m_utils.encodeStringWildcards(term)).append("%'");
|
||||
else if (SearchMode.SUBSTRING.equals(mode))
|
||||
sql.append("LIKE '%").append(m_utils.encodeStringWildcards(term)).append("%'");
|
||||
else if (SearchMode.REGEXP.equals(mode))
|
||||
sql.append("REGEXP '").append(m_utils.encodeString(term)).append('\'');
|
||||
sql.append(" AND dontuse = 0;");
|
||||
|
||||
// execute the operation!
|
||||
stmt = conn.createStatement();
|
||||
rs = stmt.executeQuery(sql.toString());
|
||||
return SQLUtils.getReturnCountInt(rs,1);
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end getSearchCount
|
||||
|
||||
} // end class CategoryOps_mysql
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (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.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.community;
|
||||
|
||||
import java.util.List;
|
||||
import com.silverwrist.dynamo.except.DatabaseException;
|
||||
import com.silverwrist.venice.SearchMode;
|
||||
import com.silverwrist.venice.iface.VeniceCategory;
|
||||
|
||||
public interface CategoryService
|
||||
{
|
||||
public boolean isValidCategoryID(int catid);
|
||||
|
||||
public List getRootCategoryList() throws DatabaseException;
|
||||
|
||||
public VeniceCategory getCategory(int catid) throws DatabaseException;
|
||||
|
||||
public List searchForCategories(SearchMode mode, String term, int offset, int count) throws DatabaseException;
|
||||
|
||||
public int getSearchCategoryCount(SearchMode mode, String term) throws DatabaseException;
|
||||
|
||||
} // end interface CategoryService
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (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.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.community;
|
||||
|
||||
class CategoryTuple
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private int m_catid;
|
||||
private int m_parent;
|
||||
private int m_symlink;
|
||||
private String m_name;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
CategoryTuple(int catid, int parent, int symlink, String name)
|
||||
{
|
||||
m_catid = catid;
|
||||
m_parent = parent;
|
||||
m_symlink = symlink;
|
||||
m_name = name;
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Public getters
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int getCategoryID()
|
||||
{
|
||||
return m_catid;
|
||||
|
||||
} // end getCategoryID
|
||||
|
||||
int getParentCategoryID()
|
||||
{
|
||||
return m_parent;
|
||||
|
||||
} // end getParentCategoryID
|
||||
|
||||
int getSymlink()
|
||||
{
|
||||
return m_symlink;
|
||||
|
||||
} // end getSymLink
|
||||
|
||||
String getName()
|
||||
{
|
||||
return m_name;
|
||||
|
||||
} // end getName
|
||||
|
||||
} // end class CategoryTuple
|
||||
@@ -0,0 +1,18 @@
|
||||
# The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
# (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.mozilla.org/MPL/>.
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
# WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
# language governing rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is the Venice Web Communities System.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
# Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# ---------------------------------------------------------------------------------
|
||||
# This file has been localized for the en_US locale
|
||||
cat.notfound=The category with ID#{0} does not exist in the database.
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (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.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.iface;
|
||||
|
||||
import java.util.List;
|
||||
import com.silverwrist.dynamo.except.DatabaseException;
|
||||
|
||||
public interface VeniceCategory
|
||||
{
|
||||
public int getCategoryID();
|
||||
|
||||
public int getNumLevels();
|
||||
|
||||
public int getIDAtLevel(int level);
|
||||
|
||||
public String getTitleAtLevel(int level);
|
||||
|
||||
public List getSubCategories() throws DatabaseException;
|
||||
|
||||
public VeniceCategory getSuperCategory(int levels);
|
||||
|
||||
public VeniceCategory getParentCategory();
|
||||
|
||||
public int getLinkedCategoryID();
|
||||
|
||||
public boolean isSymbolicLink();
|
||||
|
||||
public VeniceCategory getLinkedCategory() throws DatabaseException;
|
||||
|
||||
public boolean equals(Object obj);
|
||||
|
||||
public int hashCode();
|
||||
|
||||
public String toString();
|
||||
|
||||
} // end interface VeniceCategory
|
||||
@@ -20,6 +20,7 @@ package com.silverwrist.venice.script;
|
||||
import com.silverwrist.dynamo.Namespaces;
|
||||
import com.silverwrist.dynamo.except.*;
|
||||
import com.silverwrist.dynamo.iface.*;
|
||||
import com.silverwrist.venice.community.CategoryService;
|
||||
import com.silverwrist.venice.iface.*;
|
||||
|
||||
public class LibraryVeniceCast
|
||||
@@ -86,6 +87,12 @@ public class LibraryVeniceCast
|
||||
|
||||
} // end queryButtonProvider
|
||||
|
||||
public final CategoryService queryCategoryService(Object obj)
|
||||
{
|
||||
return (CategoryService)query(obj,CategoryService.class);
|
||||
|
||||
} // end queryCategoryService
|
||||
|
||||
public final ContentBlockProvider queryContentBlockProvider(Object obj)
|
||||
{
|
||||
return (ContentBlockProvider)query(obj,ContentBlockProvider.class);
|
||||
|
||||
Reference in New Issue
Block a user