Coverage report

  %line %branch
org.apache.turbine.om.security.peer.GroupPeer
0% 
0% 

 1  
 package org.apache.turbine.om.security.peer;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License")
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import com.workingdogs.village.Record;
 20  
 import java.util.ArrayList;
 21  
 import java.util.List;
 22  
 import java.util.Map;
 23  
 import org.apache.torque.TorqueException;
 24  
 import org.apache.torque.om.BaseObject;
 25  
 import org.apache.torque.om.NumberKey;
 26  
 import org.apache.torque.util.BasePeer;
 27  
 import org.apache.torque.util.Criteria;
 28  
 import org.apache.turbine.om.security.Group;
 29  
 import org.apache.turbine.om.security.SecurityObject;
 30  
 import org.apache.turbine.om.security.TurbineGroup;
 31  
 import org.apache.turbine.services.security.TurbineSecurity;
 32  
 import org.apache.turbine.util.ObjectUtils;
 33  
 import org.apache.turbine.util.db.map.TurbineMapBuilder;
 34  
 import org.apache.turbine.util.security.DataBackendException;
 35  
 import org.apache.turbine.util.security.GroupSet;
 36  
 
 37  
 /**
 38  
  * This class handles all the database access for the Group table.
 39  
  * This table contains all the Groups that a given member can play.
 40  
  *
 41  
  * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
 42  
  * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
 43  
  * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
 44  
  * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
 45  
  * @version $Id: GroupPeer.java 264148 2005-08-29 14:21:04Z henning $
 46  
  */
 47  0
 public class GroupPeer extends BasePeer
 48  
 {
 49  
     /** Serial Version UID */
 50  
     private static final long serialVersionUID = 2902002237040953323L;
 51  
 
 52  
     /** The map builder for this Peer. */
 53  0
     private static final TurbineMapBuilder MAP_BUILDER = (TurbineMapBuilder)
 54  0
             getMapBuilder(TurbineMapBuilder.class.getName());
 55  
 
 56  
     /** The table name for this peer. */
 57  0
     private static final String TABLE_NAME = MAP_BUILDER.getTableGroup();
 58  
 
 59  
     /** The column name for the Group id field. */
 60  0
     public static final String GROUP_ID = MAP_BUILDER.getGroup_GroupId();
 61  
 
 62  
     /** The column name for the name field. */
 63  0
     public static final String NAME = MAP_BUILDER.getGroup_Name();
 64  
 
 65  
     /** The column name for the ObjectData field */
 66  0
     public static final String OBJECTDATA = MAP_BUILDER.getGroup_ObjectData();
 67  
 
 68  
     /**
 69  
      * Retrieves/assembles a GroupSet of all of the Groups.
 70  
      *
 71  
      * @return A GroupSet.
 72  
      * @exception Exception a generic exception.
 73  
      */
 74  
     public static GroupSet retrieveSet() throws Exception
 75  
     {
 76  0
         return retrieveSet(new Criteria());
 77  
     }
 78  
 
 79  
     /**
 80  
      * Retrieves/assembles a GroupSet based on the Criteria passed in
 81  
      *
 82  
      * @param criteria The criteria to use.
 83  
      * @throws Exception a generic exception.
 84  
      * @return a GroupSet
 85  
      */
 86  
     public static GroupSet retrieveSet(Criteria criteria) throws Exception
 87  
     {
 88  0
         List results = GroupPeer.doSelect(criteria);
 89  0
         GroupSet rs = new GroupSet();
 90  0
         for (int i = 0; i < results.size(); i++)
 91  
         {
 92  0
             rs.add((Group) results.get(i));
 93  
         }
 94  0
         return rs;
 95  
     }
 96  
 
 97  
     /**
 98  
      * Issues a select based on a criteria.
 99  
      *
 100  
      * @param criteria object containing data that is used to create
 101  
      *        the SELECT statement.
 102  
      * @return Vector containing Group objects.
 103  
      * @exception TorqueException a generic exception.
 104  
      */
 105  
     public static List doSelect(Criteria criteria) throws TorqueException
 106  
     {
 107  
         try
 108  
         {
 109  0
             criteria.addSelectColumn(GROUP_ID)
 110  
                     .addSelectColumn(NAME)
 111  
                     .addSelectColumn(OBJECTDATA);
 112  
 
 113  0
             if (criteria.getOrderByColumns() == null
 114  
                     || criteria.getOrderByColumns().size() == 0)
 115  
             {
 116  0
                 criteria.addAscendingOrderByColumn(NAME);
 117  
             }
 118  
 
 119  
             // Place any checks here to intercept criteria which require
 120  
             // custom SQL.  For example:
 121  
             // if ( criteria.containsKey("SomeTable.SomeColumn") )
 122  
             // {
 123  
             //     String whereSql = "SomeTable.SomeColumn IN (Select ...";
 124  
             //     criteria.add("SomeTable.SomeColumn",
 125  
             //                  whereSQL, criteria.CUSTOM);
 126  
             // }
 127  
 
 128  
             // BasePeer returns a Vector of Value (Village) arrays.  The
 129  
             // array order follows the order columns were placed in the
 130  
             // Select clause.
 131  0
             List rows = BasePeer.doSelect(criteria);
 132  0
             List results = new ArrayList();
 133  
 
 134  
             // Populate the object(s).
 135  0
             for (int i = 0; i < rows.size(); i++)
 136  
             {
 137  0
                 Group obj = TurbineSecurity.getGroupInstance(null);
 138  0
                 Record row = (Record) rows.get(i);
 139  0
                 ((SecurityObject) obj).setPrimaryKey(
 140  
                         new NumberKey(row.getValue(1).asInt()));
 141  0
                 ((SecurityObject) obj).setName(row.getValue(2).asString());
 142  0
                 byte[] objectData = row.getValue(3).asBytes();
 143  0
                 Map temp = (Map) ObjectUtils.deserialize(objectData);
 144  0
                 if (temp != null)
 145  
                 {
 146  0
                     ((SecurityObject) obj).setAttributes(temp);
 147  
                 }
 148  0
                 results.add(obj);
 149  
             }
 150  
 
 151  0
             return results;
 152  
         }
 153  0
         catch (Exception ex)
 154  
         {
 155  0
             throw new TorqueException(ex);
 156  
         }
 157  
     }
 158  
 
 159  
     /**
 160  
      * Issues an update based on a criteria.
 161  
      *
 162  
      * @param criteria object containing data that is used to create
 163  
      *        the UPDATE statement.
 164  
      * @exception TorqueException a generic exception.
 165  
      */
 166  
     public static void doUpdate(Criteria criteria)
 167  
         throws TorqueException
 168  
     {
 169  0
         Criteria selectCriteria = new Criteria(2);
 170  0
         selectCriteria.put(GROUP_ID, criteria.remove(GROUP_ID));
 171  0
         BasePeer.doUpdate(selectCriteria, criteria);
 172  0
     }
 173  
 
 174  
     /**
 175  
      * Checks if a Group is defined in the system. The name
 176  
      * is used as query criteria.
 177  
      *
 178  
      * @param group The Group to be checked.
 179  
      * @return <code>true</code> if given Group exists in the system.
 180  
      * @throws DataBackendException when more than one Group with
 181  
      *         the same name exists.
 182  
      * @throws Exception a generic exception.
 183  
      */
 184  
     public static boolean checkExists(Group group)
 185  
         throws DataBackendException, Exception
 186  
     {
 187  0
         Criteria criteria = new Criteria();
 188  0
         criteria.addSelectColumn(GROUP_ID);
 189  0
         criteria.add(NAME, ((SecurityObject) group).getName());
 190  0
         List results = BasePeer.doSelect(criteria);
 191  0
         if (results.size() > 1)
 192  
         {
 193  0
             throw new DataBackendException("Multiple groups named '"
 194  
                     + ((TurbineGroup) group).getName() + "' exist!");
 195  
         }
 196  0
         return (results.size() == 1);
 197  
     }
 198  
 
 199  
     /**
 200  
      * Get the name of this table.
 201  
      *
 202  
      * @return A String with the name of the table.
 203  
      */
 204  
     public static String getTableName()
 205  
     {
 206  0
         return TABLE_NAME;
 207  
     }
 208  
 
 209  
     /**
 210  
      * Returns the full name of a column.
 211  
      *
 212  
      * @param name name of the column
 213  
      * @return A String with the full name of the column.
 214  
      */
 215  
     public static String getColumnName(String name)
 216  
     {
 217  0
         StringBuffer sb = new StringBuffer();
 218  0
         sb.append(TABLE_NAME);
 219  0
         sb.append(".");
 220  0
         sb.append(name);
 221  0
         return sb.toString();
 222  
     }
 223  
 
 224  
     /**
 225  
      * Builds a criteria object based upon an Group object
 226  
      *
 227  
      * @param group object to build the Criteria
 228  
      * @return the Criteria
 229  
      */
 230  
     public static Criteria buildCriteria(Group group)
 231  
     {
 232  0
         Criteria criteria = new Criteria();
 233  0
         criteria.add(NAME, ((SecurityObject) group).getName());
 234  0
         if (!((BaseObject) group).isNew())
 235  
         {
 236  0
             criteria.add(GROUP_ID, ((BaseObject) group).getPrimaryKey());
 237  
         }
 238  
         // Causing the removal and updating of a group to
 239  
         // crap out.
 240  
         //criteria.add(OBJECTDATA, group.getAttributes());
 241  0
         return criteria;
 242  
     }
 243  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.