Xtend: Generate Switch Case - jvm

I need to generate switch case inside a method. Something like this:
switch(phr){
case PENDING_CONFIRMATION:
phrResource.add(new ExtendedLink(linkTo(
methodOn(PHRController.class).rejectPhr(phr.getId()))
.toString(), "rejectPHR_Update", "DELETE"));
How to do this in Xtend-JVM?

Related

Does Mongoengine allow pull from <variable>?

I have a few pull queries that look like this:
Site.objects(siteid).update_one(pull__somelist__refid=myid)
I would like to reuse this code by making 'somelist' a variable - something like this:
listvar = 'somelist'
Site.objects(siteid).update_one(pull__<listvar>__refid=myid)
I have tried various wrappers such as [listvar] and (listvar) without success.
Is there a way to inject the variable value into the query?
You should be able to abuse the kwarg notation for this
myvar = "some_var"
funky_kwarg = {f"pull__{myvar}__refid": myid}
Site.objects(siteid).update_one(**funky_kwarg)

ColdFusion ORMExecuteQuery ORM missing mapping

I am trying to use ORMExecuteQuery. To do queries something like this:
ORMExecuteQuery("select count(*) from Customer");
This shows an error. So I have reduced the complexity of statement now to something smaller
// This works
rc.Customers = EntityLoad("Customer");
// This crashes
rc.Customers2 = ORMExecuteQuery("from Customer");
I have seen issues with ORMExecuteQuery() and the case of the object name.
Try using
ORMExecuteQuery("from customer");

Ruby on Rails find_by case insensitive

I need to find a record from 2 parameters but I need one of them to be case insensitive. The current case sensitive line is
c = Course.find_by(subject_area: area, cat_number: cat)
But I need subject_area to be case insensitive. How would I achieve that?
It depends on the database, and you may need to pass in db-specific SQL for that (and not use find_by).
Are you using postrges? if so, this would normally work:
Course.where("LOWER(subject_area) = ? AND cat_number = ?", area.downcase, cat)
alternatively you could convert your subject_area to downcase every time you save a new one... then just use:
Course.find_by(subject_area: area.downcase, cat_number: cat)
I could be wrong, but don't currently know of any rails-native way of doing a case insensitive rails find_by
An alternative can be
c = Course.find_by("LOWER(subject_area)= ? AND cat_number = ?", area.downcase, cat)
If you are using postgres, you could do something like:
> c = Course.find_by('subject_area ILIKE ? AND cat_number LIKE ?', area, cat)
(ILIKE is used to do insensitive search)
If you need to have this attribute be case-insensitive then the right way is to ensure it's always one particular in your model
before_save { self.subject_area = subject_area.downcase }
You can migrate your existing data to be downcased as well.
Having done that your find by operation still needs to ensure that the area is downcased in query as suggested.
Course.find_by(subject_area: area.downcase, cat_number: cat)
Option 2:
I knew I was forgetting this. Let's say you dont want to go migration path. Just define a scope.
http://guides.rubyonrails.org/v4.1/active_record_querying.html#scopes
scope :area_nocase, (area) -> { where("LOWER(subject_area) = ?", area.downcase) }
then you can use it like
Course.area_nocase(area) or cat.course.area_nocase(area)
or chain it however you need to.

Writing Case in MDX query?

I have an MDX code like this,
({[Ping].[ID].&[20] : [Ping].[ID].&[200]})
.
.
I have to write it with the use of Switch/Case statement.
This is what I done, but something is missing, not working.
WITH MEMBER [Ping].[ID].[FORMAT2] AS
CASE
WHEN [Ping].[ID].&[10]
THEN [Ping].[ID].&[100]
WHEN [Ping].[ID].&[20]
THEN [Ping].[ID].&[200]
ELSE [Ping].[ID].[FORMAT]
END
Please help me.
WHEN [Ping].[ID].&[10]
is not a condition. The WHEN statements inside a case need to be a condition that evaluates to true or false.
Something like
WHEN [Ping].[ID].CurrentMember IS [Ping].[ID].&[10]
or something similar.

Worklight project - dojo query() use variable instead of a text

If i use this dojo instruction, and all work correctly.
sampleStore.query({ item_name:/^aa/}, {sort: [{attribute: "des"}]});
How can i use a variable(filter) instead of "aa" such as
var filter="aa";
sampleStore.query({ item_name:/^filter/}, {sort: [{attribute: "des"}]});//don't work
or
sampleStore.query({ item_name:/^"+filter+"/}, {sort: [{attribute: "des"}]});//don't work
You cannot use Strings in JavaScript regular expressions. If you want to do something like that you need to use new RegExp() to create a regular expression based on a string.
sampleStore.query({ item_name: new RegExp('^' + filter) }, {sort: [{attribute: "des"}]});
NOTE: If you use regular expressions this way, you cannot add the delimiter /. If you need to add modifiers like i (case insensitive /.*/i), you can do that by using:
new RegExp(".*", i);