stella.sql
Class TargetDatabase

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by mysql.AbstractSql
                  extended by stella.sql.TargetDatabase
All Implemented Interfaces:
Cloneable, HistoryProviding, TargetProviding<ParsedTarget>, TargetQuickProviding<ParsedTarget>, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying

public class TargetDatabase
extends AbstractSql
implements TargetQuickProviding<ParsedTarget>, HistoryProviding

A database provider roams through a sql database to load STELLA targets. The table used is a TaskSql, a TargetSql contains information of astronomical targets, i.e. stars.


Nested Class Summary
static class TargetDatabase.Listing
          Test class for changing from target list to target database.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  Map<String,ParsedTarget> active
          My parsed collection of active targets, available after init.
private  Map<String,ParsedTarget> all
          Names to targets for all targets, available after init.
private static boolean DEFCONSISTENCY
          On default, we do not check for consistency.
private static boolean DEFREMOVEDAUGHTERS
          On default, we remove all resolved daughters from the selectable list.
private static boolean DEFREMOVESUCCESSOR
          On default, we remove successors from the selectable list.
private  Map<String,ParsedTarget> finished
          My parsed collection of finished targets, available after init.
private  HistorySql histsql
          The history table for reconstructing the obs.
static String KEY_CONSISTENCY
          If true check for database consitency.
static String KEY_HISTORYDB
          If present, the properties of the history database.
static String KEY_PROPOSALDB
          If present, the properties of the proposal database.
static String KEY_REMOVEDAUGHTERS
          If true, remove resolved daughters.
static String KEY_REMOVEFILE
          The key to the ascii-file of unwanted targets.
static String KEY_REMOVELIST
          The key to the comma-list of unwanted targets.
static String KEY_REMOVESUCCESSOR
          If true, remove resolved daughters.
static String KEY_STELLA
          The telescope we work on.
static String KEY_TARGETDB
          If present, the properties of the target database.
static String KEY_TASKDB
          If present, the properties of the task database.
private  ProposalSql propsql
          The task sql we drain the targets from.
private  TargetSql starsql
          The target sql we drain the ra/de of stars from.
private  TaskSql tasksql
          The task sql we drain the targets from.
 
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 stella.TargetProviding
SERIAL, XML
 
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
TargetDatabase(Map<String,String> sprop)
          Constructs a new target database provider.
 
Method Summary
 boolean addTarget(ParsedTarget dom)
          Adds a new target to this provider.
 void clear()
          Empties the targets hash map.
 Collection<ParsedTarget> getActiveTargets()
          Returns all active targets.
 Collection<ParsedTarget> getAllTargets()
          Returns all targets known to this provider.
 Collection<ParsedTarget> getCompletedTargets()
          Parsed Targets provide a complete flag.
 ParsedTarget getFromActive(String name)
          Returns a set of all target names.
 ParsedTarget getFromAll(String name)
          Returns a set of all target names.
 HistorySql getHistorySql()
          Access to the history database.
 void init()
          The init section.
 Map<String,StarDescription> mapToStars()
          If only a linking of target names to main stars is needed, try this method, it is much faster.
 Map<String,String> mapToUsers()
          If only access to target names vs.
private  boolean removeFrom(Map<String,ParsedTarget> map, ParsedTarget dom)
          Removes the specified target from the table.
 boolean removeTarget(ParsedTarget dom)
          Removes the target-defining DOM from the scheduler, classified by its name.
 boolean restore()
          Restores all targets.
private  boolean restoreTargets()
          Restores all targets.
private static void trimHistory(List<? extends HistoryAware.Pick> history, long notlater)
          Trimming the histroy means removing any pick that is later than the stated day.
 
Methods inherited from class mysql.AbstractSql
getPassword, getTable, getUserName, 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_REMOVELIST

public static final String KEY_REMOVELIST
The key to the comma-list of unwanted targets.

See Also:
Constant Field Values

KEY_REMOVEFILE

public static final String KEY_REMOVEFILE
The key to the ascii-file of unwanted targets.

See Also:
Constant Field Values

KEY_REMOVEDAUGHTERS

public static final String KEY_REMOVEDAUGHTERS
If true, remove resolved daughters.

See Also:
Constant Field Values

KEY_REMOVESUCCESSOR

public static final String KEY_REMOVESUCCESSOR
If true, remove resolved daughters.

See Also:
Constant Field Values

KEY_CONSISTENCY

public static final String KEY_CONSISTENCY
If true check for database consitency. Only useful on write-hosts.

See Also:
Constant Field Values

KEY_STELLA

public static final String KEY_STELLA
The telescope we work on.

See Also:
Constant Field Values

KEY_HISTORYDB

public static final String KEY_HISTORYDB
If present, the properties of the history database.

See Also:
Constant Field Values

KEY_TASKDB

public static final String KEY_TASKDB
If present, the properties of the task database.

See Also:
Constant Field Values

KEY_TARGETDB

public static final String KEY_TARGETDB
If present, the properties of the target database.

See Also:
Constant Field Values

KEY_PROPOSALDB

public static final String KEY_PROPOSALDB
If present, the properties of the proposal database.

See Also:
Constant Field Values

DEFREMOVEDAUGHTERS

private static final boolean DEFREMOVEDAUGHTERS
On default, we remove all resolved daughters from the selectable list.

See Also:
Constant Field Values

DEFREMOVESUCCESSOR

private static final boolean DEFREMOVESUCCESSOR
On default, we remove successors from the selectable list.

See Also:
Constant Field Values

