Пример #1
0
  /* get/create device list entry */
  public static GroupList getGroupList(User user, String groupID, boolean createOK)
      throws DBException {
    // does not return null, if 'createOK' is true

    /* User specified? */
    if (user == null) {
      throw new DBException("User not specified.");
    }
    String accountID = user.getAccountID();
    String userID = user.getUserID();

    /* group exists? */
    if (StringTools.isBlank(groupID)) {
      throw new DBException("DeviceGroup ID not specified.");
    } else if (!DeviceGroup.exists(accountID, groupID)) {
      throw new DBException("DeviceGroup does not exist: " + accountID + "/" + groupID);
    }

    /* create/save record */
    GroupList.Key grpListKey = new GroupList.Key(accountID, userID, groupID);
    if (grpListKey.exists()) { // may throw DBException
      // already exists
      GroupList listItem = grpListKey.getDBRecord(true);
      listItem.setUser(user);
      return listItem;
    } else if (createOK) {
      GroupList listItem = grpListKey.getDBRecord();
      listItem.setCreationDefaultValues();
      listItem.setUser(user);
      return listItem;
    } else {
      // record doesn't exist, and caller doesn't want us to create it
      return null;
    }
  }
Пример #2
0
 public static DBFactory<GroupList> getFactory() {
   if (factory == null) {
     factory =
         DBFactory.createDBFactory(
             GroupList.TABLE_NAME(),
             GroupList.FieldInfo,
             DBFactory.KeyType.PRIMARY,
             GroupList.class,
             GroupList.Key.class,
             true /*editable*/,
             true /*viewable*/);
     factory.addParentTable(Account.TABLE_NAME());
     factory.addParentTable(User.TABLE_NAME());
     factory.addParentTable(DeviceGroup.TABLE_NAME());
   }
   return factory;
 }