net.sf.xtvdclient.xtvd.parser
Class RDBMSParser

java.lang.Object
  extended by net.sf.xtvdclient.xtvd.parser.AbstractParser
      extended by net.sf.xtvdclient.xtvd.parser.RDBMSParser
All Implemented Interfaces:
Parser

public class RDBMSParser
extends AbstractParser

A parser implementation that is used to parse the specified XML stream, and then write the data to a relational database.

Since:
ddclient version 1.4

Field Summary
static java.lang.String CREW_STATEMENT
          The parametrised statement that is to be executed for inserting crew records to the crew table.
static java.lang.String GENRE_STATEMENT
          The parametrised statement that is to be executed for inserting programGenre records to the program_genre table.
static java.lang.String LINEUP_STATEMENT
          The parametrised statement that is to be executed for inserting lineup records to the lineups table.
static java.lang.String MAP_STATEMENT
          The parametrised statement that is to be executed for inserting map records to the lineup_map table.
static java.lang.String PROGRAM_MOVIE_ADVISORY_STATEMENT
          The parametrised statement that is to be executed for inserting program advisories records to the program_movie_advisories intersection table.
static java.lang.String PROGRAM_STATEMENT
          The parametrised statement that is to be executed for inserting program records to the programs table.
static java.lang.String SCHEDULE_STATEMENT
          The parametrised statement that is to be executed for inserting schedule records to the schedules table.
static java.lang.String STATION_STATEMENT
          The parametrised statement that is to be executed for inserting station records to the stations table.
 
Fields inherited from class net.sf.xtvdclient.xtvd.parser.AbstractParser
log, reader, sdf
 
Fields inherited from interface net.sf.xtvdclient.xtvd.parser.Parser
END_OF_LINE
 
Constructor Summary
protected RDBMSParser(java.io.Reader in, java.sql.Connection connection)
          Create a new instance of the parser that reads the data from the specified Reader and writes to the database using the specified Connection.
 
Method Summary
protected  void closeStatement(java.sql.Statement statement)
          Close the specified statement and the batch of statements associated with it.
protected  void parseGenres()
          Parse the genres top-level element from the AbstractParser.reader, and populate the program_genres table with the data.
protected  void parseLineups()
          Parse the lineups top-level element from the AbstractParser.reader, and write the parsed data to the lineups and lineup_map tables.
protected  void parseProductionCrew()
          Parse the productionCrew top-level element from the AbstractParser.reader, and populate the crew table with the data.
protected  void parsePrograms()
          Parse the programs top-level element from the AbstractParser.reader and write the parsed data to the programs table.
protected  void parseSchedules()
          Parse the schedules top-level element from the AbstractParser.reader, and write the parsed data to the schedules table.
protected  void parseStations()
          Parse an individual station record from the AbstractParser.reader, and write the parsed data to the stations table.
 void parseXTVD()
          Read the xml data from the AbstractParser.reader, parse the XTVD document and populate the #xtvd class fields.
 
Methods inherited from class net.sf.xtvdclient.xtvd.parser.AbstractParser
getCrew, getCrew, getGenre, getGenre, getLineup, getLineup, getLog, getMap, getMap, getMember, getMember, getMessages, getPart, getPart, getProgram, getProgram, getProgramGenre, getProgramGenre, getSchedule, getSchedule, getStation, getStation, setLog, toStartTag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATION_STATEMENT

public static final java.lang.String STATION_STATEMENT
The parametrised statement that is to be executed for inserting station records to the stations table.

"insert into stations columns( id, call_sign, name, affiliate, fcc_channel_number ) values( ?, ?, ?, ?, ? )"

See Also:
Constant Field Values

LINEUP_STATEMENT

public static final java.lang.String LINEUP_STATEMENT
The parametrised statement that is to be executed for inserting lineup records to the lineups table.

"insert into lineups columns( id, name, location, type, device, postalCode ) values( ?, ?, ?, ?, ?, ? )"

See Also:
Constant Field Values

MAP_STATEMENT

public static final java.lang.String MAP_STATEMENT
The parametrised statement that is to be executed for inserting map records to the lineup_map table.

"insert into lineup_map columns( lineup, station, channel, channel_minor, from, to ) values( ?, ?, ?, ?, ?, ? )"

See Also:
Constant Field Values

SCHEDULE_STATEMENT

public static final java.lang.String SCHEDULE_STATEMENT
The parametrised statement that is to be executed for inserting schedule records to the schedules table.

"insert into schedules columns( program, station, time, duration, tv_rating, repeat, stereo, subtitled, hdtv, close_captioned, part_number, part_total ) values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"

See Also:
Constant Field Values

PROGRAM_STATEMENT

public static final java.lang.String PROGRAM_STATEMENT
The parametrised statement that is to be executed for inserting program records to the programs table.

