Skip to content

Commit

Permalink
refactoring of services responsible for handling queries
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekkup committed Aug 28, 2013
1 parent 9aa4591 commit 4614dc4
Show file tree
Hide file tree
Showing 22 changed files with 443 additions and 262 deletions.
Expand Up @@ -28,6 +28,7 @@ qx.Class.define("helenos.components.tab.browse.AbstractPage",

this._manager = new qx.ui.form.validation.Manager();
this._resetter = new qx.ui.form.Resetter();
this._disabler = new helenos.ui.form.Disabler();
this.__buildMainPane();
},

Expand All @@ -36,6 +37,7 @@ qx.Class.define("helenos.components.tab.browse.AbstractPage",
_cfDef : null,
_manager : null,
_resetter : null,
_disabler : null,
_resultsTree : null,
_consistencyLevelSB : null,
_searchButtonMenu : null,
Expand All @@ -60,6 +62,10 @@ qx.Class.define("helenos.components.tab.browse.AbstractPage",
this._resetter.add(widget);
},

_addToDisabler : function(widget) {
this._disabler.add(widget);
},

_initConsistencyLevelSB : function() {
this._consistencyLevelSB = new qx.ui.form.SelectBox();

Expand Down
Expand Up @@ -12,35 +12,46 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",

construct : function(ksName, cfName)
{
this._keyMode = this.self(arguments).PREDICATE;
this._colMode = this.self(arguments).RANGE;
this.base(arguments, ksName, cfName);

this.__disableNextPrevBtns();
},


statics : {
PREDICATE : 'predicate',
NAME : 'name',
RANGE : 'range',
KEY_RANGE : 'key range'
},

members :
{
__keyModeRBG : null,
__columnsByRBG : null,

__keyFromTF : null,
__keyToTF : null,
__keyMode : 'predicate',
__keyMode : null,
__keyTF : null,
__keysLimitTF : null,

__nameStartTF : null,
__nameEndTF : null,
__sNameTF : null,
__columnNamesTF : null,
__colMode : 'range',
__colMode : null,

__keysPredicateCP : null,
__keysRangeCP : null,
__rangeColNamesCP : null,
__rangeFromToCP : null,
__reversedCB : null,
__colsLimitTF : null,
__firstKeyID : null,
__lastKeyID : null,
// for pagination
__firstID : null,
__lastID : null,
__prevPageBtn : null,
__nextPageBtn : null,
__nextPrevBtnsEnabled : false,
Expand All @@ -56,14 +67,11 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",
},

_performSearch : function(e) {
var keyFrom = this.__keyFromTF.getValue();
var keyTo = this.__keyToTF.getValue();

var sName = (this.__sNameTF == null ? null : this.__sNameTF.getValue());
var consistencyLevel = this._consistencyLevelSB.getSelection()[0].getLabel();

var nameStart, nameEnd, reversed, columnNames;
if (this.__columnsByRBG.getSelection()[0].getLabel() == 'range') {
if (this.__columnsByRBG.getSelection()[0].getLabel() == this.self(arguments).RANGE) {
nameStart = this.__nameStartTF.getValue();
nameEnd = this.__nameEndTF.getValue();
reversed = this.__reversedCB.getValue();
Expand All @@ -72,17 +80,33 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",
}

var result = null;
if (this.__keyMode == 'predicate') {
result = helenos.util.RpcActionsProvider.queryPredicate(this._cfDef, consistencyLevel, keyFrom, columnNames, nameStart, nameEnd, sName, reversed);
if (this.__keyMode == this.self(arguments).PREDICATE) {
var key = this._keyTF.getValue();
result = helenos.util.RpcActionsProvider.queryPredicate(this._cfDef, consistencyLevel, key, columnNames, nameStart, nameEnd, sName, reversed);
} else {
var keyFrom = this.__keyFromTF.getValue();
var keyTo = this.__keyToTF.getValue();
result = helenos.util.RpcActionsProvider.queryKeyRange(this._cfDef, consistencyLevel, keyFrom, keyTo, columnNames, nameStart, nameEnd, sName, reversed);
}

this.__firstKeyID = result[0].key;
this.__lastKeyID = result[result.length-1].key;
this._collectPaginationData(result);

return result;
},

_collectPaginationData : function(result) {
if (this.__keyMode == this.self(arguments).KEY_RANGE) {
this.__firstID = result[0].key;
this.__lastID = result[result.length-1].key;
} else {
if (this.__colMode == this.self(arguments).RANGE) {}
var columnsRange = result[0].columns;
this.__firstID = columnsRange[0].name;
this.__lastID = columnsRange[columnsRange.length-1].name;
}
}
},

_getResultsPane : function() {
var pane = this.base(arguments);
pane.add(this.__getButtonsBar());
Expand Down Expand Up @@ -123,7 +147,7 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",
},

__validateNextPrevMode : function() {
if (this._colMode == 'range' && this._keyMode != 'predicate') {
if (this._colMode == this.self(arguments).RANGE && this._keyMode == this.self(arguments).KEY_RANGE) {
(new dialog.Alert({
"message" : 'You can not paginate with key mode and column mode set to \'range\'',
'image' : 'icon/48/status/dialog-error.png'
Expand Down Expand Up @@ -163,6 +187,8 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",

__resetSearchForm : function(e) {
this._resetter.reset();
this._disabler.enable();
this._disableNextPrevBtns();
},

__disableNextPrevBtns : function() {
Expand Down Expand Up @@ -200,7 +226,9 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",
this.__nameEndTF = new helenos.ui.TextField(this._cfDef.comparatorType.className);
}
this._addToResetter(this.__nameStartTF);
this._addToDisabler(this.__nameStartTF);
this._addToResetter(this.__nameEndTF);
this._addToDisabler(this.__nameEndTF);

columnsGB.add(this.__getRangeFromToBox());
columnsGB.add(this.__getRangeColNamesBox());
Expand Down Expand Up @@ -232,6 +260,7 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",
this.__keysPredicateCP = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({padding : 0});
this.__keyTF = new helenos.ui.TextField(this._cfDef.keyValidationClass);
this._addToResetter(this.__keyTF);
this._addToDisabler(this.__keyTF);
this.__keysPredicateCP.add(new qx.ui.basic.Label('Key:'));
this.__keysPredicateCP.add(this.__keyTF);

Expand All @@ -243,8 +272,11 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",
this.__keyToTF = new helenos.ui.TextField(this._cfDef.keyValidationClass);
this.__keysLimitTF = new qx.ui.form.TextField().set({filter : /[0-9]/, value : '10'});
this._addToResetter(this.__keyFromTF);
this._addToDisabler(this.__keyFromTF);
this._addToResetter(this.__keyToTF);
this._addToDisabler(this.__keyToTF);
this._addToResetter(this.__keysLimitTF);
this._addToDisabler(this.__keysLimitTF);

this.__keysRangeCP = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({padding : 0, visibility : 'excluded'});
this.__keysRangeCP.add(new qx.ui.basic.Label('From:'));
Expand All @@ -257,11 +289,12 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",
},

__getRangeModeBG : function() {
var byNameBT = new qx.ui.form.RadioButton('name');
var byRangeBT = new qx.ui.form.RadioButton('range');
var byNameBT = new qx.ui.form.RadioButton(this.self(arguments).NAME);
var byRangeBT = new qx.ui.form.RadioButton(this.self(arguments).RANGE);

this.__columnsByRBG = new qx.ui.form.RadioButtonGroup(new qx.ui.layout.HBox(8));
this._addToResetter(this.__columnsByRBG);
this._addToDisabler(this.__columnsByRBG);
this.__columnsByRBG.add(byNameBT);
this.__columnsByRBG.add(byRangeBT);
this.__columnsByRBG.setSelection([byRangeBT]);
Expand All @@ -270,11 +303,12 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",
},

__getKeyModeBG : function() {
var predicateBT = new qx.ui.form.RadioButton('predicate');
var keyRangeBT = new qx.ui.form.RadioButton('key range');
var predicateBT = new qx.ui.form.RadioButton(this.self(arguments).PREDICATE);
var keyRangeBT = new qx.ui.form.RadioButton(this.self(arguments).KEY_RANGE);

this.__keyModeRBG = new qx.ui.form.RadioButtonGroup(new qx.ui.layout.HBox(5));
this._addToResetter(this.__keyModeRBG);
this._addToDisabler(this.__keyModeRBG);
this.__keyModeRBG.add(predicateBT);
this.__keyModeRBG.add(keyRangeBT);
this.__keyModeRBG.setSelection([predicateBT]);
Expand All @@ -287,6 +321,7 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",

this.__colsLimitTF = new qx.ui.form.TextField().set({filter : /[0-9]/, value : '10'});
this._addToResetter(this.__colsLimitTF);
this._addToDisabler(this.__colsLimitTF);

this.__rangeFromToCP.add(new qx.ui.basic.Label('From:'));
this.__rangeFromToCP.add(this.__nameStartTF);
Expand All @@ -297,6 +332,7 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",

this.__reversedCB = new qx.ui.form.CheckBox('Reversed');
this._addToResetter(this.__reversedCB);
this._addToDisabler(this.__reversedCB);
this.__rangeFromToCP.add(this.__reversedCB);

return this.__rangeFromToCP;
Expand All @@ -307,6 +343,7 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",

this.__columnNamesTF = new qx.ui.form.TextArea().set({placeholder : 'comma separated columns list'});
this._addToResetter(this.__columnNamesTF);
this._addToDisabler(this.__columnNamesTF);
this.__rangeColNamesCP.add(new qx.ui.basic.Label('Column names:'));
this.__rangeColNamesCP.add(this.__columnNamesTF);

Expand All @@ -315,7 +352,7 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",

_onRangeModeToggled : function(e) {
this._colMode = e.getData()[0].getLabel();
if (this._colMode == 'name') {
if (this._colMode == this.self(arguments).NAME) {
this.__rangeFromToCP.setVisibility('excluded');
this.__rangeColNamesCP.setVisibility('visible');
} else {
Expand All @@ -326,7 +363,7 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",

_onKeyModeToggled : function(e) {
this.__keyMode = e.getData()[0].getLabel();
if (this.__keyMode == 'predicate') {
if (this.__keyMode == this.self(arguments).PREDICATE) {
this.__keysRangeCP.setVisibility('excluded');
this.__keysPredicateCP.setVisibility('visible');
} else {
Expand All @@ -335,4 +372,4 @@ qx.Class.define("helenos.components.tab.browse.PredicatePage",
}
}
}
});
});
40 changes: 40 additions & 0 deletions src/main/frontend/source/class/helenos/ui/form/Disabler.js
@@ -0,0 +1,40 @@
/* ************************************************************************
Copyright:
2012 Tomek Kuprowski
License:
GPLv2: http://www.gnu.org/licences/gpl.html
Authors:
Tomek Kuprowski (tomekkuprowski at gmail dot com)
************************************************************************ */
qx.Class.define("helenos.ui.form.Disabler",
{
extend : qx.core.Object,

construct : function()
{
this.base(arguments);

this.__items = [];
},

members :
{
__items : null,

disable : function() {
for (var i = 0; i < this.__items.length; i++) {
this.__items[i].setEnabled(false);
}
},

enable : function() {
for (var i = 0; i < this.__items.length; i++) {
this.__items[i].setEnabled(true);
}
},

add : function(item) {
this.__items.push(item);
}
}
});
Expand Up @@ -3,8 +3,9 @@
import com.googlecode.jsonrpc4j.JsonRpcParam;
import java.util.List;
import tomekkup.helenos.types.Slice;
import tomekkup.helenos.types.qx.query.CqlQuery;
import tomekkup.helenos.types.qx.query.RangeQuery;
import tomekkup.helenos.types.qx.query.QxCqlQuery;
import tomekkup.helenos.types.qx.query.QxPredicateQuery;
import tomekkup.helenos.types.qx.query.QxRangeQuery;

/**
* ********************************************************
Expand All @@ -16,9 +17,9 @@
* *******************************************************
*/
public interface StandardQueryProvider {
<K, N, V> List<Slice<K, N, V>> predicate(@JsonRpcParam("query") RangeQuery<K, N, V> query);
<K, N, V> List<Slice<K, N, V>> predicate(@JsonRpcParam("query") QxPredicateQuery<K, N, V> query);

<K, N, V> List<Slice<K, N, V>> keyRange(tomekkup.helenos.types.qx.query.RangeQuery<K, N, V> query);
<K, N, V> List<Slice<K, N, V>> keyRange(@JsonRpcParam("query") QxRangeQuery<K, N, V> query);

<K, N, V> List<Slice<K, N, V>> cql(@JsonRpcParam("query") CqlQuery<K, N, V> query);
<K, N, V> List<Slice<K, N, V>> cql(@JsonRpcParam("query") QxCqlQuery<K, N, V> query);
}
Expand Up @@ -3,7 +3,8 @@
import com.googlecode.jsonrpc4j.JsonRpcParam;
import java.util.List;
import tomekkup.helenos.types.Slice;
import tomekkup.helenos.types.qx.query.SubRangeQuery;
import tomekkup.helenos.types.qx.query.QxSubPredicateQuery;
import tomekkup.helenos.types.qx.query.QxSubRangeQuery;

/**
* ********************************************************
Expand All @@ -16,7 +17,7 @@
*/
public interface SuperQueryProvider {

<K, SN, N, V> List<Slice<K, N, V>> predicate(@JsonRpcParam("query") SubRangeQuery<K,SN,N,V> query);
<K, SN, N, V> List<Slice<K, N, V>> predicate(@JsonRpcParam("query") QxSubPredicateQuery<K,SN,N,V> query);

<K, SN, N, V> List<Slice<K, N, V>> keyRange(tomekkup.helenos.types.qx.query.SubRangeQuery<K,SN,N,V> query);
<K, SN, N, V> List<Slice<K, N, V>> keyRange(@JsonRpcParam("query") QxSubRangeQuery<K,SN,N,V> query);
}
Expand Up @@ -17,10 +17,10 @@
*/
public abstract class AbstractQueryProvider extends AbstractProvider {

protected <N,V> List<Column<N,V>> toJsonColumns(List<HColumn<N,V>> columns) {
List<Column<N,V>> retColumns = new ArrayList<Column<N,V>>(1);
Iterator<HColumn<N,V>> iterator = columns.iterator();
while(iterator.hasNext()) {
protected <N, V> List<Column<N, V>> toJsonColumns(List<HColumn<N, V>> columns) {
List<Column<N, V>> retColumns = new ArrayList<Column<N, V>>(1);
Iterator<HColumn<N, V>> iterator = columns.iterator();
while (iterator.hasNext()) {
retColumns.add(mapper.map(iterator.next(), Column.class));
}
return retColumns;
Expand Down

0 comments on commit 4614dc4

Please sign in to comment.