コード例 #1
0
  @Override
  public List<SyncDLObject> findByModifiedTime(
      long modifiedTime, long repositoryId, long parentFolderId, String type, int start, int end) {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(getClass(), FIND_BY_MODIFIED_TIME);

      if (modifiedTime <= 0) {
        sql = StringUtil.replace(sql, "(SyncDLObject.modifiedTime > ?) AND", StringPool.BLANK);
      }

      if (parentFolderId == 0) {
        sql = StringUtil.replace(sql, "AND (SyncDLObject.treePath LIKE ?)", StringPool.BLANK);
      }

      if (type == null) {
        sql = StringUtil.replace(sql, "AND (SyncDLObject.type_ = ?)", StringPool.BLANK);
      }

      if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS)) {
        sql = CustomSQLUtil.removeOrderBy(sql);
      }

      SQLQuery sqlQuery = session.createSynchronizedSQLQuery(sql);

      sqlQuery.addEntity("SyncDLObject", SyncDLObjectImpl.class);

      QueryPos qPos = QueryPos.getInstance(sqlQuery);

      if (modifiedTime > 0) {
        qPos.add(modifiedTime);
      }

      qPos.add(repositoryId);

      if (parentFolderId != 0) {
        qPos.add("%/" + parentFolderId + "/%");
      }

      if (type != null) {
        qPos.add(type);
      }

      return (List<SyncDLObject>) QueryUtil.list(sqlQuery, getDialect(), start, end);
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
コード例 #2
0
  @Override
  public List<BookmarksFolder> findByNoAssets() {
    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(getClass(), FIND_BY_NO_ASSETS);

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity("BookmarksFolder", BookmarksFolderImpl.class);

      return q.list(true);
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
コード例 #3
0
  @Override
  public List<Long> filterFindByR_U_T(long groupId, long userId, long[] typePKs) {

    if (ArrayUtil.isEmpty(typePKs)) {
      return Collections.emptyList();
    }

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(getClass(), FIND_BY_TYPE_PKS);

      sql =
          StringUtil.replace(
              sql,
              new String[] {"[$TYPE_PKS$]", "[$ROLE_IDS_OR_OWNER_ID$]"},
              new String[] {getTypePKsSQL(typePKs), getRoleOwnerIdsSQL(groupId, userId)});

      SQLQuery sqlQuery = session.createSynchronizedSQLQuery(sql);

      sqlQuery.addScalar("primKey", Type.LONG);

      QueryPos qPos = QueryPos.getInstance(sqlQuery);

      qPos.add(CompanyThreadLocal.getCompanyId());
      qPos.add(ResourceConstants.SCOPE_INDIVIDUAL);

      return (List<Long>) sqlQuery.list();
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
コード例 #4
0
  protected List<Object> doFindF_E_ByG_F(
      long groupId, long folderId, QueryDefinition<?> queryDefinition, boolean inlineSQLHelper) {

    Session session = null;

    try {
      session = openSession();

      StringBundler sb = new StringBundler(5);

      sb.append("SELECT * FROM (");

      String sql = null;

      if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) {
        sql = CustomSQLUtil.get(getClass(), FIND_F_BY_G_P);
      } else {
        sql = CustomSQLUtil.get(getClass(), FIND_F_BY_G_P_S);

        sql = replaceExcludeStatus(sql, queryDefinition);
      }

      if (inlineSQLHelper) {
        sql =
            InlineSQLHelperUtil.replacePermissionCheck(
                sql, BookmarksFolder.class.getName(), "BookmarksFolder.folderId", groupId);
      }

      sb.append(sql);
      sb.append(" UNION ALL ");

      if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) {
        sql = CustomSQLUtil.get(getClass(), FIND_E_BY_G_F);
      } else {
        sql = CustomSQLUtil.get(getClass(), FIND_E_BY_G_F_S);

        sql = replaceExcludeStatus(sql, queryDefinition);
      }

      if (inlineSQLHelper) {
        sql =
            InlineSQLHelperUtil.replacePermissionCheck(
                sql, BookmarksEntry.class.getName(), "BookmarksEntry.fileEntryId", groupId);
      }

      sb.append(sql);
      sb.append(") TEMP_TABLE ORDER BY modelName ASC");

      sql = sb.toString();

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addScalar("modelId", Type.LONG);
      q.addScalar("modelName", Type.STRING);
      q.addScalar("modelFolder", Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(groupId);
      qPos.add(folderId);

      if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
        qPos.add(queryDefinition.getStatus());
      }

      qPos.add(groupId);
      qPos.add(folderId);

      if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
        qPos.add(queryDefinition.getStatus());
      }

      List<Object> models = new ArrayList<>();

      Iterator<Object[]> itr =
          (Iterator<Object[]>)
              QueryUtil.iterate(
                  q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd());

      while (itr.hasNext()) {
        Object[] array = itr.next();

        long modelId = (Long) array[0];
        // String name = (String)array[1];
        long modelFolder = (Long) array[2];

        Object obj = null;

        if (modelFolder == 0) {
          obj = BookmarksFolderUtil.findByPrimaryKey(modelId);
        } else {
          obj = BookmarksEntryUtil.findByPrimaryKey(modelId);
        }

        models.add(obj);
      }

      return models;
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
コード例 #5
0
  protected int doCountF_E_ByG_F(
      long groupId, long folderId, QueryDefinition<?> queryDefinition, boolean inlineSQLHelper) {

    Session session = null;

    try {
      session = openSession();

      StringBundler sb = new StringBundler(5);

      sb.append(StringPool.OPEN_PARENTHESIS);

      String sql = null;

      if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) {
        sql = CustomSQLUtil.get(getClass(), COUNT_F_BY_G_P);
      } else {
        sql = CustomSQLUtil.get(getClass(), COUNT_F_BY_G_P_S);

        sql = replaceExcludeStatus(sql, queryDefinition);
      }

      if (inlineSQLHelper) {
        sql =
            InlineSQLHelperUtil.replacePermissionCheck(
                sql, BookmarksFolder.class.getName(), "BookmarksFolder.folderId", groupId);
      }

      sb.append(sql);
      sb.append(") UNION ALL (");

      if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) {
        sql = CustomSQLUtil.get(getClass(), COUNT_E_BY_G_F);
      } else {
        sql = CustomSQLUtil.get(getClass(), COUNT_E_BY_G_F_S);

        sql = replaceExcludeStatus(sql, queryDefinition);
      }

      if (inlineSQLHelper) {
        sql =
            InlineSQLHelperUtil.replacePermissionCheck(
                sql, BookmarksEntry.class.getName(), "BookmarksEntry.fileEntryId", groupId);
      }

      sb.append(sql);
      sb.append(StringPool.CLOSE_PARENTHESIS);

      sql = sb.toString();

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(groupId);
      qPos.add(folderId);

      if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
        qPos.add(queryDefinition.getStatus());
      }

      qPos.add(groupId);
      qPos.add(folderId);

      if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
        qPos.add(queryDefinition.getStatus());
      }

      int count = 0;

      Iterator<Long> itr = q.iterate();

      while (itr.hasNext()) {
        Long l = itr.next();

        if (l != null) {
          count += l.intValue();
        }
      }

      return count;
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }