Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Apr 27, 2017
1 parent ed770d6 commit 952d1de
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static PPOrderLinesView cast(final IDocumentViewSelection view)
{
return (PPOrderLinesView)view;
}

private final ViewId parentViewId;

private final ViewId viewId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;

import de.metas.ui.web.window.datatypes.WindowId;
import de.metas.ui.web.window.model.DocumentQueryOrderBy;

/*
Expand Down Expand Up @@ -74,6 +75,16 @@ public ViewId getViewId()
{
return viewId;
}

public WindowId getWindowId()
{
return viewId.getWindowId();
}

public String getSelectionId()
{
return viewId.getViewId();
}

public long getSize()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ private SqlDocumentViewSelection(final Builder builder)

//
// Attributes
attributesProvider = DocumentViewAttributesProviderFactory.instance.createProviderOrNull(defaultSelection.getViewId().getWindowId());
attributesProvider = DocumentViewAttributesProviderFactory.instance.createProviderOrNull(defaultSelection.getWindowId());

//
// Cache
cache_documentViewsById = CCache.newLRUCache( //
tableName + "#DocumentViewById#viewId=" + defaultSelection.getViewId() // cache name
tableName + "#DocumentViewById#viewId=" + defaultSelection.getSelectionId() // cache name
, 100 // maxSize
, 2 // expireAfterMinutes
);
Expand Down Expand Up @@ -267,11 +267,11 @@ public DocumentViewResult getPage(final int firstRow, final int pageLength, fina
final DocumentViewOrderedSelection orderedSelection = getOrderedSelection(orderBys);
logger.debug("Using: {}", orderedSelection);

final ViewId viewId = orderedSelection.getViewId();
final String selectionId = orderedSelection.getSelectionId();
final int firstSeqNo = firstRow + 1; // NOTE: firstRow is 0-based while SeqNo are 1-based
final int lastSeqNo = firstRow + pageLength;

final Object[] sqlParams = new Object[] { viewId.getViewId(), firstSeqNo, lastSeqNo };
final Object[] sqlParams = new Object[] { selectionId, firstSeqNo, lastSeqNo };
PreparedStatement pstmt = null;
ResultSet rs = null;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import de.metas.ui.web.view.DocumentViewOrderedSelection;
import de.metas.ui.web.view.IDocumentViewOrderedSelectionFactory;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.window.datatypes.WindowId;
import de.metas.ui.web.window.model.DocumentQueryOrderBy;

/*
Expand Down Expand Up @@ -62,11 +63,15 @@ public String toString()
@Override
public DocumentViewOrderedSelection createFromView(final DocumentViewOrderedSelection fromView, final List<DocumentQueryOrderBy> orderBys)
{
final ViewId fromViewId = fromView.getViewId();
final ViewId newViewId = ViewId.random(fromViewId.getWindowId());
final WindowId windowId = fromView.getWindowId();
final String fromSelectionId = fromView.getSelectionId();

final ViewId newViewId = ViewId.random(windowId);
final String newSelectionId = newViewId.getViewId();

final String sqlOrderBys = buildOrderBys(orderBys); // NOTE: we assume it's not empty!
final String sqlFinal = sqlCreateFromViewId.replace(SqlDocumentViewBinding.PLACEHOLDER_OrderBy, sqlOrderBys);
final int rowCount = DB.executeUpdateEx(sqlFinal, new Object[] { newViewId.getViewId(), fromViewId.getViewId() }, ITrx.TRXNAME_ThreadInherited);
final int rowCount = DB.executeUpdateEx(sqlFinal, new Object[] { newSelectionId, fromSelectionId }, ITrx.TRXNAME_ThreadInherited);

return DocumentViewOrderedSelection.builder()
.setViewId(newViewId)
Expand Down

0 comments on commit 952d1de

Please sign in to comment.