Author: tv
Date: Mon Jun 28 20:16:06 2010
New Revision: 958701
URL: http://svn.apache.org/viewvc?rev=958701&view=rev
Log:
Adjusted TorqueSecurityService to the new interfaces
Added:
turbine/core/trunk/conf/test/create-db.sql
turbine/core/trunk/src/test/org/apache/turbine/test/HsqlDB.java (with
props)
turbine/core/trunk/src/torque/
turbine/core/trunk/src/torque/schema/
turbine/core/trunk/src/torque/schema/id-table-schema.xml (with props)
turbine/core/trunk/src/torque/schema/torque-security-schema.xml (with
props)
Modified:
turbine/core/trunk/conf/test/intake.xml
turbine/core/trunk/pom.xml
turbine/core/trunk/src/java/org/apache/turbine/services/security/torque/TorqueSecurityService.java
turbine/core/trunk/src/java/org/apache/turbine/services/security/torque/TorqueUserManager.java
turbine/core/trunk/src/test/org/apache/turbine/services/security/torque/TestTorqueSecurity.java
Added: turbine/core/trunk/conf/test/create-db.sql
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/conf/test/create-db.sql?rev=958701&view=auto
==============================================================================
--- turbine/core/trunk/conf/test/create-db.sql (added)
+++ turbine/core/trunk/conf/test/create-db.sql Mon Jun 28 20:16:06 2010
@@ -0,0 +1,146 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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.
+alter table TURBINE_USER_GROUP_ROLE drop constraint FK576574BAF73AEE0F;
+alter table TURBINE_USER_GROUP_ROLE drop constraint FK576574BA1E2E76DB;
+alter table TURBINE_USER_GROUP_ROLE drop constraint FK576574BA52119584;
+alter table TURBINE_ROLE_PERMISSION drop constraint FK78A122C852119584;
+alter table TURBINE_ROLE_PERMISSION drop constraint FK78A122C8AAA7A58B;
+drop table TURBINE_GROUP if exists;
+drop table TURBINE_PERMISSION if exists;
+drop table TURBINE_ROLE if exists;
+drop table TURBINE_USER_GROUP_ROLE if exists;
+drop table TURBINE_ROLE_PERMISSION if exists;
+drop table TURBINE_USER if exists;
+drop table ID_TABLE if exists;
+create table TURBINE_GROUP (
+ group_id BIGINT not null,
+ group_name VARCHAR(64) not null,
+ primary key (group_id)
+);
+create table TURBINE_PERMISSION (
+ permission_id BIGINT not null,
+ permission_name VARCHAR(64) not null,
+ primary key (permission_id)
+);
+create table TURBINE_ROLE (
+ role_id BIGINT not null,
+ role_name VARCHAR(64) not null,
+ primary key (role_id)
+);
+create table TURBINE_USER_GROUP_ROLE (
+ role_id BIGINT not null,
+ user_id BIGINT not null,
+ group_id BIGINT not null,
+ primary key (role_id, user_id, group_id)
+);
+create table TURBINE_ROLE_PERMISSION (
+ role_id BIGINT not null,
+ permission_id BIGINT not null,
+ primary key (permission_id, role_id)
+);
+create table TURBINE_USER (
+ user_id BIGINT not null,
+ login_name VARCHAR(64) not null,
+ password_value VARCHAR(64) not null,
+ first_name VARCHAR(64) not null,
+ last_name VARCHAR(64) not null,
+ email VARCHAR(64),
+ confirm_value VARCHAR(16),
+ created TIMESTAMP,
+ modified TIMESTAMP,
+ last_login TIMESTAMP,
+ objectdata VARBINARY(255),
+ primary key (user_id)
+);
+alter table TURBINE_USER_GROUP_ROLE add constraint FK576574BAF73AEE0F foreign
key (user_id) references turbine_user;
+alter table TURBINE_USER_GROUP_ROLE add constraint FK576574BA1E2E76DB foreign
key (group_id) references turbine_group;
+alter table TURBINE_USER_GROUP_ROLE add constraint FK576574BA52119584 foreign
key (role_id) references turbine_role;
+alter table TURBINE_ROLE_PERMISSION add constraint FK78A122C852119584 foreign
key (role_id) references turbine_role;
+alter table TURBINE_ROLE_PERMISSION add constraint FK78A122C8AAA7A58B foreign
key (permission_id) references turbine_permission;
+
+
+
+create table ID_TABLE (
+ id integer not null,
+ table_name varchar (255) not null,
+ next_id integer not null,
+ quantity integer not null,
+ primary key (id)
+);
+
+insert into ID_TABLE (id, table_name, next_id, quantity) VALUES (1000,
'TURBINE_USER', 10000, 100);
+insert into ID_TABLE (id, table_name, next_id, quantity) VALUES (1001,
'TURBINE_GROUP', 10000, 100);
+insert into ID_TABLE (id, table_name, next_id, quantity) VALUES (1002,
'TURBINE_ROLE', 10000, 100);
+insert into ID_TABLE (id, table_name, next_id, quantity) VALUES (1003,
'TURBINE_PERMISSION', 10000, 100);
+insert into ID_TABLE (id, table_name, next_id, quantity) VALUES (1004,
'TURBINE_USER_GROUP_ROLE', 10000, 100);
+insert into ID_TABLE (id, table_name, next_id, quantity) VALUES (1005,
'TURBINE_ROLE_PERMISSION', 10000, 100);
+insert into ID_TABLE (id, table_name, next_id, quantity) VALUES (1006,
'ID_TABLE', 10000, 100);
+
+INSERT INTO TURBINE_USER
(USER_ID,LOGIN_NAME,PASSWORD_VALUE,FIRST_NAME,LAST_NAME)
+ VALUES (1,'admin','admin','Mister','Admin');
+
+
+INSERT INTO TURBINE_USER
(USER_ID,LOGIN_NAME,PASSWORD_VALUE,FIRST_NAME,LAST_NAME)
+ VALUES (2,'user','user','Mister','User');
+
+
+INSERT INTO TURBINE_PERMISSION (PERMISSION_ID,PERMISSION_NAME)
+ VALUES (1,'Login');
+
+
+INSERT INTO TURBINE_PERMISSION (PERMISSION_ID,PERMISSION_NAME)
+ VALUES (2,'Application');
+
+
+INSERT INTO TURBINE_PERMISSION (PERMISSION_ID,PERMISSION_NAME)
+ VALUES (3,'Admin');
+
+
+INSERT INTO TURBINE_ROLE (ROLE_ID,ROLE_NAME)
+ VALUES (1,'User');
+
+
+INSERT INTO TURBINE_ROLE (ROLE_ID,ROLE_NAME)
+ VALUES (2,'Admin');
+
+
+INSERT INTO TURBINE_GROUP (GROUP_ID,GROUP_NAME)
+ VALUES (1,'global');
+
+
+INSERT INTO TURBINE_GROUP (GROUP_ID,GROUP_NAME)
+ VALUES (2,'Turbine');
+
+
+INSERT INTO TURBINE_ROLE_PERMISSION (ROLE_ID,PERMISSION_ID)
+ VALUES (1,1);
+
+
+INSERT INTO TURBINE_ROLE_PERMISSION (ROLE_ID,PERMISSION_ID)
+ VALUES (1,2);
+
+
+INSERT INTO TURBINE_ROLE_PERMISSION (ROLE_ID,PERMISSION_ID)
+ VALUES (2,3);
+
+
+INSERT INTO TURBINE_USER_GROUP_ROLE (USER_ID,GROUP_ID,ROLE_ID)
+ VALUES (1,2,2);
+
+
+INSERT INTO TURBINE_USER_GROUP_ROLE (USER_ID,GROUP_ID,ROLE_ID)
+ VALUES (2,2,1);
Modified: turbine/core/trunk/conf/test/intake.xml
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/conf/test/intake.xml?rev=958701&r1=958700&r2=958701&view=diff
==============================================================================
--- turbine/core/trunk/conf/test/intake.xml (original)
+++ turbine/core/trunk/conf/test/intake.xml Mon Jun 28 20:16:06 2010
@@ -18,7 +18,7 @@
under the License.
-->
<!DOCTYPE input-data SYSTEM
- "http://turbine.apache.org/dtd/intake_2_3.dtd">
+ "http://turbine.apache.org/dtd/intake_2_4.dtd">
<input-data basePackage="org.apache.turbine.services.intake.">
<group name="LoginGroup" key="loginGroupKey" mapToObject="LoginForm">
<field name="Username" key="loginUsernameKey" type="String"
Modified: turbine/core/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/pom.xml?rev=958701&r1=958700&r2=958701&view=diff
==============================================================================
--- turbine/core/trunk/pom.xml (original)
+++ turbine/core/trunk/pom.xml Mon Jun 28 20:16:06 2010
@@ -705,23 +705,18 @@
<targetDatabase>mysql</targetDatabase>
<targetPackage>org.apache.turbine.services.security.torque.om</targetPackage>
<correctGetters>true</correctGetters>
+
<outputDir>${project.build.directory}/generated-sources/torque</outputDir>
+ <schemaDir>src/torque/schema</schemaDir>
+ <runOnlyOnSchemaChange>true</runOnlyOnSchemaChange>
</configuration>
- <!-- executions>
+ <executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>om</goal>
- <goal>documentation</goal>
</goals>
</execution>
- </executions -->
- <dependencies>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.0.4</version>
- </dependency>
- </dependencies>
+ </executions>
</plugin>
</plugins>
@@ -829,7 +824,7 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>taglist-maven-plugin</artifactId>
<version>2.1</version>
- </plugin>
+ </plugin>
</plugins>
</reporting>
Modified:
turbine/core/trunk/src/java/org/apache/turbine/services/security/torque/TorqueSecurityService.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/security/torque/TorqueSecurityService.java?rev=958701&r1=958700&r2=958701&view=diff
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/services/security/torque/TorqueSecurityService.java
(original)
+++
turbine/core/trunk/src/java/org/apache/turbine/services/security/torque/TorqueSecurityService.java
Mon Jun 28 20:16:06 2010
@@ -25,16 +25,13 @@ import java.util.Iterator;
import java.util.List;
import org.apache.commons.configuration.Configuration;
-
import org.apache.commons.lang.StringUtils;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
+import org.apache.torque.TorqueException;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
-
import org.apache.turbine.om.security.Group;
import org.apache.turbine.om.security.Permission;
import org.apache.turbine.om.security.Role;
@@ -495,27 +492,37 @@ public class TorqueSecurityService
* @throws DataBackendException if there was an error accessing the data
* backend.
*/
- public GroupSet getGroups(Criteria criteria)
+ public GroupSet getGroups(Object criteria)
throws DataBackendException
{
- Criteria torqueCriteria = new Criteria();
- Iterator keys = criteria.keySet().iterator();
- while (keys.hasNext())
- {
- String key = (String) keys.next();
- torqueCriteria.put(GroupPeerManager.getColumnName(key),
- criteria.get(key));
- }
- List groups = new ArrayList(0);
- try
+ if (criteria instanceof Criteria)
{
- groups = GroupPeerManager.doSelect(criteria);
+ Criteria torqueCriteria = new Criteria();
+ Criteria c = (Criteria)criteria;
+ Iterator keys = c.keySet().iterator();
+ while (keys.hasNext())
+ {
+ String key = (String) keys.next();
+ torqueCriteria.put(GroupPeerManager.getColumnName(key),
+ c.get(key));
+ }
+ List groups = new ArrayList(0);
+ try
+ {
+ groups = GroupPeerManager.doSelect(torqueCriteria);
+ }
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("getGroups(Object) failed", e);
+ }
+
+ return new GroupSet(groups);
}
- catch (Exception e)
+ else
{
- throw new DataBackendException("getGroups(Criteria) failed", e);
+ throw new DataBackendException(
+ "getGroups(Object) failed with invalid criteria");
}
- return new GroupSet(groups);
}
/**
@@ -526,27 +533,36 @@ public class TorqueSecurityService
* @throws DataBackendException if there was an error accessing the data
* backend.
*/
- public RoleSet getRoles(Criteria criteria)
+ public RoleSet getRoles(Object criteria)
throws DataBackendException
{
- Criteria torqueCriteria = new Criteria();
- Iterator keys = criteria.keySet().iterator();
- while (keys.hasNext())
- {
- String key = (String) keys.next();
- torqueCriteria.put(RolePeerManager.getColumnName(key),
- criteria.get(key));
- }
- List roles = new ArrayList(0);
- try
+ if (criteria instanceof Criteria)
{
- roles = RolePeerManager.doSelect(criteria);
+ Criteria torqueCriteria = new Criteria();
+ Criteria c = (Criteria)criteria;
+ Iterator keys = c.keySet().iterator();
+ while (keys.hasNext())
+ {
+ String key = (String) keys.next();
+ torqueCriteria.put(RolePeerManager.getColumnName(key),
+ c.get(key));
+ }
+ List roles = new ArrayList(0);
+ try
+ {
+ roles = RolePeerManager.doSelect(torqueCriteria);
+ }
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("getRoles(Criteria) failed", e);
+ }
+ return new RoleSet(roles);
}
- catch (Exception e)
+ else
{
- throw new DataBackendException("getRoles(Criteria) failed", e);
+ throw new DataBackendException(
+ "getRoles(Object) failed with invalid criteria");
}
- return new RoleSet(roles);
}
/**
@@ -557,28 +573,38 @@ public class TorqueSecurityService
* @throws DataBackendException if there was an error accessing the data
* backend.
*/
- public PermissionSet getPermissions(Criteria criteria)
+ public PermissionSet getPermissions(Object criteria)
throws DataBackendException
{
- Criteria torqueCriteria = new Criteria();
- Iterator keys = criteria.keySet().iterator();
- while (keys.hasNext())
- {
- String key = (String) keys.next();
- torqueCriteria.put(PermissionPeerManager.getColumnName(key),
- criteria.get(key));
- }
- List permissions = new ArrayList(0);
- try
+ if (criteria instanceof Criteria)
{
- permissions = PermissionPeerManager.doSelect(criteria);
+ Criteria torqueCriteria = new Criteria();
+ Criteria c = (Criteria)criteria;
+ Iterator keys = c.keySet().iterator();
+ while (keys.hasNext())
+ {
+ String key = (String) keys.next();
+ torqueCriteria.put(PermissionPeerManager.getColumnName(key),
+ c.get(key));
+ }
+ List permissions = new ArrayList(0);
+ try
+ {
+ permissions = PermissionPeerManager.doSelect(torqueCriteria);
+ }
+ catch (TorqueException e)
+ {
+ throw new DataBackendException(
+ "getPermissions(Object) failed", e);
+ }
+
+ return new PermissionSet(permissions);
}
- catch (Exception e)
+ else
{
throw new DataBackendException(
- "getPermissions(Criteria) failed", e);
+ "getPermissions(Object) failed with invalid criteria");
}
- return new PermissionSet(permissions);
}
/**
@@ -1155,4 +1181,63 @@ public class TorqueSecurityService
return PermissionPeerManager.checkExists(permission);
}
+
+ /**
+ * Retrieves all groups defined in the system.
+ *
+ * @return the names of all groups defined in the system.
+ * @throws DataBackendException if there was an error accessing the
+ * data backend.
+ */
+ public GroupSet getAllGroups() throws DataBackendException
+ {
+ return getGroups(new Criteria());
+ }
+
+
+ /**
+ * 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
+ {
+ return getPermissions(new Criteria());
+ }
+
+
+ /**
+ * Retrieves all roles 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 RoleSet getAllRoles() throws DataBackendException
+ {
+ return getRoles(new Criteria());
+ }
+
+
+ /**
+ * Retrieve a set of users that meet the specified criteria.
+ *
+ * As the keys for the criteria, you should use the constants that
+ * are defined in {...@link User} interface, plus the names
+ * of the custom attributes you added to your user representation
+ * in the data storage. Use verbatim names of the attributes -
+ * without table name prefix in case of Torque implementation.
+ *
+ * @param criteria The criteria of selection.
+ * @return a List of users meeting the criteria.
+ * @throws DataBackendException if there is a problem accessing the
+ * storage.
+ */
+ public List getUserList(Object criteria) throws DataBackendException
+ {
+ return getUserManager().retrieveList(criteria);
+ }
+
}
Modified:
turbine/core/trunk/src/java/org/apache/turbine/services/security/torque/TorqueUserManager.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/security/torque/TorqueUserManager.java?rev=958701&r1=958700&r2=958701&view=diff
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/services/security/torque/TorqueUserManager.java
(original)
+++
turbine/core/trunk/src/java/org/apache/turbine/services/security/torque/TorqueUserManager.java
Mon Jun 28 20:16:06 2010
@@ -134,7 +134,7 @@ public class TorqueUserManager
Criteria criteria = new Criteria();
criteria.add(UserPeerManager.getNameColumn(), userName);
- List users = retrieveList(criteria);;
+ List users = retrieveList(criteria);
if (users.size() > 1)
{
@@ -186,7 +186,7 @@ public class TorqueUserManager
* @throws DataBackendException if there is a problem accessing the
* storage.
*/
- public User[] retrieve(Criteria criteria)
+ public User[] retrieve(Object criteria)
throws DataBackendException
{
return (User [])retrieveList(criteria).toArray(new User[0]);
@@ -206,35 +206,43 @@ public class TorqueUserManager
* @throws DataBackendException if there is a problem accessing the
* storage.
*/
- public List retrieveList(Criteria criteria)
+ public List retrieveList(Object criteria)
throws DataBackendException
{
- for (Iterator keys = criteria.keySet().iterator(); keys.hasNext(); )
+ if (criteria instanceof Criteria)
{
- String key = (String) keys.next();
-
- // set the table name for all attached criterion
- Criteria.Criterion[] criterion = criteria
- .getCriterion(key).getAttachedCriterion();
-
- for (int i = 0; i < criterion.length; i++)
+ Criteria c = (Criteria)criteria;
+ for (Iterator keys = c.keySet().iterator(); keys.hasNext(); )
{
- if (StringUtils.isEmpty(criterion[i].getTable()))
+ String key = (String) keys.next();
+
+ // set the table name for all attached criterion
+ Criteria.Criterion[] criterion =
+ c.getCriterion(key).getAttachedCriterion();
+
+ for (int i = 0; i < criterion.length; i++)
{
- criterion[i].setTable(UserPeerManager.getTableName());
+ if (StringUtils.isEmpty(criterion[i].getTable()))
+ {
+ criterion[i].setTable(UserPeerManager.getTableName());
+ }
}
}
+ List users = null;
+ try
+ {
+ users = UserPeerManager.doSelect(c);
+ }
+ catch (Exception e)
+ {
+ throw new DataBackendException("Failed to retrieve users", e);
+ }
+ return users;
}
- List users = null;
- try
- {
- users = UserPeerManager.doSelect(criteria);
- }
- catch (Exception e)
+ else
{
- throw new DataBackendException("Failed to retrieve users", e);
+ throw new DataBackendException("Failed to retrieve users with
invalid criteria");
}
- return users;
}
/**
Modified:
turbine/core/trunk/src/test/org/apache/turbine/services/security/torque/TestTorqueSecurity.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/test/org/apache/turbine/services/security/torque/TestTorqueSecurity.java?rev=958701&r1=958700&r2=958701&view=diff
==============================================================================
---
turbine/core/trunk/src/test/org/apache/turbine/services/security/torque/TestTorqueSecurity.java
(original)
+++
turbine/core/trunk/src/test/org/apache/turbine/services/security/torque/TestTorqueSecurity.java
Mon Jun 28 20:16:06 2010
@@ -25,10 +25,8 @@ import junit.framework.TestSuite;
import org.apache.turbine.Turbine;
import org.apache.turbine.services.security.SecurityService;
import org.apache.turbine.services.security.TurbineSecurity;
-
-import org.apache.turbine.test.HsqlDB;
-
import org.apache.turbine.test.BaseTurbineTest;
+import org.apache.turbine.test.HsqlDB;
public class TestTorqueSecurity
extends BaseTurbineTest
@@ -40,7 +38,7 @@ public class TestTorqueSecurity
public TestTorqueSecurity(String name)
throws Exception
{
- super(name, "conf/test/TurbineResources.properties");
+ super(name, "conf/test/CompleteTurbineResources.properties");
hsqlDB = new HsqlDB("jdbc:hsqldb:.",
Turbine.getRealPath("conf/test/create-db.sql"));
}
Added: turbine/core/trunk/src/test/org/apache/turbine/test/HsqlDB.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/test/org/apache/turbine/test/HsqlDB.java?rev=958701&view=auto
==============================================================================
--- turbine/core/trunk/src/test/org/apache/turbine/test/HsqlDB.java (added)
+++ turbine/core/trunk/src/test/org/apache/turbine/test/HsqlDB.java Mon Jun 28
20:16:06 2010
@@ -0,0 +1,130 @@
+package org.apache.turbine.test;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.io.FileReader;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hsqldb.jdbcDriver;
+
+public class HsqlDB
+{
+ private Connection connection = null;
+ private static Log log = LogFactory.getLog(HsqlDB.class);
+
+ public HsqlDB(String uri, String loadFile)
+ throws Exception
+ {
+ Class.forName(jdbcDriver.class.getName());
+
+ this.connection = DriverManager.getConnection(uri, "sa", "");
+
+ if (StringUtils.isNotEmpty(loadFile))
+ {
+ loadSqlFile(loadFile);
+ }
+ }
+
+ public Connection getConnection()
+ {
+ return connection;
+ }
+
+ public void close()
+ {
+ try
+ {
+ connection.close();
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ private void loadSqlFile(String fileName)
+ throws Exception
+ {
+ Statement statement = null;
+ try
+ {
+ statement = connection.createStatement();
+ String commands = getFileContents(fileName);
+
+ for (int targetPos = commands.indexOf(';'); targetPos > -1;
targetPos = commands.indexOf(';'))
+ {
+ String cmd = commands.substring(0, targetPos + 1).trim();
+
+ if (cmd.startsWith("--"))
+ {
+ // comment
+ int lineend = commands.indexOf('\n');
+ if (lineend > -1)
+ {
+ targetPos = lineend - 1;
+ }
+ }
+ else
+ {
+ try
+ {
+ statement.execute(cmd);
+ }
+ catch (SQLException sqle)
+ {
+ log.warn("Statement: " + cmd + ": " +
sqle.getMessage());
+ }
+ }
+
+ commands = commands.substring(targetPos + 2);
+ }
+ }
+ finally
+ {
+ if (statement != null)
+ {
+ statement.close();
+ }
+ }
+ }
+
+ private String getFileContents(String fileName)
+ throws Exception
+ {
+ FileReader fr = new FileReader(fileName);
+
+ char fileBuf[] = new char[1024];
+ StringBuffer sb = new StringBuffer(1000);
+ int res = -1;
+
+ while ((res = fr.read(fileBuf, 0, 1024)) > -1)
+ {
+ sb.append(fileBuf, 0, res);
+ }
+ fr.close();
+ return sb.toString();
+ }
+}
+
Propchange: turbine/core/trunk/src/test/org/apache/turbine/test/HsqlDB.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: turbine/core/trunk/src/torque/schema/id-table-schema.xml
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/torque/schema/id-table-schema.xml?rev=958701&view=auto
==============================================================================
--- turbine/core/trunk/src/torque/schema/id-table-schema.xml (added)
+++ turbine/core/trunk/src/torque/schema/id-table-schema.xml Mon Jun 28
20:16:06 2010
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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">
+
+<!-- ==================================================================== -->
+<!-- -->
+<!-- I D B R O K E R S C H E M A -->
+<!-- -->
+<!-- ==================================================================== -->
+<!-- This is the XML schema use by Torque to generate the SQL for -->
+<!-- ID_TABLE table used by the id broker mechanism in Torque. -->
+<!-- ==================================================================== -->
+<!-- @author: <a href="mailto:[email protected]">Jason van Zyl</a> -->
+<!-- @version $Id: id-table-schema.xml 571796 2007-09-01 13:11:26Z tv $ -->
+<!-- ==================================================================== -->
+
+<database name="default">
+ <table name="ID_TABLE" idMethod="idbroker">
+ <column name="ID_TABLE_ID" required="true" primaryKey="true"
type="INTEGER"/>
+ <column name="TABLE_NAME" required="true" size="255" type="VARCHAR"/>
+ <column name="NEXT_ID" type="INTEGER"/>
+ <column name="QUANTITY" type="INTEGER"/>
+
+ <unique>
+ <unique-column name="TABLE_NAME"/>
+ </unique>
+
+ </table>
+</database>
Propchange: turbine/core/trunk/src/torque/schema/id-table-schema.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: turbine/core/trunk/src/torque/schema/torque-security-schema.xml
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/torque/schema/torque-security-schema.xml?rev=958701&view=auto
==============================================================================
--- turbine/core/trunk/src/torque/schema/torque-security-schema.xml (added)
+++ turbine/core/trunk/src/torque/schema/torque-security-schema.xml Mon Jun 28
20:16:06 2010
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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">
+
+<!-- ====================================================================
-->
+<!--
-->
+<!-- B A S E T U R B I N E S C H E M A
-->
+<!--
-->
+<!-- ====================================================================
-->
+<!-- This is the the XML schema used by Torque to generate the necessary
-->
+<!-- sources used to create/initialize the base Turbine system. Torque
-->
+<!-- will create the SQL for the database required by Turbine, and the
-->
+<!-- Peer-based Object Model used by Turbine internally to manage
-->
+<!-- users and security.
-->
+<!-- ====================================================================
-->
+<!-- @author: <a href="mailto:[email protected]">Henning P. Schmiedehausen</a>
-->
+<!-- @version $Id: torque-security-schema.xml 571796 2007-09-01 13:11:26Z tv $
-->
+<!-- ====================================================================
-->
+
+<database name="default">
+
+ <table name="TURBINE_PERMISSION" idMethod="idbroker">
+ <column name="PERMISSION_ID" required="true" primaryKey="true"
type="INTEGER"/>
+ <column name="PERMISSION_NAME" required="true" size="64" type="VARCHAR"
javaName="Name"/>
+
+ <unique>
+ <unique-column name="PERMISSION_NAME"/>
+ </unique>
+
+ </table>
+
+ <table name="TURBINE_ROLE" idMethod="idbroker">
+ <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER"/>
+ <column name="ROLE_NAME" required="true" size="64" type="VARCHAR"
javaName="Name"/>
+
+ <unique>
+ <unique-column name="ROLE_NAME"/>
+ </unique>
+
+ </table>
+
+ <table name="TURBINE_GROUP" idMethod="idbroker">
+ <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER"/>
+ <column name="GROUP_NAME" required="true" type="VARCHAR" size="64"
javaName="Name"/>
+
+ <unique>
+ <unique-column name="GROUP_NAME"/>
+ </unique>
+
+ </table>
+
+ <table name="TURBINE_ROLE_PERMISSION">
+ <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER"/>
+ <column name="PERMISSION_ID" required="true" primaryKey="true"
type="INTEGER"/>
+
+ <foreign-key foreignTable="TURBINE_ROLE">
+ <reference local="ROLE_ID" foreign="ROLE_ID"/>
+ </foreign-key>
+
+ <foreign-key foreignTable="TURBINE_PERMISSION">
+ <reference local="PERMISSION_ID" foreign="PERMISSION_ID"/>
+ </foreign-key>
+ </table>
+
+ <table name="TURBINE_USER" idMethod="idbroker">
+ <column name="USER_ID" required="true" primaryKey="true" type="INTEGER"/>
+ <column name="LOGIN_NAME" required="true" size="64" type="VARCHAR"
javaName="UserName"/>
+ <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>
+
+ <table name="TURBINE_USER_GROUP_ROLE">
+ <column name="USER_ID" required="true" primaryKey="true" type="INTEGER"/>
+ <column name="GROUP_ID" required="true" primaryKey="true" type="INTEGER"/>
+ <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER"/>
+
+ <foreign-key foreignTable="TURBINE_USER">
+ <reference local="USER_ID" foreign="USER_ID"/>
+ </foreign-key>
+
+ <foreign-key foreignTable="TURBINE_GROUP">
+ <reference local="GROUP_ID" foreign="GROUP_ID"/>
+ </foreign-key>
+
+ <foreign-key foreignTable="TURBINE_ROLE">
+ <reference local="ROLE_ID" foreign="ROLE_ID"/>
+ </foreign-key>
+ </table>
+
+</database>
Propchange: turbine/core/trunk/src/torque/schema/torque-security-schema.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain