mysql
Class TaskSql

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by mysql.AbstractSql
                  extended by mysql.TaskSql
All Implemented Interfaces:
Cloneable, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying

public class TaskSql
extends AbstractSql
implements ExitCleaning

A class that comprises actions connected with the 'task' table in the stella database.


Nested Class Summary
static class TaskSql.Force
          Forces rebuild of a target from the stated xml file, sends mail.
static class TaskSql.Rebuild
          Rebuilds the serialized parsed targets in the database.
static class TaskSql.Retrieve
          Retrieves a target.
static class TaskSql.Xml
          Updates a target from the stated xml file.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static boolean DEFDBREADRULE
          Per default we allow histroy reading and writing.
private static boolean DEFDBWRITERULE
          Per default we allow histroy reading and writing.
private static String DEFENABLEDFIELD
          The key to the enabled flag in the database.
private static String DEFFINISHEDFIELD
          The key to the finished timestamp in the database.
private static String DEFOBJECTNAMEFIELD
          The key to the main object name in the database.
private static String DEFPROPOSALFIELD
          The key to the proposal id in the database.
private static String DEFSERIALFIELD
          The key to the dom-serial field.
private static String DEFSTARTEDFIELD
          The key to the first pick timestamp in the database.
private static String DEFSUBMITTEDFIELD
          The key to the submitted timestamp in the database.
private static String DEFTABLE
          The default table name.
private static String DEFTARGETNAMEFIELD
          The key to the unique target name in the database.
private static String DEFTELESCOPEFIELD
          The default target name field in the database
private static String DEFXMLFIELD
          The key to the xml-scii field.
private static String DEFXMLSTAMPFIELD
          The key to the timestamp the xml file was serialized.
private  PreparedStatement insert
          The prepared statement for inserting a new object description.
static String KEY_DBREADRULE
          If this is set to false, target history are only read.
static String KEY_DBWRITERULE
          If this is set to false, target history are only read.
static String KEY_ENABLEDFIELD
          The key to the enabled flag in the database.
static String KEY_FINISHEDFIELD
          The key to the finished timestamp in the database.
static String KEY_OBJECTNAMEFIELD
          The key to the main object name in the database.
static String KEY_PROPOSALFIELD
          The key to the proposal id in the database.
static String KEY_SERIALFIELD
          The key to the dom-serial field.
static String KEY_STARTEDFIELD
          The key to the first pick timestamp in the database.
static String KEY_SUBMITTEDFIELD
          The key to the submitted timestamp in the database.
static String KEY_TARGETNAMEFIELD
          The key to the unique target name in the database.
static String KEY_TELESCOPEFIELD
          The key to the target name in the database.
static String KEY_XMLFIELD
          The key to the xml-scii field.
static String KEY_XMLSTAMPFIELD
          The key to the timestamp the xml file was serialized.
 
Fields inherited from class mysql.AbstractSql
KEY_TABLE
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
TaskSql(Map<String,String> prop)
          Constructs a new task sql.
 
Method Summary
private  boolean createInsert()
          Tries to create a prepared statement for entering task data into the task table.
 boolean deleteTarget(TargetDefinition td)
          Deletes the target, tries sending mail to the user.
 boolean deleteTarget(TargetDefinition td, boolean mail)
          Deletes the target, possibly sending mail to the user
private  boolean enterTarget(String telid, ParsedTarget target, Document dom, int s0, long urlstamp, boolean mail)
           
 void exit()
          On exit we close our prepared statement, if it exists.
 Date getFinished(TargetDefinition target)
          Checks, if the target with the given name is finished.
 Date getStarted(TargetDefinition target)
          Checks, if the target with the given name is started.
private  Date getTimestamp(TargetDefinition td, String fieldname)
          Returns the time stamp of the xml field.
 Date getXmlTime(TargetDefinition target)
          Returns the value of the finished timestamp or -1 if target is not finished.
 ParsedTarget newTarget(String telid, File xml)
          Reads a new target from a resource, serializes it into the database and sets all fields to according values.
 ParsedTarget newTarget(String telid, URL xml, long urlstamp, int s0)
          Reads a new target from a resource, serializes it into the database and sets all fields to according values.
 ParsedTarget newTarget(String telid, URL xml, long urlstamp, int s0, boolean sendmail)
          Reads a new target from a resource, serializes it into the database and sets all fields to according values.
 Map<String,ParsedTarget> retrieve(String telescope, Collection<String> names)
          Retrieves the collection of targets given by their name.
private  void sendAndWait(Mailer gmail, javax.mail.Address from, javax.mail.Address[] user, javax.mail.Address[] cc, javax.mail.Address[] bcc, String subj, String text)
           
 boolean setEnabled(TargetDefinition td, boolean nuen)
          Sets the enabled flag of the stated target.
 boolean setEnabled(TargetDefinition td, boolean nuen, boolean mail)
          Sets the enabled flag of the stated target.
 boolean setFinished(TargetDefinition target, Date now)
          Sets the finished timestamp to the value submitted in the date field, if a task entry for the target with the given name exists.
 boolean setStarted(TargetDefinition target, Date now)
          Sets the started timestamp to the value submitted in the date field, if a task entry for the target with the given name exists.
