Changeset 278

Show
Ignore:
Timestamp:
03/14/06 13:37:12
Author:
douglm
Message:

Mostly speed and reliability enhancements:

Removed vtimezone field from org.bedework.calfacade.ifs.CalTimezones$TimezoneInfo?
It's already stored in the ical4j timezone object so the ref is unnecessary.

Made more SimpleDateFormat? objects static.

Added the jarred source of a slightly modified version of ical4j to the repository.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/appcommon/src/org/bedework/appcommon/CalendarInfo.java

    r31 r278  
    3232import java.text.DateFormat; 
    3333import java.text.FieldPosition; 
    34 import java.text.SimpleDateFormat; 
     34//import java.text.SimpleDateFormat; 
    3535import java.util.ArrayList; 
    3636import java.util.Calendar; 
     37import java.util.Date; 
    3738import java.util.Locale; 
    3839 
     
    9697     */ 
    9798 
    98     SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE", getLocale()); 
    99     SimpleDateFormat shortDayFormat = new SimpleDateFormat("E", getLocale()); 
     99//    SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE", getLocale()); 
     100//    SimpleDateFormat shortDayFormat = new SimpleDateFormat("E", getLocale()); 
    100101 
    101102    Calendar c = Calendar.getInstance(getLocale()); 
     
    119120      c.set(Calendar.DAY_OF_WEEK, i + 1); 
    120121 
    121       dayNames[i] = dayFormat.format(c.getTime()); 
    122       shortDayNames[i] = shortDayFormat.format(c.getTime()); 
     122      Date dt = c.getTime(); 
     123      dayNames[i] = DateTimeFormatter.getDayName(dt, getLocale()); 
     124      shortDayNames[i] = DateTimeFormatter.getShortDayName(dt, getLocale()); 
    123125      dow.add(dayNames[i]); 
    124126      sdow.add(shortDayNames[i]); 
  • trunk/calendar3/appcommon/src/org/bedework/appcommon/DateTimeFormatter.java

    r274 r278  
    6565import java.text.DateFormat; 
    6666import java.text.FieldPosition; 
     67import java.text.SimpleDateFormat; 
    6768import java.util.Calendar; 
     69import java.util.Date; 
    6870import java.util.GregorianCalendar; 
    6971import java.util.HashMap; 
     
    8789  /* What we store in the table */ 
    8890  private static class Formatters { 
     91    DateFormat dayFormatter; 
     92    DateFormat shortDayFormatter; 
     93     
    8994    DateFormat longDateFormatter; 
    9095    DateFormat shortDateFormatter; 
     
    9297     
    9398    Formatters(Locale loc) { 
     99      dayFormatter = new SimpleDateFormat("EEEE", loc); 
     100      shortDayFormatter = new SimpleDateFormat("E", loc); 
     101       
    94102      longDateFormatter = DateFormat.getDateInstance(DateFormat.LONG, loc); 
    95103      shortDateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, loc); 
     
    368376  } 
    369377 
     378  /**  Get a short String representation of the day represented by the parameter 
     379   * 
     380   * @param  val           Date 
     381   * @param  loc           Locale 
     382   * @return String        Short representation of the day 
     383   *                       represented by this object. 
     384   */ 
     385  public static String getShortDayName(Date val, Locale loc) { 
     386    Formatters fmt = getFormatters(loc); 
     387     
     388    synchronized (fmt) { 
     389      return fmt.shortDayFormatter.format(val); 
     390    } 
     391  } 
     392 
     393  /**  Get a String representation of the day represented by the parameter 
     394   * 
     395   * @param  val           Date 
     396   * @param  loc           Locale 
     397   * @return String        Representation of the day represented by this object. 
     398   */ 
     399  public static String getDayName(Date val, Locale loc) { 
     400    Formatters fmt = getFormatters(loc); 
     401     
     402    synchronized (fmt) { 
     403      return fmt.dayFormatter.format(val); 
     404    } 
     405  } 
     406 
    370407  /**  Get a short String representation of the date 
    371408   * 
     
    411448    return fmt; 
    412449  } 
     450 
     451  private static Formatters getFormatters(Locale loc) { 
     452    Formatters fmt = (Formatters)formattersTbl.get(loc); 
     453     
     454    if (fmt == null) { 
     455      fmt = new Formatters(loc); 
     456      formattersTbl.put(loc, fmt); 
     457    } 
     458     
     459    return fmt; 
     460  } 
    413461} 
  • trunk/calendar3/appcommon/src/org/bedework/appcommon/EventFormatter.java

    r251 r278  
    172172 
    173173  /** Get the event's ending date and time. If the value is a date only object 
    174    * we decrement the date by 1 day to comply with accepted practice - that i
     174   * we decrement the date by 1 day to comply with accepted practice - that is
    175175   * the displayed date for a 1 day event has the end date equal to the start. 
    176176   * 
  • trunk/calendar3/appcommon/src/org/bedework/appcommon/MyCalendarVO.java

    r251 r278  
    5353  private Calendar calendar; 
    5454 
    55   private static CalendarInfo calInfo; 
    56  
    57   private DateFormat isoformat = new SimpleDateFormat("yyyyMMdd"); 
     55  private static CalendarInfo calInfo; // XXX locale - should be table with locale as key 
     56 
     57  private static DateFormat isoformat = new SimpleDateFormat("yyyyMMdd"); 
    5858 
    5959  /** Create a MyCalendarVO object representing a particular date and time 
     
    344344   */ 
    345345  public String getDateDigits() { 
    346     return getFormattedDateString(isoformat); 
     346    synchronized (isoformat) { 
     347      return getFormattedDateString(isoformat); 
     348    } 
    347349  } 
    348350 
     
    540542   */ 
    541543  public boolean isSameDate(MyCalendarVO that) { 
    542     return getFormattedDateString(isoformat).equals( 
    543           that.getFormattedDateString(isoformat)); 
     544    synchronized (isoformat) { 
     545      return getFormattedDateString(isoformat).equals( 
     546            that.getFormattedDateString(isoformat)); 
     547    } 
    544548  } 
    545549 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalTimezonesImpl.java

    r191 r278  
    115115 
    116116    if (tzinfo == null) { 
    117       tzinfo = new TimezoneInfo(tz, vtz); 
     117      tzinfo = new TimezoneInfo(tz); 
    118118      timezones.put(tzid, tzinfo); 
    119119    } else { 
    120       tzinfo.init(tz, vtz); 
     120      tzinfo.init(tz); 
    121121    } 
    122122  } 
     
    136136      } 
    137137 
    138       tzinfo = new TimezoneInfo(new TimeZone(vTimeZone), vTimeZone); 
     138      tzinfo = new TimezoneInfo(new TimeZone(vTimeZone)); 
    139139      timezones.put(id, tzinfo); 
    140140    } 
     
    158158    TimezoneInfo tzinfo = lookup(id); 
    159159 
    160     if ((tzinfo != null) && (tzinfo.getVtz() != null)) { 
    161       return tzinfo.getVtz(); 
     160    if ((tzinfo != null) && (tzinfo.getTz().getVTimeZone() != null)) { 
     161      return tzinfo.getTz().getVTimeZone(); 
    162162    } 
    163163 
     
    167167    } 
    168168 
    169     tzinfo = new TimezoneInfo(new TimeZone(vTimeZone), vTimeZone); 
    170     timezones.put(id, tzinfo); 
     169    if (tzinfo != null) { 
     170      tzinfo.init(new TimeZone(vTimeZone)); 
     171    } else { 
     172      tzinfo = new TimezoneInfo(new TimeZone(vTimeZone)); 
     173      timezones.put(id, tzinfo); 
     174    } 
    171175 
    172176    return vTimeZone; 
     
    212216            } 
    213217 
    214             tzinfo = new TimezoneInfo(new TimeZone(vtz), vtz, true); 
     218            /* Don't save the vtimezone, there are a lot and it's a significant 
     219             * amount of space. We probably only look at 2-3 of them after this. 
     220             * The find timezone method will look it up again if requested and 
     221             * cache it at that point. 
     222             */ 
     223            tzinfo = new TimezoneInfo(new TimeZone(vtz), true); 
    215224            systemTimezones.put(btz.getTzid(), tzinfo); 
    216225          } 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/HibSession.java

    r257 r278  
    9191  /** Exception from this session. */ 
    9292  Throwable exc; 
     93   
     94  private SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd"); 
    9395 
    9496  /** Set up for a hibernate interaction. Throw the object away on exception. 
     
    475477    try { 
    476478      // Remove any time component 
    477       java.sql.Date dt = java.sql.Date.valueOf( 
    478           new SimpleDateFormat("yyyy-MM-dd").format(parVal)); 
    479       q.setDate(parName, dt); 
     479      synchronized (dateFormatter) { 
     480        q.setDate(parName, java.sql.Date.valueOf(dateFormatter.format(parVal))); 
     481      } 
    480482    } catch (Throwable t) { 
    481483      handleException(t); 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalTimezones.java

    r191 r278  
    8787    TimeZone tz; 
    8888 
    89     /* If tz was derived from a db object, this is the data */ 
    90     VTimeZone vtz; 
    91  
    9289    boolean publick; 
    9390     
    9491    /** 
    9592     * @param tz 
    96      * @param vtz 
    9793     */ 
    98     public TimezoneInfo(TimeZone tz, VTimeZone vtz) { 
    99       init(tz, vtz); 
     94    public TimezoneInfo(TimeZone tz) { 
     95      init(tz); 
    10096    } 
    10197     
     
    10399     *  
    104100     * @param tz 
    105      * @param vtz 
    106101     * @param publick 
    107102     */ 
    108     public TimezoneInfo(TimeZone tz, VTimeZone vtz, boolean publick) { 
    109       this.tz = tz; 
    110       this.vtz = vtz; 
     103    public TimezoneInfo(TimeZone tz, boolean publick) { 
     104      init(tz); 
    111105      this.publick = publick; 
    112106    } 
     
    117111     * @param vtz 
    118112     */ 
    119     public void init(TimeZone tz, VTimeZone vtz) { 
     113    public void init(TimeZone tz) { 
    120114      this.tz = tz; 
    121       this.vtz = vtz; 
    122115    } 
    123116     
    124117    public TimeZone getTz() { 
    125118      return tz; 
    126     } 
    127      
    128     public VTimeZone getVtz() { 
    129       return vtz; 
    130119    } 
    131120     
     
    186175     
    187176    if (tzinfo == null) { 
    188       tzinfo = new TimezoneInfo(timezone, null); 
     177      tzinfo = new TimezoneInfo(timezone); 
    189178      timezones.put(id, tzinfo); 
    190179    } else { 
  • trunk/calendar3/caldav/src/edu/rpi/cct/webdav/servlet/common/MethodBase.java

    r2 r278  
    110110  public abstract void init(); 
    111111 
     112  private SimpleDateFormat httpDateFormatter =  
     113      new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss "); 
     114 
    112115  /** 
    113116   * @param req 
     
    463466    } 
    464467 
    465     return new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss ").format(val) + "GMT"; 
     468    synchronized (httpDateFormatter) { 
     469      return httpDateFormatter.format(val) + "GMT"; 
     470    } 
    466471  } 
    467472 
  • trunk/calendar3/dumprestore/src/org/bedework/dumprestore/restore/TimezonesImpl.java

    r191 r278  
    134134 
    135135    if (tzinfo == null) { 
    136       tzinfo = new TimezoneInfo(tz, vtz); 
     136      tzinfo = new TimezoneInfo(tz); 
    137137      timezones.put(tzid, tzinfo); 
    138138    } else { 
    139       tzinfo.init(tz, vtz); 
     139      tzinfo.init(tz); 
    140140    } 
    141141  } 
     
    169169    TimezoneInfo tzinfo = lookup(id); 
    170170 
    171     if ((tzinfo != null) && (tzinfo.getVtz() != null)) { 
    172       return tzinfo.getVtz(); 
     171    if ((tzinfo != null) && (tzinfo.getTz().getVTimeZone() != null)) { 
     172      return tzinfo.getTz().getVTimeZone(); 
    173173    } 
    174174