"insert into programs columns( id, series, title, subtitle, description, mpaa_rating, star_rating, runtime, year, show_type, color_code, syn_epi_num, original_air_date ) values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"

See Also:
Constant Field Values

PROGRAM_MOVIE_ADVISORY_STATEMENT

public static final java.lang.String PROGRAM_MOVIE_ADVISORY_STATEMENT
The parametrised statement that is to be executed for inserting program advisories records to the program_movie_advisories intersection table.

"insert into program_movie_advisories columns( program, movie_advisory, ranking ) values( ?, ?, ? )"

See Also:
Constant Field Values

CREW_STATEMENT

public static final java.lang.String CREW_STATEMENT
The parametrised statement that is to be executed for inserting crew records to the crew table.

"insert into crew columns( program, role, given_name, surname ) values( ?, ?, ?, ? )"

See Also:
Constant Field Values

GENRE_STATEMENT

public static final java.lang.String GENRE_STATEMENT
The parametrised statement that is to be executed for inserting programGenre records to the program_genre table.

"insert into program_genre columns( program, genre, relevance ) values( ?, ?, ? )"

See Also:
Constant Field Values
Constructor Detail

RDBMSParser

protected RDBMSParser(java.io.Reader in,
                      java.sql.Connection connection)
               throws DataDirectException
Create a new instance of the parser that reads the data from the specified Reader and writes to the database using the specified Connection. Also set the autoCommit property for the connection to false.

Note: The connection reference set in the constructor will not be closed in this class. Calling classes should take care of closing the Connection.

Parameters:
Reader - in - The Reader from which the XML data is to be parsed. Make sure that the reader object has the character encoding properly set to UTF-8.
Connection - connection - The connection to be used.
Throws:
DataDirectException - - If errors are encountered while initialising the parser or reading the data.
Method Detail

parseXTVD

public void parseXTVD()
               throws DataDirectException
Read the xml data from the AbstractParser.reader, parse the XTVD document and populate the #xtvd class fields.

Specified by:
parseXTVD in interface Parser
Specified by:
parseXTVD in class AbstractParser
Throws:
DataDirectException - - If errors are encountered while parsing the XML data stream.
See Also:
#parseRootElement(), parseStations(), #getLineup(net.sf.xtvdclient.xtvd.Lineup), AbstractParser.getSchedule(net.sf.xtvdclient.xtvd.datatypes.Schedule), AbstractParser.getProgram(Program), #getCrew(net.sf.xtvdclient.xtvd.Crew), AbstractParser.getProgramGenre(net.sf.xtvdclient.xtvd.datatypes.ProgramGenre)

parseStations

protected void parseStations()
                      throws DataDirectException
Parse an individual station record from the AbstractParser.reader, and write the parsed data to the stations table. Adds each station record that is to be written as a batch entry to a PreparedStatement. The batch is executed after all the station records have been processed.

Throws:
DataDirectException - - If errors are encountered while reading or writing the XML data.
See Also:
AbstractParser.getStation()

parseLineups

protected void parseLineups()
                     throws DataDirectException
Parse the lineups top-level element from the AbstractParser.reader, and write the parsed data to the lineups and lineup_map tables.

Throws:
DataDirectException - - If errors are encountered while reading or writing the XML data.
See Also:
AbstractParser.getLineup()

parseSchedules

protected void parseSchedules()
                       throws DataDirectException
Parse the schedules top-level element from the AbstractParser.reader, and write the parsed data to the schedules table.

Note: The part_number and part_total columns will be populated with values of 0 if no data is available.

Throws:
DataDirectException - - If errors are encountered while reading or writing the XML data.
See Also:
AbstractParser.getSchedule()

parsePrograms

protected void parsePrograms()
                      throws DataDirectException
Parse the programs top-level element from the AbstractParser.reader and write the parsed data to the programs table.

Throws:
DataDirectException - - If errors are encountered while reading or writing the XML data.
See Also:
AbstractParser.getProgram()

parseProductionCrew

protected void parseProductionCrew()
                            throws DataDirectException
Parse the productionCrew top-level element from the AbstractParser.reader, and populate the crew table with the data.

Throws:
DataDirectException - - If errors are encountered while reading or writing the XML data.
See Also:
AbstractParser.getCrew()

parseGenres

protected void parseGenres()
                    throws DataDirectException
Parse the genres top-level element from the AbstractParser.reader, and populate the program_genres table with the data.

Throws:
DataDirectException - - If errors are encountered while reading or writing the XML data.
See Also:
AbstractParser.getProgramGenre()

closeStatement

protected void closeStatement(java.sql.Statement statement)
Close the specified statement and the batch of statements associated with it. Log any errors encountered while closing the statement or clearing the batch to AbstractParser.log.

Parameters:
Statement - statement - The Statement that is to be closed.