directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: r354314 - in /directory/authx/trunk: core/src/java/org/apache/authx/authentication/ core/src/java/org/apache/authx/authentication/realm/ jdbc/src/java/org/apache/authx/authentication/realm/ jdbc/src/java/org/apache/authx/authentication/real...
Date Tue, 06 Dec 2005 05:08:01 GMT
Author: vtence
Date: Mon Dec  5 21:07:36 2005
New Revision: 354314

URL: http://svn.apache.org/viewcvs?rev=354314&view=rev
Log:
Quite a major refactoring to JDBC code. Extracted SQL statement generation code into their own classes, which simplified mapping result sets to object. Renamed Persister to Type. Got rid of ReflectionPersister (I need to stop smoking) in favor of custom types. I think I got the model correct now.

Added:
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ClassMapping.java
      - copied, changed from r351546, directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/TableMapping.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLType.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Statement.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Type.java   (contents, props changed)
      - copied, changed from r351546, directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Persister.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Create.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Drop.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Insert.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Select.java
      - copied, changed from r354062, directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Select.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/PasswordCredentialType.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SQLStringType.java   (contents, props changed)
      - copied, changed from r351546, directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLStringType.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SQLTypes.java
      - copied, changed from r351546, directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLTypes.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SimpleType.java
      - copied, changed from r351546, directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SimpleTypePersister.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/UsernameCredentialType.java
Removed:
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Persister.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionException.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionPersister.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLStringType.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLTypes.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Select.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SimpleTypePersister.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/TableMapping.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/ReflectionPersisterTest.java
Modified:
    directory/authx/trunk/core/src/java/org/apache/authx/authentication/CredentialSet.java
    directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/UsernamePasswordAuthentication.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Column.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/CredentialSetMapping.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCException.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCSelector.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/PreparedSQLStatement.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLStatement.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Table.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Columns.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Creds.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCRealmTest.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCSelectorTest.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/MemoryDatabase.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Tables.java

Modified: directory/authx/trunk/core/src/java/org/apache/authx/authentication/CredentialSet.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/java/org/apache/authx/authentication/CredentialSet.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/core/src/java/org/apache/authx/authentication/CredentialSet.java (original)
+++ directory/authx/trunk/core/src/java/org/apache/authx/authentication/CredentialSet.java Mon Dec  5 21:07:36 2005
@@ -82,17 +82,17 @@
      * of credentials composed of all credentials
      * of the given type.
      *
-     * @param c the class of credential to be returned.
+     * @param type the class of credential to be returned.
      * @return a new CredentialSet containing all
      *         of the credential objects of the given type.
      */
