Changeset 7392


Ignore:
Timestamp:
Jun 9, 2017, 9:33:19 AM (5 years ago)
Author:
Nicklas Nordborg
Message:

References #2085: Sticky news

Added sticky flag to news items in the Core API.

Location:
trunk/src/core/net/sf/basedb/core
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Install.java

    r7381 r7392  
    119119    method.
    120120  */
    121   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(137).intValue();
     121  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(138).intValue();
    122122 
    123123  public static synchronized int createTables(SchemaGenerator.Mode mode, ProgressReporter progress,
  • trunk/src/core/net/sf/basedb/core/News.java

    r7308 r7392  
    309309    checkPermission(Permission.WRITE);
    310310    getData().setEndDate(DateUtil.setNullableDate(endDate, "endDate"));
     311  }
     312 
     313  /**
     314    Sticky news items should be sorted before non-sticky ones, but
     315    that is up to the client application to implement.
     316    @return TRUE if the item is sticky, FALSE if not
     317    @since 3.12
     318  */
     319  public boolean isSticky()
     320  {
     321    return getData().isSticky();
     322  }
     323 
     324  /**
     325    Set the sticky flag for this news item.
     326    @param sticky TRUE to make the new item sticky
     327    @throws PermissionDeniedException If the logged in user doesn't have
     328      {@link Permission#WRITE} permission
     329    @since 3.12
     330  */
     331  public void setSticky(boolean sticky)
     332    throws PermissionDeniedException
     333  {
     334    checkPermission(Permission.WRITE);
     335    getData().setSticky(sticky);
    311336  }
    312337
  • trunk/src/core/net/sf/basedb/core/Update.java

    r7390 r7392  
    365365    </td>
    366366  </tr>
     367  <tr>
     368    <td>138</td>
     369    <td>
     370      Added {@link NewsData#isSticky()}. The update should set
     371      the value for all existing news items to false.
     372    </td>
     373  </tr>
    367374 
    368375  </table>
     
    591598        if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 137...");
    592599        schemaVersion = setSchemaVersionInTransaction(session, 137);
     600        progress_current += progress_step;
     601      }
     602     
     603      if (schemaVersion < 138)
     604      {
     605        if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 138...");
     606        schemaVersion = setSchemaVersionInTransaction(session, 138);
    593607        progress_current += progress_step;
    594608      }
     
    921935      }
    922936     
     937      if (schemaVersion < 138)
     938      {
     939        System.out.println("Setting news.sticky to false");
     940        // Set sticky=false on all news
     941        org.hibernate.query.Query<?> query = HibernateUtil.createQuery(session,
     942          "UPDATE NewsData n " +
     943          "SET n.sticky = false " +
     944          "WHERE n.sticky IS NULL");
     945        query.executeUpdate();
     946      }
     947
    923948      //  Commit the changes
    924949      HibernateUtil.commit(tx);
  • trunk/src/core/net/sf/basedb/core/data/NewsData.java

    r7015 r7392  
    145145    this.endDate = endDate;
    146146  }
     147 
     148  private boolean sticky;
     149  /**
     150    Sticky news should be sorted before non-sticky news regardless of
     151    the date.
     152    @since 3.12
     153    @hibernate.property column="`sticky`" type="boolean" not-null="true"
     154  */
     155  public boolean isSticky()
     156  {
     157    return sticky;
     158  }
     159  public void setSticky(boolean sticky)
     160  {
     161    this.sticky = sticky;
     162  }
     163
    147164}
Note: See TracChangeset for help on using the changeset viewer.