Changeset 3190 for trunk/src


Ignore:
Timestamp:
Mar 13, 2007, 11:05:42 AM (16 years ago)
Author:
Johan Enell
Message:

Merged log:branches/2.2.2#3116:3186 to trunk.

Location:
trunk/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/formatter/FormatterSettings.java

    r2981 r3190  
    8080  {
    8181    sc.setUserClientSetting("formatter.number.decimals", Integer.toString(numDecimals));
    82     sc.setSessionSetting("formatter.number", null);
     82    sc.setSessionSetting("formatter.double", null);
     83    sc.setSessionSetting("formatter.float", null);
    8384  }
    8485 
  • trunk/src/core/common-queries.xml

    r3086 r3190  
    202202    <description>
    203203      Load the ID of all users which has a quota group from one of the given groups.
     204    </description>
     205  </query>
     206
     207  <query id="GET_USER_IDS_FOR_PROJECT" type="HQL">
     208    <sql>
     209      SELECT up.userId
     210      FROM UserProjects up
     211      WHERE up.projectId = :projectId
     212    </sql>
     213    <description>
     214      Load the ID of all users which are direct member of the given project
     215    </description>
     216  </query>
     217
     218  <query id="GET_GROUP_IDS_FOR_PROJECT" type="HQL">
     219    <sql>
     220      SELECT gp.groupId
     221      FROM GroupProjects gp
     222      WHERE gp.projectId = :projectId
     223    </sql>
     224    <description>
     225      Load the ID of all groups which are direct member of the given project
    204226    </description>
    205227  </query>
     
    25232545  </query>
    25242546
    2525   <query id="GET_SUM_USED_QUANTITY_EVENTS" type="HQL">
    2526     <sql>
    2527       SELECT evt.bioMaterial, SUM(evt.usedQuantity)
     2547  <query id="GET_USED_QUANTITY_EVENTS" type="HQL">
     2548    <sql>
     2549      SELECT evt.bioMaterial, evt.usedQuantity
    25282550      FROM BioMaterialEventData evt
    2529       GROUP BY evt.bioMaterial
    2530     </sql>
    2531     <description>
    2532       A HQL query that loads the sum of the used quantity
    2533       grouped by the biomaterial for all BioMaterialEvent:s.
    2534     </description>
    2535   </query>
    2536  
    2537   <query id="GET_SUM_USED_QUANTITY_SOURCES" type="HQL">
    2538     <sql>
    2539       SELECT index(src), SUM(src.usedQuantity)
     2551    </sql>
     2552    <description>
     2553      A HQL query that loads the biomaterial and the used quantity
     2554      for all BioMaterialEvent:s.
     2555    </description>
     2556  </query>
     2557 
     2558  <query id="GET_USED_QUANTITY_SOURCES" type="HQL">
     2559    <sql>
     2560      SELECT index(src), src.usedQuantity
    25402561      FROM BioMaterialEventData evt
    25412562      JOIN evt.sources src
    2542       GROUP BY index(src)
    2543     </sql>
    2544     <description>
    2545       A HQL query that loads the sum of the used quantity
    2546       grouped by the biomaterial for all sources to
    2547       BioMaterialEvent:s.
     2563    </sql>
     2564    <description>
     2565      A HQL query that loads the used quantity
     2566      for all sources to BioMaterialEvent:s.
    25482567    </description>
    25492568  </query>
  • trunk/src/core/net/sf/basedb/core/Group.java

    r2898 r3190  
    2929import net.sf.basedb.core.query.Hql;
    3030
     31import java.util.Collection;
    3132import java.util.HashSet;
    3233import java.util.Set;
     
    124125  public static Set<Integer> getGroupsRecursive(DbControl dc, Set<Integer> groups)
    125126  {
     127    return getGroupsRecursive(dc.getHibernateSession(), groups);
     128  }
     129
     130  static Set<Integer> getGroupsRecursive(org.hibernate.Session session, Collection<Integer> groups)
     131  {
    126132    Set<Integer> allGroups = new HashSet<Integer>(groups);
    127133    if (allGroups.size() > 0)
    128134    {
    129135     
    130       org.hibernate.Query query = HibernateUtil.getPredefinedQuery(dc.getHibernateSession(),
     136      org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session,
    131137        "GET_CHILDGROUPS_IDS_FOR_GROUPS");
    132138      /*
     
    143149    return allGroups;
    144150  }
     151
    145152 
    146153  /**
  • trunk/src/core/net/sf/basedb/core/Install.java

    r3086 r3190  
    102102    method.
    103103  */
    104   public static final int NEW_SCHEMA_VERSION = 29;
    105 
     104  public static final int NEW_SCHEMA_VERSION = 30;
     105 
    106106  public static synchronized void createTables(boolean update, final ProgressReporter progress)
    107107    throws BaseException
  • trunk/src/core/net/sf/basedb/core/Keyring.java

    r2981 r3190  
    450450    Load all users which are member of at least one group where the
    451451    logged in user is also a member and put that information
    452     in the {@link #users} variable.
     452    in the {@link #users} variable. If a project is active, also load the members
     453    and owner of that project.
    453454  */
    454455  private void loadUsers(org.hibernate.Session session)
    455456    throws BaseException
    456457  {
    457     Set<Integer> temp;
     458    Set<Integer> temp = new HashSet<Integer>();
    458459    try
    459460    {
     
    468469        */
    469470        query.setParameterList("groups", groups, org.hibernate.Hibernate.INTEGER);
    470         temp = new HashSet<Integer>(HibernateUtil.loadList(Integer.class, query));
     471        temp.addAll(HibernateUtil.loadList(Integer.class, query));
    471472       
    472473        // Get the users that have a quota group among the same groups
     
    479480        query.setParameterList("groups", groups, org.hibernate.Hibernate.INTEGER);
    480481        temp.addAll(HibernateUtil.loadList(Integer.class, query));
     482      }
     483     
     484      if (projectId != 0)
     485      {
     486        // Get the owner of the active project
     487        ProjectData pd = HibernateUtil.loadData(session, ProjectData.class, projectId);
     488        temp.add(pd.getOwner().getId());
    481489       
    482         users = Collections.unmodifiableSet(temp);
    483       }
     490        // Get direct members of the active project
     491        org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_USER_IDS_FOR_PROJECT");
     492        /*
     493          SELECT up.userId
     494          FROM UserProjects up
     495          WHERE up.projectId = :projectId
     496        */
     497        query.setInteger("projectId", projectId);
     498        temp.addAll(HibernateUtil.loadList(Integer.class, query));
     499       
     500        // Get groups that are direct members of the active project
     501        query = HibernateUtil.getPredefinedQuery(session, "GET_GROUP_IDS_FOR_PROJECT");
     502        /*
     503          SELECT gp.groupId
     504          FROM GroupProjects gp
     505          WHERE gp.projectId = :projectId
     506        */
     507        query.setInteger("projectId", projectId);
     508        // Load the direct groups and subgroups
     509        Set<Integer> projectGroups = Group.getGroupsRecursive(session, HibernateUtil.loadList(Integer.class, query));
     510
     511        // Load users that are members of the project groups
     512        temp.addAll(User.getAllMembers(session, projectGroups));
     513       
     514      }
     515      users = Collections.unmodifiableSet(temp);
    484516    }
    485517    catch (HibernateException ex)
     
    717749  {
    718750    if (getReload() && !reload()) projectData = null;
     751    int oldProjectId = projectId;
    719752    if (projectData == null)
    720753    {
     
    725758    {
    726759      projectId = projectData.getId();
    727       org.hibernate.Session session = null;
    728       org.hibernate.Transaction tx = null;
    729       try
    730       {
    731         session = HibernateUtil.newSession();
    732         tx = HibernateUtil.newTransaction(session);
    733         loadMaxProjectPermission(session, projectData);
    734         loadProjectKeys(session);
    735       }
    736       catch (BaseException ex)
    737       {
    738         projectId = 0;
    739         maxProjectPermission = 0;
    740         throw ex;
    741       }
    742       finally
    743       {
    744         if (tx != null) HibernateUtil.commit(tx);
    745         if (session != null) HibernateUtil.close(session);
    746       }
    747     }
     760    }
     761    reload = projectId != oldProjectId;
    748762  }
    749763 
  • trunk/src/core/net/sf/basedb/core/Trashcan.java

    r2218 r3190  
    9090            if (item.hasPermission(Permission.DELETE))
    9191            {
    92               if (!useLimit || (index >= firstItem && index < lastItem))
     92              SharedItem parent = item instanceof ChildItem ?
     93                  dc.getItem(SharedItem.class, ((ChildItem)item).getSharedParent()) : null;
     94             
     95              if ( (parent != null && parent.isOwner()) || (parent == null))
    9396              {
    94                 items.add((Removable)item);
     97                if (!useLimit || (index >= firstItem && index < lastItem))
     98                {
     99                  items.add((Removable)item);
     100                }
     101                index++;
     102                totalItems++;
    95103              }
    96               index++;
    97               totalItems++;
    98104            }
    99105          }
  • trunk/src/core/net/sf/basedb/core/Update.java

    r3120 r3190  
    346346  <tr>
    347347    <td>29</td>
     348    <td>
     349      No changes at all except increasing the schema version number.
     350      The veryfication of remaining quantity is moved to next update of schema version.
     351    </td>
     352  </tr>
     353 
     354  <tr>
     355    <td>30</td>
    348356    <td>
    349357      No schema change as such, but we need to verify and possibly update the
     
    505513      }
    506514     
     515     
     516      if (schemaVersion < 30)
     517      {
     518        if (progress != null) progress.display((int)(29*progress_factor), "--Updating schema version: " + schemaVersion + " -> 30...");     
     519        schemaVersion = updateToSchemaVersion30(session);
     520      }
     521     
    507522      /*
    508       if (schemaVersion < 30)
    509       {
    510         if (progress != null) progress.display((int)(29*progress_factor), "--Updating schema version: " + schemaVersion + " -> 30...");
    511         schemaVersion = setSchemaVersionInTransaction(session, 30);
     523      if (schemaVersion < 31)
     524      {
     525        if (progress != null) progress.display((int)(30*progress_factor), "--Updating schema version: " + schemaVersion + " -> 30...");
     526        schemaVersion = setSchemaVersionInTransaction(session, 31);
    512527        - or -
    513         schemaVersion = updateToSchemaVersion30(session);
     528        schemaVersion = updateToSchemaVersion31(session);
    514529      }
    515530      ... etc...
     
    10711086  /**
    10721087    Vefify and update the remaining quantity of all biomaterials.
    1073     @return The new schema version (=29)
     1088    @return The new schema version (=30)
    10741089  */
    1075   private static int updateToSchemaVersion29(org.hibernate.Session session)
     1090  private static int updateToSchemaVersion30(org.hibernate.Session session)
    10761091    throws BaseException
    10771092  {
    1078     final int schemaVersion = 29;
     1093    final int schemaVersion = 30;
    10791094   
    10801095    org.hibernate.Transaction tx = null;
     
    10861101      Map<MeasuredBioMaterialData, Float> remaining = new HashMap<MeasuredBioMaterialData, Float>();
    10871102     
    1088       // Load sum of used quantity for all events
     1103      // Load used quantity for all events
    10891104      org.hibernate.Query eventQuery = HibernateUtil.getPredefinedQuery(session,
    1090         "GET_SUM_USED_QUANTITY_EVENTS");
    1091       /*
    1092         SELECT evt.bioMaterial, SUM(evt.usedQuantity)
    1093         FROM BioMaterialEventData evt
    1094         GROUP BY evt.bioMaterial
    1095       */
    1096       // Load sum of used quantity for sources to all events
     1105        "GET_USED_QUANTITY_EVENTS");
     1106        /*       
     1107          SELECT evt.bioMaterial, evt.usedQuantity
     1108          FROM BioMaterialEventData evt
     1109        */
     1110     
     1111      // Load used quantity for sources to all events
    10971112      org.hibernate.Query sourcesQuery = HibernateUtil.getPredefinedQuery(session,
    1098         "GET_SUM_USED_QUANTITY_SOURCES");
     1113        "GET_USED_QUANTITY_SOURCES");
    10991114        /*
    1100           SELECT index(src), SUM(src.usedQuantity)
     1115          SELECT index(src), src.usedQuantity
    11011116          FROM BioMaterialEventData evt
    1102           JOIN evt.sources src
    1103           GROUP BY index(src)
     1117          JOIN evt.sources src         
    11041118         */
    11051119      List<Object[]> events = HibernateUtil.loadList(Object[].class, eventQuery);
     
    11071121     
    11081122      // Calculate the remaining quantity for each biomaterial
    1109       // o[0] = biomaterial, o[1] = sum of used quantity
     1123      // o[0] = biomaterial, o[1] = used quantity     
    11101124      for (Object[] o : events)
    11111125      {
    1112         MeasuredBioMaterialData bioMaterial = (MeasuredBioMaterialData)o[0];
    1113         Double sumUsedQuantity = (Double)o[1];
    1114         if (sumUsedQuantity != null)
     1126        MeasuredBioMaterialData bioMaterial = (MeasuredBioMaterialData)o[0];       
     1127        Float usedQuantity = (Float)o[1];       
     1128        if (usedQuantity != null)
    11151129        {
    11161130          Float currentRemaining = remaining.get(bioMaterial);
    11171131          if (currentRemaining == null) currentRemaining = 0.0f;
    1118           currentRemaining = currentRemaining - sumUsedQuantity.floatValue();
     1132          currentRemaining = currentRemaining - usedQuantity;
    11191133          remaining.put(bioMaterial, currentRemaining);
    11201134        }
     
    11431157      // Commit the changes
    11441158      HibernateUtil.commit(tx);
    1145       log.info("updateToSchemaVersion29: OK");
     1159      log.info("updateToSchemaVersion30: OK");
    11461160    }
    11471161    catch (BaseException ex)
    11481162    {
    11491163      if (tx != null) HibernateUtil.rollback(tx);
    1150       log.error("updateToSchemaVersion29: FAILED", ex);
     1164      log.error("updateToSchemaVersion30: FAILED", ex);
    11511165      throw ex;
    11521166    }
  • trunk/src/core/net/sf/basedb/core/User.java

    r2902 r3190  
    3636
    3737import java.util.ArrayList;
     38import java.util.Collection;
    3839import java.util.Date;
    3940import java.util.HashSet;
     
    124125  public static Set<Integer> getAllMembers(DbControl dc, Set<Integer> groupIds)
    125126  {
     127    return getAllMembers(dc.getHibernateSession(), groupIds);
     128  }
     129 
     130  static Set<Integer> getAllMembers(org.hibernate.Session session, Collection<Integer> groupIds)
     131  {
    126132    Set<Integer> userIds = new HashSet<Integer>();
    127133    if (groupIds != null && groupIds.size() > 0)
    128134    {
    129       org.hibernate.Session session = dc.getHibernateSession();
    130135      // Get the users which are members of the same groups
    131136      org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_USER_IDS_FOR_GROUPS");
     
    149154    }
    150155    return userIds;
    151    
    152   }
     156  }
     157
    153158 
    154159  /**
  • trunk/src/core/net/sf/basedb/core/query/Hql.java

    r2497 r3190  
    2727import net.sf.basedb.core.InvalidDataException;
    2828import net.sf.basedb.core.InvalidUseOfNullException;
     29import net.sf.basedb.core.data.BasicData;
    2930
    3031import java.util.regex.Pattern;
     
    5556
    5657  /**
    57     Create an expression representing an item. In the query the actual
    58     value used is the id of the entity. See {@link #property(String, String)}
    59     for a code example.
     58    Create an expression representing an item which is a subclass of BasicItem.
     59    In the query the actual value used is the id of the entity.
     60    See {@link #property(String, String)} for a code example.
    6061
    6162    @param entity The entity
    62     @throws InvalidDataException If the etity is null
     63    @throws InvalidDataException If the entity is null
     64    @see #entity(BasicData)
    6365  */
    6466  public static Expression entity(BasicItem entity)
     
    6971  }
    7072 
     73  /**
     74    Create an expression representing an item which is a subclass of BasicData,
     75    for example a reporter. In the query the actual value used is the id of the entity.
     76    See {@link #property(String, String)} for a code example.
     77 
     78    @param entity The entity
     79    @throws InvalidDataException If the entity is null
     80    @see #entity(BasicItem)
     81    @since 2.2.2
     82  */
     83  public static Expression entity(BasicData entity)
     84    throws InvalidDataException
     85  {
     86    if (entity == null) throw new InvalidUseOfNullException("entity");
     87    return new HqlEntityExpression(entity);
     88  }
     89   
    7190  /**
    7291    Same as <code>property(null, property)</code>.
  • trunk/src/core/net/sf/basedb/core/query/HqlEntityExpression.java

    r2667 r3190  
    2929import net.sf.basedb.core.BasicItem;
    3030import net.sf.basedb.core.BaseException;
     31import net.sf.basedb.core.data.BasicData;
    3132
    3233/**
     
    3940  @version 2.0
    4041  @see Hql#entity(BasicItem)
     42  @see Hql#entity(BasicData)
    4143  @base.modified $Date$
    4244*/
     
    4446  implements Expression
    4547{
    46   private final BasicItem item;
     48  private final int id;
     49  private final String item;
    4750
    4851  HqlEntityExpression(BasicItem item)
    4952  {
    50     this.item = item;
     53    this.id = item.getId();
     54    this.item = item.toString();
     55  }
     56 
     57  /**
     58    @since 2.2.2
     59  */
     60  HqlEntityExpression(BasicData data)
     61  {
     62    this.id = data.getId();
     63    this.item = data.toString();
    5164  }
    5265
     
    6073    if (query.getQueryType() == QueryType.HQL)
    6174    {
    62       return Integer.toString(item.getId());
     75      return Integer.toString(id);
    6376    }
    6477    else
     
    8194  public String toString()
    8295  {
    83     return item.toString();
     96    return item;
    8497  }
    8598  // -------------------------------------------
  • trunk/src/core/net/sf/basedb/util/Values.java

    r2981 r3190  
    628628      result.append(lNumber).append(".");
    629629      String theDecimals = Long.toString(Math.round(fNumber*exp-lNumber*exp));
    630       result.append(theDecimals);
    631630      if (theDecimals.length() < decimals)
    632631      {
     
    636635        }
    637636      }
     637      result.append(theDecimals);
    638638    }
    639639    if (unit != null) result.append(unit);
  • trunk/src/core/net/sf/basedb/util/overview/ExperimentOverview.java

    r3062 r3190  
    281281    this.annotatableParents = new HashMap<Annotatable, Set<Annotatable>>();
    282282   
    283     // Load 'Required for MIAME' annotation types
     283    // Load 'Required for MIAME' annotation types (parameter='false' must also be set)
    284284    ItemQuery<AnnotationType> query = initQuery(AnnotationType.getQuery(null), "name");
    285285    query.restrict(
    286286      Restrictions.eq(
    287287        Hql.property("requiredForMiame"),
    288         Expressions.parameter("flag", true, Type.BOOLEAN)
     288        Expressions.parameter("miameFlag", true, Type.BOOLEAN)
     289      )
     290    );
     291    query.restrict(
     292      Restrictions.eq(
     293        Hql.property("protocolParameter"),
     294        Expressions.parameter("parameterFlag", false, Type.BOOLEAN)
    289295      )
    290296    );
     
    619625      for (Node factorNode : efNode.getChildren())
    620626      {
    621         Node annotationNode = annotationsNode.getChild("annotationtype." + factorNode.getItem().getId());
     627        Node annotationNode = annotationsNode == null ?
     628            null : annotationsNode.getChild("annotationtype." + factorNode.getItem().getId());
    622629        if (annotationNode == null)
    623630        {
     
    15411548          failures.add(new Failure(Validator.MISSING_PARAMETER, parentNode,
    15421549            "Missing parameter value: " + pp.getName(),
    1543             new Fix("Add parameter value", parentItem, pp, false)));
     1550            new Fix("Add parameter value for: " + pp.getName(), parentItem, pp, false)));
    15441551        }
    15451552      }
     
    15791586        {
    15801587          AnnotationType at = a.getAnnotationType();
    1581           if (protocol == null || protocol.isParameter(at))
     1588          // Protocol parameters are handled elsewhere
     1589          if (protocol == null || !protocol.isParameter(at))
    15821590          {
    15831591            Node atNode = new Node("annotationtype."+at.getId(), at.getName(), annotationsNode, at);
Note: See TracChangeset for help on using the changeset viewer.