You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by tv...@apache.org on 2007/04/05 19:28:55 UTC
svn commit: r525904 [1/4] - in
/jakarta/turbine/fulcrum/trunk/security/torque: ./ schema/ src/java/
src/java/org/apache/ src/java/org/apache/fulcrum/security/torque/
src/java/org/apache/fulcrum/security/torque/basic/
src/java/org/apache/fulcrum/securit...
Author: tv
Date: Thu Apr 5 10:28:53 2007
New Revision: 525904
URL: http://svn.apache.org/viewvc?view=rev&rev=525904
Log:
Complete rewrite of the Torque Security Service. Torque
objects can now be used directly and instances are (more or
less) unique.
Added:
jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-basic-schema.xml
jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-dynamic-schema.xml
jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-turbine-schema.xml
- copied, changed from r448687, jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-schema.xml
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractSecurityEntity.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueAbstractBasicGroup.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueAbstractBasicUser.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicGroup.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicPermission.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicRole.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicUser.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueAbstractTurbineGroup.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueAbstractTurbinePermission.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueAbstractTurbineRole.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueAbstractTurbineUser.java
jakarta/turbine/fulcrum/trunk/security/torque/src/test/fulcrum-basic-schema-idtable-init.sql
jakarta/turbine/fulcrum/trunk/security/torque/src/test/fulcrum-basic-schema.sql
jakarta/turbine/fulcrum/trunk/security/torque/src/test/fulcrum-dynamic-schema-idtable-init.sql
jakarta/turbine/fulcrum/trunk/security/torque/src/test/fulcrum-dynamic-schema.sql
jakarta/turbine/fulcrum/trunk/security/torque/src/test/fulcrum-turbine-schema-idtable-init.sql
jakarta/turbine/fulcrum/trunk/security/torque/src/test/fulcrum-turbine-schema.sql
Removed:
jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-schema.xml
jakarta/turbine/fulcrum/trunk/security/torque/src/test/fulcrum-schema-idtable-init.sql
jakarta/turbine/fulcrum/trunk/security/torque/src/test/fulcrum-schema.sql
Modified:
jakarta/turbine/fulcrum/trunk/security/torque/maven.xml
jakarta/turbine/fulcrum/trunk/security/torque/project.properties
jakarta/turbine/fulcrum/trunk/security/torque/project.xml
jakarta/turbine/fulcrum/trunk/security/torque/src/java/ (props changed)
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/ (props changed)
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractGroupManager.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractPermissionManager.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractRoleManager.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractUserManager.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicGroupManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicModelManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicUserManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicGroupManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicModelManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicPermissionManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicRoleManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicUserManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueTurbineGroupManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueTurbineModelManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueTurbinePermissionManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueTurbineRoleManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/TorqueTurbineUserManagerImpl.java
jakarta/turbine/fulcrum/trunk/security/torque/src/test/BasicTorqueComponentConfig.xml
jakarta/turbine/fulcrum/trunk/security/torque/src/test/BasicTorqueRoleConfig.xml
jakarta/turbine/fulcrum/trunk/security/torque/src/test/DynamicTorqueComponentConfig.xml
jakarta/turbine/fulcrum/trunk/security/torque/src/test/DynamicTorqueRoleConfig.xml
jakarta/turbine/fulcrum/trunk/security/torque/src/test/Torque.properties
jakarta/turbine/fulcrum/trunk/security/torque/src/test/TurbineTorqueComponentConfig.xml
jakarta/turbine/fulcrum/trunk/security/torque/src/test/TurbineTorqueRoleConfig.xml
jakarta/turbine/fulcrum/trunk/security/torque/src/test/id-table-schema.sql
jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/TorqueGroupManagerTest.java
jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/TorquePermissionManagerTest.java
jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/TorqueRoleManagerTest.java
jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/TorqueUserManagerTest.java
jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/basic/TorqueBasicModelManagerTest.java
jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicModelManagerTest.java
jakarta/turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/turbine/TorqueTurbineModelManagerTest.java
Modified: jakarta/turbine/fulcrum/trunk/security/torque/maven.xml
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/maven.xml?view=diff&rev=525904&r1=525903&r2=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/maven.xml (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/maven.xml Thu Apr 5 10:28:53 2007
@@ -1,8 +1,11 @@
<project default="jar:jar" xmlns:maven="jelly:maven" xmlns:j="jelly:core" xmlns:util="jelly:util">
<preGoal name="java:compile">
- <attainGoal name="torque-gen:prepare"/>
<attainGoal name="torque:om"/>
+ </preGoal>
+
+ <preGoal name="torque:init">
+ <attainGoal name="torque-gen:prepare"/>
</preGoal>
<goal name="torque-gen:prepare">
Modified: jakarta/turbine/fulcrum/trunk/security/torque/project.properties
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/project.properties?view=diff&rev=525904&r1=525903&r2=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/project.properties (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/project.properties Thu Apr 5 10:28:53 2007
@@ -117,15 +117,16 @@
torque.output.dir = ./target
torque.schema.dir = ${torque.output.dir}/schema
-torque.addGetByNameMethod = true
+torque.addGetByNameMethod = false
torque.addIntakeRetrievable = false
torque.addSaveMethod = true
torque.addTimeStamp = true
torque.basePrefix = Base
-torque.complexObjectModel = false
+torque.complexObjectModel = true
torque.correctGetters = true
torque.useManagers = false
-torque.objectIsCaching = false
+torque.objectIsCaching = true
+torque.saveException = TorqueException
# -------------------------------------------------------------------
#
Modified: jakarta/turbine/fulcrum/trunk/security/torque/project.xml
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/project.xml?view=diff&rev=525904&r1=525903&r2=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/project.xml (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/project.xml Thu Apr 5 10:28:53 2007
@@ -42,7 +42,7 @@
<dependency>
<artifactId>torque</artifactId>
<groupId>torque</groupId>
- <version>3.2</version>
+ <version>3.3-RC1</version>
<url>http://db.apache.org/torque</url>
</dependency>
@@ -97,7 +97,7 @@
<dependency>
<artifactId>maven-torque-plugin</artifactId>
<groupId>torque</groupId>
- <version>3.2</version>
+ <version>3.3-RC1</version>
<type>plugin</type>
</dependency>
Added: jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-basic-schema.xml
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-basic-schema.xml?view=auto&rev=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-basic-schema.xml (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-basic-schema.xml Thu Apr 5 10:28:53 2007
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ Copyright 2001-2005 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.
+-->
+<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_3.dtd">
+
+<!-- ==================================================================== -->
+<!-- -->
+<!-- F U L C R U M B A S I C S E C U R I T Y S C H E M A -->
+<!-- -->
+<!-- ==================================================================== -->
+<!-- @author: <a href="mailto:tv@apache.org">Thomas Vandahl</a> -->
+<!-- @version $Id: torque-security-schema.xml,v 1.1 2005/09/26 14:10:04 tvan Exp $ -->
+<!-- ==================================================================== -->
+
+<database name="@DATABASE_DEFAULT@">
+
+ <table name="FULCRUM_BASIC_GROUP" javaName="TorqueBasicGroup" idMethod="idbroker"
+ baseClass="org.apache.fulcrum.security.torque.basic.TorqueAbstractBasicGroup">
+ <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaName="EntityId" javaType="object"/>
+ <column name="GROUP_NAME" required="true" type="VARCHAR" size="64" javaName="EntityName"/>
+
+ <unique>
+ <unique-column name="GROUP_NAME"/>
+ </unique>
+
+ </table>
+
+ <table name="FULCRUM_BASIC_USER" javaName="TorqueBasicUser" idMethod="idbroker"
+ baseClass="org.apache.fulcrum.security.torque.basic.TorqueAbstractBasicUser">
+ <column name="USER_ID" required="true" primaryKey="true" type="INTEGER" javaName="EntityId" javaType="object"/>
+ <column name="LOGIN_NAME" required="true" size="64" type="VARCHAR" javaName="EntityName"/>
+ <column name="PASSWORD_VALUE" required="true" size="16" type="VARCHAR" javaName="Password"/>
+<!--
+ <column name="FIRST_NAME" required="true" size="64" type="VARCHAR"/>
+ <column name="LAST_NAME" required="true" size="64" type="VARCHAR"/>
+ <column name="EMAIL" size="64" type="VARCHAR"/>
+ <column name="CONFIRM_VALUE" size="16" type="VARCHAR" javaName="Confirmed"/>
+ <column name="MODIFIED" type="TIMESTAMP"/>
+ <column name="CREATED" type="TIMESTAMP" javaName="CreateDate"/>
+ <column name="LAST_LOGIN" type="TIMESTAMP"/>
+ <column name="OBJECTDATA" type="VARBINARY"/>
+-->
+ <unique>
+ <unique-column name="LOGIN_NAME"/>
+ </unique>
+
+ </table>
+
+ <!-- Basic Security Model -->
+ <table name="FULCRUM_BASIC_USER_GROUP" javaName="TorqueBasicUserGroup">
+ <column name="USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+ <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+
+ <foreign-key foreignTable="FULCRUM_BASIC_USER">
+ <reference local="USER_ID" foreign="USER_ID"/>
+ </foreign-key>
+
+ <foreign-key foreignTable="FULCRUM_BASIC_GROUP">
+ <reference local="GROUP_ID" foreign="GROUP_ID"/>
+ </foreign-key>
+ </table>
+
+</database>
Added: jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-dynamic-schema.xml
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-dynamic-schema.xml?view=auto&rev=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-dynamic-schema.xml (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-dynamic-schema.xml Thu Apr 5 10:28:53 2007
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ Copyright 2001-2005 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.
+-->
+<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_3.dtd">
+
+<!-- ==================================================================== -->
+<!-- -->
+<!-- F U L C R U M D Y N A M I C S E C U R I T Y S C H E M A -->
+<!-- -->
+<!-- ==================================================================== -->
+<!-- @author: <a href="mailto:tv@apache.org">Thomas Vandahl</a> -->
+<!-- @version $Id: torque-security-schema.xml,v 1.1 2005/09/26 14:10:04 tvan Exp $ -->
+<!-- ==================================================================== -->
+
+<database name="@DATABASE_DEFAULT@">
+
+ <table name="FULCRUM_DYNAMIC_PERMISSION" javaName="TorqueDynamicPermission" idMethod="idbroker"
+ baseClass="org.apache.fulcrum.security.torque.dynamic.TorqueAbstractDynamicPermission">
+ <column name="PERMISSION_ID" required="true" primaryKey="true" type="INTEGER" javaName="EntityId" javaType="object"/>
+ <column name="PERMISSION_NAME" required="true" size="64" type="VARCHAR" javaName="EntityName"/>
+
+ <unique>
+ <unique-column name="PERMISSION_NAME"/>
+ </unique>
+
+ </table>
+
+ <table name="FULCRUM_DYNAMIC_ROLE" javaName="TorqueDynamicRole" idMethod="idbroker"
+ baseClass="org.apache.fulcrum.security.torque.dynamic.TorqueAbstractDynamicRole">
+ <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaName="EntityId" javaType="object"/>
+ <column name="ROLE_NAME" required="true" size="64" type="VARCHAR" javaName="EntityName"/>
+
+ <unique>
+ <unique-column name="ROLE_NAME"/>
+ </unique>
+
+ </table>
+
+ <table name="FULCRUM_DYNAMIC_GROUP" javaName="TorqueDynamicGroup" idMethod="idbroker"
+ baseClass="org.apache.fulcrum.security.torque.dynamic.TorqueAbstractDynamicGroup">
+ <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaName="EntityId" javaType="object"/>
+ <column name="GROUP_NAME" required="true" type="VARCHAR" size="64" javaName="EntityName"/>
+
+ <unique>
+ <unique-column name="GROUP_NAME"/>
+ </unique>
+
+ </table>
+
+ <table name="FULCRUM_DYNAMIC_USER" javaName="TorqueDynamicUser" idMethod="idbroker"
+ baseClass="org.apache.fulcrum.security.torque.dynamic.TorqueAbstractDynamicUser">
+ <column name="USER_ID" required="true" primaryKey="true" type="INTEGER" javaName="EntityId" javaType="object"/>
+ <column name="LOGIN_NAME" required="true" size="64" type="VARCHAR" javaName="EntityName"/>
+ <column name="PASSWORD_VALUE" required="true" size="16" type="VARCHAR" javaName="Password"/>
+<!--
+ <column name="FIRST_NAME" required="true" size="64" type="VARCHAR"/>
+ <column name="LAST_NAME" required="true" size="64" type="VARCHAR"/>
+ <column name="EMAIL" size="64" type="VARCHAR"/>
+ <column name="CONFIRM_VALUE" size="16" type="VARCHAR" javaName="Confirmed"/>
+ <column name="MODIFIED" type="TIMESTAMP"/>
+ <column name="CREATED" type="TIMESTAMP" javaName="CreateDate"/>
+ <column name="LAST_LOGIN" type="TIMESTAMP"/>
+ <column name="OBJECTDATA" type="VARBINARY"/>
+-->
+ <unique>
+ <unique-column name="LOGIN_NAME"/>
+ </unique>
+
+ </table>
+
+ <!-- Dynamic Security Model -->
+ <table name="DYNAMIC_ROLE_PERMISSION" javaName="TorqueDynamicRolePermission">
+ <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+ <column name="PERMISSION_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+
+ <foreign-key foreignTable="FULCRUM_DYNAMIC_ROLE">
+ <reference local="ROLE_ID" foreign="ROLE_ID"/>
+ </foreign-key>
+
+ <foreign-key foreignTable="FULCRUM_DYNAMIC_PERMISSION">
+ <reference local="PERMISSION_ID" foreign="PERMISSION_ID"/>
+ </foreign-key>
+ </table>
+
+ <table name="DYNAMIC_USER_GROUP" javaName="TorqueDynamicUserGroup">
+ <column name="USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+ <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+
+ <foreign-key foreignTable="FULCRUM_DYNAMIC_USER">
+ <reference local="USER_ID" foreign="USER_ID"/>
+ </foreign-key>
+
+ <foreign-key foreignTable="FULCRUM_DYNAMIC_GROUP">
+ <reference local="GROUP_ID" foreign="GROUP_ID"/>
+ </foreign-key>
+ </table>
+
+ <table name="DYNAMIC_GROUP_ROLE" javaName="TorqueDynamicGroupRole">
+ <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+ <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+
+ <foreign-key foreignTable="FULCRUM_DYNAMIC_GROUP">
+ <reference local="GROUP_ID" foreign="GROUP_ID"/>
+ </foreign-key>
+
+ <foreign-key foreignTable="FULCRUM_DYNAMIC_ROLE">
+ <reference local="ROLE_ID" foreign="ROLE_ID"/>
+ </foreign-key>
+ </table>
+
+ <table name="DYNAMIC_USER_DELEGATES" javaName="TorqueDynamicUserDelegates">
+ <column name="DELEGATOR_USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+ <column name="DELEGATEE_USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
+
+ <foreign-key foreignTable="FULCRUM_DYNAMIC_USER">
+ <reference local="DELEGATOR_USER_ID" foreign="USER_ID"/>
+ </foreign-key>
+
+ <foreign-key foreignTable="FULCRUM_DYNAMIC_USER">
+ <reference local="DELEGATEE_USER_ID" foreign="USER_ID"/>
+ </foreign-key>
+ </table>
+
+</database>
Copied: jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-turbine-schema.xml (from r448687, jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-schema.xml)
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-turbine-schema.xml?view=diff&rev=525904&p1=jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-schema.xml&r1=448687&p2=jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-turbine-schema.xml&r2=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-schema.xml (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/schema/fulcrum-turbine-schema.xml Thu Apr 5 10:28:53 2007
@@ -14,11 +14,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_2.dtd">
+<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_3.dtd">
<!-- ==================================================================== -->
<!-- -->
-<!-- F U L C R U M S E C U R I T Y S C H E M A -->
+<!-- F U L C R U M T U R B I N E S E C U R I T Y S C H E M A -->
<!-- -->
<!-- ==================================================================== -->
<!-- @author: <a href="mailto:tv@apache.org">Thomas Vandahl</a> -->
@@ -27,9 +27,10 @@
<database name="@DATABASE_DEFAULT@">
- <table name="FULCRUM_PERMISSION" javaName="TorquePermission" idMethod="idbroker">
- <column name="PERMISSION_ID" required="true" primaryKey="true" type="INTEGER" javaName="Id" javaType="object"/>
- <column name="PERMISSION_NAME" required="true" size="64" type="VARCHAR" javaName="Name"/>
+ <table name="FULCRUM_TURBINE_PERMISSION" javaName="TorqueTurbinePermission" idMethod="idbroker"
+ baseClass="org.apache.fulcrum.security.torque.turbine.TorqueAbstractTurbinePermission">
+ <column name="PERMISSION_ID" required="true" primaryKey="true" type="INTEGER" javaName="EntityId" javaType="object"/>
+ <column name="PERMISSION_NAME" required="true" size="64" type="VARCHAR" javaName="EntityName"/>
<unique>
<unique-column name="PERMISSION_NAME"/>
@@ -37,9 +38,10 @@
</table>
- <table name="FULCRUM_ROLE" javaName="TorqueRole" idMethod="idbroker">
- <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaName="Id" javaType="object"/>
- <column name="ROLE_NAME" required="true" size="64" type="VARCHAR" javaName="Name"/>
+ <table name="FULCRUM_TURBINE_ROLE" javaName="TorqueTurbineRole" idMethod="idbroker"
+ baseClass="org.apache.fulcrum.security.torque.turbine.TorqueAbstractTurbineRole">
+ <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaName="EntityId" javaType="object"/>
+ <column name="ROLE_NAME" required="true" size="64" type="VARCHAR" javaName="EntityName"/>
<unique>
<unique-column name="ROLE_NAME"/>
@@ -47,9 +49,10 @@
</table>
- <table name="FULCRUM_GROUP" javaName="TorqueGroup" idMethod="idbroker">
- <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaName="Id" javaType="object"/>
- <column name="GROUP_NAME" required="true" type="VARCHAR" size="64" javaName="Name"/>
+ <table name="FULCRUM_TURBINE_GROUP" javaName="TorqueTurbineGroup" idMethod="idbroker"
+ baseClass="org.apache.fulcrum.security.torque.turbine.TorqueAbstractTurbineGroup">
+ <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaName="EntityId" javaType="object"/>
+ <column name="GROUP_NAME" required="true" type="VARCHAR" size="64" javaName="EntityName"/>
<unique>
<unique-column name="GROUP_NAME"/>
@@ -57,9 +60,10 @@
</table>
- <table name="FULCRUM_USER" javaName="TorqueUser" idMethod="idbroker">
- <column name="USER_ID" required="true" primaryKey="true" type="INTEGER" javaName="Id" javaType="object"/>
- <column name="LOGIN_NAME" required="true" size="64" type="VARCHAR" javaName="Name"/>
+ <table name="FULCRUM_TURBINE_USER" javaName="TorqueTurbineUser" idMethod="idbroker"
+ baseClass="org.apache.fulcrum.security.torque.turbine.TorqueAbstractTurbineUser">
+ <column name="USER_ID" required="true" primaryKey="true" type="INTEGER" javaName="EntityId" javaType="object"/>
+ <column name="LOGIN_NAME" required="true" size="64" type="VARCHAR" javaName="EntityName"/>
<column name="PASSWORD_VALUE" required="true" size="16" type="VARCHAR" javaName="Password"/>
<!--
<column name="FIRST_NAME" required="true" size="64" type="VARCHAR"/>
@@ -77,83 +81,16 @@
</table>
- <!-- Basic Security Model -->
- <table name="BASIC_USER_GROUP" javaName="TorqueBasicUserGroup">
- <column name="USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
- <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
-
- <foreign-key foreignTable="FULCRUM_USER">
- <reference local="USER_ID" foreign="USER_ID"/>
- </foreign-key>
-
- <foreign-key foreignTable="FULCRUM_GROUP">
- <reference local="GROUP_ID" foreign="GROUP_ID"/>
- </foreign-key>
- </table>
-
- <!-- Dynamic Security Model -->
- <table name="DYNAMIC_ROLE_PERMISSION" javaName="TorqueDynamicRolePermission">
- <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
- <column name="PERMISSION_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
-
- <foreign-key foreignTable="FULCRUM_ROLE">
- <reference local="ROLE_ID" foreign="ROLE_ID"/>
- </foreign-key>
-
- <foreign-key foreignTable="FULCRUM_PERMISSION">
- <reference local="PERMISSION_ID" foreign="PERMISSION_ID"/>
- </foreign-key>
- </table>
-
- <table name="DYNAMIC_USER_GROUP" javaName="TorqueDynamicUserGroup">
- <column name="USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
- <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
-
- <foreign-key foreignTable="FULCRUM_USER">
- <reference local="USER_ID" foreign="USER_ID"/>
- </foreign-key>
-
- <foreign-key foreignTable="FULCRUM_GROUP">
- <reference local="GROUP_ID" foreign="GROUP_ID"/>
- </foreign-key>
- </table>
-
- <table name="DYNAMIC_GROUP_ROLE" javaName="TorqueDynamicGroupRole">
- <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
- <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
-
- <foreign-key foreignTable="FULCRUM_GROUP">
- <reference local="GROUP_ID" foreign="GROUP_ID"/>
- </foreign-key>
-
- <foreign-key foreignTable="FULCRUM_ROLE">
- <reference local="ROLE_ID" foreign="ROLE_ID"/>
- </foreign-key>
- </table>
-
- <table name="DYNAMIC_USER_DELEGATES" javaName="TorqueDynamicUserDelegates">
- <column name="DELEGATOR_USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
- <column name="DELEGATEE_USER_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
-
- <foreign-key foreignTable="FULCRUM_USER">
- <reference local="DELEGATOR_USER_ID" foreign="USER_ID"/>
- </foreign-key>
-
- <foreign-key foreignTable="FULCRUM_USER">
- <reference local="DELEGATEE_USER_ID" foreign="USER_ID"/>
- </foreign-key>
- </table>
-
<!-- Turbine Security Model -->
<table name="TURBINE_ROLE_PERMISSION" javaName="TorqueTurbineRolePermission">
<column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
<column name="PERMISSION_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
- <foreign-key foreignTable="FULCRUM_ROLE">
+ <foreign-key foreignTable="FULCRUM_TURBINE_ROLE">
<reference local="ROLE_ID" foreign="ROLE_ID"/>
</foreign-key>
- <foreign-key foreignTable="FULCRUM_PERMISSION">
+ <foreign-key foreignTable="FULCRUM_TURBINE_PERMISSION">
<reference local="PERMISSION_ID" foreign="PERMISSION_ID"/>
</foreign-key>
</table>
@@ -163,15 +100,15 @@
<column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
<column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
- <foreign-key foreignTable="FULCRUM_USER">
+ <foreign-key foreignTable="FULCRUM_TURBINE_USER">
<reference local="USER_ID" foreign="USER_ID"/>
</foreign-key>
- <foreign-key foreignTable="FULCRUM_GROUP">
+ <foreign-key foreignTable="FULCRUM_TURBINE_GROUP">
<reference local="GROUP_ID" foreign="GROUP_ID"/>
</foreign-key>
- <foreign-key foreignTable="FULCRUM_ROLE">
+ <foreign-key foreignTable="FULCRUM_TURBINE_ROLE">
<reference local="ROLE_ID" foreign="ROLE_ID"/>
</foreign-key>
</table>
Propchange: jakarta/turbine/fulcrum/trunk/security/torque/src/java/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Apr 5 10:28:53 2007
@@ -1,2 +1,2 @@
-
-report.fulcrum.om.generation
+report.fulcrum.om.generation
+*.generation
Propchange: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Apr 5 10:28:53 2007
@@ -0,0 +1 @@
+torque
Modified: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractGroupManager.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractGroupManager.java?view=diff&rev=525904&r1=525903&r2=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractGroupManager.java (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractGroupManager.java Thu Apr 5 10:28:53 2007
@@ -15,61 +15,142 @@
* limitations under the License.
*/
import java.sql.Connection;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.fulcrum.security.entity.Group;
import org.apache.fulcrum.security.spi.AbstractGroupManager;
-import org.apache.fulcrum.security.torque.om.TorqueGroup;
-import org.apache.fulcrum.security.torque.om.TorqueGroupPeer;
import org.apache.fulcrum.security.util.DataBackendException;
-import org.apache.fulcrum.security.util.EntityExistsException;
import org.apache.fulcrum.security.util.GroupSet;
import org.apache.fulcrum.security.util.UnknownEntityException;
import org.apache.torque.NoRowsException;
+import org.apache.torque.TooManyRowsException;
import org.apache.torque.TorqueException;
-import org.apache.torque.om.SimpleKey;
-import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;
+
/**
* This implementation persists to a database via Torque.
*
- * The names of the group class, group peer class and the
- * columns of the group class can be overridden in a
- * configuration like this:
- * <pre>
- * <groupClass>
- * <className>org.fulcrum.security.torque.om.TorqueGroup</className>
- * <peerName>org.fulcrum.security.torque.om.TorqueGroupPeer</peerName>
- * <idColumn>GROUP_ID</idColumn>
- * <nameColumn>GROUP_NAME</nameColumn>
- * </group>
- * </pre>
* @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
* @version $Id:$
*/
public abstract class TorqueAbstractGroupManager extends AbstractGroupManager
{
- public static final String GROUP = "group";
-
/**
- * Provides the attached object lists for the given group
- *
- * @param group the group for which the lists should be retrieved
+ * Get all specialized Groups
+ *
* @param con a database connection
+ *
+ * @return a List of Group instances
+ *
+ * @throws TorqueException if any database error occurs
*/
- protected abstract void attachObjectsForGroup(Group group, Connection con)
- throws TorqueException, DataBackendException;
-
+ protected abstract List doSelectAllGroups(Connection con)
+ throws TorqueException;
+
+ /**
+ * Get a specialized Group by name
+ *
+ * @param name the name of the group
+ * @param con a database connection
+ *
+ * @return a Group instance
+ *
+ * @throws NoRowsException if no such group exists
+ * @throws TooManyRowsException if multiple groups with the given name exist
+ * @throws TorqueException if any other database error occurs
+ */
+ protected abstract Group doSelectByName(String name, Connection con)
+ throws NoRowsException, TooManyRowsException, TorqueException;
+
/**
- * @see org.apache.fulcrum.security.spi.AbstractEntityManager#configure(org.apache.avalon.framework.configuration.Configuration)
+ * Get a specialized Group by id
+ *
+ * @param id the id of the group
+ * @param con a database connection
+ *
+ * @return a Group instance
+ *
+ * @throws NoRowsException if no such group exists
+ * @throws TooManyRowsException if multiple groups with the given id exist
+ * @throws TorqueException if any other database error occurs
*/
- public void configure(Configuration conf) throws ConfigurationException
+ protected abstract Group doSelectById(Integer id, Connection con)
+ throws NoRowsException, TooManyRowsException, TorqueException;
+
+ /**
+ * Creates a new group with specified attributes.
+ *
+ * @param group the object describing the group to be created.
+ * @return a new Group object that has id set up properly.
+ * @throws DataBackendException if there was an error accessing the data
+ * backend.
+ * @throws EntityExistsException if the group already exists.
+ */
+ protected synchronized Group persistNewGroup(Group group) throws DataBackendException
{
- super.configure(conf);
+ try
+ {
+ ((TorqueAbstractSecurityEntity)group).save();
+ }
+ catch (Exception e)
+ {
+ throw new DataBackendException("Adding Group '" + group.getName() + "' failed", e);
+ }
+
+ return group;
+ }
+
+ /**
+ * Renames an existing Group.
+ *
+ * @param group The object describing the group to be renamed.
+ * @param name the new name for the group.
+ * @throws DataBackendException if there was an error accessing the data
+ * backend.
+ * @throws UnknownEntityException if the group does not exist.
+ */
+ public synchronized void renameGroup(Group group, String name) throws DataBackendException, UnknownEntityException
+ {
+ if (checkExists(group))
+ {
+ group.setName(name);
+
+ try
+ {
+ TorqueAbstractSecurityEntity g = (TorqueAbstractSecurityEntity)group;
+ g.setNew(false);
+ g.save();
+ }
+ catch (Exception e)
+ {
+ throw new DataBackendException("Renaming Group '" + group.getName() + "' failed", e);
+ }
+ }
+ else
+ {
+ throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
+ }
+ }
+
+ /**
+ * Removes a Group from the system.
+ *
+ * @param group The object describing the group to be removed.
+ * @throws DataBackendException if there was an error accessing the data
+ * backend.
+ * @throws UnknownEntityException if the group does not exist.
+ */
+ public synchronized void removeGroup(Group group) throws DataBackendException, UnknownEntityException
+ {
+ try
+ {
+ ((TorqueAbstractSecurityEntity)group).delete();
+ }
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("Removing Group '" + group.getName() + "' failed", e);
+ }
}
/**
@@ -81,51 +162,43 @@
* data backend.
* @throws UnknownEntityException if the group does not exist.
*/
- public Group getGroupByName(String name)
- throws DataBackendException, UnknownEntityException
+ public Group getGroupByName(String name) throws DataBackendException, UnknownEntityException
{
- Group group = getGroupInstance();
- List groups = Collections.EMPTY_LIST;
+ Group group = null;
Connection con = null;
-
+
try
{
- con = Transaction.begin(TorqueGroupPeer.DATABASE_NAME);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getGroupInstance()).getDatabaseName());
- Criteria criteria = new Criteria();
- criteria.add(TorqueGroupPeer.GROUP_NAME, name);
-
- groups = TorqueGroupPeer.doSelect(criteria, con);
-
- if (groups.size() == 1)
- {
- TorqueGroup g = (TorqueGroup) groups.get(0);
-
- group.setId(g.getId());
- group.setName(g.getName());
-
- // Add dependent objects if they exist
- attachObjectsForGroup(group, con);
- }
-
+ group = doSelectByName(name, con);
+
+ // Add dependent objects if they exist
+ ((TorqueAbstractSecurityEntity)group).retrieveAttachedObjects(con);
+
Transaction.commit(con);
+ con = null;
}
- catch (TorqueException e)
- {
- Transaction.safeRollback(con);
- throw new DataBackendException("Error retrieving group information", e);
- }
-
- if (groups.size() == 0)
+ catch (NoRowsException e)
{
throw new UnknownEntityException("Could not find group" + name);
}
-
- if (groups.size() > 1)
+ catch (TooManyRowsException e)
{
throw new DataBackendException("Multiple Groups with same name '" + name + "'");
}
-
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("Error retrieving group information", e);
+ }
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
+ }
+
return group;
}
@@ -140,91 +213,39 @@
{
GroupSet groupSet = new GroupSet();
Connection con = null;
-
+
try
{
- con = Transaction.begin(TorqueGroupPeer.DATABASE_NAME);
-
- List groups = TorqueGroupPeer.doSelect(new Criteria(), con);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getGroupInstance()).getDatabaseName());
+
+ List groups = doSelectAllGroups(con);
for (Iterator i = groups.iterator(); i.hasNext();)
{
- Group group = getGroupInstance();
- TorqueGroup g = (TorqueGroup)i.next();
- group.setId(g.getId());
- group.setName(g.getName());
+ Group group = (Group)i.next();
// Add dependent objects if they exist
- attachObjectsForGroup(group, con);
-
+ ((TorqueAbstractSecurityEntity)group).retrieveAttachedObjects(con);
+
groupSet.add(group);
}
-
+
Transaction.commit(con);
+ con = null;
}
catch (TorqueException e)
{
- Transaction.safeRollback(con);
throw new DataBackendException("Error retrieving group information", e);
}
-
- return groupSet;
- }
-
- /**
- * Removes a Group from the system.
- *
- * @param group The object describing the group to be removed.
- * @throws DataBackendException if there was an error accessing the data
- * backend.
- * @throws UnknownEntityException if the group does not exist.
- */
- public synchronized void removeGroup(Group group)
- throws DataBackendException, UnknownEntityException
- {
- try
- {
- TorqueGroupPeer.doDelete(SimpleKey.keyFor((Integer)group.getId()));
- }
- catch (TorqueException e)
- {
- throw new DataBackendException("Removing Group '" + group + "' failed", e);
- }
- }
-
- /**
- * Renames an existing Group.
- *
- * @param group The object describing the group to be renamed.
- * @param name the new name for the group.
- * @throws DataBackendException if there was an error accessing the data
- * backend.
- * @throws UnknownEntityException if the group does not exist.
- */
- public synchronized void renameGroup(Group group, String name)
- throws DataBackendException, UnknownEntityException
- {
- if (checkExists(group))
+ finally
{
- group.setName(name);
-
- try
+ if (con != null)
{
- TorqueGroup g = new TorqueGroup();
- g.setId((Integer)group.getId());
- g.setName(name);
- g.setNew(false);
- g.save();
- }
- catch (Exception e)
- {
- throw new DataBackendException("Renaming Group '" + group + "' failed", e);
+ Transaction.safeRollback(con);
}
}
- else
- {
- throw new UnknownEntityException("Unknown group '" + group + "'");
- }
+
+ return groupSet;
}
/**
@@ -237,55 +258,43 @@
*/
public boolean checkExists(String groupName) throws DataBackendException
{
- List groups;
-
+ boolean exists = false;
+
+ Connection con = null;
+
try
{
- Criteria criteria = new Criteria();
- criteria.add(TorqueGroupPeer.GROUP_NAME, groupName);
-
- groups = TorqueGroupPeer.doSelect(criteria);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getGroupInstance()).getDatabaseName());
+
+ doSelectByName(groupName, con);
+
+ Transaction.commit(con);
+ con = null;
+
+ exists = true;
}
- catch (TorqueException e)
+ catch (NoRowsException e)
{
- throw new DataBackendException("Error retrieving group information", e);
+ exists = false;
}
-
- if (groups.size() > 1)
+ catch (TooManyRowsException e)
{
throw new DataBackendException(
"Multiple groups with same name '" + groupName + "'");
}
-
- return (groups.size() == 1);
- }
-
- /**
- * Creates a new group with specified attributes.
- *
- * @param group the object describing the group to be created.
- * @return a new Group object that has id set up properly.
- * @throws DataBackendException if there was an error accessing the data
- * backend.
- * @throws EntityExistsException if the group already exists.
- */
- protected synchronized Group persistNewGroup(Group group)
- throws DataBackendException
- {
- try
+ catch (TorqueException e)
{
- TorqueGroup g = new TorqueGroup();
- g.setName(group.getName());
- g.save();
-
- group.setId(g.getId());
+ throw new DataBackendException("Error retrieving group information", e);
}
- catch (Exception e)
+ finally
{
- throw new DataBackendException("Adding Group '" + group + "' failed", e);
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
}
-
- return group;
+
+ return exists;
}
/**
@@ -299,45 +308,47 @@
* @throws UnknownEntityException
* if the group does not exist.
*/
- public Group getGroupById(Object id)
- throws DataBackendException, UnknownEntityException
+ public Group getGroupById(Object id) throws DataBackendException, UnknownEntityException
{
- Group group = getGroupInstance();
-
+ Group group;
+
if (id != null && id instanceof Integer)
{
Connection con = null;
-
+
try
{
- con = Transaction.begin(TorqueGroupPeer.DATABASE_NAME);
-
- TorqueGroup g = TorqueGroupPeer.retrieveByPK((Integer)id, con);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getGroupInstance()).getDatabaseName());
- group.setId(g.getId());
- group.setName(g.getName());
+ group = doSelectById((Integer)id, con);
// Add dependent objects if they exist
- attachObjectsForGroup(group, con);
-
+ ((TorqueAbstractSecurityEntity)group).retrieveAttachedObjects(con);
+
Transaction.commit(con);
+ con = null;
}
catch (NoRowsException e)
{
- Transaction.safeRollback(con);
throw new UnknownEntityException("Group with id '" + id + "' does not exist.", e);
}
catch (TorqueException e)
{
- Transaction.safeRollback(con);
throw new DataBackendException("Error retrieving group information", e);
}
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
+ }
}
else
{
- throw new UnknownEntityException("Invalid group id '" + group.getId() + "'");
+ throw new UnknownEntityException("Invalid group id '" + id + "'");
}
-
+
return group;
}
}
Modified: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractPermissionManager.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractPermissionManager.java?view=diff&rev=525904&r1=525903&r2=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractPermissionManager.java (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractPermissionManager.java Thu Apr 5 10:28:53 2007
@@ -15,22 +15,18 @@
* limitations under the License.
*/
import java.sql.Connection;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.fulcrum.security.entity.Permission;
import org.apache.fulcrum.security.spi.AbstractPermissionManager;
-import org.apache.fulcrum.security.torque.om.TorquePermission;
-import org.apache.fulcrum.security.torque.om.TorquePermissionPeer;
import org.apache.fulcrum.security.util.DataBackendException;
import org.apache.fulcrum.security.util.EntityExistsException;
import org.apache.fulcrum.security.util.PermissionSet;
import org.apache.fulcrum.security.util.UnknownEntityException;
import org.apache.torque.NoRowsException;
+import org.apache.torque.TooManyRowsException;
import org.apache.torque.TorqueException;
-import org.apache.torque.om.SimpleKey;
-import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;
/**
* This implementation persists to a database via Torque.
@@ -41,57 +37,46 @@
public abstract class TorqueAbstractPermissionManager extends AbstractPermissionManager
{
/**
- * Provides the attached object lists for the given permission
- *
- * @param permission the permission for which the lists should be retrieved
+ * Get all specialized Permissions
+ *
* @param con a database connection
+ *
+ * @return a List of Permission instances
+ *
+ * @throws TorqueException if any database error occurs
*/
- protected abstract void attachObjectsForPermission(Permission permission, Connection con)
- throws TorqueException, DataBackendException;
+ protected abstract List doSelectAllPermissions(Connection con)
+ throws TorqueException;
/**
- * Retrieves all permissions defined in the system.
+ * Get a specialized Permission by name
+ *
+ * @param name the name of the group
+ * @param con a database connection
+ *
+ * @return a Permission instance
*
- * @return the names of all roles defined in the system.
- * @throws DataBackendException
- * if there was an error accessing the data backend.
+ * @throws NoRowsException if no such group exists
+ * @throws TooManyRowsException if multiple groups with the given name exist
+ * @throws TorqueException if any other database error occurs
*/
- public PermissionSet getAllPermissions() throws DataBackendException
- {
- PermissionSet permissionSet = new PermissionSet();
- Connection con = null;
-
- try
- {
- con = Transaction.begin(TorquePermissionPeer.DATABASE_NAME);
-
- List permissions = TorquePermissionPeer.doSelect(new Criteria(), con);
-
- for (Iterator i = permissions.iterator(); i.hasNext();)
- {
- TorquePermission p = (TorquePermission)i.next();
-
- // TODO: This throws UnknownEntityException.
- Permission permission = getPermissionInstance();
- permission.setId(p.getId());
- permission.setName(p.getName());
-
- // Add attached objects if they exist
- attachObjectsForPermission(permission, con);
-
- permissionSet.add(permission);
- }
+ protected abstract Permission doSelectByName(String name, Connection con)
+ throws NoRowsException, TooManyRowsException, TorqueException;
- Transaction.commit(con);
- }
- catch (Exception e)
- {
- Transaction.safeRollback(con);
- throw new DataBackendException("Error retrieving permission information", e);
- }
-
- return permissionSet;
- }
+ /**
+ * Get a specialized Permission by id
+ *
+ * @param id the id of the group
+ * @param con a database connection
+ *
+ * @return a Permission instance
+ *
+ * @throws NoRowsException if no such group exists
+ * @throws TooManyRowsException if multiple groups with the given id exist
+ * @throws TorqueException if any other database error occurs
+ */
+ protected abstract Permission doSelectById(Integer id, Connection con)
+ throws NoRowsException, TooManyRowsException, TorqueException;
/**
* Renames an existing Permission.
@@ -105,8 +90,7 @@
* @throws UnknownEntityException
* if the permission does not exist.
*/
- public synchronized void renamePermission(Permission permission, String name)
- throws DataBackendException, UnknownEntityException
+ public synchronized void renamePermission(Permission permission, String name) throws DataBackendException, UnknownEntityException
{
if (checkExists(permission))
{
@@ -114,55 +98,19 @@
try
{
- TorquePermission p = new TorquePermission();
- p.setId((Integer)permission.getId());
- p.setName(name);
+ TorqueAbstractSecurityEntity p = (TorqueAbstractSecurityEntity)permission;
p.setNew(false);
p.save();
}
catch (Exception e)
{
- throw new DataBackendException("Renaming Permission '" + permission + "' failed", e);
+ throw new DataBackendException("Renaming Permission '" + permission.getName() + "' failed", e);
}
}
else
{
- throw new UnknownEntityException("Unknown permission '" + permission + "'");
- }
- }
-
- /**
- * Determines if the <code>Permission</code> exists in the security
- * system.
- *
- * @param permissionName
- * a <code>Permission</code> value
- * @return true if the permission name exists in the system, false otherwise
- * @throws DataBackendException
- * when more than one Permission with the same name exists.
- */
- public boolean checkExists(String permissionName) throws DataBackendException
- {
- List permissions;
-
- try
- {
- Criteria criteria = new Criteria();
- criteria.add(TorquePermissionPeer.PERMISSION_NAME, permissionName);
-
- permissions = TorquePermissionPeer.doSelect(criteria);
- }
- catch (TorqueException e)
- {
- throw new DataBackendException("Error retrieving permission information", e);
+ throw new UnknownEntityException("Unknown permission '" + permission.getName() + "'");
}
-
- if (permissions.size() > 1)
- {
- throw new DataBackendException("Multiple permissions with same name '" + permissionName + "'");
- }
-
- return (permissions.size() == 1);
}
/**
@@ -175,23 +123,22 @@
* @throws UnknownEntityException
* if the permission does not exist.
*/
- public synchronized void removePermission(Permission permission)
- throws DataBackendException, UnknownEntityException
+ public synchronized void removePermission(Permission permission) throws DataBackendException, UnknownEntityException
{
if (checkExists(permission))
{
try
{
- TorquePermissionPeer.doDelete(SimpleKey.keyFor((Integer)permission.getId()));
+ ((TorqueAbstractSecurityEntity)permission).delete();
}
catch (TorqueException e)
{
- throw new DataBackendException("Removing Permission '" + permission + "' failed", e);
+ throw new DataBackendException("Removing Permission '" + permission.getName() + "' failed", e);
}
}
else
{
- throw new UnknownEntityException("Unknown permission '" + permission + "'");
+ throw new UnknownEntityException("Unknown permission '" + permission.getName() + "'");
}
}
@@ -206,26 +153,125 @@
* @throws EntityExistsException
* if the permission already exists.
*/
- protected synchronized Permission persistNewPermission(Permission permission)
- throws DataBackendException
+ protected synchronized Permission persistNewPermission(Permission permission) throws DataBackendException
{
try
{
- TorquePermission p = new TorquePermission();
- p.setName(permission.getName());
- p.save();
-
- permission.setId(p.getId());
+ ((TorqueAbstractSecurityEntity)permission).save();
}
catch (Exception e)
{
- throw new DataBackendException("Adding Permission '" + permission + "' failed", e);
+ throw new DataBackendException("Adding Permission '" + permission.getName() + "' failed", e);
}
-
+
return permission;
}
/**
+ * Retrieves all permissions defined in the system.
+ *
+ * @return the names of all roles defined in the system.
+ * @throws DataBackendException
+ * if there was an error accessing the data backend.
+ */
+ public PermissionSet getAllPermissions() throws DataBackendException
+ {
+ PermissionSet permissionSet = new PermissionSet();
+ Connection con = null;
+
+ try
+ {
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getPermissionInstance()).getDatabaseName());
+
+ List permissions = doSelectAllPermissions(con);
+
+ for (Iterator i = permissions.iterator(); i.hasNext();)
+ {
+ Permission p = (Permission)i.next();
+
+ // Add attached objects if they exist
+ ((TorqueAbstractSecurityEntity)p).retrieveAttachedObjects(con);
+
+ permissionSet.add(p);
+ }
+
+ Transaction.commit(con);
+ con = null;
+ }
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("Error retrieving permission information", e);
+ }
+ catch (UnknownEntityException e)
+ {
+ throw new DataBackendException("Error retrieving permission information", e);
+ }
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
+ }
+
+ return permissionSet;
+ }
+
+ /**
+ * Determines if the <code>Permission</code> exists in the security
+ * system.
+ *
+ * @param permissionName
+ * a <code>Permission</code> value
+ * @return true if the permission name exists in the system, false otherwise
+ * @throws DataBackendException
+ * when more than one Permission with the same name exists.
+ */
+ public boolean checkExists(String permissionName) throws DataBackendException
+ {
+ boolean exists = false;
+
+ Connection con = null;
+
+ try
+ {
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getPermissionInstance()).getDatabaseName());
+
+ doSelectByName(permissionName, con);
+
+ Transaction.commit(con);
+ con = null;
+
+ exists = true;
+ }
+ catch (NoRowsException e)
+ {
+ exists = false;
+ }
+ catch (TooManyRowsException e)
+ {
+ throw new DataBackendException("Multiple permissions with same name '" + permissionName + "'");
+ }
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("Error retrieving permission information", e);
+ }
+ catch (UnknownEntityException e)
+ {
+ throw new DataBackendException("Error retrieving permission information", e);
+ }
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
+ }
+
+ return exists;
+ }
+
+ /**
* Retrieve a Permission object with specified id.
*
* @param id
@@ -236,45 +282,47 @@
* @throws UnknownEntityException
* if the permission does not exist.
*/
- public Permission getPermissionById(Object id)
- throws DataBackendException, UnknownEntityException
+ public Permission getPermissionById(Object id) throws DataBackendException, UnknownEntityException
{
- Permission permission = getPermissionInstance();
-
+ Permission permission;
+
if (id != null && id instanceof Integer)
{
Connection con = null;
-
+
try
{
- con = Transaction.begin(TorquePermissionPeer.DATABASE_NAME);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getPermissionInstance()).getDatabaseName());
- TorquePermission p =
- TorquePermissionPeer.retrieveByPK((Integer)id, con);
- permission.setId(p.getId());
- permission.setName(p.getName());
-
+ permission = doSelectById((Integer)id, con);
+
// Add attached objects if they exist
- attachObjectsForPermission(permission, con);
-
+ ((TorqueAbstractSecurityEntity)permission).retrieveAttachedObjects(con);
+
Transaction.commit(con);
+ con = null;
}
catch (NoRowsException e)
{
- Transaction.safeRollback(con);
throw new UnknownEntityException("Permission with id '" + id + "' does not exist.", e);
}
catch (TorqueException e)
{
- Transaction.safeRollback(con);
throw new DataBackendException("Error retrieving permission information", e);
}
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
+ }
}
else
{
- throw new UnknownEntityException("Invalid permission id '" + permission.getId() + "'");
+ throw new UnknownEntityException("Invalid permission id '" + id + "'");
}
-
+
return permission;
}
@@ -287,51 +335,43 @@
* data backend.
* @throws UnknownEntityException if the group does not exist.
*/
- public Permission getPermissionByName(String name)
- throws DataBackendException, UnknownEntityException
+ public Permission getPermissionByName(String name) throws DataBackendException, UnknownEntityException
{
- Permission permission = getPermissionInstance();
- List permissions = Collections.EMPTY_LIST;
+ Permission permission = null;
Connection con = null;
-
+
try
{
- con = Transaction.begin(TorquePermissionPeer.DATABASE_NAME);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getPermissionInstance()).getDatabaseName());
- Criteria criteria = new Criteria();
- criteria.add(TorquePermissionPeer.PERMISSION_NAME, name);
-
- permissions = TorquePermissionPeer.doSelect(criteria, con);
-
- if (permissions.size() == 1)
- {
- TorquePermission p = (TorquePermission) permissions.get(0);
-
- permission.setId(p.getId());
- permission.setName(p.getName());
-
- // Add attached objects if they exist
- attachObjectsForPermission(permission, con);
- }
-
+ permission = doSelectByName(name, con);
+
+ // Add attached objects if they exist
+ ((TorqueAbstractSecurityEntity)permission).retrieveAttachedObjects(con);
+
Transaction.commit(con);
+ con = null;
}
- catch (TorqueException e)
- {
- Transaction.safeRollback(con);
- throw new DataBackendException("Error retrieving permission information", e);
- }
-
- if (permissions.size() == 0)
+ catch (NoRowsException e)
{
throw new UnknownEntityException("Could not find permission " + name);
}
-
- if (permissions.size() > 1)
+ catch (TooManyRowsException e)
{
throw new DataBackendException("Multiple Permissions with same name '" + name + "'");
}
-
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("Error retrieving permission information", e);
+ }
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
+ }
+
return permission;
}
}
Modified: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractRoleManager.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractRoleManager.java?view=diff&rev=525904&r1=525903&r2=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractRoleManager.java (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractRoleManager.java Thu Apr 5 10:28:53 2007
@@ -15,22 +15,18 @@
* limitations under the License.
*/
import java.sql.Connection;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.fulcrum.security.entity.Role;
import org.apache.fulcrum.security.spi.AbstractRoleManager;
-import org.apache.fulcrum.security.torque.om.TorqueRole;
-import org.apache.fulcrum.security.torque.om.TorqueRolePeer;
import org.apache.fulcrum.security.util.DataBackendException;
import org.apache.fulcrum.security.util.EntityExistsException;
import org.apache.fulcrum.security.util.RoleSet;
import org.apache.fulcrum.security.util.UnknownEntityException;
import org.apache.torque.NoRowsException;
+import org.apache.torque.TooManyRowsException;
import org.apache.torque.TorqueException;
-import org.apache.torque.om.SimpleKey;
-import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;
/**
* This implementation persists to a database via Torque.
@@ -41,13 +37,47 @@
public abstract class TorqueAbstractRoleManager extends AbstractRoleManager
{
/**
- * Provides the attached object lists for the given role
- *
- * @param role the role for which the lists should be retrieved
+ * Get all specialized Roles
+ *
* @param con a database connection
+ *
+ * @return a List of Role instances
+ *
+ * @throws TorqueException if any database error occurs
+ */
+ protected abstract List doSelectAllRoles(Connection con)
+ throws TorqueException;
+
+ /**
+ * Get a specialized Role by name
+ *
+ * @param name the name of the group
+ * @param con a database connection
+ *
+ * @return a Role instance
+ *
+ * @throws NoRowsException if no such group exists
+ * @throws TooManyRowsException if multiple groups with the given name exist
+ * @throws TorqueException if any other database error occurs
+ */
+ protected abstract Role doSelectByName(String name, Connection con)
+ throws NoRowsException, TooManyRowsException, TorqueException;
+
+ /**
+ * Get a specialized Role by id
+ *
+ * @param id the id of the group
+ * @param con a database connection
+ *
+ * @return a Role instance
+ *
+ * @throws NoRowsException if no such group exists
+ * @throws TooManyRowsException if multiple groups with the given id exist
+ * @throws TorqueException if any other database error occurs
*/
- protected abstract void attachObjectsForRole(Role role, Connection con)
- throws TorqueException, DataBackendException, UnknownEntityException;
+ protected abstract Role doSelectById(Integer id, Connection con)
+ throws NoRowsException, TooManyRowsException, TorqueException;
+
/**
* Renames an existing Role.
@@ -58,8 +88,7 @@
* backend.
* @throws UnknownEntityException if the role does not exist.
*/
- public synchronized void renameRole(Role role, String name)
- throws DataBackendException, UnknownEntityException
+ public synchronized void renameRole(Role role, String name) throws DataBackendException, UnknownEntityException
{
if (checkExists(role))
{
@@ -67,20 +96,68 @@
try
{
- TorqueRole r = new TorqueRole();
- r.setId((Integer)role.getId());
- r.setName(name);
+ TorqueAbstractSecurityEntity r = (TorqueAbstractSecurityEntity)role;
r.setNew(false);
r.save();
}
catch (Exception e)
{
- throw new DataBackendException("Renaming Role '" + role + "' failed", e);
+ throw new DataBackendException("Renaming Role '" + role.getName() + "' failed", e);
+ }
+ }
+ else
+ {
+ throw new UnknownEntityException("Unknown Role '" + role.getName() + "'");
+ }
+ }
+
+ /**
+ * Creates a new role with specified attributes.
+ *
+ * @param role the object describing the role to be created.
+ * @return a new Role object that has id set up properly.
+ * @throws DataBackendException if there was an error accessing the data
+ * backend.
+ * @throws EntityExistsException if the role already exists.
+ */
+ protected synchronized Role persistNewRole(Role role) throws DataBackendException
+ {
+ try
+ {
+ ((TorqueAbstractSecurityEntity)role).save();
+ }
+ catch (Exception e)
+ {
+ throw new DataBackendException("Adding Role '" + role.getName() + "' failed", e);
+ }
+
+ return role;
+ }
+
+ /**
+ * Removes a Role from the system.
+ *
+ * @param role The object describing the role to be removed.
+ * @throws DataBackendException if there was an error accessing the data
+ * backend.
+ * @throws UnknownEntityException if the role does not exist.
+ */
+ public synchronized void removeRole(Role role) throws DataBackendException, UnknownEntityException
+ {
+ if (checkExists(role))
+ {
+ try
+ {
+ ((TorqueAbstractSecurityEntity)role).delete();
+ }
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("Removing Role '" + role.getName() + "' failed", e);
}
}
else
{
- throw new UnknownEntityException("Unknown Role '" + role + "'");
+ throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
}
}
@@ -94,26 +171,42 @@
*/
public boolean checkExists(String roleName) throws DataBackendException
{
- List roles;
-
+ boolean exists = false;
+
+ Connection con = null;
+
try
{
- Criteria criteria = new Criteria();
- criteria.add(TorqueRolePeer.ROLE_NAME, roleName);
-
- roles = TorqueRolePeer.doSelect(criteria);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getRoleInstance()).getDatabaseName());
+
+ doSelectByName(roleName, con);
+
+ Transaction.commit(con);
+ con = null;
+
+ exists = true;
+ }
+ catch (NoRowsException e)
+ {
+ exists = false;
+ }
+ catch (TooManyRowsException e)
+ {
+ throw new DataBackendException("Multiple roles with same name '" + roleName + "'");
}
catch (TorqueException e)
{
throw new DataBackendException("Error retrieving role information", e);
}
-
- if (roles.size() > 1)
+ finally
{
- throw new DataBackendException("Multiple roles with same name '" + roleName + "'");
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
}
-
- return (roles.size() == 1);
+
+ return exists;
}
/**
@@ -127,94 +220,39 @@
{
RoleSet roleSet = new RoleSet();
Connection con = null;
-
+
try
{
- con = Transaction.begin(TorqueRolePeer.DATABASE_NAME);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getRoleInstance()).getDatabaseName());
- List roles = TorqueRolePeer.doSelect(new Criteria(), con);
+ List roles = doSelectAllRoles(con);
for (Iterator i = roles.iterator(); i.hasNext();)
{
- Role role = getRoleInstance();
- TorqueRole r = (TorqueRole)i.next();
- role.setId(r.getId());
- role.setName(r.getName());
-
+ Role role = (Role)i.next();
+
// Add attached objects if they exist
- attachObjectsForRole(role, con);
-
+ ((TorqueAbstractSecurityEntity)role).retrieveAttachedObjects(con);
+
roleSet.add(role);
}
-
+
Transaction.commit(con);
+ con = null;
}
catch (TorqueException e)
{
- Transaction.safeRollback(con);
throw new DataBackendException("Error retrieving role information", e);
}
- catch (UnknownEntityException e)
- {
- Transaction.safeRollback(con);
- throw new DataBackendException("Error creating permission instance", e);
- }
-
- return roleSet;
- }
-
- /**
- * Creates a new role with specified attributes.
- *
- * @param role the object describing the role to be created.
- * @return a new Role object that has id set up properly.
- * @throws DataBackendException if there was an error accessing the data
- * backend.
- * @throws EntityExistsException if the role already exists.
- */
- protected synchronized Role persistNewRole(Role role) throws DataBackendException
- {
- try
- {
- TorqueRole r = new TorqueRole();
- r.setName(role.getName());
- r.save();
-
- role.setId(r.getId());
- }
- catch (Exception e)
+ finally
{
- throw new DataBackendException("Adding Role '" + role + "' failed", e);
- }
-
- return role;
- }
-
- /**
- * Removes a Role from the system.
- *
- * @param role The object describing the role to be removed.
- * @throws DataBackendException if there was an error accessing the data
- * backend.
- * @throws UnknownEntityException if the role does not exist.
- */
- public synchronized void removeRole(Role role) throws DataBackendException, UnknownEntityException
- {
- if (checkExists(role))
- {
- try
- {
- TorqueRolePeer.doDelete(SimpleKey.keyFor((Integer)role.getId()));
- }
- catch (TorqueException e)
+ if (con != null)
{
- throw new DataBackendException("Removing Role '" + role + "' failed", e);
+ Transaction.safeRollback(con);
}
}
- else
- {
- throw new UnknownEntityException("Unknown role '" + role + "'");
- }
+
+ return roleSet;
}
/**
@@ -228,45 +266,47 @@
* @throws UnknownEntityException
* if the role does not exist.
*/
- public Role getRoleById(Object id)
- throws DataBackendException, UnknownEntityException
+ public Role getRoleById(Object id) throws DataBackendException, UnknownEntityException
{
- Role role = getRoleInstance();
-
+ Role role;
+
if (id != null && id instanceof Integer)
{
Connection con = null;
-
+
try
{
- con = Transaction.begin(TorqueRolePeer.DATABASE_NAME);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getRoleInstance()).getDatabaseName());
- TorqueRole r =
- TorqueRolePeer.retrieveByPK((Integer)id, con);
- role.setId(r.getId());
- role.setName(r.getName());
+ role = doSelectById((Integer)id, con);
// Add attached objects if they exist
- attachObjectsForRole(role, con);
-
+ ((TorqueAbstractSecurityEntity)role).retrieveAttachedObjects(con);
+
Transaction.commit(con);
+ con = null;
}
catch (NoRowsException e)
{
- Transaction.safeRollback(con);
throw new UnknownEntityException("Role with id '" + id + "' does not exist.", e);
}
catch (TorqueException e)
{
- Transaction.safeRollback(con);
throw new DataBackendException("Error retrieving role information", e);
}
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
+ }
}
else
{
- throw new UnknownEntityException("Invalid role id '" + role.getId() + "'");
+ throw new UnknownEntityException("Invalid role id '" + id + "'");
}
-
+
return role;
}
@@ -279,51 +319,43 @@
* data backend.
* @throws UnknownEntityException if the role does not exist.
*/
- public Role getRoleByName(String name)
- throws DataBackendException, UnknownEntityException
+ public Role getRoleByName(String name) throws DataBackendException, UnknownEntityException
{
- Role role = getRoleInstance();
- List roles = Collections.EMPTY_LIST;
+ Role role = null;
Connection con = null;
-
+
try
{
- con = Transaction.begin(TorqueRolePeer.DATABASE_NAME);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getRoleInstance()).getDatabaseName());
- Criteria criteria = new Criteria();
- criteria.add(TorqueRolePeer.ROLE_NAME, name);
-
- roles = TorqueRolePeer.doSelect(criteria, con);
-
- if (roles.size() == 1)
- {
- TorqueRole r = (TorqueRole) roles.get(0);
-
- role.setId(r.getId());
- role.setName(r.getName());
-
- // Add attached objects if they exist
- attachObjectsForRole(role, con);
- }
-
+ role = doSelectByName(name, con);
+
+ // Add attached objects if they exist
+ ((TorqueAbstractSecurityEntity)role).retrieveAttachedObjects(con);
+
Transaction.commit(con);
+ con = null;
}
- catch (TorqueException e)
- {
- Transaction.safeRollback(con);
- throw new DataBackendException("Error retrieving role information", e);
- }
-
- if (roles.size() == 0)
+ catch (NoRowsException e)
{
throw new UnknownEntityException("Could not find role" + name);
}
-
- if (roles.size() > 1)
+ catch (TooManyRowsException e)
{
throw new DataBackendException("Multiple Roles with same name '" + name + "'");
}
-
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("Error retrieving role information", e);
+ }
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
+ }
+
return role;
}
}
Added: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractSecurityEntity.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractSecurityEntity.java?view=auto&rev=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractSecurityEntity.java (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractSecurityEntity.java Thu Apr 5 10:28:53 2007
@@ -0,0 +1,128 @@
+package org.apache.fulcrum.security.torque;
+/*
+ * Copyright 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.
+ */
+import java.sql.Connection;
+
+import org.apache.fulcrum.security.entity.SecurityEntity;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.BaseObject;
+/**
+ * This abstract class provides the SecurityInterface to the managers.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public abstract class TorqueAbstractSecurityEntity extends BaseObject
+ implements SecurityEntity
+{
+ /**
+ * Get a numeric entity id
+ *
+ * @return numeric id of this entity
+ */
+ public abstract Integer getEntityId();
+
+ /**
+ * Set a numeric entity id
+ *
+ * @param id numeric id of this entity
+ */
+ public abstract void setEntityId(Integer id) throws TorqueException;
+
+ /**
+ * Get the name of the entity
+ *
+ * @return name of this entity
+ */
+ public abstract String getEntityName();
+
+ /**
+ * Set the name of the entity
+ *
+ * @param name the name of the entity
+ */
+ public abstract void setEntityName(String name);
+
+ /**
+ * Retrieve attached objects such as users, permissions, ...
+ *
+ * @param con A database connection
+ */
+ public abstract void retrieveAttachedObjects(Connection con) throws TorqueException;
+
+ /**
+ * Update this instance to the database with all dependend objects
+ *
+ * @param con A database connection
+ */
+ public abstract void update(Connection con) throws TorqueException;
+
+ /**
+ * Get the name of the connection pool associated to this object
+ *
+ * @return the logical Torque database name
+ */
+ public abstract String getDatabaseName();
+
+ /**
+ * Delete this entity
+ *
+ * @throws TorqueException if any database operation fails
+ */
+ public abstract void delete() throws TorqueException;
+
+ /**
+ * @see org.apache.fulcrum.security.entity.SecurityEntity#getId()
+ */
+ public Object getId()
+ {
+ return getEntityId();
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.entity.SecurityEntity#setId(java.lang.Object)
+ */
+ public void setId(Object id)
+ {
+ try
+ {
+ setEntityId((Integer)id);
+ }
+ catch (TorqueException e)
+ {
+ // should not happen
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.entity.SecurityEntity#getName()
+ */
+ public String getName()
+ {
+ return getEntityName();
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.entity.SecurityEntity#setName(java.lang.String)
+ */
+ public void setName(String name)
+ {
+ if (name != null)
+ {
+ setEntityName(name.toLowerCase());
+ }
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org