-    public CredentialSet getCredentials( Class c )
+    public CredentialSet getCredentials( Class type )
     {
         final CredentialSet subSet = new CredentialSet();
         for ( Iterator it = m_credentials.iterator(); it.hasNext(); )
         {
             final Object credential = it.next();
-            if ( c.isInstance( credential ) ) subSet.add( credential );
+            if ( type.isInstance( credential ) ) subSet.add( credential );
         }
 
         return subSet;
@@ -102,18 +102,23 @@
      * Returns the only credential in this set that matches
      * the given type.
      *
-     * @param c the class of credential to be returned.
+     * @param type the class of credential to be returned.
      * @return the sole credential of this type in the set
      * @throws IllegalArgumentException if none or more than one
      *         credential of the given type exists in the set
      */
-    public Object getUniqueCredential( Class c )
+    public Object getUniqueCredential( Class type )
     {
-        CredentialSet creds = getCredentials( c );
-        if ( creds.isEmpty() ) throw new IllegalArgumentException( "No such credential: " + c.getName() );
-        if ( creds.size() > 1 ) throw new IllegalArgumentException( "Multiple matching credentials: " + c.getName() );
+        CredentialSet creds = getCredentials( type );
+        if ( creds.isEmpty() ) throw new IllegalArgumentException( "No such credential: " + type.getName() );
+        if ( creds.size() > 1 ) throw new IllegalArgumentException( "Multiple matching credentials: " + type.getName() );
 
         return creds.m_credentials.iterator().next();
+    }
+
+    public boolean hasCredentialOfType( Class type )
+    {
+        return !getCredentials( type ).isEmpty();
     }
 
     public boolean contains( Object credential )

Modified: directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/UsernamePasswordAuthentication.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/UsernamePasswordAuthentication.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/UsernamePasswordAuthentication.java (original)
+++ directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/UsernamePasswordAuthentication.java Mon Dec  5 21:07:36 2005
@@ -31,6 +31,7 @@
 
     public Principal principal( CredentialSet credentialSet )
     {
+        if ( !credentialSet.hasCredentialOfType( UsernameCredential.class ) ) return null;
         UsernameCredential username = (UsernameCredential) credentialSet.getUniqueCredential( UsernameCredential.class );
         return new UsernamePrincipal( username.getUsername() );
     }

Copied: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ClassMapping.java (from r351546, directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/TableMapping.java)
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ClassMapping.java?p2=directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ClassMapping.java&p1=directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/TableMapping.java&r1=351546&r2=354314&rev=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/TableMapping.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ClassMapping.java Mon Dec  5 21:07:36 2005
@@ -1,11 +1,8 @@
 package org.apache.authx.authentication.realm;
 
 import java.util.Map;
-import java.sql.ResultSet;
 
-public interface TableMapping
+public interface ClassMapping
 {
-    Class getMappedType();
-
-    Object instanciate( Map columns, ResultSet rs );
+    Object instanciate( Map resultSet );
 }

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Column.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Column.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Column.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Column.java Mon Dec  5 21:07:36 2005
@@ -22,12 +22,12 @@
 public class Column
 {
     private final String m_name;
-    private final Persister m_persister;
+    private final Type m_type;
 
-    public Column( String name, Persister persister )
+    public Column( String name, Type type )
     {
         m_name = name;
-        m_persister = persister;
+        m_type = type;
     }
 
     public String getName()
@@ -35,14 +35,20 @@
         return m_name;
     }
 
-    public Class getMappedType()
+    public boolean canHold( Object property )
     {
-        return m_persister.getPersistentType();
+        return m_type.getJavaType().isInstance( property );
+    }
+
+    public SQLStatement define( SQLStatement st )
+    {
+        m_type.getSQLType().define( st.appendWithSpace( getName() ) );
+        return st;
     }
 
     public void setProperty( SQLStatement statement, Object property )
     {
-        m_persister.setProperty( statement, property );
+        m_type.setProperty( statement, property );
     }
 
     public Object getProperty( ResultSet rs ) throws JDBCException
@@ -50,7 +56,7 @@
         Object property;
         try
         {
-            property = m_persister.getProperty( rs, m_name );
+            property = m_type.getProperty( rs, m_name );
         }
         catch ( SQLException e )
         {
@@ -62,9 +68,9 @@
     public boolean equals( Object o )
     {
         if ( this == o ) return true;
-        if ( !( o instanceof Column ) ) return false;
+        if ( !(o instanceof Column) ) return false;
 
-        final Column column = ( Column ) o;
+        final Column column = (Column) o;
 
         if ( !m_name.equals( column.m_name ) ) return false;
 
@@ -76,9 +82,8 @@
         return m_name.hashCode();
     }
 
-
     public String toString()
     {
-        return "m_name=" + m_name + ", m_type=" + m_persister.getPersistentType();
+        return "name=" + m_name + ", type=" + m_type.getJavaType();
     }
 }

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/CredentialSetMapping.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/CredentialSetMapping.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/CredentialSetMapping.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/CredentialSetMapping.java Mon Dec  5 21:07:36 2005
@@ -2,27 +2,12 @@
 
 import org.apache.authx.authentication.CredentialSet;
 
-import java.sql.ResultSet;
-import java.util.Iterator;
 import java.util.Map;
 
-public class CredentialSetMapping implements TableMapping
+public class CredentialSetMapping implements ClassMapping
 {
-    public Class getMappedType()
+    public Object instanciate( Map resultSet )
     {
-        return CredentialSet.class;
+        return new CredentialSet( resultSet.values() );
     }
-
-    public Object instanciate( Map columns, ResultSet rs )
-    {
-        CredentialSet creds = new CredentialSet();
-        for ( Iterator it = columns.keySet().iterator(); it.hasNext(); )
-        {
-            Column column = (Column) columns.get( it.next() );
-            creds.add( column.getProperty( rs ) );
-        }
-
-        return creds;
-    }
-
 }

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCException.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCException.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCException.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCException.java Mon Dec  5 21:07:36 2005
@@ -33,4 +33,9 @@
     {
         return m_cause;
     }
+
+    public String getMessage()
+    {
+        return m_cause.getMessage();
+    }
 }

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCSelector.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCSelector.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCSelector.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCSelector.java Mon Dec  5 21:07:36 2005
@@ -16,16 +16,21 @@
  */
 package org.apache.authx.authentication.realm;
 
