/** * Creates a timestamp tracker object for persisting the currently extracted timestamp. * * @return The timestamp tracker. */ private TimestampTracker getTimestampTracker() { return new TimestampTracker(TSTAMP_FILE, TSTAMP_NEW_FILE); }
timestampTracker = new TimestampTracker( new File(workingDirectory, TSTAMP_FILE), new File(workingDirectory, TSTAMP_NEW_FILE) currentTime = timestampTracker.getTime(); timestampTracker.setTime(currentTime);
/** * Initializes a working directory. */ private void initializeDirectory() { File configFile; File timestampFile; File newTimestampFile; ResourceFileManager resourceFileManager; // Instantiate utility objects. resourceFileManager = new ResourceFileManager(); // Build file objects from file names. configFile = new File(workingDirectory, CONFIG_FILE_NAME); timestampFile = new File(workingDirectory, TSTAMP_FILE_NAME); newTimestampFile = new File(workingDirectory, TSTAMP_NEW_FILE_NAME); if (configFile.exists()) { throw new OsmosisRuntimeException("Config file " + CONFIG_FILE_NAME + " already exists."); } resourceFileManager.copyResourceToFile(getClass(), CONFIG_RESOURCE, configFile); if (timestampFile.exists()) { throw new OsmosisRuntimeException("Timestamp file " + TSTAMP_FILE_NAME + " already exists."); } new TimestampTracker(timestampFile, newTimestampFile).setTime(initialDate); }
/** * Provides information about the state of the current working directory. */ private void infoCommand() { Configuration configuration; TimestampTracker timestampTracker; configuration = getConfiguration(); timestampTracker = getTimestampTracker(); System.out.println("Configuration"); System.out.println("\thost: " + configuration.getHost()); System.out.println("\tdatabase: " + configuration.getDatabase()); System.out.println("\tuser: " + configuration.getUser()); System.out.println("\tpassword: " + configuration.getPassword()); System.out.println("\tdb: " + configuration.getDbType()); System.out.println("\tintervalLength: " + configuration.getIntervalLength()); System.out.println("\tlagLength: " + configuration.getLagLength()); System.out.println("\tchangeSetBeginFormat: " + configuration.getChangeFileBeginFormat()); System.out.println("\tchangeSetEndFormat: " + configuration.getChangeFileEndFormat()); System.out.println(); System.out.println("Data"); System.out.println("\tCurrent Timestamp: " + timestampTracker.getTime()); }
/** * Initialises the current working directory. * * @param args * The input arguments. * @param initialArgIndex * The current offset into the arguments. */ private void initializeCommand(String[] args, int initialArgIndex) { int currentArgIndex; Date initialExtractDate; ResourceFileManager resourceFileManager; // Get the command line arguments. currentArgIndex = initialArgIndex; initialExtractDate = getDateArgument(args, currentArgIndex++); if (CONFIG_FILE.exists()) { throw new OsmosisRuntimeException("Config file " + CONFIG_FILE + " already exists."); } resourceFileManager = new ResourceFileManager(); resourceFileManager.copyResourceToFile(getClass(), CONFIG_RESOURCE, CONFIG_FILE); if (!DATA_DIR.exists()) { if (!DATA_DIR.mkdir()) { throw new OsmosisRuntimeException("Unable to create directory " + DATA_DIR); } } if (TSTAMP_FILE.exists()) { throw new OsmosisRuntimeException("Extract timestamp file " + TSTAMP_FILE + " already exists."); } getTimestampTracker().setTime(initialExtractDate); }
/** * Update the stored time. * * @param time * The time to set. */ public void setTime(Date time) { try (BufferedWriter writer = new BufferedWriter(new FileWriter(newTimestampFile))) { writer.write(dateFormatter.format(time)); } catch (IOException e) { throw new OsmosisRuntimeException( "Unable to write the time to temporary file " + newTimestampFile + ".", e); } renameNewFileToCurrent(); } }
timestampTracker = new TimestampTracker( new File(workingDirectory, TSTAMP_FILE), new File(workingDirectory, TSTAMP_NEW_FILE) currentTime = timestampTracker.getTime(); timestampTracker.setTime(currentTime);
/** * Initializes a working directory. */ private void initializeDirectory() { File configFile; File timestampFile; File newTimestampFile; ResourceFileManager resourceFileManager; // Instantiate utility objects. resourceFileManager = new ResourceFileManager(); // Build file objects from file names. configFile = new File(workingDirectory, CONFIG_FILE_NAME); timestampFile = new File(workingDirectory, TSTAMP_FILE_NAME); newTimestampFile = new File(workingDirectory, TSTAMP_NEW_FILE_NAME); if (configFile.exists()) { throw new OsmosisRuntimeException("Config file " + CONFIG_FILE_NAME + " already exists."); } resourceFileManager.copyResourceToFile(getClass(), CONFIG_RESOURCE, configFile); if (timestampFile.exists()) { throw new OsmosisRuntimeException("Timestamp file " + TSTAMP_FILE_NAME + " already exists."); } new TimestampTracker(timestampFile, newTimestampFile).setTime(initialDate); }
/** * Update the stored time. * * @param time * The time to set. */ public void setTime(Date time) { try (BufferedWriter writer = new BufferedWriter(new FileWriter(newTimestampFile))) { writer.write(dateFormatter.format(time)); } catch (IOException e) { throw new OsmosisRuntimeException( "Unable to write the time to temporary file " + newTimestampFile + ".", e); } renameNewFileToCurrent(); } }
/** * Creates a timestamp tracker object for persisting the currently extracted timestamp into the * data directory for consumers to download. * * @return The timestamp tracker. */ private TimestampTracker getDataTimestampSetter() { return new TimestampTracker(DATA_TSTAMP_FILE, DATA_TSTAMP_NEW_FILE); }