directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r349160 - /directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java
Date Sun, 27 Nov 2005 00:44:59 GMT
Author: akarasulu
Date: Sat Nov 26 16:44:56 2005
New Revision: 349160

URL: http://svn.apache.org/viewcvs?rev=349160&view=rev
Log:
added executeProcedure() method

Modified:
    directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java

Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java?rev=349160&r1=349159&r2=349160&view=diff
==============================================================================
--- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java
(original)
+++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java
Sat Nov 26 16:44:56 2005
@@ -17,6 +17,7 @@
 package org.apache.ldap.server.jndi;
 
 
+import java.lang.reflect.InvocationTargetException;
 import java.util.Hashtable;
 
 import javax.naming.Name;
@@ -27,9 +28,15 @@
 import javax.naming.ldap.LdapContext;
 
 import org.apache.ldap.common.NotImplementedException;
+import org.apache.ldap.common.exception.LdapNamingException;
+import org.apache.ldap.common.message.ResultCodeEnum;
+import org.apache.ldap.common.name.LdapName;
 import org.apache.ldap.server.DirectoryService;
 import org.apache.ldap.server.authn.LdapPrincipal;
 import org.apache.ldap.server.partition.DirectoryPartitionNexus;
+import org.apache.ldap.server.storedprocs.JavaStoredProcedure;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -40,6 +47,7 @@
  */
 public class ServerLdapContext extends ServerDirContext implements LdapContext
 {
+	private static final Logger log = LoggerFactory.getLogger( ServerLdapContext.class );
     private static final Control[] EMPTY_CONTROLS = new Control[0];
     private Control[] requestControls = EMPTY_CONTROLS;
     private Control[] responseControls = EMPTY_CONTROLS;
@@ -75,6 +83,9 @@
 
 
     /**
+     * @todo Once the POJO for a stored procedure extended request is defined this method
will only make sure 
+     * requests of that type are executed for now.
+     * 
      * @see javax.naming.ldap.LdapContext#extendedOperation(
      * javax.naming.ldap.ExtendedRequest)
      */
@@ -83,6 +94,55 @@
         throw new NotImplementedException();
     }
 
+    
+    /**
+     * Executes a stored procedure within the server.
+     * 
+     * @param qualifiedProcedure the fully qualified name of the stored procedure
+     * @param paramTypes the parameters types in order
+     * @param params the parameter values in order
+     * @return the return value object
+     * @throws NamingException if there is a problem invoking the procedure
+     */
+    public Object executeProcedure( String qualifiedProcedure, Class[] paramTypes, Object[]
params ) throws NamingException
+    {
+    	ServerLdapContext root = new ServerLdapContext( getPrincipal(), getNexusProxy(), getEnvironment(),
new LdapName() );
+    	root.setRequestControls( getRequestControls() );
+    	JavaStoredProcedure procedure = null;
+    	
+    	// @todo figure out the ldap exceptions and result codes that correspond to these exceptions
+    	
+		try 
+		{
+			procedure = new JavaStoredProcedure( root, qualifiedProcedure, paramTypes );
+		} 
+		catch ( SecurityException e1 ) 
+		{
+			e1.printStackTrace();
+		} 
+		catch ( ClassNotFoundException e1 ) 
+		{
+			e1.printStackTrace();
+		} 
+		catch ( NoSuchMethodException e1 ) 
+		{
+			e1.printStackTrace();
+		}
+    	
+        try
+        {
+        	return procedure.call( params );
+        }
+        catch( InvocationTargetException e )
+        {
+        	String msg = "procedure call failed while executing";
+        	log.error( msg, e );
+        	NamingException wrapper = new LdapNamingException( msg, ResultCodeEnum.OPERATIONSERROR
);
+        	wrapper.setRootCause( e.getCause() );
+        	throw wrapper;
+        }
+    }
+    
 
     /**
      * @see javax.naming.ldap.LdapContext#newInstance(



Mime
View raw message