private  boolean setTimestamp(TargetDefinition target, String field, Date now)
          Sets a timestamp using the provided target definition in the named field.
 boolean updateTarget(String telid, File xml)
          Reads a new target from a resource, serializes it into the database and sets all fields to according values.
 boolean updateTarget(String telid, File xml, boolean mailit)
           
 boolean updateTarget(String telid, File xml, boolean mailit, boolean force)
          Reads a new target from a resource, serializes it into the database and sets all fields to according values.
 boolean updateTarget(String telid, URL xml, long urlstamp, int s0)
          Reads a new target from a resource, serializes it into the database and sets all fields to according values.
 boolean updateTarget(String telid, URL xml, long urlstamp, int s0, boolean mailit, boolean force)
          Reads a new target from a resource, serializes it into the database and sets all fields to according values.
 
Methods inherited from class mysql.AbstractSql
getPassword, getTable, getUserName, init, isEntry
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 

Field Detail

KEY_TARGETNAMEFIELD

public static final String KEY_TARGETNAMEFIELD
The key to the unique target name in the database.

See Also:
Constant Field Values

KEY_OBJECTNAMEFIELD

public static final String KEY_OBJECTNAMEFIELD
The key to the main object name in the database.

See Also:
Constant Field Values

KEY_PROPOSALFIELD

public static final String KEY_PROPOSALFIELD
The key to the proposal id in the database.

See Also:
Constant Field Values

KEY_ENABLEDFIELD

public static final String KEY_ENABLEDFIELD
The key to the enabled flag in the database.

See Also:
Constant Field Values

KEY_SUBMITTEDFIELD

public static final String KEY_SUBMITTEDFIELD
The key to the submitted timestamp in the database.

See Also:
Constant Field Values

KEY_STARTEDFIELD

public static final String KEY_STARTEDFIELD
The key to the first pick timestamp in the database.

See Also:
Constant Field Values

KEY_FINISHEDFIELD

public static final String KEY_FINISHEDFIELD
The key to the finished timestamp in the database.

See Also:
Constant Field Values

KEY_XMLSTAMPFIELD

public static final String KEY_XMLSTAMPFIELD
The key to the timestamp the xml file was serialized.

See Also:
Constant Field Values

KEY_XMLFIELD

public static final String KEY_XMLFIELD
The key to the xml-scii field.

See Also:
Constant Field Values

KEY_SERIALFIELD

public static final String KEY_SERIALFIELD
The key to the dom-serial field.

See Also:
Constant Field Values

KEY_TELESCOPEFIELD

public static final String KEY_TELESCOPEFIELD
The key to the target name in the database.

See Also:
Constant Field Values

KEY_DBREADRULE

public static final String KEY_DBREADRULE
If this is set to false, target history are only read.

See Also:
Constant Field Values

KEY_DBWRITERULE

public static final String KEY_DBWRITERULE
If this is set to false, target history are only read.

See Also:
Constant Field Values

DEFTABLE

private static final String DEFTABLE
The default table name.

See Also:
Constant Field Values

DEFTARGETNAMEFIELD

private static final String DEFTARGETNAMEFIELD
The key to the unique target name in the database.

See Also:
Constant Field Values

DEFOBJECTNAMEFIELD

private static final String DEFOBJECTNAMEFIELD
The key to the main object name in the database.

See Also:
Constant Field Values

DEFPROPOSALFIELD

private static final String DEFPROPOSALFIELD
The key to the proposal id in the database.

See Also:
Constant Field Values

DEFENABLEDFIELD

private static final String DEFENABLEDFIELD
The key to the enabled flag in the database.

See Also:
Constant Field Values

DEFSUBMITTEDFIELD

private static final String DEFSUBMITTEDFIELD
The key to the submitted timestamp in the database.

See Also:
Constant Field Values

DEFSTARTEDFIELD

private static final String DEFSTARTEDFIELD
The key to the first pick timestamp in the database.

See Also:
Constant Field Values

DEFFINISHEDFIELD

private static final String DEFFINISHEDFIELD
The key to the finished timestamp in the database.

See Also:
Constant Field Values

DEFXMLSTAMPFIELD

private static final String DEFXMLSTAMPFIELD
The key to the timestamp the xml file was serialized.

See Also:
Constant Field Values

DEFXMLFIELD

private static final String DEFXMLFIELD
The key to the xml-scii field.

See Also:
Constant Field Values

DEFSERIALFIELD

private static final String DEFSERIALFIELD
The key to the dom-serial field.

See Also:
Constant Field Values

DEFTELESCOPEFIELD

private static final String DEFTELESCOPEFIELD
The default target name field in the database

See Also:
Constant Field Values

DEFDBREADRULE

