SonarQube issues : Have a boolean and Sonar tells me to make it "final" - static

When I make it "final", Sonar tells me to make it static too.
I don't want both of those 2 recommandations. How can I do to just have this for my boolean :
private boolean myBoolean = true; ???

Related

How to implement “NOT IN” clause with Dapper Extensions Predicate?

I found how to implement IN clause using Dapper Extensions here.
Now, I want to implement NOT IN clause.
So, I am expecting SQL query something like below:
SELECT * FROM MyTable
WHERE MyField NOT IN (param1, param2)
But I could not find anything about NOT IN or NOT clause in Dapper Extensions.
How can I implement NOT IN clause with Dapper Extensions Predicate?
Please refer to this answer (linked in question as well) to understand how to implement IN clause.
To turn the IN clause as mentioned above to NOT IN clause, use the last bool not parameter.
This is optional parameter and default value for it is false.
That is why; even though so obvious, it is bit hidden and hence undiscovered.
Documentation does not mention it explicitly either.
Below are the definitions of each predicate defined in Dapper Extensions source code:
public static class Predicates
{
public static IBetweenPredicate Between<T>(Expression<Func<T, object>> expression, BetweenValues values, bool not = false) where T : class;
public static IExistsPredicate Exists<TSub>(IPredicate predicate, bool not = false) where TSub : class;
public static IFieldPredicate Field<T>(Expression<Func<T, object>> expression, Operator op, object value, bool not = false) where T : class;
public static IPropertyPredicate Property<T, T2>(Expression<Func<T, object>> expression, Operator op, Expression<Func<T2, object>> expression2, bool not = false)
where T : class
where T2 : class;
}
Sample code is as below:
var predicate = Predicates.Field<Customer>
(f => f.CustomerID, Operator.Eq, listOfIDs, true);
Observe the value true for last parameter in above code. The listOfIDs is an IEnumerable of your data type.
Please refer to this for more source code.

Retrieve executionId inside CommandInterceptor

I am implementing my own Activiti command intereceptor like this :
public class ActivitiCommandInterceptor extends AbstractCommandInterceptor {
private RuntimeService runtimeService;
private CommandInterceptor delegate;
public ActivitiSpringTxCommandInterceptor(RuntimeService runtimeService, CommandInterceptor delegate) {
this.runtimeService = runtimeService;
this.delegate=delegate;
}
#Override
public <T> T execute(CommandConfig config, Command<T> command) {
String myVariable = runtimeService.getVariable(<missingExecutionId>, "myVariableName");
...
}
}
Inside the execute() method I need to retrieve a variable from the execution context related to this command.
To do that, I need to have the executionId, but I can't find a way to retrieve it.
How can I get my variable from this interceptor?
Thanks
You can create a nativeExecutionQuery
This allows us to use SQL to perform operations directly on DB.
For your case, just find all the execution IDs that contains your variables, and filter them according to your need.

Map Java Boolean to bit in SQL Server

I am trying to map a Boolean variable in java with a bit column (nullible )in SQL Server. I can see the record getting updated in DB but the status value is not updated . Do i need to change the data type to anything else . please suggest.
My pojo element looks like below.
#Column(name = "status")
#Override
public Boolean getStatus() {
return super.getStatus();
}

Default value for missing parameter in a Camel route

I have an application that uses Apache Camel with Active MQ. In my RouteBuilder class where I configure the routes, it is possible that a parameter may be missing from the in body. In that case, I would like to give it a default value.
Here is what I have now:
#Override
public void configure() throws Exception {
...
String invocation = "aMethod( ${body[context]}, ${body[aParam]}, ${body[param2]} )";
from(url).routeId(url).bean(bean, invocation);
}
In my case, param2 is a boolean which I would like to send forward to aMethod as false in case it doesn't exist. How can I do that?
I saw something here: http://camel.apache.org/simple.html#Simple-OGNLexpressionsupport where it says "You can also use the null safe operator (?.) to avoid NPE if for example the body does NOT have an address", but I can't figure how to write the invocation so I don't have an error in the specified case.
I believe you are looking to use a conditional similar to this:
from("")
.choice()
.when(header("myHeader").isNull())
.setHeader("myHeader").simple("false")
.end() //This might be endChoice can't remember syntax exactly
.bean(myBean, myMethod);
..revised for Object in the body
from("")
.processor( new Processor(Exchange exchange) {
MyObject obj = exchange.getIn().getBody(MyObject.class);
Boolean b = obj.getParam2();
if(b == null)
obj.setParam2(Boolean.FALSE);
}
.bean(myBean, myMethod);
NOTE: If your actual java class uses 'boolean' and not the 'Boolean' class wrapper, then all booleans when initialized are by default set to false. So if you have an object in your body and nobody has the the boolean it will default to false.

GWT - Fail to Read properties

When I run in hosted mode, it able to get the result.
But when I deploy it to tomcat then I cant get the result at all.
Anyone can tell me what is the problem??
public class Customwidget implements EntryPoint {
private static final SystemConfig constants = (SystemConfig)GWT.create(SystemConfig.class);
public void onModuleLoad() {
Window.alert(constants.DBServerName());
}
SystemConfig.properties :
DBServerName=guaz
SystemConfig.java :
import com.google.gwt.i18n.client.Constants;
public interface SystemConfig extends Constants {
String DBServerName();
String DB_ServerName();
String DB_PortNumber();
String DB_DatabaseName();
String DB_IntegratedSecurity();
String DB_Password();
String DB_User();
}
thanks
Your properties files must be located/copied in the /WEB-INF/classes subfolder of your web application.

Resources