[Bedework-commit] calendarapi r808 - in trunk: calsvc/src/org/bedework/calsvc calsvci/src/org/bedework/calsvci

svnadmin at bedework.org svnadmin at bedework.org
Fri Feb 13 10:51:03 EST 2009


Author: douglm
Date: 2009-02-13 10:51:02 -0500 (Fri, 13 Feb 2009)
New Revision: 808

Modified:
   trunk/calsvc/src/org/bedework/calsvc/CalSvc.java
   trunk/calsvc/src/org/bedework/calsvc/EventPropertiesImpl.java
   trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java
   trunk/calsvci/src/org/bedework/calsvci/EventProperties.java
Log:
Change to help fix dump/restore. Use uid throughout for retrieval of event properties.

Modified: trunk/calsvc/src/org/bedework/calsvc/CalSvc.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/CalSvc.java	2009-02-12 16:25:27 UTC (rev 807)
+++ trunk/calsvc/src/org/bedework/calsvc/CalSvc.java	2009-02-13 15:51:02 UTC (rev 808)
@@ -174,11 +174,11 @@
 
   private ViewsI viewsHandler;
 
-  private EventProperties<BwCategory, BwString> categoriesHandler;
+  private EventProperties<BwCategory> categoriesHandler;
 
-  private EventProperties<BwLocation, String> locationsHandler;
+  private EventProperties<BwLocation> locationsHandler;
 
-  private EventProperties<BwContact, String> contactsHandler;
+  private EventProperties<BwContact> contactsHandler;
 
   private Collection<CalSvcDb> handlers = new ArrayList<CalSvcDb>();
 
@@ -687,10 +687,10 @@
   /* (non-Javadoc)
    * @see org.bedework.calsvci.CalSvcI#getCategoriesHandler()
    */
