private File generateNewFile(File sourceFile, java.io.File file, FileType fileType, Connection dbConnection) throws SQLException {
		long size = file.length(); // size of file in bytes
		Timestamp currentTimestamp = new Timestamp(System.currentTimeMillis());
		PreparedStatement s = dbConnection.prepareStatement("INSERT INTO files (in_use,created_at,updated_at,size,file_type_id,source_file_id,heartbeat,process_state) VALUES(0,?,?,?,?,?,?,1)", Statement.RETURN_GENERATED_KEYS);
		s.setTimestamp(1, currentTimestamp);
		s.setTimestamp(2, currentTimestamp);
		s.setLong(3, size);
		s.setInt(4, fileType.getObj().getId());
		s.setInt(5, sourceFile.getId());
		// so that nothing else will pick up this file and it can be registered with the heartbeat manager immediately
		s.setTimestamp(6, currentTimestamp);
		while(true) {
			int numAttempts = 0;
			try {
				if (s.executeUpdate() != 1) {
					s.close();
					logger.warn("Error occurred when creating database entry for a file.");
					return null;
				}
				else {
					break;
				}
			}
			catch(MySQLTransactionRollbackException e) {
				// http://stackoverflow.com/a/17748793/1048589 and http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html
				if (++numAttempts >= 3) {
					// if this has failed 3 times then abort by rethrowing the exception.
					s.close();
					throw(e);
				}
				e.printStackTrace();
				logger.warn("Mysql deadlock occurred. Retrying.");
			}
		}
		
		ResultSet generatedKeys = s.getGeneratedKeys();
		generatedKeys.next();
		int id = generatedKeys.getInt(1);
		s.close();
		return new File(id, null, size, fileType.getObj());
	}