use of com.cloud.utils.db.GenericSearchBuilder.Select in project CloudStack-archive by CloudStack-extras.
the class SearchCriteria2 method done.
private void done() {
if (_entity != null) {
Factory factory = (Factory) _entity;
factory.setCallback(0, null);
_entity = null;
}
if (_selects == null || _selects.size() == 0) {
_selectType = SelectType.Entity;
assert _entityBeanType.equals(_resultType) : "Expecting " + _entityBeanType + " because you didn't specify any selects but instead got " + _resultType;
return;
}
for (Select select : _selects) {
if (select.field == null) {
assert (_selects.size() == 1) : "You didn't specify any fields to put the result in but you're specifying more than one select so where should I put the selects?";
_selectType = SelectType.Single;
return;
}
if (select.func != null) {
_selectType = SelectType.Result;
return;
}
}
_selectType = SelectType.Fields;
}
use of com.cloud.utils.db.GenericSearchBuilder.Select in project CloudStack-archive by CloudStack-extras.
the class SearchCriteria method getSelect.
public void getSelect(StringBuilder str, int insertAt) {
if (_selects == null || _selects.size() == 0) {
return;
}
for (Select select : _selects) {
String func = select.func.toString() + ",";
if (select.attr == null) {
func = func.replace("@", "*");
} else {
func = func.replace("@", select.attr.table + "." + select.attr.columnName);
}
str.insert(insertAt, func);
insertAt += func.length();
if (select.field == null) {
break;
}
}
str.delete(insertAt - 1, insertAt);
}
use of com.cloud.utils.db.GenericSearchBuilder.Select in project CloudStack-archive by CloudStack-extras.
the class SearchCriteria2 method selectField.
@Override
public void selectField(Object... useless) {
assert _entity != null : "SearchBuilder cannot be modified once it has been setup";
assert _specifiedAttrs.size() > 0 : "You didn't specify any attributes";
if (_selects == null) {
_selects = new ArrayList<Select>();
}
for (Attribute attr : _specifiedAttrs) {
Field field = null;
try {
field = _resultType.getDeclaredField(attr.field.getName());
field.setAccessible(true);
} catch (SecurityException e) {
} catch (NoSuchFieldException e) {
}
_selects.add(new Select(Func.NATIVE, attr, field, null));
}
_specifiedAttrs.clear();
}