protected long getActionIds(String name) throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps =
          con.prepareStatement(
              "select sum(bitwiseValue) as actionIds from ResourceAction " + "where name = ?");

      ps.setString(1, name);

      rs = ps.executeQuery();

      if (rs.next()) {
        return rs.getLong("actionIds");
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }

    return 0;
  }
  protected boolean hasResourceAction(String name) throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps = con.prepareStatement("select count(*) from ResourceAction where name = ?");

      ps.setString(1, name);

      rs = ps.executeQuery();

      while (rs.next()) {
        int count = rs.getInt(1);

        if (count > 0) {
          return true;
        }
      }

      return false;
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
Example #3
0
  private void _reorgTables(String[] templates) throws SQLException {
    Set<String> tableNames = new HashSet<String>();

    for (String template : templates) {
      if (template.startsWith("alter table")) {
        tableNames.add(template.split(" ")[2]);
      }
    }

    if (tableNames.size() == 0) {
      return;
    }

    Connection con = null;
    CallableStatement callStmt = null;

    try {
      con = DataAccess.getConnection();

      for (String tableName : tableNames) {
        String sql = "call sysproc.admin_cmd(?)";

        callStmt = con.prepareCall(sql);

        String param = "reorg table " + tableName;

        callStmt.setString(1, param);

        callStmt.execute();
      }
    } finally {
      DataAccess.cleanUp(con, callStmt);
    }
  }
  protected void addResourcePermission(
      long resourcePermissionId, long companyId, String name, long primKey, long ownerId)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps =
          con.prepareStatement(
              "insert into ResourcePermission (resourcePermissionId, "
                  + "companyId, name, scope, primKey, roleId, ownerId, "
                  + "actionIds) values (?, ?, ?, ?, ?, ?, ?, ?)");

      ps.setLong(1, resourcePermissionId);
      ps.setLong(2, companyId);
      ps.setString(3, name);
      ps.setLong(4, ResourceConstants.SCOPE_INDIVIDUAL);
      ps.setString(5, String.valueOf(primKey));
      ps.setLong(6, getRoleId(companyId, RoleConstants.OWNER));
      ps.setLong(7, ownerId);
      ps.setLong(8, getActionIds(name));

      ps.executeUpdate();

    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
  protected void addPortletPreferences(
      long ownerId, int ownerType, long plid, String portletId, String preferences)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;

    try {
      con = DataAccess.getConnection();

      ps =
          con.prepareStatement(
              "insert into PortletPreferences (portletPreferencesId, "
                  + "ownerId, ownerType, plid, portletId, preferences) "
                  + "values (?, ?, ?, ?, ?, ?)");

      ps.setLong(1, increment());
      ps.setLong(2, ownerId);
      ps.setInt(3, ownerType);
      ps.setLong(4, plid);
      ps.setString(5, portletId);
      ps.setString(6, preferences);

      ps.executeUpdate();
    } finally {
      DataAccess.cleanUp(con, ps);
    }
  }
  protected void updateLayout(long oldGroupId, long newGroupId, boolean privateLayout)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps =
          con.prepareStatement(
              "update Layout set groupId = ?, privateLayout = ? where "
                  + "(groupId = ?) and (privateLayout = ?)");

      ps.setLong(1, newGroupId);
      ps.setBoolean(2, true);
      ps.setLong(3, oldGroupId);
      ps.setBoolean(4, privateLayout);

      ps.executeUpdate();
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
  protected void addLayoutSetPrototype(long layoutSetPrototypeId, long companyId, String name)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps =
          con.prepareStatement(
              "insert into LayoutSetPrototype (layoutSetPrototypeId, "
                  + "companyId, name, description, active_) values (?, ?, ?, "
                  + "?, ?)");

      ps.setLong(1, layoutSetPrototypeId);
      ps.setLong(2, companyId);
      ps.setString(3, getNameXML(name));
      ps.setString(4, name);
      ps.setBoolean(5, true);

      ps.execute();
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
  protected long getMessageIdsCount() throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      StringBundler sb = new StringBundler(7);

      sb.append("select count(*) from ");
      sb.append("MBMessage childMessage ");
      sb.append("inner join MBMessage parentMessage on ");
      sb.append("childMessage.parentMessageId = ");
      sb.append("parentMessage.messageId where ");
      sb.append("parentMessage.categoryId != childMessage.categoryId ");
      sb.append("or parentMessage.threadId != childMessage.threadId");

      String sql = sb.toString();

      ps = con.prepareStatement(sql);

      rs = ps.executeQuery();

      while (rs.next()) {
        return rs.getLong(1);
      }

      return 0;
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
  protected void updateUserGroup(long userGroupId, boolean privateLayout, long layoutSetPrototypeId)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      String layoutSetPrototypeIdColumnName = null;

      if (privateLayout) {
        layoutSetPrototypeIdColumnName = "privateLayoutSetPrototypeId";
      } else {
        layoutSetPrototypeIdColumnName = "publicLayoutSetPrototypeId";
      }

      ps =
          con.prepareStatement(
              "update UserGroup set "
                  + layoutSetPrototypeIdColumnName
                  + " = ? where userGroupId = ?");

      ps.setLong(1, layoutSetPrototypeId);
      ps.setLong(2, userGroupId);

      ps.executeUpdate();
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
  protected long getPortletPreferencesId(long ownerId, int ownerType, long plid, String portletId)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps =
          con.prepareStatement(
              "select portletPreferencesId from PortletPreferences where "
                  + "ownerId = ? and ownerType = ? and plid = ? and "
                  + "portletId = ?");

      ps.setLong(1, ownerId);
      ps.setInt(2, ownerType);
      ps.setLong(3, plid);
      ps.setString(4, portletId);

      rs = ps.executeQuery();

      if (rs.next()) {
        return rs.getLong("portletPreferencesId");
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }

    return 0;
  }
