ome.services.delete
Class BaseDeleteSpec

java.lang.Object
  extended by ome.services.delete.BaseDeleteSpec
All Implemented Interfaces:
DeleteSpec, org.springframework.beans.factory.BeanNameAware
Direct Known Subclasses:
AnnotationDeleteSpec

public class BaseDeleteSpec
extends Object
implements DeleteSpec, org.springframework.beans.factory.BeanNameAware

DeleteSpec which takes the id of some id as the root of deletion.

Since:
Beta4.2.1
Author:
Josh Moore, josh at glencoesoftware.com
See Also:
IDelete

Nested Class Summary
static class BaseDeleteSpec.SubSpecIterator
          Iterator which walks returns all DeleteSpecs which are reachable from the given spec, depth first including the spec itself.
 
Field Summary
protected  List<DeleteEntry> entries
          The paths which make up this delete specification.
protected  long id
          The id of the root type which will be deleted.
protected  Map<String,String> options
          Options passed to the #initialize(long, Map) method, which may be used during #delete(Session, int) to alter behavior.
protected  String superspec
          Path of the superspec.
 
Constructor Summary
BaseDeleteSpec(List<String> entries)
           
BaseDeleteSpec(String name, String... entries)
          Simplified constructor, primarily used for testing.
 
Method Summary
 void close()
           
 List<DeleteEntry> entries()
          Returns a copy of the list of DeleteEntry instances contained in this DeleteSpec
 CurrentDetails getCurrentDetails()
           
 Class<ome.model.IObject> getHibernateClass(String table)
          Return the Hibernate type (ome.model.*) for the given table.
 String getName()
          The name of this specification.
 String getSuperSpec()
          Specification of where this DeleteSpec is attached under another .
 int initialize(long id, String superspec, Map<String,String> options)
          Called as each delete command is started.