-  public EventProperties<BwCategory, BwString> getCategoriesHandler()
+  public EventProperties<BwCategory> getCategoriesHandler()
           throws CalFacadeException {
     if (categoriesHandler == null) {
-      categoriesHandler = new EventPropertiesImpl<BwCategory, BwString>(this,
+      categoriesHandler = new EventPropertiesImpl<BwCategory>(this,
                                                                         getUser(),
                                                                         debug);
       categoriesHandler.init("word", "word",
@@ -706,10 +706,10 @@
   /* (non-Javadoc)
    * @see org.bedework.calsvci.CalSvcI#getLocationsHandler()
    */
-  public EventProperties<BwLocation, String> getLocationsHandler()
+  public EventProperties<BwLocation> getLocationsHandler()
           throws CalFacadeException {
     if (locationsHandler == null) {
-      locationsHandler = new EventPropertiesImpl<BwLocation, String>(this,
+      locationsHandler = new EventPropertiesImpl<BwLocation>(this,
                                                                      getUser(),
                                                                      debug);
       locationsHandler.init("uid", "address",
@@ -725,10 +725,10 @@
   /* (non-Javadoc)
    * @see org.bedework.calsvci.CalSvcI#getContactsHandler()
    */
-  public EventProperties<BwContact, String> getContactsHandler()
+  public EventProperties<BwContact> getContactsHandler()
           throws CalFacadeException {
     if (contactsHandler == null) {
-      contactsHandler = new EventPropertiesImpl<BwContact, String>(this, getUser(), debug);
+      contactsHandler = new EventPropertiesImpl<BwContact>(this, getUser(), debug);
       contactsHandler.init("uid", "name",
                   BwContact.class.getName(),
                   "getContactRefs", "removeContactForAll",

Modified: trunk/calsvc/src/org/bedework/calsvc/EventPropertiesImpl.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/EventPropertiesImpl.java	2009-02-12 16:25:27 UTC (rev 807)
+++ trunk/calsvc/src/org/bedework/calsvc/EventPropertiesImpl.java	2009-02-13 15:51:02 UTC (rev 808)
@@ -47,10 +47,9 @@
  * @author Mike Douglass   douglm - rpi.edu
  *
  * @param <T> type of property, Location, contact etc.
- * @param <K> type of key - String or subclass of BwDbentity
  */
-public class EventPropertiesImpl <T extends BwEventProperty, K>
-        extends CalSvcDb implements EventProperties<T, K>, PrivilegeDefs {
+public class EventPropertiesImpl <T extends BwEventProperty>
+        extends CalSvcDb implements EventProperties<T>, PrivilegeDefs {
   private String keyFieldName;
 
   private String finderFieldName;
@@ -174,9 +173,9 @@
    * @see org.bedework.calcorei.EventProperties#get(java.lang.Object, org.bedework.calfacade.BwUser)
    */
   @SuppressWarnings("unchecked")
-  public T get(K keyVal, BwUser owner) throws CalFacadeException {
-    if (keyVal == null) {
-      throw new CalFacadeException("Missing key value");
+  public T get(String uid, BwUser owner) throws CalFacadeException {
+    if (uid == null) {
+      throw new CalFacadeException("Missing uid value");
     }
 
     if (owner == null) {
@@ -187,19 +186,17 @@
 
     StringBuilder qstr = new StringBuilder("from ");
     qstr.append(className);
-    qstr.append(" ent where ");
-    addKeyTerms(keyVal, qstr);
-    qstr.append("and ent.owner=:owner");
+    qstr.append(" ent where uid=:uid and ent.owner=:owner");
 
     sess.createQuery(qstr.toString());
 
-    addKeyvals(keyVal);
+    sess.setString("uid", uid);
     sess.setEntity("owner", owner);
 
     return check((T)sess.getUnique());
   }
 
-  public T get(K keyVal) throws CalFacadeException {
+  public T get(String uid) throws CalFacadeException {
     BwUser owner;
     if (!isPublicAdmin()) {
       owner = getUser();
@@ -207,11 +204,11 @@
       owner = getPublicUser();
     }
 
-    return get(keyVal, owner);
+    return get(uid, owner);
   }
 
-  public T getPublic(K keyVal) throws CalFacadeException {
-    return get(keyVal, getPublicUser());
+  public T getPublic(String uid) throws CalFacadeException {
+    return get(uid, getPublicUser());
   }
 
   /* (non-Javadoc)
@@ -398,34 +395,6 @@
     return ent;
   }
 
-  private void addKeyTerms(K key, StringBuilder sb) throws CalFacadeException {
-    if (key instanceof String) {
-      sb.append("ent.");
-      sb.append(keyFieldName);
-      sb.append("=:keyval ");
-
-      return;
-    }
-
-    if (!(key instanceof BwString)) {
-      throw new CalFacadeException("org.bedework.error.invalidkeytype");
-    }
-
-    addBwStringKeyTerms((BwString)key, keyFieldName, sb);
-  }
-
-  private void addKeyvals(K key) throws CalFacadeException {
-    HibSession sess = getSess();
-
-    if (key instanceof String) {
-      sess.setString("keyval", (String)key);
-
-      return;
-    }
-
-    addBwStringKeyvals((BwString)key);
-  }
-
   private void addBwStringKeyTerms(BwString key, String keyName,
                                    StringBuilder sb) throws CalFacadeException {
     sb.append("((ent.");
@@ -495,35 +464,6 @@
     }
   }
 
-  /*
-  private void findVenueQuery(boolean count,
-                              String uid, BwUser owner) throws CalFacadeException {
-    if (uid == null) {
-      throw new CalFacadeException("Missing uid value");
-    }
-
-    if (owner == null) {
-      throw new CalFacadeException("Missing owner value");
-    }
-
-    HibSession sess = getSess();
-
-    StringBuilder qstr = new StringBuilder();
-    if (count) {
-      qstr.append("select count(*) ");
-    }
-
-    qstr.append("from ");
-    qstr.append(className);
-    qstr.append(" ent where (ent.venue is not null) and (ent.venue.uid=:uid) ");
-    qstr.append("and (ent.owner=:owner)");
-
-    sess.createQuery(qstr.toString());
-
-    sess.setString("uid", uid);
-    sess.setEntity("owner", owner);
-  }*/
-
   private void deleteOK(T ent) throws CalFacadeException {
     if (ent == null) {
       return;

Modified: trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java
===================================================================
--- trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java	2009-02-12 16:25:27 UTC (rev 807)
+++ trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java	2009-02-13 15:51:02 UTC (rev 808)
@@ -29,7 +29,6 @@
 import org.bedework.calfacade.BwLocation;
 import org.bedework.calfacade.BwContact;
 import org.bedework.calfacade.BwStats;
-import org.bedework.calfacade.BwString;
 import org.bedework.calfacade.BwUser;
 import org.bedework.calfacade.BwStats.StatsEntry;
 import org.bedework.calfacade.base.BwDbentity;
@@ -331,7 +330,7 @@
    * @return EventProperties
    * @throws CalFacadeException
    */
-  public abstract EventProperties<BwCategory, BwString> getCategoriesHandler()
+  public abstract EventProperties<BwCategory> getCategoriesHandler()
         throws CalFacadeException;
 
   /** Return the locations maintenance object.
@@ -339,7 +338,7 @@
    * @return EventProperties
    * @throws CalFacadeException
    */
-  public abstract EventProperties<BwLocation, String> getLocationsHandler()
+  public abstract EventProperties<BwLocation> getLocationsHandler()
         throws CalFacadeException;
 
   /** Return the contacts maintenance object.
@@ -347,7 +346,7 @@
    * @return EventProperties
    * @throws CalFacadeException
    */
-  public abstract EventProperties<BwContact, String> getContactsHandler()
+  public abstract EventProperties<BwContact> getContactsHandler()
         throws CalFacadeException;
 
   /* ====================================================================

Modified: trunk/calsvci/src/org/bedework/calsvci/EventProperties.java
===================================================================
--- trunk/calsvci/src/org/bedework/calsvci/EventProperties.java	2009-02-12 16:25:27 UTC (rev 807)
+++ trunk/calsvci/src/org/bedework/calsvci/EventProperties.java	2009-02-13 15:51:02 UTC (rev 808)
@@ -42,9 +42,8 @@
  * @author Mike Douglass   douglm - rpi.edu
  *
  * @param <T> type of property, Location, Sponsor etc.
- * @param <K> type of key - String or subclass of BwDbentity
  */
-public interface EventProperties <T extends BwEventProperty, K> extends Serializable {
+public interface EventProperties <T extends BwEventProperty> extends Serializable {
   /** Initialise the object
    *
    * @param keyFieldName  Name of entity keyfield
@@ -101,35 +100,35 @@
    */
   public Collection<T> getEditable() throws CalFacadeException;
 
-  /** Return an entity matching the given key fields if the user has access or null.
-   * The combination of key and owner should be guaranteed to produce a
-   * single result, for example a uid + owner.
+  /** Return an entity matching the given uid if the user has access or null.
+   * The combination of uid and owner should be guaranteed to produce a
+   * single result
    *
-   * @param keyVal       key field value
+   * @param uid          uid value
    * @param owner        BwUser owner
    * @return BwEventProperty object representing the entity in question
    *                     null if it doesn't exist.
    * @throws CalFacadeException
    */
-  public T get(K keyVal, BwUser owner) throws CalFacadeException;
+  public T get(String uid, BwUser owner) throws CalFacadeException;
 
-  /** Return an entity matching the given key field if the user has access or null.
+  /** Return an entity given the uid if the user has access
    *
-   * @param keyVal       key field value
+   * @param uid       String uid
    * @return BwEventProperty object representing the entity in question
    *                     null if it doesn't exist.
    * @throws CalFacadeException
    */
-  public T get(K keyVal) throws CalFacadeException;
+  public T get(String uid) throws CalFacadeException;
 
   /** Return an entity matching the given key field if the user has access or null.
    *
-   * @param keyVal       key field value
+   * @param uid       String uid
    * @return BwEventProperty object representing the entity in question
    *                     null if it doesn't exist.
    * @throws CalFacadeException
    */
-  public T getPublic(K keyVal) throws CalFacadeException;
+  public T getPublic(String uid) throws CalFacadeException;
 
   /** Return one or more entities matching the given BwString to which the
    * user has access.



More information about the Bedework-commit mailing list