Example #11
0
  private static long _getResourceCodesCount() throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps = con.prepareStatement("select count(*) from ResourceCode");

      rs = ps.executeQuery();

      if (rs.next()) {
        int count = rs.getInt(1);

        return count;
      }

      return 0;
    } catch (Exception e) {
      return 0;
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
Example #12
0
  protected void deleteConflictingIGPermissions(String igResourceName, String dlResourceName)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      DatabaseMetaData databaseMetaData = con.getMetaData();

      boolean supportsBatchUpdates = databaseMetaData.supportsBatchUpdates();

      ps =
          con.prepareStatement(
              "select companyId, scope, primKey, roleId from "
                  + "ResourcePermission where name = ?");

      ps.setString(1, igResourceName);

      rs = ps.executeQuery();

      ps =
          con.prepareStatement(
              "delete from ResourcePermission where name = ? and "
                  + "companyId = ? and scope = ? and primKey = ? and "
                  + "roleId = ?");

      int count = 0;

      while (rs.next()) {
        ps.setString(1, dlResourceName);
        ps.setLong(2, rs.getLong("companyId"));
        ps.setLong(3, rs.getLong("scope"));
        ps.setLong(4, rs.getLong("primKey"));
        ps.setLong(5, rs.getLong("roleId"));

        if (supportsBatchUpdates) {
          ps.addBatch();

          if (count == PropsValues.HIBERNATE_JDBC_BATCH_SIZE) {
            ps.executeBatch();

            count = 0;
          } else {
            count++;
          }
        } else {
          ps.executeUpdate();
        }
      }

      if (supportsBatchUpdates && (count > 0)) {
        ps.executeBatch();
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
  protected long getRoleId(long companyId, String name) throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps =
          con.prepareStatement(
              "select roleId from Role_ where (companyId = ?) and (name = " + "?)");

      ps.setLong(1, companyId);
      ps.setString(2, name);

      rs = ps.executeQuery();

      if (rs.next()) {
        return rs.getLong("roleId");
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }

    return 0;
  }
  protected long getGroupId(long companyId, long classNameId, long classPK) throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    long groupId = 0;

    try {
      con = DataAccess.getConnection();

      ps =
          con.prepareStatement(
              "select groupId from Group_ where (companyId = ?) and "
                  + "(classNameId = ?) and (classPK = ?)");

      ps.setLong(1, companyId);
      ps.setLong(2, classNameId);
      ps.setLong(3, classPK);

      rs = ps.executeQuery();

      if (rs.next()) {
        groupId = rs.getLong("groupId");
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }

    return groupId;
  }
Example #15
0
  protected void convertResourcePermissions(String name, String tableName, String pkColumnName)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps = con.prepareStatement("select " + pkColumnName + ", companyId from " + tableName);

      rs = ps.executeQuery();

      while (rs.next()) {
        long primKey = rs.getLong(pkColumnName);
        long companyId = rs.getLong("companyId");

        ResourceBlock resourceBlock = convertResourcePermissions(companyId, name, primKey);

        if (_log.isInfoEnabled() && ((resourceBlock.getResourceBlockId() % 100) == 0)) {

          _log.info("Processed 100 resource blocks for " + name);
        }
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }

    List<ResourcePermission> resourcePermissions =
        ResourcePermissionLocalServiceUtil.getScopeResourcePermissions(_SCOPES);

    for (ResourcePermission resourcePermission : resourcePermissions) {
      int scope = resourcePermission.getScope();

      if (!name.equals(resourcePermission.getName())) {
        continue;
      }

      if ((scope == ResourceConstants.SCOPE_COMPANY)
          || (scope == ResourceConstants.SCOPE_GROUP_TEMPLATE)) {

        ResourceBlockLocalServiceUtil.setCompanyScopePermissions(
            resourcePermission.getCompanyId(),
            name,
            resourcePermission.getRoleId(),
            resourcePermission.getActionIds());
      } else if (scope == ResourceConstants.SCOPE_GROUP) {
        ResourceBlockLocalServiceUtil.setGroupScopePermissions(
            resourcePermission.getCompanyId(),
            GetterUtil.getLong(resourcePermission.getPrimaryKey()),
            name,
            resourcePermission.getRoleId(),
            resourcePermission.getActionIds());
      }
    }
  }
