portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbregistry PortletDbEntryPeer.java
Date Tue, 20 Jul 2004 04:08:04 GMT
taylor      2004/07/19 21:08:04

  Added:       src/java/org/apache/jetspeed/om/dbregistry
                        PortletDbEntryPeer.java
  Log:
  first phase of Portlet DB Registry impl
  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbregistry/PortletDbEntryPeer.java
  
  Index: PortletDbEntryPeer.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.om.dbregistry;
  
  import java.sql.Connection;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.jetspeed.om.registry.PortletEntry;
  import org.apache.jetspeed.om.registry.RegistryException;
  import org.apache.jetspeed.om.registry.base.BasePortletEntry;
  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
  import org.apache.jetspeed.services.logging.JetspeedLogger;
  import org.apache.torque.Torque;
  import org.apache.torque.TorqueException;
  import org.apache.torque.util.Criteria;
  
  /**
   * Implements the Portlet Registry database operations
   * 
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
   * @version $Id: PortletDbEntryPeer.java,v 1.1 2004/07/20 04:08:04 taylor Exp $
   */
  public class PortletDbEntryPeer extends
          org.apache.jetspeed.om.dbregistry.BasePortletDbEntryPeer
  {
  
      private static final JetspeedLogger logger = JetspeedLogFactoryService
              .getLogger(PortletDbEntryPeer.class.getName());
  
      public static PortletEntry lookupPortletEntry(String entryName)
      {
          PortletEntry pe = null;
          try
          {
              PortletDbEntry pde = lookup(entryName);
              pe = mapDatabaseToEntry(pde);
          } catch (Exception e)
          {
              logger.error("Exception retrieving Portlet Entry: " + entryName, e);
          }
          return pe;
      }
  
      private static PortletDbEntry lookup(String entryName)
              throws TorqueException
      {
          Criteria criteria = new Criteria();
          criteria.add(PortletDbEntryPeer.NAME, entryName);
          List result = PortletDbEntryPeer.doSelect(criteria);
          if (null == result || result.isEmpty()) { return null; }
          return (PortletDbEntry) result.get(0);
      }
  
      public static PortletEntry mapDatabaseToEntry(PortletDbEntry sde)
              throws TorqueException
      {
          PortletEntry pe = new BasePortletEntry(sde.getId());
          return pe;
      }
  
      public static void removePortletSubObjects(long id)
              throws RegistryException
      {
          try
          {
              Criteria criteria = new Criteria();
              criteria.add(PortletParameterPeer.PORTLET_ID, id);
              PortletParameterPeer.doDelete(criteria);
              /*
               * criteria = new Criteria();
               * criteria.add(PortletParameterPeer.PORTLET_ID, id);
               * PortletParameterPeer.doDelete(criteria);
               * 
               * criteria = new Criteria(); criteria.add(PortletMediatypePeer.,
               * id); PortletParameterPeer.doDelete(criteria);
               */
  
          } catch (TorqueException e)
          {
              logger.error("Exception Removing Portlet Entry Accesses: " + id, e);
              throw new RegistryException("Exception Removing Portlet Entry: "
                      + id + ", " + e.toString());
          }
      }
  
      public static List fetchExtent() throws RegistryException
      {
          List extent = new ArrayList();
          try
          {
              Iterator result = PortletDbEntryPeer.doSelect(new Criteria())
                      .iterator();
              while (result.hasNext())
              {
                  PortletEntry se = mapDatabaseToEntry((PortletDbEntry) result
                          .next());
                  extent.add(se);
              }
          } catch (TorqueException e)
          {
              String msg = "Exception Fetching Extent for Portlet ";
              logger.error(msg, e);
              throw new RegistryException(msg + e);
          }
          return extent;
      }
  
      public static void storePortletEntry(PortletEntry pe)
              throws RegistryException
      {
          Connection conn = null;
          boolean autoCommit = false;
          try
          {
              // get fresh copy in case its changed on another node
              PortletDbEntry pde = lookup(pe.getName());
              if (null != pde)
              {
                  PortletDbEntryPeer.removePortletSubObjects(pde.getId());
              } else
              {
                  pde = new PortletDbEntry();
              }
              conn = Torque.getConnection(DATABASE_NAME);
              autoCommit = conn.getAutoCommit();
              conn.setAutoCommit(false);
  
              pde.setName(pe.getName());
              pde.setTitle(pe.getTitle());
              pde.setDescription(pe.getDescription());
              // TODO: LEFT OFF here
              pde.save(conn);
  
              Iterator parameters = pe.getParameterNames();
              while (parameters.hasNext())
              {
                  /*
                   * PortletAccess access = (SecurityAccess)accesses.next();
                   * SecurityAccessDbEntry sade = new SecurityAccessDbEntry();
                   * sade.setAction(access.getAction());
                   * sade.setEntryId(sde.getId()); sade.save(conn);
                   * 
                   * Iterator allows = access.getAllAllows().iterator(); while
                   * (allows.hasNext()) { SecurityAllow allow =
                   * (SecurityAllow)allows.next(); SecurityAllowDbEntry sa = new
                   * SecurityAllowDbEntry(); if (allow.isOwner()) {
                   * sa.setAllowType(ALLOW_OWNER); sa.setAllowValue(ALLOW_OWNER); }
                   * else if (allow.getRole() != null && allow.getGroup() != null)
{
                   * sa.setAllowType(ALLOW_BOTH);
                   * sa.setAllowValue(allow.getRole());
                   * sa.setAllowGroup(allow.getGroup()); } else if
                   * (allow.getRole() != null) { sa.setAllowType(ALLOW_ROLE);
                   * sa.setAllowValue(allow.getRole()); } else if
                   * (allow.getGroup() != null) { sa.setAllowType(ALLOW_GROUP);
                   * sa.setAllowValue(allow.getGroup()); } else {
                   * sa.setAllowType(ALLOW_USER);
                   * sa.setAllowValue(allow.getUser()); }
                   * sa.setAccessId(sade.getId()); sa.save(conn); }
                   */
              }
  
          } catch (Exception e)
          {
              try
              {
                  conn.rollback();
              } catch (Exception e2)
              {
                  logger.error("Failed to rollback", e2);
              }
              logger.error("Exception storing Portlet Entry: " + pe.getName(), e);
              throw new RegistryException("Exception storing Portlet Entry: "
                      + pe.getName() + ", " + e.toString());
          } finally
          {
              // make sure to release the database connection
              Torque.closeConnection(conn);
              try
              {
                  conn.setAutoCommit(autoCommit);
              } catch (Exception e)
              {
              }
          }
  
      }
  
      public static void removePortletEntry(String entryName)
              throws RegistryException
      {
          try
          {
              Criteria criteria = new Criteria();
              criteria.add(PortletDbEntryPeer.NAME, entryName);
              PortletDbEntryPeer.doDelete(criteria);
          } catch (TorqueException e)
          {
              logger.error("Exception Removing Portlet Entry: " + entryName, e);
              throw new RegistryException("Exception Removing Portlet Entry: "
                      + entryName + ", " + e.toString());
          }
      }
  
  }
  
  

---------------------------------------------------------------------
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