Does mybatis support check property exist? - mybatis

I want to dynamically construct sql with different concrete subclass
List<CommonDO> commonQuery(AbstractQuery query)
but if property not exists it will throw exception like below
Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'foo' in 'class ...'
So is there some manner could avoid this, e.g. check property exists first
<if test="foo">
...
</if>

Related

Bind global parameter, available in all mybatis mappers

Is there any way to bind global parameter, which will be available for all mappers?
I'm trying to use parameter which I set with:
sqlSessionFactory.getConfiguration().getVariables().setProperty("1param", "1value");
but when I invoke specific metod with construction
<if test='1param == "1value"'>
I'm getting exception that parameter is not available.

Mdriven Designer class attribute Allow Null=False not working

I have a class named "Project" with attribute "Name" having type of String. I have changed it from Allow Null=True to False and then I have saved the model and restarted the WECPOF prototyper in xml mode. But it still allows me to create and save instances of Project without adding a name. What might I be doing wrong?
Try to keep your attributes "nullable", i.e. Allow null = True. Why? Because you usually end up wanting to see the difference between "nothing" and "empty".
As Hans suggested, add a contraint on the class with a expression like this "not self.Name.isNullOrEmpty".
I guess the string is not null but empty "". Strings are tricky that way - the only type that is presented the same as null and as its simplest possible value.
To signal to user that you do not allow a null or empty you can do a constraint on the class or add a validation expression in the ViewModel.

"Extraneous Property" and "Parser Mismatched Metadata" errors in the Facebook debug validator

I am working on refactoring of one older page and I have problem with Facebook debug validator.
Extraneous Property
Objects of this type do not allow properties named 'twitter:card'.
Extraneous Property
Objects of this type do not allow properties named 'twitter:title'.
Extraneous Property
Objects of this type do not allow properties named 'twitter:description'.
Parser Mismatched Metadata
The parser's result for this metadata did not match the input metadata. Likely, this was caused by the data being ordered in an unexpected way, multiple values being given for a property only expecting a single value, or property values for a given property being mismatched. Here are the input properties that were not seen in the parsed result: 'twitter:card, twitter:title, twitter:description'
Should these tags has any importance? Or how I can repair it?

NDepend query to consider the getter and setter for a property as one single method

I have followed the link Can I find number of methods without number of getters via CQL? and excluded the properties from one of my NDepend queries.
One of our coding guidelines is also to ensure that the number of properties in a class(including auto-properties) should not exceed 10.(To be consistent with another guideline that no more than 20 methods can be defined for a class.)
The problem is even if we have 10 properties in a class, which is within the defined limits, the number of methods is being shown as 20. I understand that this is because a get_ and set_ for a single property are being counted as two different methods. But is there any way, by which we can change the NDepend query to have the get_ and set_ methods for a property to be counted as a single method?
Thanks
Here is a CQLinq rules that warn for types having more than 10 properties and that lists the properties through a getter or (exclusive) a setter. The astute consists in using a Lookup table where getters and/or setters are indexed by the property name, inferred from getter/setter names:
// <Name>A class should not have more than 10 properties</Name>
warnif count > 0
from t in Application.Types
let accessers = t.Methods.Where(m => m.IsPropertyGetter || m.IsPropertySetter)
where accessers.Count() > 0 // Optimization!
// Here we build a lookup that associate for each property name, the getter, the setter, or both.
// The property name is getter and/or setter simple names, without "get_" or "set_" prefixes (4 chars).
let propertiesLookup = accessers.ToLookup(a => a.SimpleName.Substring(4, a.SimpleName.Length -4))
where propertiesLookup.Count() > 10
let properties = propertiesLookup.Select(p => p.First())
select new { t, properties }
This rule also lists properties for each matched class.
We have demand on our User Voice for creating an NDepend.CodeModel.IProperty interface, that will make such rule easier to develop, don't hesitate to vote for this!

Strongly typed ViewModel contains unexpected null value

I have a case that is very similar to this, but following the advice in the answers does not solve my problem.
I have a ViewModel in an MVC 2 application that contains another class. I have a controller that contains a strongly typed create method:
[Authorize]
[HttpPost]
public ActionResult Create(AIViewModel ai)
{
}
When I look at the ModelState when I enter the Create method, the data indicates that the simple properties that are present within the AIViewModel class are bound correctly, while the complex type that is in there fails with the following error message:
"The parameter conversion from type 'System.String' to type 'xyz' failed because no type converter can convert between these types."
If I look at the value that it tries to bind, it has indeed the System.String type and value "Create". Anybody has a clue on what I could be doing wrong?
UPDATE: I have found the problem: The property is called Action, which somehow fools the the modelbinder. Renaming the property solved the issue.