Example #16
0
  protected void updateIGFolderEntries() throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps = con.prepareStatement("select * from IGFolder order by folderId asc");

      rs = ps.executeQuery();

      Map<Long, Long> folderIds = new HashMap<Long, Long>();

      while (rs.next()) {
        String uuid = rs.getString("uuid_");
        long folderId = rs.getLong("folderId");
        long groupId = rs.getLong("groupId");
        long companyId = rs.getLong("companyId");
        long userId = rs.getLong("userId");
        String userName = rs.getString("userName");
        Date createDate = rs.getDate("createDate");
        Date modifiedDate = rs.getDate("modifiedDate");
        long parentFolderId = rs.getLong("parentFolderId");
        String name = rs.getString("name");
        String description = rs.getString("description");

        if (folderIds.containsKey(parentFolderId)) {
          parentFolderId = folderIds.get(parentFolderId);
        }

        boolean update = updateIGImageFolderId(groupId, name, parentFolderId, folderId, folderIds);

        if (!update) {
          addDLFolderEntry(
              uuid,
              folderId,
              groupId,
              companyId,
              userId,
              userName,
              createDate,
              modifiedDate,
              groupId,
              parentFolderId,
              name,
              description,
              modifiedDate);
        }
      }

      runSQL("drop table IGFolder");
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
  protected void updatePortletPreferencesOwner() throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      StringBundler sb = new StringBundler(8);

      sb.append("select portletPreferencesId, plid, portletId, ");
      sb.append("preferences from PortletPreferences where ownerId = ");
      sb.append(PortletKeys.PREFS_OWNER_ID_DEFAULT);
      sb.append(" and ownerType = ");
      sb.append(PortletKeys.PREFS_OWNER_TYPE_LAYOUT);
      sb.append(" and portletId in ('8', '19', '33')");

      String sql = sb.toString();

      ps = con.prepareStatement(sql);

      rs = ps.executeQuery();

      while (rs.next()) {
        long plid = rs.getLong("plid");
        String portletId = rs.getString("portletId");
        String preferences = rs.getString("preferences");

        long ownerId = getOwnerId(plid);

        if (ownerId == 0) {
          continue;
        }

        long portletPreferencesId =
            getPortletPreferencesId(
                ownerId,
                PortletKeys.PREFS_OWNER_TYPE_GROUP,
                PortletKeys.PREFS_PLID_SHARED,
                portletId);

        if (portletPreferencesId != 0) {
          continue;
        }

        addPortletPreferences(
            ownerId,
            PortletKeys.PREFS_OWNER_TYPE_GROUP,
            PortletKeys.PREFS_PLID_SHARED,
            portletId,
            preferences);
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
Example #18
0
  protected void writeTimeJDBC(long time) throws SQLException {
    try (Connection connection = DataAccess.getConnection();
        PreparedStatement preparedStatement =
            connection.prepareStatement(_WRITE_RELEASE_MODIFIED_DATE)) {

      preparedStatement.setTimestamp(1, new Timestamp(time));

      Assert.assertEquals(1, preparedStatement.executeUpdate());
    }
  }
Example #19
0
  protected void addDLFolderEntry(
      String uuid,
      long folderId,
      long groupId,
      long companyId,
      long userId,
      String userName,
      Date createDate,
      Date modifiedDate,
      long repositoryId,
      long parentFolderId,
      String name,
      String description,
      Date lastPostDate)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;

    try {
      con = DataAccess.getConnection();

      StringBundler sb = new StringBundler(5);

      sb.append("insert into DLFolder (uuid_, folderId, groupId, ");
      sb.append("companyId, userId, userName, createDate, ");
      sb.append("modifiedDate, repositoryId, mountPoint, ");
      sb.append("parentFolderId, name, description, lastPostDate) ");
      sb.append("values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

      String sql = sb.toString();

      ps = con.prepareStatement(sql);

      ps.setString(1, uuid);
      ps.setLong(2, folderId);
      ps.setLong(3, groupId);
      ps.setLong(4, companyId);
      ps.setLong(5, userId);
      ps.setString(6, userName);
      ps.setDate(7, createDate);
      ps.setDate(8, modifiedDate);
      ps.setLong(9, repositoryId);
      ps.setBoolean(10, false);
      ps.setLong(11, parentFolderId);
      ps.setString(12, name);
      ps.setString(13, description);
      ps.setDate(14, lastPostDate);

      ps.executeUpdate();
    } finally {
      DataAccess.cleanUp(con, ps);
    }
  }
  protected long addGroup(
      long companyId, long creatorUserId, String groupName, long layoutSetPrototypeId)
      throws Exception {

    long layoutSetPrototypeClassNameId = getClassNameId(LayoutSetPrototype.class.getName());

    long groupId = getGroupId(companyId, layoutSetPrototypeClassNameId, layoutSetPrototypeId);

    if (groupId > 0) {
      return groupId;
    }

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      StringBundler sb = new StringBundler(5);

      sb.append("insert into Group_ (groupId, companyId, ");
      sb.append("creatorUserId, classNameId, classPK, parentGroupId, ");
      sb.append("liveGroupId, name, description, type_, typeSettings, ");
      sb.append("friendlyURL, site, active_) values (?, ?, ?, ?, ?, 0, ");
      sb.append("0, ?, ?, 0, ?, ?, ?, ?)");

      String sql = sb.toString();

      ps = con.prepareStatement(sql);

      groupId = increment();

      ps.setLong(1, groupId);
      ps.setLong(2, companyId);
      ps.setLong(3, creatorUserId);
      ps.setLong(4, layoutSetPrototypeClassNameId);
      ps.setLong(5, layoutSetPrototypeId);
      ps.setString(6, groupId + StringPool.MINUS + groupName);
      ps.setString(7, StringPool.BLANK);
      ps.setString(8, StringPool.BLANK);
      ps.setString(9, "/template-" + layoutSetPrototypeId);
      ps.setBoolean(10, false);
      ps.setBoolean(11, true);

      ps.execute();

      return groupId;
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
Example #21
0
  protected long readTimeJDBC() throws SQLException {
    try (Connection connection = DataAccess.getConnection();
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(_READ_RELEASE_MODIFIED_DATE)) {

      Assert.assertTrue(resultSet.next());

      Timestamp timestamp = resultSet.getTimestamp("modifiedDate");

      Assert.assertFalse(resultSet.next());

      return timestamp.getTime();
    }
  }
  protected long addLayoutSet(
      long layoutSetId,
      long companyId,
      long groupId,
      long layoutSetPrototypeId,
      UserGroupTemplateInfo userGroupTemplateInfo)
      throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      StringBundler sb = new StringBundler(5);

      sb.append("insert into LayoutSet (layoutSetId, groupId, ");
      sb.append("companyId, privateLayout, logo, logoId, themeId, ");
      sb.append("colorSchemeId, wapThemeId, wapColorSchemeId, css, ");
      sb.append("pageCount, settings_, layoutSetPrototypeId) values ");
      sb.append("(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

      String sql = sb.toString();

      ps = con.prepareStatement(sql);

      ps.setLong(1, layoutSetId);
      ps.setLong(2, groupId);
      ps.setLong(3, companyId);
      ps.setBoolean(4, userGroupTemplateInfo.isPrivateLayout());
      ps.setShort(5, userGroupTemplateInfo.getLogo());
      ps.setLong(6, userGroupTemplateInfo.getLogoId());
      ps.setString(7, userGroupTemplateInfo.getThemeId());
      ps.setString(8, userGroupTemplateInfo.getColorSchemeId());
      ps.setString(9, userGroupTemplateInfo.getWapThemeId());
      ps.setString(10, userGroupTemplateInfo.getWapColorSchemeId());
      ps.setString(11, userGroupTemplateInfo.getCss());
      ps.setLong(12, userGroupTemplateInfo.getPageCount());
      ps.setString(13, userGroupTemplateInfo.getSettings());
      ps.setLong(14, layoutSetPrototypeId);

      ps.execute();

      return layoutSetId;

    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
Example #23
0
  protected void executePreparedStatement(String sql) throws Exception {
    Connection connection = null;
    PreparedStatement preparedStatement = null;

    try {
      connection = DataAccess.getConnection();

      preparedStatement = connection.prepareStatement(sql);

      preparedStatement.execute();
    } catch (SQLException sqle) {
    } finally {
      DataAccess.cleanUp(connection, preparedStatement);
    }
  }
Example #24
0
  protected void executeStatement(String sql) throws Exception {
    Connection connection = null;
    Statement statement = null;

    try {
      connection = DataAccess.getConnection();

      statement = connection.createStatement();

      statement.execute(sql);
    } catch (SQLException sqle) {
    } finally {
      DataAccess.cleanUp(connection, statement);
    }
  }
  protected void updateLayout(long plid, String typeSettings) throws Exception {

    Connection con = null;
    PreparedStatement ps = null;

    try {
      con = DataAccess.getConnection();

      ps = con.prepareStatement("update Layout set typeSettings = ? where plid = " + plid);

      ps.setString(1, typeSettings);

      ps.executeUpdate();
    } finally {
      DataAccess.cleanUp(con, ps);
    }
  }
  @Override
  public List<Index> getIndexes() throws SQLException {
    List<Index> indexes = new ArrayList<Index>();

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      DatabaseMetaData databaseMetaData = con.getMetaData();

      if (databaseMetaData.getDatabaseMajorVersion() <= _SQL_SERVER_2000) {

        return null;
      }

      StringBundler sb = new StringBundler(6);

      sb.append("select sys.tables.name as table_name, ");
      sb.append("sys.indexes.name as index_name, is_unique from ");
      sb.append("sys.indexes inner join sys.tables on ");
      sb.append("sys.tables.object_id = sys.indexes.object_id where ");
      sb.append("sys.indexes.name like 'LIFERAY_%' or sys.indexes.name ");
      sb.append("like 'IX_%'");

      String sql = sb.toString();

      ps = con.prepareStatement(sql);

      rs = ps.executeQuery();

      while (rs.next()) {
        String indexName = rs.getString("index_name");
        String tableName = rs.getString("table_name");
        boolean unique = !rs.getBoolean("is_unique");

        indexes.add(new Index(indexName, tableName, unique));
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }

    return indexes;
  }
  private long[] _getCompanyIdsBySQL() throws SQLException {
    List<Long> companyIds = new ArrayList<>();

    String currentShardName = ShardUtil.setTargetSource(PropsValues.SHARD_DEFAULT_NAME);

    if (Validator.isNotNull(currentShardName)) {
      ShardUtil.pushCompanyService(PropsValues.SHARD_DEFAULT_NAME);
    }

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      ps = con.prepareStatement(_GET_COMPANY_IDS);

      if (Validator.isNotNull(currentShardName)) {
        ps.setString(1, currentShardName);
      } else {
        ps.setString(1, PropsValues.SHARD_DEFAULT_NAME);
      }

      rs = ps.executeQuery();

      while (rs.next()) {
        long companyId = rs.getLong("companyId");

        companyIds.add(companyId);
      }
    } finally {
      if (Validator.isNotNull(currentShardName)) {
        ShardUtil.popCompanyService();

        ShardUtil.setTargetSource(currentShardName);
      }

      DataAccess.cleanUp(con, ps, rs);
    }

    return ArrayUtil.toArray(companyIds.toArray(new Long[companyIds.size()]));
  }
  protected void updateMessage() throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      StringBundler sb = new StringBundler(8);

      sb.append("select childMessage.messageId, ");
      sb.append("parentMessage.categoryId, parentMessage.threadId ");
      sb.append("from MBMessage childMessage ");
      sb.append("inner join MBMessage parentMessage on ");
      sb.append("childMessage.parentMessageId = ");
      sb.append("parentMessage.messageId where ");
      sb.append("parentMessage.categoryId != childMessage.categoryId ");
      sb.append("or parentMessage.threadId != childMessage.threadId");

      String sql = sb.toString();

      ps = con.prepareStatement(sql);

      rs = ps.executeQuery();

      while (rs.next()) {
        long messageId = rs.getLong(1);
        long categoryId = rs.getLong(2);
        long threadId = rs.getLong(3);

        runSQL(
            "update MBMessage set categoryId = "
                + categoryId
                + ", threadId = "
                + threadId
                + " where messageId = "
                + messageId);
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
Example #29
0
  @Override
  public List<Index> getIndexes() throws SQLException {
    List<Index> indexes = new ArrayList<Index>();

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getConnection();

      StringBundler sb = new StringBundler(3);

      sb.append("select index_name, table_name, uniqueness from ");
      sb.append("user_indexes where index_name like 'LIFERAY_%' or ");
      sb.append("index_name like 'IX_%'");

      String sql = sb.toString();

      ps = con.prepareStatement(sql);

      rs = ps.executeQuery();

      while (rs.next()) {
        String indexName = rs.getString("index_name");
        String tableName = rs.getString("table_name");
        String uniqueness = rs.getString("uniqueness");

        boolean unique = true;

        if (uniqueness.equalsIgnoreCase("NONUNIQUE")) {
          unique = false;
        }

        indexes.add(new Index(indexName, tableName, unique));
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }

    return indexes;
  }
Example #30
0
  private static void _updateReleaseState(int state) throws Exception {
    Connection con = null;
    PreparedStatement ps = null;

    try {
      con = DataAccess.getConnection();

      ps =
          con.prepareStatement(
              "update Release_ set modifiedDate = ?, state_ = ? where " + "releaseId = ?");

      ps.setDate(1, new Date(System.currentTimeMillis()));
      ps.setInt(2, state);
      ps.setLong(3, ReleaseConstants.DEFAULT_ID);

      ps.executeUpdate();
    } finally {
      DataAccess.cleanUp(con, ps);
    }
  }