directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r718206 - in /directory/sandbox/kayyagari/server-scheduler/src: main/java/org/apache/ main/java/org/apache/directory/ main/java/org/apache/directory/server/ main/java/org/apache/directory/server/scheduler/ main/java/org/apache/directory/ser...
Date Mon, 17 Nov 2008 09:13:25 GMT
Author: kayyagari
Date: Mon Nov 17 01:13:25 2008
New Revision: 718206

URL: http://svn.apache.org/viewvc?rev=718206&view=rev
Log:
an LDAP store implementation for quartz scheduling service
(atm supports CRUD operations on jobs and triggers)

Added:
    directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/
    directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/
    directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/
    directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/
    directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/
    directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/DefaultJobStore.java
    directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapJobStore.java
    directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapQuartzDelegate.java
Removed:
    directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apahe/
Modified:
    directory/sandbox/kayyagari/server-scheduler/src/test/java/org/apahe/directory/server/scheduler/store/LdapJobStoreITest.java

Added: directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/DefaultJobStore.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/DefaultJobStore.java?rev=718206&view=auto
==============================================================================
--- directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/DefaultJobStore.java (added)
+++ directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/DefaultJobStore.java Mon Nov 17 01:13:25 2008
@@ -0,0 +1,334 @@
+/*
+ *   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.
+ *
+ */
+package org.apache.directory.server.scheduler.store;
+
+import java.util.Set;
+
+import org.quartz.Calendar;
+import org.quartz.JobDetail;
+import org.quartz.JobPersistenceException;
+import org.quartz.ObjectAlreadyExistsException;
+import org.quartz.SchedulerConfigException;
+import org.quartz.SchedulerException;
+import org.quartz.Trigger;
+import org.quartz.core.SchedulingContext;
+import org.quartz.spi.ClassLoadHelper;
+import org.quartz.spi.JobStore;
+import org.quartz.spi.SchedulerSignaler;
+import org.quartz.spi.TriggerFiredBundle;
+
+// FIXME this is a dummy clas to help incremental development of the original implementation of JobStore
+// which helps in avoiding this eclipse TODO boilerplate stuff
+public class DefaultJobStore implements JobStore
+{
+
+    public Trigger acquireNextTrigger( SchedulingContext ctxt, long noLaterThan ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public String[] getCalendarNames( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public String[] getJobGroupNames( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public String[] getJobNames( SchedulingContext ctxt, String groupName ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public int getNumberOfCalendars( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int getNumberOfJobs( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int getNumberOfTriggers( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public Set getPausedTriggerGroups( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public String[] getTriggerGroupNames( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public String[] getTriggerNames( SchedulingContext ctxt, String groupName ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public int getTriggerState( SchedulingContext ctxt, String triggerName, String triggerGroup )
+        throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public Trigger[] getTriggersForJob( SchedulingContext ctxt, String jobName, String groupName )
+        throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public void initialize( ClassLoadHelper loadHelper, SchedulerSignaler signaler ) throws SchedulerConfigException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void pauseAll( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void pauseJob( SchedulingContext ctxt, String jobName, String groupName ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void pauseJobGroup( SchedulingContext ctxt, String groupName ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void pauseTrigger( SchedulingContext ctxt, String triggerName, String groupName )
+        throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void pauseTriggerGroup( SchedulingContext ctxt, String groupName ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void releaseAcquiredTrigger( SchedulingContext ctxt, Trigger trigger ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public boolean removeCalendar( SchedulingContext ctxt, String calName ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    public boolean removeJob( SchedulingContext ctxt, String jobName, String groupName ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    public boolean removeTrigger( SchedulingContext ctxt, String triggerName, String groupName )
+        throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    public boolean replaceTrigger( SchedulingContext ctxt, String triggerName, String groupName, Trigger newTrigger )
+        throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    public void resumeAll( SchedulingContext ctxt ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void resumeJob( SchedulingContext ctxt, String jobName, String groupName ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void resumeJobGroup( SchedulingContext ctxt, String groupName ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void resumeTrigger( SchedulingContext ctxt, String triggerName, String groupName )
+        throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void resumeTriggerGroup( SchedulingContext ctxt, String groupName ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public Calendar retrieveCalendar( SchedulingContext ctxt, String calName ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public JobDetail retrieveJob( SchedulingContext ctxt, String jobName, String groupName )
+        throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Trigger retrieveTrigger( SchedulingContext ctxt, String triggerName, String groupName )
+        throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public void schedulerStarted() throws SchedulerException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void shutdown()
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void storeCalendar( SchedulingContext ctxt, String name, Calendar calendar, boolean replaceExisting,
+        boolean updateTriggers ) throws ObjectAlreadyExistsException, JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void storeJob( SchedulingContext ctxt, JobDetail newJob, boolean replaceExisting )
+        throws ObjectAlreadyExistsException, JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void storeJobAndTrigger( SchedulingContext ctxt, JobDetail newJob, Trigger newTrigger )
+        throws ObjectAlreadyExistsException, JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public void storeTrigger( SchedulingContext ctxt, Trigger newTrigger, boolean replaceExisting )
+        throws ObjectAlreadyExistsException, JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    public boolean supportsPersistence()
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    public TriggerFiredBundle triggerFired( SchedulingContext ctxt, Trigger trigger ) throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public void triggeredJobComplete( SchedulingContext ctxt, Trigger trigger, JobDetail jobDetail, int triggerInstCode )
+        throws JobPersistenceException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Added: directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapJobStore.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapJobStore.java?rev=718206&view=auto
==============================================================================
--- directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapJobStore.java (added)
+++ directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapJobStore.java Mon Nov 17 01:13:25 2008
@@ -0,0 +1,453 @@
+/*
+ *   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.
+ *
+ */
+package org.apache.directory.server.scheduler.store;
+
+
+import static org.quartz.impl.jdbcjobstore.Constants.STATE_ACQUIRED;
+import static org.quartz.impl.jdbcjobstore.Constants.STATE_BLOCKED;
+import static org.quartz.impl.jdbcjobstore.Constants.STATE_PAUSED;
+import static org.quartz.impl.jdbcjobstore.Constants.STATE_PAUSED_BLOCKED;
+import static org.quartz.impl.jdbcjobstore.Constants.STATE_WAITING;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.directory.olm.Entry;
+import org.apache.directory.olm.FiredTriggerEntry;
+import org.apache.directory.olm.JobDetailEntry;
+import org.apache.directory.olm.TriggerEntry;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.quartz.CronTrigger;
+import org.quartz.JobDetail;
+import org.quartz.JobPersistenceException;
+import org.quartz.ObjectAlreadyExistsException;
+import org.quartz.SchedulerConfigException;
+import org.quartz.SchedulerException;
+import org.quartz.SimpleTrigger;
+import org.quartz.Trigger;
+import org.quartz.core.SchedulingContext;
+import org.quartz.spi.ClassLoadHelper;
+import org.quartz.spi.JobStore;
+import org.quartz.spi.SchedulerSignaler;
+import org.quartz.utils.Key;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * 
+ * TODO LdapJobStore.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+//FIXME : the quartz version present in maven repo is 1.5.2 need to uplod 1.6.0
+public class LdapJobStore extends DefaultJobStore //implements JobStore
+{
+
+    /** the partition to store the schedular data*/
+    //    private Partition partition;
+    /** container under the partition which holds all the schedular related data*/
+    private LdapDN schedulerRootDn;
+
+    private DirectoryService directoryService;
+
+    private Registries registries;
+    private AttributeTypeRegistry attrTypeRegistry;
+
+    /** containers */
+    private LdapDN jobDetailsDn;
+    private LdapDN triggersDn;
+
+    private static final Logger LOG = LoggerFactory.getLogger( LdapJobStore.class );
+
+    private ClassLoadHelper classLoadHelper;
+
+    private LdapQuartzDelegate delegate;
+
+
+    //    private MisfireHandler misfireHandler;
+
+    /**
+     * 
+     * Creates a new instance of LdapJobStore.
+     *
+     * @param partition the partition to store the scheduler data
+     * @param schedulerContainer name of the container in the above given partition
+     * @param directoryService the DirectoryService
+     * @throws Exception if the schedulerContainer is not a valid LDAP name
+     */
+    public LdapJobStore( DirectoryService directoryService, String schedulerContainer ) throws Exception
+    {
+
+        if ( schedulerContainer == null || schedulerContainer.trim().length() == 0 )
+        {
+            throw new IllegalArgumentException( "Name of LDAP container to store schedular data cannot be null" );
+        }
+
+        this.directoryService = directoryService;
+
+        delegate = new LdapQuartzDelegate( directoryService.getRegistries(), directoryService.getAdminSession(),
+            schedulerContainer );
+    }
+
+
+    /**
+     * @see JobStore#initialize(ClassLoadHelper, SchedulerSignaler)
+     */
+    public void initialize( ClassLoadHelper loadHelper, SchedulerSignaler signaler ) throws SchedulerConfigException
+    {
+        classLoadHelper = loadHelper;
+
+        try
+        {
+            delegate.initializeContainers();
+        }
+        catch ( Exception e )
+        {
+            throw new SchedulerConfigException( e.getMessage(), e );
+        }
+    }
+
+
+    public void schedulerStarted() throws SchedulerException
+    {
+        //        misfireHandler = new MisfireHandler();
+        //        misfireHandler.initialize();
+    }
+
+
+    /**
+     * @see JobStore#storeJob(SchedulingContext, JobDetail, boolean)
+     */
+    public void storeJob( SchedulingContext ctxt, JobDetail newJob, boolean replaceExisting )
+        throws ObjectAlreadyExistsException, JobPersistenceException
+    {
+        JobDetailEntry jobEntry;
+
+        jobEntry = delegate.getJobEntry( newJob.getName(), newJob.getGroup() );
+
+        try
+        {
+            if ( jobEntry != null )
+            {
+                if ( !replaceExisting )
+                {
+                    throw new ObjectAlreadyExistsException( newJob );
+                }
+
+                delegate.updateJobDetail( newJob, jobEntry );
+            }
+            else
+            {
+                delegate.insertJobDetail( newJob );
+            }
+        }
+        catch ( ObjectAlreadyExistsException e )
+        {
+            throw e;
+        }
+        catch ( IOException e )
+        {
+            throw new JobPersistenceException( "Couldn't store job: " + e.getMessage(), e );
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Failed to persist the job", e );
+        }
+
+    }
+
+
+    /**
+     * @see JobStore#retrieveJob(SchedulingContext, String, String)
+     */
+    public JobDetail retrieveJob( SchedulingContext ctxt, String jobName, String groupName )
+        throws JobPersistenceException
+    {
+        try
+        {
+            return delegate.selectJobDetail( jobName, groupName, classLoadHelper );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new JobPersistenceException( "Couldn't retrieve job because a required class was not found: "
+                + e.getMessage(), e, SchedulerException.ERR_PERSISTENCE_JOB_DOES_NOT_EXIST );
+        }
+        catch ( IOException e )
+        {
+            throw new JobPersistenceException( "Couldn't retrieve job because the BLOB couldn't be deserialized: "
+                + e.getMessage(), e, SchedulerException.ERR_PERSISTENCE_JOB_DOES_NOT_EXIST );
+        }
+        catch ( Exception e )
+        {
+            LOG.error( "Failed to retrieve job", e );
+            //throw new JobPersistenceException( "Failed to retrieve job", e );
+        }
+
+        return null;
+    }
+
+
+    /**
+     * @see JobStore#removeJob(SchedulingContext, String, String)
+     */
+    public boolean removeJob( SchedulingContext ctxt, String jobName, String groupName ) throws JobPersistenceException
+    {
+        try
+        {
+            Key[] jobTriggers = getDelegate().selectTriggerNamesForJob( jobName, groupName );
+            for ( Key k : jobTriggers )
+            {
+                getDelegate().searchNDeleteTrigger( k.getName(), k.getGroup() );
+            }
+
+            getDelegate().deleteJobDetail( jobName, groupName );
+        }
+        catch ( Exception e )
+        {
+            //throw new JobPersistenceException( "Couldn't remove job: " + e.getMessage(), e );
+            return false;
+        }
+
+        return true;
+    }
+
+
+    /**
+     * @see JobStore#storeTrigger(SchedulingContext, Trigger, boolean)
+     */
+    public void storeTrigger( SchedulingContext ctxt, Trigger newTrigger, boolean replaceExisting )
+        throws ObjectAlreadyExistsException, JobPersistenceException
+    {
+        storeTrigger( ctxt, newTrigger, null, replaceExisting, STATE_WAITING, false, false );
+    }
+
+
+    public Trigger retrieveTrigger( SchedulingContext ctxt, String triggerName, String groupName )
+        throws JobPersistenceException
+    {
+        return retrieveTrigger( triggerName, groupName );
+    }
+
+
+    protected Trigger retrieveTrigger( String triggerName, String groupName ) throws JobPersistenceException
+    {
+        try
+        {
+            Trigger trigger = getDelegate().selectTrigger( triggerName, groupName );
+            return trigger;
+        }
+        catch ( Exception e )
+        {
+            LOG.error( "Couldn't retrieve trigger: {}", e.getMessage() );
+            return null;
+        }
+    }
+
+
+    public boolean removeTrigger( SchedulingContext ctxt, String triggerName, String groupName )
+        throws JobPersistenceException
+    {
+        try
+        {
+            // this must be called before we delete the trigger, obviously
+            JobDetail job = getDelegate().selectJobForTrigger( triggerName, groupName, classLoadHelper );
+
+            delegate.searchNDeleteTrigger( triggerName, groupName );
+
+            if ( null != job && !job.isDurable() )
+            {
+                int numTriggers = getDelegate().selectNumTriggersForJob( job.getName(), job.getGroup() );
+                if ( numTriggers == 0 )
+                {
+                    // Don't call removeJob() because we don't want to check for
+                    // triggers again.
+                    getDelegate().deleteJobDetail( job.getName(), job.getGroup() );
+                }
+            }
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new JobPersistenceException( "Couldn't remove trigger: " + e.getMessage(), e );
+        }
+        catch ( Exception e )
+        {
+            LOG.error( "Couldn't remove trigger: {}", e.getMessage() );
+            return false;
+        }
+
+        return true;
+    }
+
+
+    // ---------------------- private utility methods ---------------------------
+
+    private void storeTrigger( SchedulingContext ctxt, Trigger newTrigger, JobDetail job, boolean replaceExisting,
+        String state, boolean forceState, boolean recovering ) throws ObjectAlreadyExistsException,
+        JobPersistenceException
+    {
+        TriggerEntry triggerEntry = delegate.getTriggerEntry( newTrigger.getName(), newTrigger.getGroup() );
+
+        if ( triggerEntry != null && ( !replaceExisting ) )
+        {
+            throw new ObjectAlreadyExistsException( newTrigger );
+        }
+
+        try
+        {
+            boolean shouldBepaused = false;
+
+            if ( !forceState )
+            {
+                shouldBepaused = delegate.isTriggerGroupPaused( newTrigger.getGroup() );
+
+                if ( shouldBepaused )
+                {
+                    delegate.insertPausedTriggerGroup( newTrigger.getGroup() );
+                }
+
+                if ( shouldBepaused && ( state.equals( STATE_WAITING ) || state.equals( STATE_ACQUIRED ) ) )
+                {
+                    state = STATE_PAUSED;
+                }
+            }
+
+            if ( job == null )
+            {
+                job = delegate.selectJobDetail( newTrigger.getJobName(), newTrigger.getJobGroup(), classLoadHelper );
+            }
+            if ( job == null )
+            {
+                throw new JobPersistenceException( "The job (" + newTrigger.getFullJobName()
+                    + ") referenced by the trigger does not exist." );
+            }
+            if ( job.isVolatile() && !newTrigger.isVolatile() )
+            {
+                throw new JobPersistenceException( "It does not make sense to "
+                    + "associate a non-volatile Trigger with a volatile Job!" );
+            }
+
+            if ( job.isStateful() && !recovering )
+            {
+                state = checkBlockedState( ctxt, job.getName(), job.getGroup(), state );
+            }
+
+            if ( triggerEntry != null )
+            {
+                if ( newTrigger.getClass() == SimpleTrigger.class )
+                {
+                    delegate.updateSimpleTrigger( ( SimpleTrigger ) newTrigger );
+                }
+                else if ( newTrigger.getClass() == CronTrigger.class )
+                {
+                    delegate.updateCronTrigger( ( CronTrigger ) newTrigger );
+                }
+                else
+                {
+                    delegate.updateBlobTrigger( newTrigger );
+                }
+                delegate.updateTrigger( triggerEntry, newTrigger, state, job );
+            }
+            else
+            {
+                delegate.insertTrigger( newTrigger, state, job );
+                if ( newTrigger.getClass() == SimpleTrigger.class )
+                {
+                    delegate.insertSimpleTrigger( ( SimpleTrigger ) newTrigger );
+                }
+                else if ( newTrigger.getClass() == CronTrigger.class )
+                {
+                    delegate.insertCronTrigger( ( CronTrigger ) newTrigger );
+                }
+                else
+                {
+                    delegate.insertBlobTrigger( newTrigger );
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            LOG.error( "Failed to store trigger" );
+            e.printStackTrace();
+            throw new JobPersistenceException( "Failed to store trigger", e );
+        }
+    }
+
+
+    /**
+     * Determines if a Trigger for the given job should be blocked.  
+     * State can only transition to STATE_PAUSED_BLOCKED/STATE_BLOCKED from 
+     * STATE_PAUSED/STATE_WAITING respectively.
+     * 
+     * @return STATE_PAUSED_BLOCKED, STATE_BLOCKED, or the currentState. 
+     */
+    protected String checkBlockedState( SchedulingContext ctxt, String jobName, String jobGroupName, String currentState )
+        throws JobPersistenceException
+    {
+
+        // State can only transition to BLOCKED from PAUSED or WAITING.
+        if ( ( currentState.equals( STATE_WAITING ) == false ) && ( currentState.equals( STATE_PAUSED ) == false ) )
+        {
+            return currentState;
+        }
+
+        try
+        {
+            List<Entry> lst = getDelegate().selectFiredTriggerRecordsByJob( jobName, jobGroupName );
+
+            if ( lst.size() > 0 )
+            {
+                FiredTriggerEntry rec = ( FiredTriggerEntry ) lst.get( 0 );
+                if ( rec.getStateful().getValue() )
+                { // TODO: worry about
+                    // failed/recovering/volatile job
+                    // states?
+                    return ( STATE_PAUSED.equals( currentState ) ) ? STATE_PAUSED_BLOCKED : STATE_BLOCKED;
+                }
+            }
+
+            return currentState;
+        }
+        catch ( Exception e )
+        {
+            throw new JobPersistenceException( "Couldn't determine if trigger should be in a blocked state '"
+                + jobGroupName + "." + jobName + "': " + e.getMessage(), e );
+        }
+
+    }
+
+
+    public boolean supportsPersistence()
+    {
+        return true;
+    }
+
+
+    // FIXME remove this if not required later cause the 'delegate'variable is available 
+    public LdapQuartzDelegate getDelegate()
+    {
+        return delegate;
+    }
+
+}

Added: directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapQuartzDelegate.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapQuartzDelegate.java?rev=718206&view=auto
==============================================================================
--- directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapQuartzDelegate.java (added)
+++ directory/sandbox/kayyagari/server-scheduler/src/main/java/org/apache/directory/server/scheduler/store/LdapQuartzDelegate.java Mon Nov 17 01:13:25 2008
@@ -0,0 +1,1503 @@
+package org.apache.directory.server.scheduler.store;
+
+
+import static org.quartz.impl.jdbcjobstore.Constants.ALL_GROUPS_PAUSED;
+import static org.quartz.impl.jdbcjobstore.Constants.TTYPE_BLOB;
+import static org.quartz.impl.jdbcjobstore.Constants.TTYPE_CRON;
+import static org.quartz.impl.jdbcjobstore.Constants.TTYPE_SIMPLE;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TimeZone;
+
+import org.apache.directory.olm.BlobData;
+import org.apache.directory.olm.BlobTriggerEntry;
+import org.apache.directory.olm.CronTriggerEntry;
+import org.apache.directory.olm.Entry;
+import org.apache.directory.olm.FiredTriggerEntry;
+import org.apache.directory.olm.JobData;
+import org.apache.directory.olm.JobDetailEntry;
+import org.apache.directory.olm.JobGroup;
+import org.apache.directory.olm.JobListener;
+import org.apache.directory.olm.JobName;
+import org.apache.directory.olm.OrganizationalUnitEntry;
+import org.apache.directory.olm.PausedTriggerGroup;
+import org.apache.directory.olm.PausedTriggersEntry;
+import org.apache.directory.olm.QuartzGroupEntry;
+import org.apache.directory.olm.SimpleTriggerEntry;
+import org.apache.directory.olm.TaskDesc;
+import org.apache.directory.olm.TriggerEntry;
+import org.apache.directory.olm.TriggerGroup;
+import org.apache.directory.olm.TriggerListener;
+import org.apache.directory.olm.TriggerName;
+import org.apache.directory.olm.util.LdapPersistenceUtil;
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import org.apache.directory.shared.ldap.filter.AndNode;
+import org.apache.directory.shared.ldap.filter.EqualityNode;
+import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.apache.directory.shared.ldap.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.DateUtils;
+import org.quartz.Calendar;
+import org.quartz.CronTrigger;
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+import org.quartz.SimpleTrigger;
+import org.quartz.Trigger;
+import org.quartz.spi.ClassLoadHelper;
+import org.quartz.utils.Key;
+import org.quartz.utils.TriggerStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * 
+ * A helper class for LdapStore. This performs the low level LDAP operations for managing the store.
+ * 
+ * Unlike the JDBC store this Quartz LDAP store keeps the listeners along with the respective job/trigger entry 
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapQuartzDelegate
+{
+
+    private LdapDN schedulerRootDn;
+
+    private AttributeTypeRegistry attrTypeRegistry;
+
+    /** containers */
+    private LdapDN jobDetailsDn;
+    private LdapDN triggersDn;
+    private LdapDN firedTriggerDn;
+    private LdapDN simpleTriggersDn;
+    private LdapDN cronTriggersDn;
+    private LdapDN blobTriggersDn;
+
+    private LdapDN calendarsDn;
+
+    private static final Logger LOG = LoggerFactory.getLogger( LdapQuartzDelegate.class );
+
+    private LdapPersistenceUtil ldapUtil;
+
+
+    public LdapQuartzDelegate( Registries registries, CoreSession session, String schedulerContainer ) throws Exception
+    {
+        attrTypeRegistry = registries.getAttributeTypeRegistry();
+
+        schedulerRootDn = new LdapDN( schedulerContainer );
+        schedulerRootDn.normalize( attrTypeRegistry.getNormalizerMapping() );
+
+        ldapUtil = new LdapPersistenceUtil( registries, session );
+    }
+
+
+    public void initializeContainers() throws Exception
+    {
+        if ( !ldapUtil.exists( schedulerRootDn ) )
+        {
+            String ou = schedulerRootDn.getRdn().getUpName().split( "=" )[1];
+
+            OrganizationalUnitEntry ouEntry = new OrganizationalUnitEntry( ou );
+            ouEntry.setDN( schedulerRootDn.getUpName() );
+
+            PausedTriggersEntry pausedTriggers = new PausedTriggersEntry();
+            pausedTriggers.setPausedTriggerGroup( " " );// a dummy group value to keep the attribute non null in the entry
+            ouEntry.addEntry( pausedTriggers );
+
+            ldapUtil.save( ouEntry );
+        }
+
+        List<LdapDN> childDns = new ArrayList<LdapDN>();
+
+        jobDetailsDn = getChildDn( "ou=jobs", schedulerRootDn );
+        childDns.add( jobDetailsDn );
+
+        triggersDn = getChildDn( "ou=triggers", schedulerRootDn );
+        childDns.add( triggersDn );
+
+        firedTriggerDn = getChildDn( "ou=firedTriggers", schedulerRootDn );
+        childDns.add( firedTriggerDn );
+
+        simpleTriggersDn = getChildDn( "ou=simpleTriggers", schedulerRootDn );
+        childDns.add( simpleTriggersDn );
+
+        cronTriggersDn = getChildDn( "ou=cronTriggers", schedulerRootDn );
+        childDns.add( cronTriggersDn );
+
+        blobTriggersDn = getChildDn( "ou=blobTriggers", schedulerRootDn );
+        childDns.add( blobTriggersDn );
+
+        calendarsDn = getChildDn( "ou=calendars", schedulerRootDn );
+        childDns.add( calendarsDn );
+
+        for ( LdapDN dn : childDns )
+        {
+            if ( ldapUtil.exists( dn ) )
+            {
+                continue;
+            }
+
+            OrganizationalUnitEntry ouEntry = new OrganizationalUnitEntry( dn.getRdn().getUpName().split( "=" )[1] );
+            ouEntry.setDN( dn.getUpName() );
+
+            ldapUtil.save( ouEntry );
+        }
+
+        if ( LOG.isInfoEnabled() )
+        {
+            LOG.info( "Schedular entry containers initialized" );
+        }
+    }
+
+
+    public JobDetailEntry getJobEntry( String jobName, String jobGroup )
+    {
+        JobDetailEntry jobEntry = null;
+
+        try
+        {
+            jobEntry = ( JobDetailEntry ) ldapUtil.fetch( getJobDn( jobName, jobGroup ) );
+        }
+        catch ( Exception e )
+        {
+            LOG.error( "Failed to search for job with name '{}' and group '{}'", jobName, jobGroup );
+        }
+
+        return jobEntry;
+    }
+
+
+    public TriggerEntry getTriggerEntry( String tName, String tGroup )
+    {
+        TriggerEntry triggerEntry = null;
+
+        try
+        {
+            triggerEntry = ( TriggerEntry ) ldapUtil.fetch( getTriggerDn( tName, tGroup, triggersDn ) );
+        }
+        catch ( Exception e )
+        {
+            LOG.error( "Failed to search for trigger with name '{}' and group '{}'", tName, tGroup );
+        }
+
+        return triggerEntry;
+    }
+
+
+    private LdapDN getChildDn( String childRdn, LdapDN parent ) throws Exception
+    {
+        LdapDN childDn = new LdapDN( parent.getUpName() );
+
+        childDn.add( childRdn );
+        childDn.normalize( attrTypeRegistry.getNormalizerMapping() );
+
+        return childDn;
+    }
+
+
+    private LdapDN getJobDn( String jobName, String jobGroup ) throws Exception
+    {
+        LdapDN jobDn = new LdapDN( jobDetailsDn.getUpName() );
+
+        jobDn.add( JobGroup.NAME + "=" + jobGroup );
+        jobDn.add( JobName.NAME + "=" + jobName );
+        jobDn.normalize( attrTypeRegistry.getNormalizerMapping() );
+
+        return jobDn;
+    }
+
+
+    public LdapDN getTriggerDn( String tName, String tGroup, LdapDN parentDn ) throws Exception
+    {
+        LdapDN tDn = new LdapDN( parentDn.getUpName() );
+
+        tDn.add( TriggerGroup.NAME + "=" + tGroup );
+        tDn.add( TriggerName.NAME + "=" + tName );
+        tDn.normalize( attrTypeRegistry.getNormalizerMapping() );
+
+        return tDn;
+    }
+
+
+    private byte[] objectToBytes( Object obj ) throws IOException
+    {
+        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+        ObjectOutputStream objOut = new ObjectOutputStream( byteOut );
+
+        objOut.writeObject( obj );
+        byte[] bytes = byteOut.toByteArray();
+        byteOut.close();
+
+        return bytes;
+    }
+
+
+    private Object bytesToObject( byte[] data ) throws Exception
+    {
+        if ( data == null )
+        {
+            return null;
+        }
+
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+        Object obj = in.readObject();
+        in.close();
+
+        return obj;
+    }
+
+
+    /** 
+     * updates an existing job entry's values except the values of name and group
+     */
+    public void updateJobDetail( JobDetail job, JobDetailEntry jobEntry ) throws Exception
+    {
+        jobEntry.setTaskDesc( job.getDescription() );
+        jobEntry.setDurable( job.isDurable() );
+        jobEntry.setStateful( job.isStateful() );
+        jobEntry.setVolatileFlag( job.isVolatile() );
+        jobEntry.setRequestsRecovery( job.requestsRecovery() );
+
+        if ( job.getJobDataMap().isEmpty() )
+        {
+            jobEntry.setJobData( null );
+        }
+        else
+        {
+            byte[] data = objectToBytes( job.getJobDataMap() );
+            jobEntry.setJobData( data );
+        }
+
+        String[] jobListeners = job.getJobListenerNames();
+
+        jobEntry.setJobListener( jobListeners );
+
+        ldapUtil.modify( jobEntry );
+
+    }
+
+
+    private void createJobGroupIfNotExixts( JobDetail job ) throws Exception
+    {
+        LdapDN dn = getChildDn( JobGroup.NAME + "=" + job.getGroup(), jobDetailsDn );
+
+        if ( !ldapUtil.exists( dn ) )
+        {
+            QuartzGroupEntry quartzGroupEntry = new QuartzGroupEntry();
+            quartzGroupEntry.setJobGroup( job.getGroup() );
+            quartzGroupEntry.setDN( dn.getUpName() );
+
+            ldapUtil.save( quartzGroupEntry );
+        }
+    }
+
+
+    private LdapDN createTriggerGroupIfNotExixts( Trigger trigger, LdapDN parentDn ) throws Exception
+    {
+        LdapDN dn = getChildDn( TriggerGroup.NAME + "=" + trigger.getGroup(), parentDn );
+
+        if ( !ldapUtil.exists( dn ) )
+        {
+            QuartzGroupEntry quartzGroupEntry = new QuartzGroupEntry();
+            quartzGroupEntry.setTriggerGroup( trigger.getGroup() );
+            quartzGroupEntry.setDN( dn.getUpName() );
+
+            ldapUtil.save( quartzGroupEntry );
+        }
+
+        return dn;
+    }
+
+
+    // ========================== public methods =====================
+
+    public boolean calendarExists( String calendarName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    public boolean calendarIsReferenced( String calendarName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    public int deleteAllPausedTriggerGroups() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int deleteBlobTrigger( String triggerName, String groupName ) throws Exception
+    {
+        ldapUtil.delete( getTriggerDn( triggerName, groupName, blobTriggersDn ) );
+        return 0;
+    }
+
+
+    public int deleteCalendar( String calendarName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int deleteCronTrigger( String triggerName, String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int deleteFiredTrigger( String entryId ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int deleteFiredTriggers( String instanceId ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int deleteFiredTriggers() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public void deleteJobDetail( String jobName, String jobGroup ) throws Exception
+    {
+        ldapUtil.delete( getJobDn( jobName, jobGroup ) );
+    }
+
+
+    public void deletePausedTriggerGroup( String groupName ) throws Exception
+    {
+        ldapUtil.removeAttributeValue( schedulerRootDn, PausedTriggerGroup.NAME, groupName );
+    }
+
+
+    public int deleteSchedulerState( String instanceId ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int deleteSimpleTrigger( String triggerName, String groupName ) throws Exception
+    {
+        ldapUtil.delete( getTriggerDn( triggerName, groupName, simpleTriggersDn ) );
+        return 0;
+    }
+
+
+    public int deleteTrigger( String triggerName, String groupName ) throws Exception
+    {
+        ldapUtil.delete( getTriggerDn( triggerName, groupName, triggersDn ) );
+        return 0;
+    }
+
+
+    public void searchNDeleteTrigger( String triggerName, String groupName ) throws Exception
+    {
+        LdapDN dn = getTriggerDn( triggerName, groupName, simpleTriggersDn );
+        if ( ldapUtil.exists( dn ) )
+        {
+            deleteSimpleTrigger( triggerName, groupName );
+        }
+        else
+        {
+            dn = getTriggerDn( triggerName, groupName, cronTriggersDn );
+            if ( ldapUtil.exists( dn ) )
+            {
+                deleteCronTrigger( triggerName, groupName );
+            }
+            else
+            // should be a blob trigger
+            {
+                deleteBlobTrigger( triggerName, groupName );
+            }
+        }
+
+        // finally delete the trigger entry
+
+        deleteTrigger( triggerName, groupName );
+    }
+
+
+    public int deleteVolatileFiredTriggers() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public void insertBlobTrigger( Trigger trigger ) throws Exception
+    {
+        LdapDN parentDn = createTriggerGroupIfNotExixts( trigger, blobTriggersDn );
+
+        BlobTriggerEntry blobTrgEntry = new BlobTriggerEntry();
+
+        blobTrgEntry.setDN( getChildDn( TriggerName.NAME + "=" + trigger.getName(), parentDn ).getUpName() );
+        blobTrgEntry.setTriggerGroup( trigger.getGroup() );
+        blobTrgEntry.setTriggerName( trigger.getName() );
+
+        blobTrgEntry.setBlobData( objectToBytes( trigger ) );
+
+        ldapUtil.save( blobTrgEntry );
+    }
+
+
+    public int insertCalendar( String calendarName, Calendar calendar ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int insertCronTrigger( CronTrigger trigger ) throws Exception
+    {
+        LdapDN parentDn = createTriggerGroupIfNotExixts( trigger, cronTriggersDn );
+
+        CronTriggerEntry cronTrgEntry = new CronTriggerEntry();
+
+        cronTrgEntry.setDN( getChildDn( TriggerName.NAME + "=" + trigger.getName(), parentDn ).getUpName() );
+
+        if ( trigger.getTimeZone() != null )
+        {
+            cronTrgEntry.setTimeZoneId( trigger.getTimeZone().getID() );
+        }
+
+        cronTrgEntry.setTriggerGroup( trigger.getGroup() );
+        cronTrgEntry.setTriggerName( trigger.getName() );
+        cronTrgEntry.setCronExpression( trigger.getCronExpression() );
+
+        ldapUtil.save( cronTrgEntry );
+        return 0;
+    }
+
+
+    public int insertFiredTrigger( Trigger trigger, String state, JobDetail jobDetail ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public void insertJobDetail( JobDetail job ) throws Exception
+    {
+        createJobGroupIfNotExixts( job );
+
+        JobDetailEntry jobEntry = new JobDetailEntry();
+        jobEntry.setDN( getJobDn( job.getName(), job.getGroup() ).getUpName() );
+
+        jobEntry.setJobName( job.getName() );
+        jobEntry.setJobGroup( job.getGroup() );
+
+        if ( job.getDescription() != null )
+        {
+            jobEntry.setTaskDesc( job.getDescription() );
+        }
+
+        jobEntry.setJobClassName( job.getJobClass().getName() );
+        jobEntry.setDurable( job.isDurable() );
+        jobEntry.setVolatileFlag( job.isVolatile() );
+        jobEntry.setStateful( job.isStateful() );
+        jobEntry.setRequestsRecovery( job.requestsRecovery() );
+
+        if ( !job.getJobDataMap().isEmpty() )
+        {
+            jobEntry.setJobData( objectToBytes( job.getJobDataMap() ) );
+        }
+
+        String[] jobListeners = job.getJobListenerNames();
+
+        jobEntry.setJobListener( jobListeners );
+
+        ldapUtil.save( jobEntry );
+    }
+
+
+    public int insertPausedTriggerGroup( String groupName ) throws Exception
+    {
+        ldapUtil.addAttributeValue( schedulerRootDn, PausedTriggerGroup.NAME, groupName );
+
+        return 0;
+    }
+
+
+    public int insertSchedulerState( String instanceId, long checkInTime, long interval, String recoverer )
+        throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int insertSimpleTrigger( SimpleTrigger trigger ) throws Exception
+    {
+        LdapDN parentDn = createTriggerGroupIfNotExixts( trigger, simpleTriggersDn );
+
+        SimpleTriggerEntry simpleTrgEntry = new SimpleTriggerEntry();
+
+        simpleTrgEntry.setDN( getChildDn( TriggerName.NAME + "=" + trigger.getName(), parentDn ).getUpName() );
+        simpleTrgEntry.setRepeatCount( ( long ) trigger.getRepeatCount() );
+        simpleTrgEntry.setRepeatInterval( trigger.getRepeatInterval() );
+        simpleTrgEntry.setTimesTriggered( ( long ) trigger.getTimesTriggered() );
+        simpleTrgEntry.setTriggerGroup( trigger.getGroup() );
+        simpleTrgEntry.setTriggerName( trigger.getName() );
+
+        ldapUtil.save( simpleTrgEntry );
+
+        return 0;
+    }
+
+
+    public void insertTrigger( Trigger trigger, String state, JobDetail jobDetail ) throws Exception
+    {
+        TriggerEntry triggerEntry = new TriggerEntry();
+
+        if ( trigger.getJobDataMap().size() > 0 )
+        {
+            triggerEntry.setJobData( objectToBytes( trigger.getJobDataMap() ) );
+        }
+
+        triggerEntry.setTriggerName( trigger.getName() );
+        triggerEntry.setTriggerGroup( trigger.getGroup() );
+        triggerEntry.setJobName( trigger.getJobName() );
+        triggerEntry.setJobGroup( trigger.getJobGroup() );
+        triggerEntry.setVolatileFlag( trigger.isVolatile() );
+
+        if( trigger.getDescription() != null )
+        {
+            triggerEntry.setTaskDesc( trigger.getDescription() );
+        }
+
+        if( trigger.getNextFireTime() != null )
+        {
+            triggerEntry.setNextFireTime( DateUtils.getGeneralizedTime( trigger.getNextFireTime() ) );
+        }
+
+        // FIXME should the fire time be initialized to -1 incase of a null value?
+        long prevFireTime = -1;
+        if ( trigger.getPreviousFireTime() != null )
+        {
+            prevFireTime = trigger.getPreviousFireTime().getTime();
+        }
+        triggerEntry.setPrevFireTime( DateUtils.getGeneralizedTime( prevFireTime ) );
+        triggerEntry.setTriggerState( state );
+
+        String tType = TTYPE_BLOB;
+        if ( trigger.getClass() == SimpleTrigger.class )
+        {
+            tType = TTYPE_SIMPLE;
+        }
+        else if ( trigger.getClass() == CronTrigger.class )
+        {
+            tType = TTYPE_CRON;
+        }
+        
+        triggerEntry.setTriggerType( tType );
+        
+        triggerEntry.setStartTime( DateUtils.getGeneralizedTime( trigger.getStartTime() ) );
+
+        if ( trigger.getEndTime() != null )
+        {
+            long endTime = trigger.getEndTime().getTime();
+            triggerEntry.setEndTime( DateUtils.getGeneralizedTime( endTime ) );
+        }
+
+        triggerEntry.setCalendarName( trigger.getCalendarName() );
+        triggerEntry.setMisFireInstr( ( long ) trigger.getMisfireInstruction() );
+        triggerEntry.setPriority( ( long ) trigger.getPriority() );
+
+        String[] trgListeners = trigger.getTriggerListenerNames();
+        triggerEntry.setTriggerListener( trgListeners );
+
+        createTriggerGroupIfNotExixts( trigger, triggersDn );
+        triggerEntry.setDN( getTriggerDn( trigger.getName(), trigger.getGroup(), triggersDn ).getUpName() );
+        ldapUtil.save( triggerEntry );
+    }
+
+
+    public boolean isExistingTriggerGroup( String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    public boolean isJobStateful( String jobName, String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    public boolean isTriggerGroupPaused( String tGroupName ) throws Exception
+    {
+        Entry entry = null;
+        boolean paused = false;
+
+        try
+        {
+            entry = ldapUtil.fetch( schedulerRootDn );
+
+            PausedTriggerGroup pausedTrgGrp = ( PausedTriggerGroup ) entry
+                .getAttribute( PausedTriggerGroup.NAME );
+            Iterator<String> itr = pausedTrgGrp.getValues();
+
+            if ( itr != null )
+            {
+                while ( itr.hasNext() )
+                {
+                    String s = itr.next();
+                    if ( s.equalsIgnoreCase( tGroupName ) || s.equalsIgnoreCase( ALL_GROUPS_PAUSED ) )
+                    {
+                        paused = true;
+                        break;
+                    }
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            LOG.error( "Failed to check whether the trigger group '{}' is paused", tGroupName );
+            e.printStackTrace();
+        }
+
+        return paused;
+    }
+
+
+    public boolean jobExists( String jobName, String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    public Calendar selectCalendar( String calendarName ) throws ClassNotFoundException, Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public String[] selectCalendars() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public List selectFiredTriggerRecords( String triggerName, String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public List<Entry> selectFiredTriggerRecordsByJob( String jobName, String groupName ) throws Exception
+    {
+        List<FiredTriggerEntry> entries;
+        String filter;
+
+        if ( jobName != null )
+        {
+            EqualityNode<String> jEq = new EqualityNode<String>( JobName.NAME,
+                new ClientStringValue( jobName ) );
+            EqualityNode<String> gEq = new EqualityNode<String>( JobGroup.NAME, new ClientStringValue(
+                groupName ) );
+
+            filter = new AndNode( jEq, gEq ).toString();
+        }
+        else
+        {
+            EqualityNode<String> gEq = new EqualityNode<String>( JobGroup.NAME, new ClientStringValue(
+                groupName ) );
+            filter = gEq.toString();
+        }
+
+        return ldapUtil.search( firedTriggerDn, filter );
+    }
+
+
+    public List selectInstancesFiredTriggerRecords( String instanceName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public JobDetail selectJobDetail( String jobName, String groupName, ClassLoadHelper loadHelper ) throws Exception
+    {
+        JobDetailEntry jobEntry = getJobEntry( jobName, groupName );
+        JobDetail job = null;
+
+        if ( jobEntry != null )
+        {
+            job = new JobDetail();
+            job.setName( jobEntry.getJobName().getValue() );
+            job.setGroup( jobEntry.getJobGroup().getValue() );
+
+            TaskDesc descAttr = jobEntry.getTaskDesc();
+            if ( descAttr != null )
+            {
+                job.setDescription( descAttr.getValue() );
+            }
+
+            job.setDurability( jobEntry.getDurable().getValue() );
+            job.setVolatility( jobEntry.getVolatileFlag().getValue() );
+            job.setRequestsRecovery( jobEntry.getRequestsRecovery().getValue() );
+
+            JobListener jl = jobEntry.getJobListener();
+            if ( jl != null )
+            {
+                Iterator<String> itr = jl.getValues();
+                while ( itr.hasNext() )
+                {
+                    job.addJobListener( itr.next() );
+                }
+            }
+
+            JobData dataAttr = jobEntry.getJobData();
+            if ( dataAttr != null )
+            {
+                job.setJobDataMap( ( JobDataMap ) bytesToObject( ( byte[] ) dataAttr.getValue() ) );
+            }
+
+            job.setJobClass( loadHelper.loadClass( jobEntry.getJobClassName().getValue() ) );
+        }
+
+        return job;
+    }
+
+
+    public int selectJobExecutionCount( String jobName, String jobGroup ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public JobDetail selectJobForTrigger( String triggerName, String groupName, ClassLoadHelper loadHelper )
+        throws ClassNotFoundException, Exception
+    {
+        JobDetail job = null;
+        
+        TriggerEntry trgEntry = getTriggerEntry( triggerName, groupName );
+        
+        if( trgEntry != null )
+        {
+            job = selectJobDetail( trgEntry.getJobName().getValue(), trgEntry.getJobGroup().getValue(), loadHelper );
+        }
+        
+        return job;
+    }
+
+
+    public String[] selectJobGroups() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public String[] selectJobListeners( String jobName, String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public String[] selectJobsInGroup( String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Key[] selectMisfiredTriggers( long ts ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Key[] selectMisfiredTriggersInGroupInState( String groupName, String state, long ts ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Key[] selectMisfiredTriggersInState( String state, long ts ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public long selectNextFireTime() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int selectNumCalendars() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int selectNumJobs() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int selectNumTriggers() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int selectNumTriggersForJob( String jobName, String groupName ) throws Exception
+    {
+        return getTriggerEntriesForJob( jobName, groupName ).size();
+    }
+
+
+    public Set selectPausedTriggerGroups() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public List selectSchedulerStateRecords( String instanceId ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public List selectStatefulJobsOfTriggerGroup( String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Trigger selectTrigger( String triggerName, String groupName ) throws Exception
+    {
+        Trigger trigger = null;
+
+        TriggerEntry entry = ( TriggerEntry ) ldapUtil.fetch( getTriggerDn( triggerName, groupName, triggersDn ) );
+
+        if ( entry == null )
+        {
+            return null;
+        }
+
+        String jobName = entry.getJobName().getValue();
+        String jobGroup = entry.getJobGroup().getValue();
+        boolean volatility = entry.getVolatileFlag().getValue();
+
+        String description = null;
+        if ( entry.getTaskDesc() != null )
+        {
+            description = entry.getTaskDesc().getValue();
+        }
+
+        long nextFireTime = 0;
+        if ( entry.getNextFireTime() != null )
+        {
+            nextFireTime = DateUtils.getDate( entry.getNextFireTime().getValue() ).getTime();
+        }
+
+        long prevFireTime = -1;
+        if ( entry.getPrevFireTime() != null )
+        {
+            prevFireTime = DateUtils.getDate( entry.getPrevFireTime().getValue() ).getTime();
+        }
+
+        String triggerType = entry.getTriggerType().getValue();
+        Date startTimeD = DateUtils.getDate( entry.getStartTime().getValue() );
+
+        long endTime = 0;
+        if ( entry.getEndTime() != null )
+        {
+            endTime = DateUtils.getDate( entry.getEndTime().getValue() ).getTime();
+        }
+
+        Date endTimeD = null;
+        if ( endTime > 0 )
+        {
+            endTimeD = new Date( endTime );
+        }
+
+        String calendarName = null;
+        if ( entry.getCalendarName() != null )
+        {
+            calendarName = entry.getCalendarName().getValue();
+        }
+
+        int misFireInstr = 0;
+        if ( entry.getMisFireInstr() != null )
+        {
+            misFireInstr = entry.getMisFireInstr().getValue().intValue();
+        }
+
+        int priority = 0;
+        if ( entry.getPriority() != null )
+        {
+            priority = entry.getPriority().getValue().intValue();
+        }
+
+        Map map = null;
+        if ( entry.getJobData() != null )
+        {
+            map = ( Map ) bytesToObject( entry.getJobData().getValue() );
+        }
+        // use of properties not supported
+        //            if ( canUseProperties() )
+        //            {
+        //                map = getMapFromProperties( rs );
+        //            }
+
+        Date nft = null;
+        if ( nextFireTime > 0 )
+        {
+            nft = new Date( nextFireTime );
+        }
+
+        Date pft = null;
+        if ( prevFireTime > 0 )
+        {
+            pft = new Date( prevFireTime );
+        }
+
+        if ( triggerType.equals( TTYPE_SIMPLE ) )
+        {
+            SimpleTriggerEntry simpleTrgEntry = ( SimpleTriggerEntry ) ldapUtil.fetch( getTriggerDn( triggerName,
+                groupName, simpleTriggersDn ) );
+
+            int repeatCount = simpleTrgEntry.getRepeatCount().getValue().intValue();
+            long repeatInterval = simpleTrgEntry.getRepeatInterval().getValue();
+            int timesTriggered = simpleTrgEntry.getTimesTriggered().getValue().intValue();
+
+            SimpleTrigger st = new SimpleTrigger( triggerName, groupName, jobName, jobGroup, startTimeD, endTimeD,
+                repeatCount, repeatInterval );
+            st.setCalendarName( calendarName );
+            st.setMisfireInstruction( misFireInstr );
+            st.setTimesTriggered( timesTriggered );
+            st.setVolatility( volatility );
+            st.setNextFireTime( nft );
+            st.setPreviousFireTime( pft );
+            st.setDescription( description );
+            st.setPriority( priority );
+            if ( null != map )
+            {
+                st.setJobDataMap( new JobDataMap( map ) );
+            }
+            trigger = st;
+        }
+        else if ( triggerType.equals( TTYPE_CRON ) )
+        {
+
+            CronTriggerEntry cronTrgEntry = ( CronTriggerEntry ) ldapUtil.fetch( getTriggerDn( triggerName, groupName,
+                cronTriggersDn ) );
+            String cronExpr = cronTrgEntry.getCronExpression().getValue();
+
+            String timeZoneId = null;
+            if ( cronTrgEntry.getTimeZoneId() != null )
+            {
+                timeZoneId = cronTrgEntry.getTimeZoneId().getValue();
+            }
+
+            CronTrigger ct = null;
+            try
+            {
+                TimeZone timeZone = null;
+                if ( timeZoneId != null )
+                {
+                    timeZone = TimeZone.getTimeZone( timeZoneId );
+                }
+                ct = new CronTrigger( triggerName, groupName, jobName, jobGroup, startTimeD, endTimeD, cronExpr,
+                    timeZone );
+            }
+            catch ( Exception neverHappens )
+            {
+                // expr must be valid, or it never would have
+                // gotten to the store...
+            }
+            if ( null != ct )
+            {
+                ct.setCalendarName( calendarName );
+                ct.setMisfireInstruction( misFireInstr );
+                ct.setVolatility( volatility );
+                ct.setNextFireTime( nft );
+                ct.setPreviousFireTime( pft );
+                ct.setDescription( description );
+                ct.setPriority( priority );
+                if ( null != map )
+                {
+                    ct.setJobDataMap( new JobDataMap( map ) );
+                }
+                trigger = ct;
+            }
+        }
+        else if ( triggerType.equals( TTYPE_BLOB ) )
+        {
+            BlobTriggerEntry blobTrgEntry = ( BlobTriggerEntry ) ldapUtil.fetch( getTriggerDn( triggerName, groupName,
+                blobTriggersDn ) );
+
+            trigger = ( Trigger ) bytesToObject( blobTrgEntry.getBlobData().getValue() );
+        }
+        else
+        {
+            throw new ClassNotFoundException( "class for trigger type '" + triggerType + "' not found." );
+        }
+
+        trigger.clearAllTriggerListeners();
+
+        TriggerListener tls = entry.getTriggerListener();
+        if ( tls != null )
+        {
+            Iterator<String> itr = tls.getValues();
+            while ( itr.hasNext() )
+            {
+                trigger.addTriggerListener( itr.next() );
+            }
+        }
+
+        return trigger;
+    }
+
+
+    public Key selectTriggerForFireTime( long fireTime ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public String[] selectTriggerGroups() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public JobDataMap selectTriggerJobDataMap( String triggerName, String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public String[] selectTriggerListeners( String triggerName, String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Key[] selectTriggerNamesForJob( String jobName, String groupName ) throws Exception
+    {
+        List<Entry> list = getTriggerEntriesForJob( jobName, groupName );
+        Key[] triggers = new Key[list.size()];
+
+        Iterator<Entry> itr = list.iterator();
+        int i = 0;
+
+        while ( itr.hasNext() )
+        {
+            TriggerEntry entry = ( TriggerEntry ) itr.next();
+            Key k = new Key( entry.getTriggerName().getValue(), entry.getTriggerGroup().getValue() );
+            triggers[i++] = k;
+        }
+
+        return triggers;
+    }
+
+    private List<Entry> getTriggerEntriesForJob( String jobName, String groupName ) throws Exception
+    {
+        EqualityNode<String> jobNameNode = new EqualityNode<String>( JobName.NAME, new ClientStringValue(
+            jobName ) );
+        EqualityNode<String> jobGroupNode = new EqualityNode<String>( JobGroup.NAME, new ClientStringValue(
+            groupName ) );
+
+        AndNode filterExpr = new AndNode( jobNameNode, jobGroupNode );
+
+        return ldapUtil.search( triggersDn, SearchScope.SUBTREE, filterExpr, AliasDerefMode.NEVER_DEREF_ALIASES, null );
+    }
+
+    public Trigger[] selectTriggersForCalendar( String calName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Trigger[] selectTriggersForJob( String jobName, String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Trigger[] selectTriggersForRecoveringJobs() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public String[] selectTriggersInGroup( String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Key[] selectTriggersInState( String state ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public String selectTriggerState( String triggerName, String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public TriggerStatus selectTriggerStatus( String triggerName, String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Key[] selectVolatileJobs() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public Key[] selectVolatileTriggers() throws Exception
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    public boolean triggerExists( String triggerName, String groupName ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    public void updateBlobTrigger( Trigger trigger ) throws Exception
+    {
+        LdapDN dn = getTriggerDn( trigger.getName(), trigger.getGroup(), blobTriggersDn );
+
+        ldapUtil.replaceAttributeValue( dn, BlobData.NAME, objectToBytes( trigger ) );
+    }
+
+
+    public int updateCalendar( String calendarName, Calendar calendar ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int updateCronTrigger( CronTrigger trigger ) throws Exception
+    {
+        CronTriggerEntry cronTriggerEntry = ( CronTriggerEntry ) ldapUtil.fetch( getTriggerDn( trigger.getName(),
+            trigger.getGroup(), cronTriggersDn ) );
+
+        cronTriggerEntry.setCronExpression( trigger.getCronExpression() );
+
+        ldapUtil.modify( cronTriggerEntry );
+
+        return 0;
+    }
+
+
+    public int updateJobData( JobDetail job ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int updateSchedulerState( String instanceId, long checkInTime, String recoverer ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int updateSimpleTrigger( SimpleTrigger trigger ) throws Exception
+    {
+        SimpleTriggerEntry simpleTrgEntry = ( SimpleTriggerEntry ) ldapUtil.fetch( getTriggerDn( trigger.getName(),
+            trigger.getGroup(), simpleTriggersDn ) );
+
+        simpleTrgEntry.setRepeatCount( ( long ) trigger.getRepeatCount() );
+        simpleTrgEntry.setRepeatInterval( trigger.getRepeatInterval() );
+        simpleTrgEntry.setTimesTriggered( ( long ) trigger.getTimesTriggered() );
+
+        ldapUtil.modify( simpleTrgEntry );
+        return 0;
+    }
+
+
+    public void updateTrigger( TriggerEntry triggerEntry, Trigger trigger, String state, JobDetail jobDetail )
+        throws Exception
+    {
+        boolean updateJobData = trigger.getJobDataMap().isDirty();
+
+        if ( updateJobData && trigger.getJobDataMap().size() > 0 )
+        {
+            byte[] jobData = objectToBytes( trigger.getJobDataMap() );
+            triggerEntry.setJobData( jobData );
+        }
+
+        triggerEntry.setJobName( trigger.getJobName() );
+        triggerEntry.setJobGroup( trigger.getJobGroup() );
+        triggerEntry.setVolatileFlag( trigger.isVolatile() );
+        triggerEntry.setTaskDesc( trigger.getDescription() );
+
+        long nextFireTime = -1;
+        if ( trigger.getNextFireTime() != null )
+        {
+            nextFireTime = trigger.getNextFireTime().getTime();
+        }
+
+        triggerEntry.setNextFireTime( DateUtils.getGeneralizedTime( nextFireTime ) );
+
+        long prevFireTime = -1;
+        if ( trigger.getPreviousFireTime() != null )
+        {
+            prevFireTime = trigger.getPreviousFireTime().getTime();
+        }
+        triggerEntry.setPrevFireTime( DateUtils.getGeneralizedTime( prevFireTime ) );
+        triggerEntry.setTriggerState( state );
+
+        String tType = TTYPE_BLOB;
+
+        if ( trigger.getClass() == SimpleTrigger.class )
+        {
+            tType = TTYPE_SIMPLE;
+        }
+        else if ( trigger.getClass() == CronTrigger.class )
+        {
+            tType = TTYPE_CRON;
+        }
+
+        triggerEntry.setTriggerType( tType );
+
+        triggerEntry.setStartTime( DateUtils.getGeneralizedTime( trigger.getStartTime() ) );
+
+        long endTime = 0;
+        if ( trigger.getEndTime() != null )
+        {
+            endTime = trigger.getEndTime().getTime();
+        }
+        triggerEntry.setEndTime( DateUtils.getGeneralizedTime( endTime ) );
+
+        triggerEntry.setCalendarName( trigger.getCalendarName() );
+        triggerEntry.setMisFireInstr( ( long ) trigger.getMisfireInstruction() );
+        triggerEntry.setPriority( ( long ) trigger.getPriority() );
+
+        String[] trgListeners = trigger.getTriggerListenerNames();
+        triggerEntry.setTriggerListener( trgListeners );
+
+        ldapUtil.modify( triggerEntry );
+    }
+
+
+    public int updateTriggerGroupStateFromOtherState( String groupName, String newState, String oldState )
+        throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int updateTriggerGroupStateFromOtherStates( String groupName, String newState, String oldState1,
+        String oldState2, String oldState3 ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int updateTriggerState( String triggerName, String groupName, String state ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int updateTriggerStateFromOtherState( String triggerName, String groupName, String newState, String oldState )
+        throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int updateTriggerStateFromOtherStates( String triggerName, String groupName, String newState,
+        String oldState1, String oldState2, String oldState3 ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int updateTriggerStateFromOtherStatesBeforeTime( String newState, String oldState1, String oldState2,
+        long time ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int updateTriggerStatesForJob( String jobName, String groupName, String state ) throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int updateTriggerStatesForJobFromOtherState( String jobName, String groupName, String state, String oldState )
+        throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    public int updateTriggerStatesFromOtherStates( String newState, String oldState1, String oldState2 )
+        throws Exception
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    /*
+         public void insertJobListener( JobDetail job, String listener ) throws Exception
+    {
+        // TODO how about keeping the listeners in the jobDetailEntry 
+        JobListenersEntry jobLnrEntry = new JobListenersEntry();
+        jobLnrEntry.setJobName( job.getName() );
+        jobLnrEntry.setJobGroup( job.getGroup() );
+        jobLnrEntry.setJobListener( listener );
+
+        String dn = JobName.NAME + "=" + job.getName();
+        dn = dn + "," + JobGroup.NAME + "=" + job.getGroup();
+        dn = dn + "," + JobListener.NAME + "=" + listener;
+        dn = dn + "," + jobListenersDn.getUpName();
+
+        jobLnrEntry.setDN( dn );
+
+        ldapUtil.save( jobLnrEntry );
+    }
+    public void insertTriggerListener( Trigger trigger, String listener ) throws Exception
+    {
+        TriggerListenersEntry trgLnrEntry = new TriggerListenersEntry();
+        trgLnrEntry.setTriggerGroup( trigger.getGroup() );
+        trgLnrEntry.setTriggerName( trigger.getName() );
+        trgLnrEntry.setTriggerListener( listener );
+
+        String dn = TriggerName.NAME + "=" + trigger.getName();
+        dn = dn + "," + TriggerGroup.NAME + "=" + trigger.getGroup();
+        dn = dn + "," + TriggerListener.NAME + "=" + listener;
+        dn = dn + "," + triggerListenersDn.getUpName();
+
+        trgLnrEntry.setDN( dn );
+
+        ldapUtil.save( trgLnrEntry );
+    }
+    public void deleteJobListeners( String jobName, String groupName ) throws Exception
+    {
+        // search for all entries under triggerListenersDn having the given
+        // trigger and group name
+
+        EqualityNode<String> jobNameNode = new EqualityNode<String>( JobName.NAME, new ClientStringValue(
+            jobName ) );
+        EqualityNode<String> jobGroupNode = new EqualityNode<String>( JobGroup.NAME, new ClientStringValue(
+            groupName ) );
+
+        AndNode filterExpr = new AndNode( jobNameNode, jobGroupNode );
+
+        List<Entry> list = ldapUtil.search( jobListenersDn, filterExpr.toString() );
+
+        Iterator<Entry> itr = list.iterator();
+
+        while ( itr.hasNext() )
+        {
+            ldapUtil.delete( itr.next().getDN() );
+        }
+    }
+    public void deleteTriggerListeners( String triggerName, String groupName ) throws Exception
+    {
+        // search for all entries under triggerListenersDn having the given
+        // trigger and group name
+
+        EqualityNode<String> trgNameNode = new EqualityNode<String>( TriggerName.NAME, new ClientStringValue(
+            triggerName ) );
+        EqualityNode<String> trgGroupNode = new EqualityNode<String>( TriggerGroup.NAME,
+            new ClientStringValue( groupName ) );
+
+        AndNode filterExpr = new AndNode( trgNameNode, trgGroupNode );
+
+        List<Entry> list = ldapUtil.search( triggerListenersDn, filterExpr.toString() );
+
+        Iterator<Entry> itr = list.iterator();
+
+        while ( itr.hasNext() )
+        {
+            ldapUtil.delete( itr.next().getDN() );
+        }
+    }
+
+     */
+}

Modified: directory/sandbox/kayyagari/server-scheduler/src/test/java/org/apahe/directory/server/scheduler/store/LdapJobStoreITest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/server-scheduler/src/test/java/org/apahe/directory/server/scheduler/store/LdapJobStoreITest.java?rev=718206&r1=718205&r2=718206&view=diff
==============================================================================
--- directory/sandbox/kayyagari/server-scheduler/src/test/java/org/apahe/directory/server/scheduler/store/LdapJobStoreITest.java (original)
+++ directory/sandbox/kayyagari/server-scheduler/src/test/java/org/apahe/directory/server/scheduler/store/LdapJobStoreITest.java Mon Nov 17 01:13:25 2008
@@ -20,12 +20,14 @@
 package org.apahe.directory.server.scheduler.store;
 
 import java.io.File;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
 import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.server.scheduler.store.LdapJobStore;
 import org.apache.directory.server.schema.SerializableComparator;
 import org.apache.directory.server.schema.bootstrap.ApacheSchema;
 import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
@@ -41,13 +43,20 @@
 import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.server.unit.AbstractServerTest;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.DateUtils;
 import org.junit.Before;
 import org.junit.Test;
+import org.quartz.Calendar;
+import org.quartz.CronTrigger;
 import org.quartz.Job;
 import org.quartz.JobDataMap;
 import org.quartz.JobDetail;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
+import org.quartz.JobPersistenceException;
+import org.quartz.SimpleTrigger;
+import org.quartz.Trigger;
+import org.quartz.simpl.ThreadContextClassLoadHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -82,8 +91,8 @@
         
         Partition partition = directoryService.getPartitionNexus().getPartition( sysDn );
         
-        store = new LdapJobStore( directoryService, partition, "ou=scheduler,ou=system" );
-        store.initialize( null, null );
+        store = new LdapJobStore( directoryService, "ou=scheduler,ou=system" );
+        store.initialize( new ThreadContextClassLoadHelper(), null );
     }
     
     @Override
@@ -114,7 +123,95 @@
     
     
     @Test
-    public void testStoreJob() throws Exception
+    public void testMisc()
+    {
+       assertTrue( store.supportsPersistence() ); 
+    }
+    
+    @Test
+    public void testStoreRetrieveJob() throws Exception
+    {
+        Map<String,Object> map = new HashMap<String,Object>();
+        map.put( "key1", "value1" );
+        map.put( "key2", 1 );
+        map.put( "key3", TestJob.class );
+        
+        JobDataMap data = new JobDataMap( map );
+        
+        JobDetail originalJob = new JobDetail( "testJobName", "testJobGroup", TestJob.class );
+        originalJob.setRequestsRecovery( true );
+        originalJob.setVolatility( true );
+        originalJob.setDurability( false );
+        originalJob.setJobDataMap( data );
+        
+        originalJob.addJobListener( "listener1" );
+        originalJob.addJobListener( "listener2" );
+        
+        store.storeJob( null, originalJob, false );
+        
+        JobDetail retrievedJob = store.retrieveJob( null, originalJob.getName(), originalJob.getGroup() );
+        LOG.warn( "retrievedjob {}", retrievedJob );
+        
+        assertNotNull( retrievedJob );
+        assertEquals( originalJob.getName(), retrievedJob.getName() );
+        assertEquals( originalJob.getGroup(), retrievedJob.getGroup() );
+        assertEquals( originalJob.requestsRecovery(), retrievedJob.requestsRecovery() );
+        assertEquals( originalJob.isDurable(), retrievedJob.isDurable() );
+        assertEquals( originalJob.isVolatile(), retrievedJob.isVolatile() );
+        assertEquals( originalJob.isStateful(), retrievedJob.isStateful() );
+        assertEquals( originalJob.getClass(), retrievedJob.getClass() );
+        assertEquals( originalJob.getJobListenerNames().length, retrievedJob.getJobListenerNames().length );
+        
+        for( Object key : originalJob.getJobDataMap().keySet() )
+        {
+            assertEquals( originalJob.getJobDataMap().get( key ), retrievedJob.getJobDataMap().get( key ) );
+        }
+
+        // try to store the same job again, should fail with exception
+        try
+        {
+            store.storeJob( null, originalJob, false );
+            fail( "Storing the same job is not allowed. This test should fail." );
+        }
+        catch( JobPersistenceException e ) { }
+
+        JobDetail clonedJob = ( JobDetail ) originalJob.clone();
+        
+        // test updating an existing job
+        clonedJob.setJobDataMap( null ); // though it is set to null job.getJobDataMap() returns an empty jobdatamap
+        clonedJob.setRequestsRecovery( false );
+        clonedJob.setVolatility( false );
+        clonedJob.setDurability( true );
+        clonedJob.setDescription( "description" );
+        clonedJob.removeJobListener( "listener1" );
+        
+        store.storeJob( null, clonedJob, true );
+        retrievedJob = store.retrieveJob( null, clonedJob.getName(), clonedJob.getGroup() );
+        assertNotNull( retrievedJob );
+
+        // these four properties remain same
+        assertEquals( originalJob.getName(), retrievedJob.getName() );
+        assertEquals( originalJob.getGroup(), retrievedJob.getGroup() );
+        assertEquals( originalJob.getClass(), retrievedJob.getClass() );
+        assertEquals( originalJob.isStateful(), retrievedJob.isStateful() );
+        
+        assertTrue( retrievedJob.getJobDataMap().isEmpty() );
+        assertFalse( retrievedJob.getDescription().equals( originalJob.getDescription() ) );
+        assertTrue( originalJob.isDurable() != retrievedJob.isDurable() );
+        assertTrue( originalJob.isVolatile() != retrievedJob.isVolatile() );
+        assertTrue( originalJob.requestsRecovery() != retrievedJob.requestsRecovery() );
+        assertEquals( clonedJob.getJobListenerNames().length, retrievedJob.getJobListenerNames().length );
+
+        // test removing job
+        store.removeJob( null, retrievedJob.getName(), retrievedJob.getGroup() );
+        retrievedJob = store.retrieveJob( null, clonedJob.getName(), clonedJob.getGroup() );
+        assertNull( retrievedJob );
+        
+//        runServer();
+    }
+    
+    @Test
+    public void testTriggerOperations() throws Exception
     {
         Map<String,Object> map = new HashMap<String,Object>();
         map.put( "key1", "value1" );
@@ -126,32 +223,98 @@
         JobDetail job = new JobDetail( "testJobName", "testJobGroup", TestJob.class );
         job.setRequestsRecovery( true );
         job.setVolatility( true );
+        job.setDurability( false );
         job.setJobDataMap( data );
         
+        job.addJobListener( "listener1" );
+        job.addJobListener( "listener2" );
+        
+
+        String trgName = "testTrigger";
+        String trgGroup = "testTriggerGroup";
+        String trgDesc = "testing trigger group";
+        String calName = "calendar1";
+        SimpleTrigger simpleTrigger = new SimpleTrigger( trgName, trgGroup );
+        simpleTrigger.setJobName( job.getName() );
+        simpleTrigger.setJobGroup( job.getGroup() );
+        simpleTrigger.setVolatility( job.isVolatile() ); // job and trigger should have the same volatility value
+        simpleTrigger.setDescription( trgDesc );
+        simpleTrigger.setStartTime( new Date() );
+        simpleTrigger.setCalendarName( calName );
+        simpleTrigger.addTriggerListener( "trgListener1" );
+        simpleTrigger.addTriggerListener( "trgListener2" );
+        
+        testTrigger( simpleTrigger, job );
+        
+        CronTrigger cronTrigger = new CronTrigger( trgName, trgGroup );
+        cronTrigger.setJobName( job.getName() );
+        cronTrigger.setJobGroup( job.getGroup() );
+        cronTrigger.setVolatility( job.isVolatile() ); // job and trigger should have the same volatility value
+        cronTrigger.setDescription( trgDesc );
+        cronTrigger.setStartTime( new Date() );
+        cronTrigger.setCalendarName( calName );
+        cronTrigger.addTriggerListener( "trgListener1" );
+        cronTrigger.addTriggerListener( "trgListener2" );
+        cronTrigger.setCronExpression( "0 1 00 * * *" );
+        
+        testTrigger( cronTrigger, job );
+
+        BlobTrigger blobTrigger = new BlobTrigger( trgName, trgGroup );
+        blobTrigger.setJobName( job.getName() );
+        blobTrigger.setJobGroup( job.getGroup() );
+        blobTrigger.setVolatility( job.isVolatile() ); // job and trigger should have the same volatility value
+        blobTrigger.setDescription( trgDesc );
+        blobTrigger.setStartTime( new Date() );
+        blobTrigger.setCalendarName( calName );
+        blobTrigger.addTriggerListener( "trgListener1" );
+        blobTrigger.addTriggerListener( "trgListener2" );
+        
+        testTrigger( blobTrigger, job );
+    }
+    
+    
+    public void testTrigger( Trigger trigger, JobDetail job ) throws Exception
+    {
         store.storeJob( null, job, false );
+        store.storeTrigger( null, trigger, false );
         
-        JobDetail retrievedJob = store.retrieveJob( null, job.getName(), job.getGroup() );
-        LOG.warn( "retrievedjob {}", retrievedJob );
+        Trigger  retrieved = store.retrieveTrigger( null, trigger.getName(), trigger.getGroup() );
+        assertNotNull( retrieved );
         
-        assertNotNull( retrievedJob );
-        assertEquals( job.getName(), retrievedJob.getName() );
-        assertEquals( job.getGroup(), retrievedJob.getGroup() );
-        assertEquals( job.requestsRecovery(), retrievedJob.requestsRecovery() );
-        assertEquals( job.isDurable(), retrievedJob.isDurable() );
-        assertEquals( job.isVolatile(), retrievedJob.isVolatile() );
-        assertEquals( job.isStateful(), retrievedJob.isStateful() );
-        assertEquals( job.getClass(), retrievedJob.getClass() );
+        assertEquals( trigger.getName(), retrieved.getName() );
+        assertEquals( trigger.getGroup(), retrieved.getGroup() );
+        assertEquals( trigger.getJobName(), retrieved.getJobName() );
+        assertEquals( trigger.getJobGroup(), retrieved.getJobGroup() );
+        assertEquals( trigger.getDescription(), retrieved.getDescription() );
+        assertEquals( DateUtils.getGeneralizedTime( trigger.getStartTime() ), DateUtils.getGeneralizedTime( retrieved.getStartTime() ) );
+        assertEquals( trigger.getCalendarName(), retrieved.getCalendarName() );
+        assertTrue( trigger.getTriggerListenerNames().length == retrieved.getTriggerListenerNames().length );
         
-        for( Object key : job.getJobDataMap().keySet() )
+        if( trigger instanceof CronTrigger )
         {
-            assertEquals( job.getJobDataMap().get( key ), retrievedJob.getJobDataMap().get( key ) );
+            String expectedCronExp = ( ( CronTrigger ) trigger ).getCronExpression();
+            String actualCronExp = ( ( CronTrigger ) retrieved ).getCronExpression();
+            assertEquals( expectedCronExp, actualCronExp );
         }
+        
+        store.removeTrigger( null, trigger.getName(), trigger.getGroup() );
+        retrieved = store.retrieveTrigger( null, trigger.getName(), trigger.getGroup() );
+        assertNull( retrieved );
+        
+        job = store.retrieveJob( null, trigger.getJobName(), trigger.getJobGroup() );
+        assertNull( job );
+    }
+    
+    
+    public void testJobListeners()
+    {
+        
     }
     
     
     public void runServer() throws Exception
     {
-        if( keepRunning )
+        if( true )
         {
             LOG.warn( "Test Server listening on port :" + port );
             LOG.warn( "Press Ctrl + C to stop. To disable test server running please set keeprunning system property to false" );
@@ -171,4 +334,112 @@
             
         }
     }
+    
+    
+    static class BlobTrigger extends Trigger
+    {
+
+        private Date startTime = null;
+
+        private Date endTime = null;
+
+        private Date nextFireTime = null;
+
+        private Date previousFireTime = null;
+
+
+        public BlobTrigger( String name, String group )
+        {
+           super( name, group ); 
+        }
+        
+        
+        @Override
+        public Date computeFirstFireTime( Calendar arg0 )
+        {
+            return null;
+        }
+
+        @Override
+        public int executionComplete( JobExecutionContext arg0, JobExecutionException arg1 )
+        {
+            return 0;
+        }
+
+        @Override
+        public Date getEndTime()
+        {
+            return endTime;
+        }
+
+        @Override
+        public Date getFinalFireTime()
+        {
+            return null;
+        }
+
+        @Override
+        public Date getFireTimeAfter( Date arg0 )
+        {
+            return null;
+        }
+
+        @Override
+        public Date getNextFireTime()
+        {
+            return nextFireTime;
+        }
+
+        @Override
+        public Date getPreviousFireTime()
+        {
+            return previousFireTime;
+        }
+
+        @Override
+        public Date getStartTime()
+        {
+            return startTime;
+        }
+
+        @Override
+        public boolean mayFireAgain()
+        {
+            return false;
+        }
+
+        @Override
+        public void setEndTime( Date date )
+        {
+            this.endTime = date;
+        }
+
+        @Override
+        public void setStartTime( Date date )
+        {
+            this.startTime = date;
+        }
+
+        @Override
+        public void triggered( Calendar arg0 )
+        {
+        }
+
+        @Override
+        public void updateAfterMisfire( Calendar arg0 )
+        {
+        }
+
+        @Override
+        public void updateWithNewCalendar( Calendar arg0, long arg1 )
+        {
+        }
+
+        @Override
+        protected boolean validateMisfireInstruction( int arg0 )
+        {
+            return false;
+        }
+        
+    }
 }



Mime
View raw message