FileDocCategorySizeDatePackage
LoadMovies.javaAPI DocExample1978Wed Dec 25 16:21:44 GMT 2002com.mediamania.prototype

LoadMovies

public class LoadMovies extends com.mediamania.MediaManiaApp

Fields Summary
private BufferedReader
reader
Constructors Summary
public LoadMovies(String filename)

        try {
            FileReader fr = new FileReader(filename);
            reader = new BufferedReader(fr);
        } catch(Exception e){
            System.err.print("Unable to open input file ");
            System.err.println(filename);
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    
Methods Summary
public voidexecute()

        try {
            while( reader.ready() ){
                String line = reader.readLine();
                parseMovieData(line);
            }
        } catch(java.io.IOException e){
            System.err.println("Exception reading input file");
            System.err.println(e);
        }
    
public static voidmain(java.lang.String[] args)

        LoadMovies loadMovies = new LoadMovies(args[0]);
        loadMovies.executeTransaction();
    
public voidparseMovieData(java.lang.String line)

        StringTokenizer tokenizer = new StringTokenizer(line, ";");
        String title = tokenizer.nextToken();
        String dateStr = tokenizer.nextToken();
        Date releaseDate = Movie.parseReleaseDate(dateStr);
        int runningTime = 0;
        try {
            runningTime = Integer.parseInt(tokenizer.nextToken());
        } catch(java.lang.NumberFormatException e){
            System.err.print("Exception parsing running time for ");
            System.err.println(title);
        }
        String rating = tokenizer.nextToken();
        String genres = tokenizer.nextToken();
        Movie movie = new Movie(title, releaseDate, runningTime, rating,genres);
        pm.makePersistent(movie);