DEFCONSISTENCY

private static final boolean DEFCONSISTENCY
On default, we do not check for consistency.

See Also:
Constant Field Values

tasksql

private TaskSql tasksql
The task sql we drain the targets from.


propsql

private ProposalSql propsql
The task sql we drain the targets from.


starsql

private TargetSql starsql
The target sql we drain the ra/de of stars from.


histsql

private HistorySql histsql
The history table for reconstructing the obs. history.


all

private Map<String,ParsedTarget> all
Names to targets for all targets, available after init.


active

private Map<String,ParsedTarget> active
My parsed collection of active targets, available after init.


finished

private Map<String,ParsedTarget> finished
My parsed collection of finished targets, available after init.

Constructor Detail

TargetDatabase

public TargetDatabase(Map<String,String> sprop)
Constructs a new target database provider. The resources are defaulted. Target loading and parsing is deferred to the init() section.

Method Detail

init

public void init()
The init section. If the #KEY_TARGETFILE is set, the target list is searched, read and passed to the #resolveFileTargets method.

Specified by:
init in interface Initializable
Overrides:
init in class AbstractSql

restore

public boolean restore()
Restores all targets. First, the db is queried for all entries. These are stored in the all Collection. The active targets start with a copy of all. After that, the non-enabled targets as well as the finished targets (i.e. those with a non-null finished date) are removed, the latter stored in finished. If the KEY_REMOVEDAUGHTERS key points to true, all resolved daughters are removed from the active list. Finally, if either of the KEY_REMOVELIST or KEY_REMOVEFILE properties is given, the targets with these names are removed from the active targets. Finally, if the KEY_CONSISTENCY trigger is set, all restored targets are checked for their consistency.

Specified by:
restore in interface TargetProviding<ParsedTarget>

getHistorySql

public HistorySql getHistorySql()
Access to the history database.

Specified by:
getHistorySql in interface HistoryProviding

restoreTargets

private boolean restoreTargets()
Restores all targets. First, the db is queried for all entries. These are stored in the all Collection. The active targets start with a copy of all. After that, the non-enabled targets as well as the finished targets (i.e. those with a non-null finished date) are removed, the latter stored in finished. If the KEY_REMOVEDAUGHTERS key points to true, all resolved daughters are removed from the active list. Finally, if either of the KEY_REMOVELIST or KEY_REMOVEFILE properties is given, the targets with these names are removed from the active targets.


getCompletedTargets

public Collection<ParsedTarget> getCompletedTargets()
Parsed Targets provide a complete flag.

Specified by:
getCompletedTargets in interface TargetProviding<ParsedTarget>
See Also:
HistoryAware, Appointable

getAllTargets

public Collection<ParsedTarget> getAllTargets()
Description copied from interface: TargetProviding
Returns all targets known to this provider.

Specified by:
getAllTargets in interface TargetProviding<ParsedTarget>

getActiveTargets

public Collection<ParsedTarget> getActiveTargets()
Description copied from interface: TargetProviding
Returns all active targets. These are the targets that take part in a scheduling process. br> This collection must be contained in the TargetProviding.getAllTargets().

Specified by:
getActiveTargets in interface TargetProviding<ParsedTarget>

trimHistory

private static final void trimHistory(List<? extends HistoryAware.Pick> history,
                                      long notlater)
Trimming the histroy means removing any pick that is later than the stated day. Used in simulators to re-do a night.


addTarget

public boolean addTarget(ParsedTarget dom)
Adds a new target to this provider. If the target allows database access, its history is read in. Children are resolved, if needed. The target is copied also to the finished list, if finished and to the active list, if not finished and enabled. The ignore-for-resolved is ignored, as well as a remove list.

The target is added to the database, if the consistency flag is set

Specified by:
addTarget in interface TargetProviding<ParsedTarget>
Returns:
True, if adding was successful.

removeTarget

public boolean removeTarget(ParsedTarget dom)
Removes the target-defining DOM from the scheduler, classified by its name. The target is physically removed and must be re-parsed from the target-definition file if re-added.

Specified by:
removeTarget in interface TargetProviding<ParsedTarget>
Returns:
True, if target was present in at least one list.

clear

public void clear()
Empties the targets hash map. All parsed information is lost. Additionally, adding targets after a call to this method may require re-hashing.

Specified by:
clear in interface TargetProviding<ParsedTarget>

getFromAll

public ParsedTarget getFromAll(String name)
Returns a set of all target names. If no targets are stored within this scheduler null is returned, instead of an empty set. Note that the returned set is backed by the targets' hash map.

Specified by:
getFromAll in interface TargetProviding<ParsedTarget>

getFromActive

public ParsedTarget getFromActive(String name)
Returns a set of all target names. If no targets are stored within this scheduler null is returned, instead of an empty set. Note that the returned set is backed by the targets' hash map.

Specified by:
getFromActive in interface TargetProviding<ParsedTarget>

mapToUsers

public Map<String,String> mapToUsers()
If only access to target names vs. user names is required, we do a single lookup, not retrieving all data from the db.

Specified by:
mapToUsers in interface TargetQuickProviding<ParsedTarget>

mapToStars

public Map<String,StarDescription> mapToStars()
If only a linking of target names to main stars is needed, try this method, it is much faster.

Specified by:
mapToStars in interface TargetQuickProviding<ParsedTarget>

removeFrom

private boolean removeFrom(Map<String,ParsedTarget> map,
                           ParsedTarget dom)
Removes the specified target from the table. Returns true, if it was present. No synch on map.