portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wea...@apache.org
Subject cvs commit: jakarta-jetspeed-2/plugin/src/java/org/apache/jetspeed/persistence/impl/jdo JDOLookUpCriteria.java JPOXJDOPersistencePlugin.java
Date Wed, 04 Feb 2004 21:02:51 GMT
weaver      2004/02/04 13:02:51

  Added:       plugin/src/java/org/apache/jetspeed/persistence/impl/jdo
                        JDOLookUpCriteria.java
                        JPOXJDOPersistencePlugin.java
  Log:
  Begins of a non-ojb JDO plugin implementation
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed-2/plugin/src/java/org/apache/jetspeed/persistence/impl/jdo/JDOLookUpCriteria.java
  
  Index: JDOLookUpCriteria.java
  ===================================================================
  /**
   * Created on Jan 26, 2004
   *
   * 
   * @author
   */
  package org.apache.jetspeed.persistence.impl.jdo;
  
  import java.util.Collection;
  import java.util.Iterator;
  
  
  import org.apache.jetspeed.persistence.LookupCriteria;
  
  
  /**
   * <p>
   * JDOLookUpCriteria
   * </p>
   * 
   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
   * @version $Id: JDOLookUpCriteria.java,v 1.1 2004/02/04 21:02:50 weaver Exp $
   *
   */
  public class JDOLookUpCriteria implements LookupCriteria
  {
   
      
      private StringBuffer filter;
      private String ordering;
  
      public JDOLookUpCriteria()
      {
     
          this.filter = new StringBuffer();
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addBetween(java.lang.String,
java.lang.Object, java.lang.Object)
       */
      public void addBetween(String arg0, Object arg1, Object arg2)
      {
          addAnd();
          filter.append(arg0 + " > " + arg1 + " && " + arg0 + " < " + arg2);
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addEqualTo(java.lang.String,
java.lang.Object)
       */
      public void addEqualTo(String arg0, Object arg1)
      {
          addAnd();
          filter.append(arg0 + " == " + arg1);
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addGreaterOrEqualThan(java.lang.String,
java.lang.Object)
       */
      public void addGreaterOrEqualThan(String arg0, Object arg1)
      {
          addAnd();
          filter.append(arg0 + " >= " + arg1);
  
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addGreaterThan(java.lang.String,
java.lang.Object)
       */
      public void addGreaterThan(String arg0, Object arg1)
      {
          addAnd();
          filter.append(arg0 + " > " + arg1);
  
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addIn(java.lang.String, java.util.Collection)
       */
      public void addIn(String attribute, Collection values)
      {
          addAnd();
          Iterator itr = values.iterator();
          filter.append("(");
          String or = "";
          while (itr.hasNext())
          {
              filter.append(or);
              filter.append(attribute + " == " + itr.next());
              or = " || ";
          }
          filter.append(")");
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addLessOrEqualThan(java.lang.String,
java.lang.Object)
       */
      public void addLessOrEqualThan(String arg0, Object arg1)
      {
          addAnd();
          filter.append(arg0 + " >= " + arg1);
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addLike(java.lang.String, java.lang.Object)
       */
      public void addLike(String arg0, Object arg1)
      {
          addAnd();
          boolean both = false;
  
          if (arg1.toString().startsWith("*"))
          {
              String value = arg1.toString().substring(1);
              if (arg1.toString().endsWith("*"))
              {
                  value = value.substring(0, value.length() - 1);
              }
  
              filter.append(arg0 + ".endsWith(\"" + value + "\")");
              both = true;            
          }
  
          if (arg1.toString().endsWith("*"))
          {
          	if(both)
          	{
          		addAnd();
          	}
          	
              String value = arg1.toString().substring(0, arg1.toString().length() - 1);
              if (arg1.toString().startsWith("*"))
              {
  				value = arg1.toString().substring(1);
              }
              filter.append(arg0 + ".startsWith(\"" + value + "\")");
          }
  
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addNotBetween(java.lang.String,
java.lang.Object, java.lang.Object)
       */
      public void addNotBetween(String arg0, Object arg1, Object arg2)
      {
  		addAnd();
          filter.append(arg0 + " < " + arg1 + " || " + arg0 + " > " + arg2);
  	   
  
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addNotEqualTo(java.lang.String,
java.lang.Object)
       */
      public void addNotEqualTo(String arg0, Object arg1)
      {
  		addAnd();
  		filter.append(arg0 + " != " + arg1);
  
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addNotLike(java.lang.String,
java.lang.Object)
       */
      public void addNotLike(String arg0, Object arg1)
      {
          // TODO Auto-generated method stub
  
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addNotNull(java.lang.String)
       */
      public void addNotNull(String arg0)
      {
          addAnd();
          filter.append(arg0+" != null");
  
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addOrCriteria(org.apache.ojb.broker.query.Criteria)
       */
      public void addOrCriteria(LookupCriteria arg0)
      {		
  		filter.append(" || ("+arg0.toString()+")"); 
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addOrderByAscending(java.lang.String)
       */
      public void addOrderByAscending(String arg0)
      {
          ordering = arg0+" ascending";
  
      }
  
      /**
       * @see org.apache.jetspeed.persistence.LookupCriteria#addOrderByDescending(java.lang.String)
       */
      public void addOrderByDescending(String arg0)
      {
  		ordering = arg0+" descending";
  
      }
  
      private void addAnd()
      {
          if (filter.length() > 0)
          {
              filter.append(" && ");
          }
      }
  
      /**
       * @see java.lang.Object#toString()
       * 
       * @return A string that is usable as a JDO OQL query
       */
      public String toString()
      {        
          return filter.toString();
      }
      
      public String getOrderingString()
      {
      	return ordering;
      }
  
  }
  
  
  
  1.1                  jakarta-jetspeed-2/plugin/src/java/org/apache/jetspeed/persistence/impl/jdo/JPOXJDOPersistencePlugin.java
  
  Index: JPOXJDOPersistencePlugin.java
  ===================================================================
  /**
   * Created on Jan 26, 2004
   *
   * 
   * @author
   */
  package org.apache.jetspeed.persistence.impl.jdo;
  
  import java.sql.Connection;
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.Properties;
  
  //import javax.jdo.JDOHelper;
  //import javax.jdo.PersistenceManager;
  //import javax.jdo.PersistenceManagerFactory;
  //import javax.jdo.Query;
  //import javax.jdo.Transaction;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.jetspeed.persistence.LookupCriteria;
  import org.apache.jetspeed.persistence.PersistencePlugin;
  import org.apache.jetspeed.persistence.TransactionStateException;
  import org.apache.jetspeed.services.plugin.PluginConfiguration;
  import org.apache.jetspeed.services.plugin.PluginInitializationException;
  
  /**
   * <p>
   * JPOXJDOPersistencePlugin
   * </p>
   * 
   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
   * @version $Id: JPOXJDOPersistencePlugin.java,v 1.1 2004/02/04 21:02:50 weaver Exp $
   *
   */
  // public class JPOXJDOPersistencePlugin implements PersistencePlugin
  public class JPOXJDOPersistencePlugin
  {
  
  //    public static final String VALIDATE_CONSTRAINTS = "org.jpox.validateConstraints";
  //    public static final String VALIDATE_TABLES = "org.jpox.validateTables";
  //    public static final String AUTOCREATE_TABLES = "org.jpox.autoCreateTables";
  //    public static final String CONNECTION_PASSWORD = "javax.jdo.option.ConnectionPassword";
  //    public static final String CONNECTION_USER_NAME = "javax.jdo.option.ConnectionUserName";
  //    public static final String CONNECTION_URL = "javax.jdo.option.ConnectionURL";
  //    public static final String CONNECTION_DRIVER_NAME = "javax.jdo.option.ConnectionDriverName";
  //    public static final String PERSISTENCE_MANAGER_FACTORY_CLASS = "javax.jdo.PersistenceManagerFactoryClass";
  //    protected static final String RESOLVE_DB_ALIAS = "resolveDbAlias";
  //
  //    private static final Log log = LogFactory.getLog(JPOXJDOPersistencePlugin.class);
  //
  //    private PersistenceManagerFactory pmf;
  //
  //    private ThreadLocal TLpm = new ThreadLocal();
  //    
  //    private PluginConfiguration conf;
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#beginTransaction()
  //     */
  //    public void beginTransaction() throws TransactionStateException
  //    {
  //        Transaction tx = getManager().currentTransaction();
  //        tx.begin();
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#commitTransaction()
  //     */
  //    public void commitTransaction() throws TransactionStateException
  //    {
  //        Transaction tx = getManager().currentTransaction();
  //        tx.commit();
  //        getManager().close();
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#prepareForDelete(java.lang.Object)
  //     */
  //    public void prepareForDelete(Object obj) throws TransactionStateException
  //    {
  //        getManager().deletePersistent(obj);
  //
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#prepareForUpdate(java.lang.Object)
  //     */
  //    public void prepareForUpdate(Object obj) throws TransactionStateException
  //    {
  //        getManager().makeTransactional(obj);
  //
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#makePersistent(java.lang.Object)
  //     */
  //    public void makePersistent(Object obj) throws TransactionStateException
  //    {
  //        getManager().makePersistent(obj);
  //
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#rollbackTransaction()
  //     */
  //    public void rollbackTransaction() throws TransactionStateException
  //    {
  //        Transaction tx = getManager().currentTransaction();
  //        try
  //        {
  //            if (tx.isActive())
  //            {
  //                tx.rollback();
  //            }
  //        }
  //        finally
  //        {
  //            getManager().close();
  //        }
  //
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#markDirty(java.lang.Object)
  //     */
  //    public Object markDirty(Object obj) throws TransactionStateException
  //    {
  //        getManager().makeTransactional(obj);
  //        return obj;
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#deleteByQuery(java.lang.Object)
  //     */
  //    public void deleteByQuery(Object query)
  //    {
  //        // TODO Auto-generated method stub
  //
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#getCollectionByQuery(java.lang.Class,
java.lang.Object)
  //     */
  //    public Collection getCollectionByQuery(Class clazz, Object query)
  //    {
  //        Query jdoQuery = (Query) query;
  //        return (Collection) jdoQuery.execute();
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#getExtent(java.lang.Class)
  //     */
  //    public Collection getExtent(Class clazz)
  //    {
  //        Query jdoQuery = getManager().newQuery(clazz);
  //        return getCollectionByQuery(clazz, jdoQuery);
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#getObjectByQuery(java.lang.Class,
java.lang.Object)
  //     */
  //    public Object getObjectByQuery(Class clazz, Object query)
  //    {
  //        Collection c = getCollectionByQuery(clazz, query);
  //        Iterator itr = c.iterator();
  //        if (itr.hasNext())
  //        {
  //            return itr.next();
  //        }
  //        else
  //        {
  //            return null;
  //        }
  //
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#generateQuery(java.lang.Class,
org.apache.jetspeed.persistence.LookupCriteria)
  //     */
  //    public Object generateQuery(Class clazz, LookupCriteria criteria)
  //    {
  //        Query jdoQuery = getManager().newQuery(clazz);
  //        JDOLookUpCriteria jdoCrit = (JDOLookUpCriteria) criteria;
  //        jdoQuery.setFilter(jdoCrit.toString());
  //        jdoQuery.setOrdering(jdoCrit.getOrderingString());
  //        return jdoQuery;
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#newLookupCriteria()
  //     */
  //    public LookupCriteria newLookupCriteria()
  //    {        
  //        return new JDOLookUpCriteria( );
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#getConfiguration()
  //     */
  //    public PluginConfiguration getConfiguration()
  //    {        
  //        return conf;
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#setDbAlias(java.lang.String)
  //     */
  //    public void setDbAlias(String dbAlias) throws UnsupportedOperationException
  //    {
  //        // TODO Auto-generated method stub
  //
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#getDbAlias()
  //     */
  //    public String getDbAlias() throws UnsupportedOperationException
  //    {
  //        // TODO Auto-generated method stub
  //        return null;
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#getSqlConnection()
  //     */
  //    public Connection getSqlConnection()
  //    {
  //        // TODO Auto-generated method stub
  //        return null;
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#releaseSqlConnection(java.sql.Connection)
  //     */
  //    public void releaseSqlConnection(Connection sqlConnection)
  //    {
  //        // TODO Auto-generated method stub
  //
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#invalidateObject(java.lang.Object)
  //     */
  //    public void invalidateObject(Object object)
  //    {
  //        getManager().evict(object);
  //
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.persistence.PersistencePlugin#clearCache()
  //     */
  //    public void clearCache()
  //    {
  //        getManager().evictAll();
  //
  //    }
  //
  //    /**
  //     * @see org.apache.jetspeed.services.plugin.Plugin#init(org.apache.jetspeed.services.plugin.PluginConfiguration)
  //     */
  //    public void init(PluginConfiguration configuration) throws PluginInitializationException
  //    {
  //    	this.conf = configuration;
  //        Properties properties = new Properties();
  //
  //        properties.setProperty(
  //            PERSISTENCE_MANAGER_FACTORY_CLASS,
  //            configuration.getProperty(PERSISTENCE_MANAGER_FACTORY_CLASS, "org.jpox.PersistenceManagerFactoryImpl"));
  //        properties.setProperty(CONNECTION_DRIVER_NAME, configuration.getProperty(CONNECTION_DRIVER_NAME));
  //
  //        //		This helps us support RDBMSes that have file system based aliases
  //        // like HSQL in stand-alone mode
  ////      boolean resolveAlias = new Boolean(configuration.getProperty(RESOLVE_DB_ALIAS,
"false")).booleanValue();
  //        String url = configuration.getProperty(CONNECTION_URL);
  ////        if (resolveAlias)
  ////        {
  ////            log.info("Resolving DB alias to absolute path.");
  ////            int startAlias = url.indexOf("://");
  ////            if (startAlias != -1)
  ////            {
  ////                startAlias = startAlias + 3;
  ////            }
  ////            String relativePath = url.substring(startAlias, url.length());
  ////            String protocol = url.substring(0, startAlias);
  ////            log.info("DB protocol: " + protocol);
  ////            log.info("DB relative path: " + relativePath);
  ////
  ////            String truePath = configuration.getPathResolver().getRealPath(relativePath);
  ////            url = protocol + truePath;
  ////        }
  //
  //        log.info("Database URL: " + url);
  //
  //        properties.setProperty(CONNECTION_URL, url);
  //        properties.setProperty(CONNECTION_USER_NAME, configuration.getProperty(CONNECTION_USER_NAME));
  //        properties.setProperty(CONNECTION_PASSWORD, configuration.getProperty(CONNECTION_PASSWORD,
""));
  //        properties.setProperty(AUTOCREATE_TABLES, configuration.getProperty(AUTOCREATE_TABLES,
"false"));
  //        properties.setProperty(VALIDATE_TABLES, configuration.getProperty(VALIDATE_TABLES,
"false"));
  //        properties.setProperty(VALIDATE_CONSTRAINTS, configuration.getProperty(VALIDATE_CONSTRAINTS,
"false"));
  //
  //        this.pmf = JDOHelper.getPersistenceManagerFactory(properties);
  //    }
  //
  //    public PersistenceManager getManager()
  //    {
  //        PersistenceManager pm = (PersistenceManager) TLpm.get();
  //        if (pm == null)
  //        {
  //            pm = this.pmf.getPersistenceManager();
  //            TLpm.set(pm);
  //        }
  //        return pm;
  //    }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message