private static final boolean DEFDBREADRULE
Per default we allow histroy reading and writing.

See Also:
Constant Field Values

DEFDBWRITERULE

private static final boolean DEFDBWRITERULE
Per default we allow histroy reading and writing.

See Also:
Constant Field Values

insert

private PreparedStatement insert
The prepared statement for inserting a new object description.

Constructor Detail

TaskSql

public TaskSql(Map<String,String> prop)
Constructs a new task sql.

Method Detail

exit

public void exit()
On exit we close our prepared statement, if it exists.

Specified by:
exit in interface ExitCleaning

retrieve

public Map<String,ParsedTarget> retrieve(String telescope,
                                         Collection<String> names)
Retrieves the collection of targets given by their name. If the collection of names is null, all targets that are in the database are returned. This method only retrieves the target-task definition, to get schedulable targets, the observational history of the target should be filled in from a HistorySql.

Returns:
A mapping of unique target names to ParsedTargets without history.

getFinished

public Date getFinished(TargetDefinition target)
Checks, if the target with the given name is finished. This is true, if a task-entry exists with the name of the specified target, and if this entry has a non-null finished field. If database retrieval fails, we consider the taret as not finished.


setFinished

public boolean setFinished(TargetDefinition target,
                           Date now)
Sets the finished timestamp to the value submitted in the date field, if a task entry for the target with the given name exists.


getStarted

public Date getStarted(TargetDefinition target)
Checks, if the target with the given name is started. This is true, if a task-entry exists with the name of the specified target, and if this entry has a non-null started field. If database retrieval fails, we consider the target as not started.


setStarted

public boolean setStarted(TargetDefinition target,
                          Date now)
Sets the started timestamp to the value submitted in the date field, if a task entry for the target with the given name exists.


getXmlTime

public Date getXmlTime(TargetDefinition target)
Returns the value of the finished timestamp or -1 if target is not finished.


deleteTarget

public boolean deleteTarget(TargetDefinition td)
Deletes the target, tries sending mail to the user.


deleteTarget

public boolean deleteTarget(TargetDefinition td,
                            boolean mail)
Deletes the target, possibly sending mail to the user


setEnabled

public boolean setEnabled(TargetDefinition td,
                          boolean nuen)
Sets the enabled flag of the stated target. Database flags overrule target-definition flags in case of reloads. Does not send mail.


setEnabled

public boolean setEnabled(TargetDefinition td,
                          boolean nuen,
                          boolean mail)
Sets the enabled flag of the stated target. Database flags overrule target-definition flags in case of reloads.


updateTarget

public boolean updateTarget(String telid,
                            File xml)
Reads a new target from a resource, serializes it into the database and sets all fields to according values.


updateTarget

public boolean updateTarget(String telid,
                            File xml,
                            boolean mailit)

updateTarget

public boolean updateTarget(String telid,
                            File xml,
                            boolean mailit,
                            boolean force)
Reads a new target from a resource, serializes it into the database and sets all fields to according values.


updateTarget

public boolean updateTarget(String telid,
                            URL xml,
                            long urlstamp,
                            int s0)
Reads a new target from a resource, serializes it into the database and sets all fields to according values.


updateTarget

public boolean updateTarget(String telid,
                            URL xml,
                            long urlstamp,
                            int s0,
                            boolean mailit,
                            boolean force)
Reads a new target from a resource, serializes it into the database and sets all fields to according values.


newTarget

public ParsedTarget newTarget(String telid,
                              File xml)
Reads a new target from a resource, serializes it into the database and sets all fields to according values. Sends mail to the user.


newTarget

public ParsedTarget newTarget(String telid,
                              URL xml,
                              long urlstamp,
                              int s0)
Reads a new target from a resource, serializes it into the database and sets all fields to according values. Sends mail to the user.


newTarget

public ParsedTarget newTarget(String telid,
                              URL xml,
                              long urlstamp,
                              int s0,
                              boolean sendmail)
Reads a new target from a resource, serializes it into the database and sets all fields to according values. Sends mail to the user.


enterTarget

private boolean enterTarget(String telid,
                            ParsedTarget target,
                            Document dom,
                            int s0,
                            long urlstamp,
                            boolean mail)

sendAndWait

private void sendAndWait(Mailer gmail,
                         javax.mail.Address from,
                         javax.mail.Address[] user,
                         javax.mail.Address[] cc,
                         javax.mail.Address[] bcc,
                         String subj,
                         String text)

setTimestamp

private boolean setTimestamp(TargetDefinition target,
                             String field,
                             Date now)
Sets a timestamp using the provided target definition in the named field.


getTimestamp

private Date getTimestamp(TargetDefinition td,
                          String fieldname)
Returns the time stamp of the xml field. This is the time the serialized version of the target has been produced.


createInsert

private boolean createInsert()
Tries to create a prepared statement for entering task data into the task table. We use this several time during the life-time of the VM. The order is fixed (use the index given in paranthesis): Does not throw exception, but returns false, if the prepared statement could not be created.