protected  void join(QueryBuilder qb, String from, String fromAlias, String to, String toAlias)
          Used to generate a join statement on the QueryBuilder making use of {@link ExtendedMetadata#getRelationship(String, String).
 boolean overrideKeep()
          Always returns false.
 void postProcess(org.springframework.beans.factory.ListableBeanFactory factory)
          Gives all specs a chance to reference subspecs.
 long[][] queryBackupIds(org.hibernate.Session session, int step, DeleteEntry subpath, QueryBuilder and)
          If a given path is deleted before its sub-path, this points to a one-to-one relationship.
 void runTopLevel(org.hibernate.Session session, List<Long> ids)
          Workaround for the removal of DeleteSpec#delete when refactoring to DeleteState.
 void setBeanName(String beanName)
           
 void setCurrentDetails(CurrentDetails details)
           
 void setExtendedMetadata(ExtendedMetadata em)
           
 String toString()
           
 Iterator<DeleteSpec> walk()
          Returns an iterator over all subspecs and their subspecs, depth-first.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

entries

protected final List<DeleteEntry> entries
The paths which make up this delete specification. These count as the steps which will be performed by multiple calls to #delete(Session, int)


id

protected long id
The id of the root type which will be deleted. Note: if this delete comes from a subspec, then the id points to the type of the supertype not the type for this entry itself. For example, if this is "/Dataset" but it is being deleted as a part of "/Project" then the id refers to the project and not the dataset.


superspec

protected String superspec
Path of the superspec.


options

protected Map<String,String> options
Options passed to the #initialize(long, Map) method, which may be used during #delete(Session, int) to alter behavior.

Constructor Detail

BaseDeleteSpec

public BaseDeleteSpec(String name,
                      String... entries)
Simplified constructor, primarily used for testing.


BaseDeleteSpec

public BaseDeleteSpec(List<String> entries)
Method Detail

setBeanName

public void setBeanName(String beanName)
Specified by:
setBeanName in interface org.springframework.beans.factory.BeanNameAware

setExtendedMetadata

public void setExtendedMetadata(ExtendedMetadata em)

setCurrentDetails

public void setCurrentDetails(CurrentDetails details)

getCurrentDetails

public CurrentDetails getCurrentDetails()
Specified by:
getCurrentDetails in interface DeleteSpec

getName

public String getName()
Description copied from interface: DeleteSpec
The name of this specification. Usually the first component of the entries in spec.xml

Specified by:
getName in interface DeleteSpec

getSuperSpec

public String getSuperSpec()
Description copied from interface: DeleteSpec
Specification of where this DeleteSpec is attached under another . The reverse of DeleteEntry.getSubSpec().

Specified by:
getSuperSpec in interface DeleteSpec

getHibernateClass

public Class<ome.model.IObject> getHibernateClass(String table)
Description copied from interface: DeleteSpec
Return the Hibernate type (ome.model.*) for the given table.

Specified by:
getHibernateClass in interface DeleteSpec

postProcess

public void postProcess(org.springframework.beans.factory.ListableBeanFactory factory)
Description copied from interface: DeleteSpec
Gives all specs a chance to reference subspecs.

Specified by:
postProcess in interface DeleteSpec

initialize

public int initialize(long id,
                      String superspec,
                      Map<String,String> options)
               throws DeleteException
Description copied from interface: DeleteSpec
Called as each delete command is started. This instance will inly be used serially (i.e. by one thread) and so this is safe. When the last step is reached, #delete(Session, int) can take clean up actions.

Specified by:
initialize in interface DeleteSpec
Parameters:
id - identifier of the root object which defines the graph to be deleted.
superspec - points to the relationship between the root object and the current graph. In many cases, this value will be null so that the current object is taken to be the root, but if this is a subspec, or a non-standard naming is being used, then the supersec will be used.
options - possibly null or empty map of options which can override the operations provided in the definition of the specification. For example, if the spec "/Image" defines "/Image/Annotation" as "HARD" (the default), then the options map could contain
 {"/Image/Annotation":"ORPHAN"}
 
to modify that setting.
Returns:
number of steps which are to be processed.
Throws:
DeleteException

walk

public Iterator<DeleteSpec> walk()
Description copied from interface: DeleteSpec
Returns an iterator over all subspecs and their subspecs, depth-first.

Specified by:
walk in interface DeleteSpec

entries

public List<DeleteEntry> entries()
Description copied from interface: DeleteSpec
Returns a copy of the list of DeleteEntry instances contained in this DeleteSpec

Specified by:
entries in interface DeleteSpec

close

public void close()
Specified by:
close in interface DeleteSpec

overrideKeep

public boolean overrideKeep()
Always returns false. See interface for documentation.

Specified by:
overrideKeep in interface DeleteSpec

queryBackupIds

public long[][] queryBackupIds(org.hibernate.Session session,
                               int step,
                               DeleteEntry subpath,
                               QueryBuilder and)
                        throws DeleteException
Description copied from interface: DeleteSpec
If a given path is deleted before its sub-path, this points to a one-to-one relationship. If the first object is deleted without having loaded the later one, then there will be no way to find the dangling object. Therefore, we load those objects first. In the case of superspecs, we also store the root ids for the sub-spec to handle cases such as links, etc. Returns a list of all root ids per step which should be deleted. These are precalculated on #initialize(long, Map) so that foreign key constraints which require a higher level object to be deleted first, can be removed. For example,
 /Channel
 /Channel/StatsInfo
 
requires the Channel to be deleted first, but without the Channel, there's no way to detect which StatsInfo should be removed. Therefore, #backupIds in this case would contain:
 [
  null,      # Nothing for Channel.
  [1,2,3],   # The ids of all StatsInfo object which should be removed.
 ]
 

Specified by:
queryBackupIds in interface DeleteSpec
Throws:
DeleteException

runTopLevel

public void runTopLevel(org.hibernate.Session session,
                        List<Long> ids)
Description copied from interface: DeleteSpec
Workaround for the removal of DeleteSpec#delete when refactoring to DeleteState. If more logic is needed by subclasses, then DeleteSpec.queryBackupIds(Session, int, DeleteEntry, QueryBuilder) should no longer return list of ids, but rather a "Action" class so that it can inject its own logic as needed, though it would be necessary to give that method its place in the graph to detect "top-ness".

Specified by:
runTopLevel in interface DeleteSpec

join

protected void join(QueryBuilder qb,
                    String from,
                    String fromAlias,
                    String to,
                    String toAlias)
             throws DeleteException
Used to generate a join statement on the QueryBuilder making use of ExtendedMetadata#getRelationship(String, String). If the value returned by that value is null, a {@link DeleteException} will be thrown. Otherwise something of the form:
 join FROM.rel as TO
 
will be added to the {@link QueryBuilder}

Throws:
DeleteException

toString

public String toString()
Overrides:
toString in class Object


OmeroJava Api

Version: Beta4.2.1-r8614-Beta4.2-b41

Copyright © 2009 The University of Dundee. All Rights Reserved.