+import org.apache.authx.authentication.realm.statements.Select;
+
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.Map;
 
 public class JDBCSelector implements Selector
 {
+    private final Table m_table;
     private final Select m_select;
     private final SQLExpressionBuilder m_builder;
 
     public JDBCSelector( Table table )
     {
+        m_table = table;
         m_select = table.select();
         m_builder = new SQLExpressionBuilder( table );
     }
@@ -38,6 +43,6 @@
 
     public Object select( Connection c ) throws SQLException
     {
-        return m_select.execute( c );
+        return m_table.instantiate( (Map) m_select.execute( c ) );
     }
 }

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/PreparedSQLStatement.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/PreparedSQLStatement.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/PreparedSQLStatement.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/PreparedSQLStatement.java Mon Dec  5 21:07:36 2005
@@ -24,6 +24,7 @@
 
 public class PreparedSQLStatement implements SQLStatement
 {
+    private static final String WS = " ";
     private final StringBuffer m_query = new StringBuffer();
     private final List m_parameters = new ArrayList();
 
@@ -39,6 +40,13 @@
     public SQLStatement append( String sqlFragment )
     {
         m_query.append( sqlFragment );
+        return this;
+    }
+
+    public SQLStatement appendWithSpace( String sqlFragment )
+    {
+        append( sqlFragment );
+        m_query.append( WS );
         return this;
     }
 

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLStatement.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLStatement.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLStatement.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLStatement.java Mon Dec  5 21:07:36 2005
@@ -20,5 +20,7 @@
 {
     SQLStatement append( String sqlFragment );
 
+    SQLStatement appendWithSpace( String sqlFragment );
+
     SQLStatement setString( String value );
 }

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLType.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLType.java?rev=354314&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLType.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLType.java Mon Dec  5 21:07:36 2005
@@ -0,0 +1,33 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.authx.authentication.realm;
+
+import org.apache.authx.authentication.realm.SQLStatement;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public interface SQLType
+{
+    Class getJavaType();
+
+    SQLStatement define( SQLStatement st );
+
+    void setValue( SQLStatement st, Object value );
+
+    Object getValue( ResultSet rs, String columnName ) throws SQLException;
+}

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Statement.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Statement.java?rev=354314&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Statement.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Statement.java Mon Dec  5 21:07:36 2005
@@ -0,0 +1,9 @@
+package org.apache.authx.authentication.realm;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public interface Statement
+{
+    Object execute( Connection c ) throws SQLException;
+}

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Table.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Table.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Table.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Table.java Mon Dec  5 21:07:36 2005
@@ -16,7 +16,11 @@
  */
 package org.apache.authx.authentication.realm;
 
-import java.sql.ResultSet;
+import org.apache.authx.authentication.realm.statements.Create;
+import org.apache.authx.authentication.realm.statements.Drop;
+import org.apache.authx.authentication.realm.statements.Insert;
+import org.apache.authx.authentication.realm.statements.Select;
+
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -26,22 +30,40 @@
 {
     private final String m_name;
     private final Map m_columns;
-    private final TableMapping m_mapping;
-
-    public Table( String name )
-    {
-        this( name, new CredentialSetMapping() );
-    }
+    private final ClassMapping m_mapping;
 
-    public Table( String name, TableMapping mapping )
+    public Table( String name, ClassMapping mapping )
     {
         m_name = name;
         m_columns = new HashMap();
         m_mapping = mapping;
     }
 
-    public Select select() {
-        return Select.from( this );
+    public Select select()
+    {
+        Select select = Select.from( getName() );
+        select.addAllColumnsToReturn( m_columns );
+        return select;
+    }
+
+    public Drop drop()
+    {
+        return Drop.table( getName() );
+    }
+
+    public Create create()
+    {
+        Create create = Create.table( getName() );
+        create.addAllColumns( m_columns.values() );
+        return create;
+    }
+
+    public Insert insert( Map values )
+    {
+        Insert insert = Insert.into( getName() );
+        insert.addAllColumns( m_columns );
+        insert.setValues( values );
+        return insert;
     }
 
     public String getName()
@@ -62,12 +84,12 @@
 
     public Column getColumn( Object key )
     {
-        return ( Column ) m_columns.get( key );
+        return (Column) m_columns.get( key );
     }
 
-    public Object instantiate( ResultSet rs )
+    public Object instantiate( Map resultSet )
     {
-        return m_mapping.instanciate( Collections.unmodifiableMap( m_columns ), rs );
+        return m_mapping.instanciate( resultSet );
     }
 
     public void addColumn( Object key, Column column )

Copied: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Type.java (from r351546, directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Persister.java)
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Type.java?p2=directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Type.java&p1=directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Persister.java&r1=351546&r2=354314&rev=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Persister.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Type.java Mon Dec  5 21:07:36 2005
@@ -19,9 +19,11 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
-public interface Persister
+public interface Type
 {
-    Class getPersistentType();
+    Class getJavaType();
+
+    SQLType getSQLType();
 
     Object getProperty( ResultSet rs, String columnName ) throws SQLException;
 

Propchange: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Type.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Create.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Create.java?rev=354314&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Create.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Create.java Mon Dec  5 21:07:36 2005
@@ -0,0 +1,87 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.authx.authentication.realm.statements;
+
+import org.apache.authx.authentication.realm.Statement;
+import org.apache.authx.authentication.realm.Column;
+import org.apache.authx.authentication.realm.PreparedSQLStatement;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+public class Create implements Statement
+{
+    private final String m_tableName;
+    private final Collection m_columns = new ArrayList();
+
+    protected Create( String tableName )
+    {
+        m_tableName = tableName;
+    }
+
+    public static Create table( String tableName )
+    {
+        return new Create( tableName );
+    }
+
+    public void addColumn( Column column )
+    {
+        m_columns.add( column );
+    }
+
+    public void addAllColumns( Collection columns )
+    {
+        m_columns.addAll( columns );
+    }
+
+    public Object execute( Connection c ) throws SQLException
+    {
+        Object result = null;
+        PreparedStatement st = null;
+        try
+        {
+            st = buildStatement().create( c );
+            result = Integer.valueOf( st.executeUpdate() );
+        }
+        finally
+        {
+            if ( st != null ) st.close();
+        }
+        return result;
+    }
+
+    private PreparedSQLStatement buildStatement()
+    {
+        PreparedSQLStatement statement = new PreparedSQLStatement( "create table " );
+        statement.append( m_tableName );
+        statement.append( " (" );
+
+        for ( Iterator it = m_columns.iterator(); it.hasNext(); )
+        {
+            Column column = (Column) it.next();
+            column.define( statement );
+            if ( it.hasNext() ) statement.append( ", " );
+        }
+
+        statement.append( ")" );
+        return statement;
+    }
+}

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Drop.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Drop.java?rev=354314&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Drop.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Drop.java Mon Dec  5 21:07:36 2005
@@ -0,0 +1,59 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.authx.authentication.realm.statements;
+
+import org.apache.authx.authentication.realm.Statement;
+import org.apache.authx.authentication.realm.PreparedSQLStatement;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+public class Drop implements Statement
+{
+    private final String m_tableName;
+
+    protected Drop( String tableName )
+    {
+        m_tableName = tableName;
+    }
+
+    public static Drop table( String tableName )
+    {
+        return new Drop( tableName );
+    }
+
+    public Object execute( Connection c ) throws SQLException
+    {
+        PreparedSQLStatement statement = new PreparedSQLStatement( "drop table " );
+        statement.append( m_tableName );
+
+        Object result = null;
+        PreparedStatement st = null;
+        try
+        {
+            st = statement.create( c );
+            result = Integer.valueOf( st.executeUpdate() );
+        }
+        finally
+        {
+            if ( st != null ) st.close();
+        }
+        return result;
+    }
+
+}

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Insert.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Insert.java?rev=354314&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Insert.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Insert.java Mon Dec  5 21:07:36 2005
@@ -0,0 +1,111 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.authx.authentication.realm.statements;
+
+import org.apache.authx.authentication.realm.Statement;
+import org.apache.authx.authentication.realm.Column;
+import org.apache.authx.authentication.realm.PreparedSQLStatement;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class Insert implements Statement
+{
+    private final String m_tableName;
+    private final Map m_columns = new HashMap();
+    private final Map m_values = new HashMap();
+
+    protected Insert( String tableName )
+    {
+        m_tableName = tableName;
+    }
+
+    public static Insert into( String tableName )
+    {
+        return new Insert( tableName );
+    }
+
+    public void addAllColumns( Map columns )
+    {
+        m_columns.putAll( columns );
+    }
+
+    public void addColumn( Object key, Column column )
+    {
+        m_columns.put( key, column );
+    }
+
+    public void setValues( Map values )
+    {
+        m_values.putAll( values );
+    }
+
+    public Object execute( Connection c ) throws SQLException
+    {
+        Object result = null;
+        PreparedStatement st = null;
+        try
+        {
+            st = buildStatement().create( c );
+            result = Integer.valueOf( st.executeUpdate() );
+        }
+        finally
+        {
+            if ( st != null ) st.close();
+        }
+        return result;
+    }
+
+    private PreparedSQLStatement buildStatement()
+    {
+        PreparedSQLStatement m_statement = new PreparedSQLStatement( "insert into " );
+        m_statement.append( m_tableName );
+        m_statement.append( " (" );
+
+        for ( Iterator it = m_columns.keySet().iterator(); it.hasNext(); )
+        {
+            Column column = (Column) m_columns.get( it.next() );
+            m_statement.append( column.getName() );
+
+            if ( it.hasNext() ) m_statement.append( ", " );
+        }
+
+        m_statement.append( ") values (" );
+
+        int i = 0;
+        for ( Iterator it = m_values.keySet().iterator(); it.hasNext(); i++ )
+        {
+            Object key = it.next();
+            Object value = m_values.get( key );
+            Column column = (Column) m_columns.get( key );
+            if ( !column.canHold( value ) )
+            {
+                throw new IllegalArgumentException( "Invalid value at column(" + i + "): " + value );
+            }
+            column.setProperty( m_statement, value );
+            if ( it.hasNext() ) m_statement.append( ", " );
+        }
+
+        m_statement.append( ")" );
+
+        return m_statement;
+    }
+}

Copied: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Select.java (from r354062, directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Select.java)
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Select.java?p2=directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Select.java&p1=directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Select.java&r1=354062&r2=354314&rev=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Select.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/statements/Select.java Mon Dec  5 21:07:36 2005
@@ -14,65 +14,109 @@
  *   limitations under the License.
  *
  */
-package org.apache.authx.authentication.realm;
+package org.apache.authx.authentication.realm.statements;
+
+import org.apache.authx.authentication.realm.Statement;
+import org.apache.authx.authentication.realm.Column;
+import org.apache.authx.authentication.realm.SQLExpression;
+import org.apache.authx.authentication.realm.PreparedSQLStatement;
 
 import java.sql.Connection;
-import java.sql.ResultSet;
 import java.sql.PreparedStatement;
+import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
-public class Select
+public class Select implements Statement
 {
-    private final Table m_table;
-    private final PreparedSQLStatement m_statement;
-    private boolean m_first = true;
+    private final String m_tableName;
+    private final Map m_columns = new HashMap();
+    private final Collection m_whereClauses = new ArrayList();
 
-    protected Select( Table table )
+    protected Select( String tableName )
     {
-        m_table = table;
-        m_statement = new PreparedSQLStatement( "select * from " );
-        m_statement.append( table.getName() );
+        m_tableName = tableName;
     }
 
-    public static Select from( Table table )
+    public static Select from( String tableName )
     {
-        return new Select( table );
+        return new Select( tableName );
     }
 
-    public Select where( SQLExpression expression )
+    public void addColumnToReturn( Object key, Column column )
     {
-        if (m_first)
-        {
-            m_first = false;
-            m_statement.append( " where ");
-        }
-        else
-        {
-            m_statement.append( " and ");
-        }
+        m_columns.put( key, column );
+    }
+
+    public void addAllColumnsToReturn( Map columns )
+    {
+        m_columns.putAll( columns );
+    }
 
-        expression.prepare( m_statement );
+    public Select where( SQLExpression expression )
+    {
+        m_whereClauses.add( expression );
         return this;
     }
 
     public Object execute( Connection c ) throws SQLException
     {
-        Object result = null;
+        if ( m_columns.isEmpty() )
+        {
+            throw new IllegalArgumentException( "No columns to select " );
+        }
+
+        Map result = new HashMap();
         PreparedStatement st = null;
-        try {
-            st = m_statement.create( c );
+        try
+        {
+            st = buildStatement().create( c );
             ResultSet rs = st.executeQuery();
             if ( rs.next() )
             {
-                result = m_table.instantiate( rs );
+                for ( Iterator it = m_columns.keySet().iterator(); it.hasNext(); )
+                {
+                    Object key = it.next();
+                    Column column = (Column) m_columns.get( key );
+                    result.put( key, column.getProperty( rs ) );
+                }
             }
             rs.close();
         }
         finally
         {
-            if (st != null) st.close();
+            if ( st != null ) st.close();
         }
         return result;
     }
 
+    private PreparedSQLStatement buildStatement()
+    {
+        PreparedSQLStatement statement = new PreparedSQLStatement( "select " );
+        for ( Iterator it = m_columns.values().iterator(); it.hasNext(); )
+        {
+            Column column = (Column) it.next();
+            statement.append( column.getName() );
+            if ( it.hasNext() ) statement.append( ", " );
+        }
+        statement.append( " from " ).append( m_tableName );
+
+        if ( !m_whereClauses.isEmpty() )
+        {
+            statement.append( " where " );
+        }
+        for ( Iterator it = m_whereClauses.iterator(); it.hasNext(); )
+        {
+            SQLExpression expression = (SQLExpression) it.next();
+            expression.prepare( statement );
+
+            if ( it.hasNext() ) statement.append( " and " );
+        }
+
+        return statement;
+    }
 }

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/PasswordCredentialType.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/PasswordCredentialType.java?rev=354314&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/PasswordCredentialType.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/PasswordCredentialType.java Mon Dec  5 21:07:36 2005
@@ -0,0 +1,50 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.authx.authentication.realm.types;
+
+import org.apache.authx.authentication.realm.types.SQLTypes;
+import org.apache.authx.authentication.realm.SQLType;
+import org.apache.authx.authentication.realm.Type;
+import org.apache.authx.authentication.realm.PasswordCredential;
+import org.apache.authx.authentication.realm.SQLStatement;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public class PasswordCredentialType implements Type
+{
+    public Class getJavaType()
+    {
+        return PasswordCredential.class;
+    }
+
+    public SQLType getSQLType()
+    {
+        return SQLTypes.STRING;
+    }
+
+    public Object getProperty( ResultSet rs, String columnName ) throws SQLException
+    {
+        String password = (String) getSQLType().getValue( rs, columnName );
+        return new PasswordCredential( password );
+    }
+
+    public void setProperty( SQLStatement st, Object property )
+    {
+        getSQLType().setValue( st, ((PasswordCredential) property).getPassword() );
+    }
+}

Copied: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SQLStringType.java (from r351546, directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLStringType.java)
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SQLStringType.java?p2=directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SQLStringType.java&p1=directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLStringType.java&r1=351546&r2=354314&rev=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLStringType.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SQLStringType.java Mon Dec  5 21:07:36 2005
@@ -14,7 +14,10 @@
  *   limitations under the License.
  *
  */
-package org.apache.authx.authentication.realm;
+package org.apache.authx.authentication.realm.types;
+
+import org.apache.authx.authentication.realm.SQLStatement;
+import org.apache.authx.authentication.realm.SQLType;
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -24,6 +27,12 @@
     public Class getJavaType()
     {
         return String.class;
+    }
+
+    public SQLStatement define( SQLStatement st )
+    {
+        st.append( "varchar(32)" );
+        return st;
     }
 
     public void setValue( SQLStatement st, Object value )

Propchange: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SQLStringType.java
------------------------------------------------------------------------------
    svn:executable = *

Copied: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SQLTypes.java (from r351546, directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLTypes.java)
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SQLTypes.java?p2=directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SQLTypes.java&p1=directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLTypes.java&r1=351546&r2=354314&rev=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLTypes.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SQLTypes.java Mon Dec  5 21:07:36 2005
@@ -1,19 +1,25 @@
-package org.apache.authx.authentication.realm;
+package org.apache.authx.authentication.realm.types;
+
+import org.apache.authx.authentication.realm.SQLType;
 
 public class SQLTypes
 {
     public static final SQLStringType STRING = new SQLStringType();
 
-    public static final SQLType[] ALL_TYPES = { STRING };
+    public static final SQLType[] ALL_TYPES = {STRING};
+
+    private SQLTypes()
+    {
+    }
 
-    private SQLTypes() {};
+    ;
 
-    public static SQLType get(Class javaType)
+    public static SQLType get( Class javaType )
     {
         for ( int i = 0; i < ALL_TYPES.length; i++ )
         {
             SQLType type = ALL_TYPES[ i ];
-            if (type.getJavaType().isAssignableFrom( javaType ) ) return type;
+            if ( type.getJavaType().isAssignableFrom( javaType ) ) return type;
         }
 
         throw new IllegalArgumentException( "Type not supported: " + javaType.getName() );

Copied: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SimpleType.java (from r351546, directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SimpleTypePersister.java)
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SimpleType.java?p2=directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SimpleType.java&p1=directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SimpleTypePersister.java&r1=351546&r2=354314&rev=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SimpleTypePersister.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/SimpleType.java Mon Dec  5 21:07:36 2005
@@ -14,25 +14,32 @@
  *   limitations under the License.
  *
  */
-package org.apache.authx.authentication.realm;
+package org.apache.authx.authentication.realm.types;
 
-import org.apache.authx.authentication.realm.*;
+import org.apache.authx.authentication.realm.SQLType;
+import org.apache.authx.authentication.realm.Type;
+import org.apache.authx.authentication.realm.SQLStatement;
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
-public class SimpleTypePersister implements Persister
+public class SimpleType implements Type
 {
     private final SQLType m_sqlType;
 
-    public SimpleTypePersister( SQLType sqlType )
+    public SimpleType( SQLType sqlType )
     {
         m_sqlType = sqlType;
     }
 
-    public Class getPersistentType()
+    public Class getJavaType()
     {
         return m_sqlType.getJavaType();
+    }
+
+    public SQLType getSQLType()
+    {
+        return m_sqlType;
     }
 
     public void setProperty( SQLStatement st, Object property )

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/UsernameCredentialType.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/UsernameCredentialType.java?rev=354314&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/UsernameCredentialType.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/types/UsernameCredentialType.java Mon Dec  5 21:07:36 2005
@@ -0,0 +1,50 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.authx.authentication.realm.types;
+
+import org.apache.authx.authentication.realm.types.SQLTypes;
+import org.apache.authx.authentication.realm.SQLType;
+import org.apache.authx.authentication.realm.Type;
+import org.apache.authx.authentication.realm.UsernameCredential;
+import org.apache.authx.authentication.realm.SQLStatement;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public class UsernameCredentialType implements Type
+{
+    public Class getJavaType()
+    {
+        return UsernameCredential.class;
+    }
+
+    public SQLType getSQLType()
+    {
+        return SQLTypes.STRING;
+    }
+
+    public Object getProperty( ResultSet rs, String columnName ) throws SQLException
+    {
+        String username = (String) getSQLType().getValue( rs, columnName );
+        return new UsernameCredential( username );
+    }
+
+    public void setProperty( SQLStatement st, Object property )
+    {
+        getSQLType().setValue( st, ((UsernameCredential) property).getUsername() );
+    }
+}

Modified: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Columns.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Columns.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Columns.java (original)
+++ directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Columns.java Mon Dec  5 21:07:36 2005
@@ -16,29 +16,22 @@
  */
 package org.apache.authx.authentication.realm;
 
-import java.lang.reflect.Method;
+import org.apache.authx.authentication.realm.types.UsernameCredentialType;
+import org.apache.authx.authentication.realm.types.PasswordCredentialType;
 
-public class Columns
+public final class Columns
 {
-    private Columns() {}
-
-    public static Column username() throws NoSuchMethodException
-    {
-        return new Column( "USERNAME", new ReflectionPersister( getUsernameMethod() ) );
-    }
-
-    private static Method getUsernameMethod() throws NoSuchMethodException
+    private Columns()
     {
-        return UsernameCredential.class.getMethod( "getUsername", null );
     }
 
-    public static Column password() throws NoSuchMethodException
+    public static Column username()
     {
-        return new Column( "PASSWORD", new ReflectionPersister( getPasswordMethod() ) );
+        return new Column( "username", new UsernameCredentialType() );
     }
 
-    private static Method getPasswordMethod() throws NoSuchMethodException
+    public static Column password()
     {
-        return PasswordCredential.class.getMethod( "getPassword", null );
+        return new Column( "password", new PasswordCredentialType() );
     }
 }

Modified: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Creds.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Creds.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Creds.java (original)
+++ directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Creds.java Mon Dec  5 21:07:36 2005
@@ -18,6 +18,10 @@
 
 import org.apache.authx.authentication.CredentialSet;
 
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
 public class Creds
 {
     private Creds() {}
@@ -44,6 +48,18 @@
         creds.add( new UsernameCredential( "joe" ) );
         creds.add( new EyeColorCredential( "brown" ) );
         return creds;
+    }
+
+    public static Map values( CredentialSet creds )
+    {
+        Map values = new HashMap( );
+        for ( Iterator it = creds.elements().iterator(); it.hasNext(); )
+        {
+            Object value =  it.next();
+            values.put( value.getClass(), value );
+        }
+
+        return values;
     }
 
     public static class EyeColorCredential

Modified: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCRealmTest.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCRealmTest.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCRealmTest.java (original)
+++ directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCRealmTest.java Mon Dec  5 21:07:36 2005
@@ -34,7 +34,7 @@
         m_db = new MemoryDatabase();
         Table table = Tables.users();
         m_db.create( table );
-        m_db.insertInto( table, Creds.joe() );
+        m_db.insertInto( table, Creds.values( Creds.joe() ) );
 
         m_realm = new JDBCRealm( m_db.getDataSource(), table );
     }

Modified: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCSelectorTest.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCSelectorTest.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCSelectorTest.java (original)
+++ directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCSelectorTest.java Mon Dec  5 21:07:36 2005
@@ -31,8 +31,8 @@
         m_db = new MemoryDatabase();
         Table users = Tables.users();
         m_db.create( users );
-        m_db.insertInto( users, Creds.joe() );
-        m_db.insertInto( users, Creds.jane() );
+        m_db.insertInto( users, Creds.values( Creds.joe() ) );
+        m_db.insertInto( users, Creds.values( Creds.jane() ) );
         m_selector = new JDBCSelector( users );
 
         m_connection = m_db.getDataSource().getConnection();

Modified: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/MemoryDatabase.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/MemoryDatabase.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/MemoryDatabase.java (original)
+++ directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/MemoryDatabase.java Mon Dec  5 21:07:36 2005
@@ -23,11 +23,9 @@
 import javax.sql.DataSource;
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.PreparedStatement;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
+import java.util.Map;
 
 public class MemoryDatabase
 {
@@ -50,70 +48,27 @@
 
     public void create( Table table ) throws SQLException
     {
-        Connection c = m_ds.getConnection();
-        Statement statement = c.createStatement();
-        StringBuffer sb = new StringBuffer( );
-        sb.append( "create table ").append( table.getName() ).append( " (\n");
-
-        for ( Iterator it = table.getColumns().iterator(); it.hasNext(); )
-        {
-            Column column = (Column) it.next();
-            sb.append( column.getName() ).append( " varchar(32)" );
-            if ( it.hasNext() ) sb.append( ",\n" );
-        }
-        sb.append( "\n)" );
-        statement.executeUpdate( sb.toString() );
-        statement.close();
-        c.close();
-
+        execute( table.create() );
         m_tables.add( table );
     }
 
     public void drop( Table table ) throws SQLException
     {
-        Connection c = m_ds.getConnection();
-        Statement statement = c.createStatement();
-        StringBuffer sb = new StringBuffer( );
-        sb.append( "drop table ").append( table.getName() );
-        statement.executeUpdate( sb.toString() );
-        statement.close();
-        c.close();
-
+        execute( table.drop() );
         m_tables.remove( table );
     }
 
-    public void insertInto( Table table, CredentialSet creds ) throws SQLException
+    public void insertInto( Table table, Map values ) throws SQLException
     {
-        PreparedSQLStatement statement = new PreparedSQLStatement( "insert into " );
-        statement.append( table.getName() ).append( "(" );
-        for ( Iterator it = creds.elements().iterator(); it.hasNext(); )
-        {
-            Object credential = it.next();
-            statement.append( table.getColumnName( credential.getClass() ) );
-            if ( it.hasNext() ) statement.append( "," );
-        }
-        statement.append( ") values( " );
-        for ( Iterator it = creds.elements().iterator(); it.hasNext(); )
-        {
-            Object credential = it.next();
-            table.getColumn( credential.getClass() ).setProperty( statement, credential );
-            if ( it.hasNext() ) statement.append( "," );
-        }
-        statement.append( ")" );
-
-        Connection c = m_ds.getConnection();
-        PreparedStatement st = statement.create( c );
-        st.executeUpdate();
-        st.close();
-        c.close();
+        execute( table.insert( values ) );
     }
 
     public void dropAll() throws SQLException
     {
-        Table[] tables = ( Table[] ) m_tables.toArray( new Table[m_tables.size()] );
+        Table[] tables = (Table[]) m_tables.toArray( new Table[m_tables.size()] );
         for ( int i = 0; i < tables.length; i++ )
         {
-            drop( tables[i] );
+            drop( tables[ i ] );
         }
     }
 
@@ -128,5 +83,19 @@
 
         }
         DatabaseManager.closeDatabases( -1 );
+    }
+
+    private void execute( Statement st ) throws SQLException
+    {
+        Connection c = null;
+        try
+        {
+            c = m_ds.getConnection();
+            st.execute( c );
+        }
+        finally
+        {
+            if ( c != null ) c.close();
+        }
     }
 }

Modified: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Tables.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Tables.java?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Tables.java (original)
+++ directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Tables.java Mon Dec  5 21:07:36 2005
@@ -16,21 +16,21 @@
  */
 package org.apache.authx.authentication.realm;
 
-public class Tables
+public final class Tables
 {
     public Tables() {}
 
-    public static Table users() throws NoSuchMethodException
+    public static Table users()
     {
-        Table table = new Table( "USERS" );
+        Table table = new Table( "Users", new CredentialSetMapping() );
         table.addColumn( UsernameCredential.class, Columns.username() );
         table.addColumn( PasswordCredential.class, Columns.password() );
         return table;
     }
 
-    public static Table undefined() throws NoSuchMethodException
+    public static Table undefined()
     {
-        Table table = new Table( "UNDEFINED" );
+        Table table = new Table( "Undefined", new CredentialSetMapping() );
         table.addColumn( UsernameCredential.class, Columns.username() );
         table.addColumn( PasswordCredential.class, Columns.password() );
         return table;



Mime
View raw message