Skip to content

Commit

Permalink
LPS-47199 rename to disambiguate; clarify relationship between userId…
Browse files Browse the repository at this point in the history
… and includeOwner in QueryDefinition, and use USER_ID instead of OWNER in sql
  • Loading branch information
arbetts authored and brianchandotcom committed Jul 27, 2015
1 parent 55b5c84 commit 6cb38ce
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
(JournalArticle.groupId = ?) AND
(JournalArticle.classNameId = ?) AND
([$FOLDER_ID$]) AND
([$OWNER$] [$OWNER_AND_OR_CONNECTOR$] [$STATUS$]) AND
([$USER_ID$] [$USER_ID_AND_OR_CONNECTOR$] [$STATUS$]) AND
(tempJournalArticle.id_ IS NULL)
]]>
</sql>
Expand Down Expand Up @@ -220,7 +220,7 @@
(JournalArticle.groupId = ?) AND
(JournalArticle.classNameId = ?) AND
([$FOLDER_ID$]) AND
([$OWNER$] [$OWNER_AND_OR_CONNECTOR$] [$STATUS$]) AND
([$USER_ID$] [$USER_ID_AND_OR_CONNECTOR$] [$STATUS$]) AND
(tempJournalArticle.id_ IS NULL)
ORDER BY
JournalArticle.id_ ASC
Expand Down Expand Up @@ -302,7 +302,7 @@
WHERE
(JournalArticle.groupId = ?) AND
(JournalArticle.classNameId = 0) AND
([$OWNER$] [$OWNER_AND_OR_CONNECTOR$] ([$STATUS$]))
([$USER_ID$] [$USER_ID_AND_OR_CONNECTOR$] ([$STATUS$]))
[$ARTICLE_FOLDER_ID$]
]]>
</sql>
Expand Down Expand Up @@ -331,7 +331,7 @@
WHERE
(JournalArticle.groupId = ?) AND
(JournalArticle.classNameId = 0) AND
([$OWNER$] [$OWNER_AND_OR_CONNECTOR$] ([$STATUS$]))
([$USER_ID$] [$USER_ID_AND_OR_CONNECTOR$] ([$STATUS$]))
[$ARTICLE_FOLDER_ID$]
GROUP BY
JournalArticle.resourcePrimKey, JournalArticle.folderId, JournalArticle.articleId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,8 +892,8 @@ protected int doCountByG_F_C(
qPos.add(groupId);
qPos.add(classNameId);

if (queryDefinition.getUserId() > 0) {
qPos.add(queryDefinition.getUserId());
if (queryDefinition.getOwnerUserId() > 0) {
qPos.add(queryDefinition.getOwnerUserId());

if (queryDefinition.isIncludeOwner()) {
qPos.add(WorkflowConstants.STATUS_IN_TRASH);
Expand Down Expand Up @@ -1245,8 +1245,8 @@ protected List<JournalArticle> doFindByG_F_C(
qPos.add(groupId);
qPos.add(classNameId);

if (queryDefinition.getUserId() > 0) {
qPos.add(queryDefinition.getUserId());
if (queryDefinition.getOwnerUserId() > 0) {
qPos.add(queryDefinition.getOwnerUserId());

if (queryDefinition.isIncludeOwner()) {
qPos.add(WorkflowConstants.STATUS_IN_TRASH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ protected int doCountF_A_ByG_F(

qPos.add(groupId);

if (queryDefinition.getUserId() > 0) {
qPos.add(queryDefinition.getUserId());
if (queryDefinition.getOwnerUserId() > 0) {
qPos.add(queryDefinition.getOwnerUserId());
qPos.add(WorkflowConstants.STATUS_IN_TRASH);
}

Expand Down Expand Up @@ -230,8 +230,8 @@ protected List<Object> doFindF_A_ByG_F(

qPos.add(groupId);

if (queryDefinition.getUserId() > 0) {
qPos.add(queryDefinition.getUserId());
if (queryDefinition.getOwnerUserId() > 0) {
qPos.add(queryDefinition.getOwnerUserId());
qPos.add(WorkflowConstants.STATUS_IN_TRASH);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void testDraftArticles() throws Exception {
_group.getGroupId(), Collections.<Long>emptyList(),
JournalArticleConstants.CLASSNAME_ID_DEFAULT, queryDefinition, 2);

queryDefinition.setUserId(TestPropsValues.getUserId());
queryDefinition.setOwnerUserId(TestPropsValues.getUserId());

JournalArticle article = JournalTestUtil.addArticleWithXMLContent(
_group.getGroupId(), _folder.getFolderId(),
Expand All @@ -201,7 +201,7 @@ public void testDraftArticles() throws Exception {
_articles.add(article);

queryDefinition.setIncludeOwner(true);
queryDefinition.setUserId(_USER_ID);
queryDefinition.setOwnerUserId(_USER_ID);
queryDefinition.setStatus(WorkflowConstants.STATUS_APPROVED);

testQueryByG_C(
Expand Down Expand Up @@ -420,7 +420,7 @@ public void testQueryByG_F_C() throws Exception {
QueryDefinition<JournalArticle> queryDefinition = new QueryDefinition<>(
WorkflowConstants.STATUS_ANY);

queryDefinition.setUserId(TestPropsValues.getUserId());
queryDefinition.setOwnerUserId(TestPropsValues.getUserId());

testQueryByG_C(
_group.getGroupId(), Collections.<Long>emptyList(),
Expand All @@ -429,7 +429,7 @@ public void testQueryByG_F_C() throws Exception {
// Status any

queryDefinition.setStatus(WorkflowConstants.STATUS_ANY);
queryDefinition.setUserId(_USER_ID);
queryDefinition.setOwnerUserId(_USER_ID);

testQueryByG_C(
_group.getGroupId(), Collections.<Long>emptyList(),
Expand All @@ -438,7 +438,7 @@ public void testQueryByG_F_C() throws Exception {
// Status in trash

queryDefinition.setStatus(WorkflowConstants.STATUS_IN_TRASH);
queryDefinition.setUserId(_USER_ID);
queryDefinition.setOwnerUserId(_USER_ID);

testQueryByG_C(
_group.getGroupId(), Collections.<Long>emptyList(),
Expand All @@ -447,7 +447,7 @@ public void testQueryByG_F_C() throws Exception {
// Status not in trash

queryDefinition.setStatus(WorkflowConstants.STATUS_IN_TRASH, true);
queryDefinition.setUserId(_USER_ID);
queryDefinition.setOwnerUserId(_USER_ID);

testQueryByG_C(
_group.getGroupId(), Collections.<Long>emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
WikiPage.groupId = ? AND
WikiPage.nodeId = ? AND
WikiPage.head = ? AND
([$OWNER$] [$OWNER_AND_OR_CONNECTOR$] [$STATUS$])
([$USER_ID$] [$USER_ID_AND_OR_CONNECTOR$] [$STATUS$])
]]>
</sql>
<sql id="com.liferay.wiki.service.persistence.WikiPageFinder.findByResourcePrimKey">
Expand Down Expand Up @@ -81,7 +81,7 @@
WikiPage.groupId = ? AND
WikiPage.nodeId = ? AND
WikiPage.head = ? AND
([$OWNER$] [$OWNER_AND_OR_CONNECTOR$] [$STATUS$])
([$USER_ID$] [$USER_ID_AND_OR_CONNECTOR$] [$STATUS$])
)
TEMP_TABLE
INNER JOIN WikiPage ON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ protected int doCountByG_N_H_S(
qPos.add(nodeId);
qPos.add(head);

if (queryDefinition.getUserId() > 0) {
qPos.add(queryDefinition.getUserId());
if (queryDefinition.getOwnerUserId() > 0) {
qPos.add(queryDefinition.getOwnerUserId());

if (queryDefinition.isIncludeOwner()) {
qPos.add(WorkflowConstants.STATUS_IN_TRASH);
Expand Down Expand Up @@ -431,8 +431,8 @@ protected List<WikiPage> doFindByG_N_H_S(
qPos.add(nodeId);
qPos.add(head);

if (queryDefinition.getUserId() > 0) {
qPos.add(queryDefinition.getUserId());
if (queryDefinition.getOwnerUserId() > 0) {
qPos.add(queryDefinition.getOwnerUserId());

if (queryDefinition.isIncludeOwner()) {
qPos.add(WorkflowConstants.STATUS_IN_TRASH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ public QueryDefinition(
}

public QueryDefinition(
int status, boolean excludeStatus, long userId, boolean includeOwner,
int start, int end, OrderByComparator<T> orderByComparator) {
int status, boolean excludeStatus, long ownerUserId,
boolean includeOwner, int start, int end,
OrderByComparator<T> orderByComparator) {

_status = status;
_excludeStatus = excludeStatus;
_userId = userId;
_ownerUserId = ownerUserId;
_includeOwner = includeOwner;
_start = start;
_end = end;
Expand All @@ -63,20 +64,20 @@ public QueryDefinition(
this(status, 0, false, start, end, orderByComparator);
}

public QueryDefinition(int status, long userId, boolean includeOwner) {
public QueryDefinition(int status, long ownerUserId, boolean includeOwner) {
if (status == WorkflowConstants.STATUS_ANY) {
setStatus(WorkflowConstants.STATUS_IN_TRASH, true);
}
else {
setStatus(status);
}

_userId = userId;
_ownerUserId = ownerUserId;
_includeOwner = includeOwner;
}

public QueryDefinition(
int status, long userId, boolean includeOwner, int start, int end,
int status, long ownerUserId, boolean includeOwner, int start, int end,
OrderByComparator<T> orderByComparator) {

if (status == WorkflowConstants.STATUS_ANY) {
Expand All @@ -86,7 +87,7 @@ public QueryDefinition(
setStatus(status);
}

_userId = userId;
_ownerUserId = ownerUserId;
_includeOwner = includeOwner;
_start = start;
_end = end;
Expand Down Expand Up @@ -122,6 +123,10 @@ public OrderByComparator<T> getOrderByComparator(String tableName) {
return new TableNameOrderByComparator<>(_orderByComparator, tableName);
}

public long getOwnerUserId() {
return _ownerUserId;
}

public int getStart() {
return _start;
}
Expand All @@ -130,10 +135,6 @@ public int getStatus() {
return _status;
}

public long getUserId() {
return _userId;
}

public boolean isExcludeStatus() {
return _excludeStatus;
}
Expand Down Expand Up @@ -166,6 +167,10 @@ public void setOrderByComparator(OrderByComparator<T> orderByComparator) {
_orderByComparator = orderByComparator;
}

public void setOwnerUserId(long ownerUserId) {
_ownerUserId = ownerUserId;
}

public void setStart(int start) {
_start = start;
}
Expand All @@ -179,17 +184,13 @@ public void setStatus(int status, boolean exclude) {
_status = status;
}

public void setUserId(long userId) {
_userId = userId;
}

private Map<String, Serializable> _attributes;
private int _end = QueryUtil.ALL_POS;
private boolean _excludeStatus;
private boolean _includeOwner;
private OrderByComparator<T> _orderByComparator;
private long _ownerUserId;
private int _start = QueryUtil.ALL_POS;
private int _status = WorkflowConstants.STATUS_ANY;
private long _userId;

}
24 changes: 12 additions & 12 deletions util-java/src/com/liferay/util/dao/orm/CustomSQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,33 +149,33 @@ public String get(
}
}

if (queryDefinition.getUserId() > 0) {
if (queryDefinition.getOwnerUserId() > 0) {
if (queryDefinition.isIncludeOwner()) {
StringBundler sb = new StringBundler();

sb.append(StringPool.OPEN_PARENTHESIS);
sb.append(tableName);
sb.append(_OWNER_CONDITION_DEFAULT);
sb.append(_USER_ID_CONDITION_DEFAULT);
sb.append(" AND ");
sb.append(tableName);
sb.append(_STATUS_CONDITION_INVERSE);
sb.append(StringPool.CLOSE_PARENTHESIS);

sql = sql.replace(_OWNER_KEYWORD, sb.toString());
sql = sql.replace(_USER_ID_KEYWORD, sb.toString());

sql = sql.replace(_OWNER_AND_OR_CONNECTOR, " OR ");
sql = sql.replace(_USER_ID_AND_OR_CONNECTOR, " OR ");
}
else {
sql = sql.replace(
_OWNER_KEYWORD, tableName.concat(_OWNER_CONDITION_DEFAULT));
_USER_ID_KEYWORD, tableName.concat(_USER_ID_CONDITION_DEFAULT));

sql = sql.replace(_OWNER_AND_OR_CONNECTOR, " AND ");
sql = sql.replace(_USER_ID_AND_OR_CONNECTOR, " AND ");
}
}
else {
sql = sql.replace(_OWNER_KEYWORD, StringPool.BLANK);
sql = sql.replace(_USER_ID_KEYWORD, StringPool.BLANK);

sql = sql.replace(_OWNER_AND_OR_CONNECTOR, StringPool.BLANK);
sql = sql.replace(_USER_ID_AND_OR_CONNECTOR, StringPool.BLANK);
}

return sql;
Expand Down Expand Up @@ -870,12 +870,12 @@ private String escapeWildCards(String keywords) {

private static final String _ORDER_BY_CLAUSE = " ORDER BY ";

private static final String _OWNER_AND_OR_CONNECTOR =
"[$OWNER_AND_OR_CONNECTOR$]";
private static final String _USER_ID_AND_OR_CONNECTOR =
"[$USER_ID_AND_OR_CONNECTOR$]";

private static final String _OWNER_CONDITION_DEFAULT = "userId = ?";
private static final String _USER_ID_CONDITION_DEFAULT = "userId = ?";

private static final String _OWNER_KEYWORD = "[$OWNER$]";
private static final String _USER_ID_KEYWORD = "[$USER_ID$]";

private static final String _STATUS_CONDITION_DEFAULT = "status = ?";

Expand Down
Loading

0 comments on commit 6cb38ce

Please sign in to comment.