MyBatis - how to define array in mybatis xml mapper file - mybatis

I would like to define array of string in mybatis mapper and pass it as argument for java static method.
It's possible?

Found one solution, I can define array in 'bind' tag and then pass it to method as argument:
<bind name='exampleArray' value='{"one", "two", "three"}'/>
${#com.example.MybatisUtil#generate(exampleArray)}

Related

How code generate from protege data property with getter single value instead collection?

I have a simple model in protege of class and data property.
But when I use code generator - in generated class - property getter have type - Collection< String > instead simple String.
I try to add something like with different types predicate in class:
"title some xsd:string"
But it is Collection yet.
Is it can be done in protege and how? May be example ontology?

Get a type identified by a string in the Scala macros

I have a bunch of strings (essentially names of java.lang. classes and some custom classes). In the macro I need to add the type to the function:
q"""propKey[${resolveType(c)(argType)}]($name, classOf[$argType])"""
where argType is String.
So far I tried q"$argType" - but that adds the weird signature propKey[String("java.lang.Integer")](...)
with c.universe.TypeName- there's no method to get a c.universe.Type instance.
c.mirror.staticClass("java.lang.String").toType

Creating class with parameter constructor in Scala reflection

I have a class that may take from 1 to 4 parameters. They are always Strings. I would like to create an object of this class based on the number of arguments passed to the function. Is there any way to go around having to create constructor and passing an array of Objects directly to newInstance?
NewInstanceWithReflection clazz = (NewInstanceWithReflection)Class.forName("NewInstanceWithReflection").newInstance();
Constructor constructor = NewInstanceWithReflection.class.getDeclaredConstructor( new Class[] {String.class});
NewInstanceWithReflection object1 = (NewInstanceWithReflection)clazz.newInstance(new Object[]{"StackOverFlow"});
This code pasted into sbt interpreter does not seem to work. Any help appreciated.
You got it all wrong (not to mention, it's java syntax, not scala).
Something like this should work in scala:
classOf[NewInstanceWithReflection]
.getDeclaredConstructor(classOf[String])
.newInstance("StackOverFlow")
And this is what you'd need in java:
NewInstanceWithReflection
.class
.getDeclaredConstructor(String.class)
.newInstance("StackOverFlow")

Spring batch: FieldSetMapper should set field to null instead of empty

I am using spring batch to read pipe (| delimited) separated file which have have 7 field. I created a class called MyLineMapper that extends spring's FieldSetMapper. This class maps field values provided in file to my object (XYZ type). Now the problem is that fieldSet object that i get inside class extending FieldSetMapper contain empty value for field that are not present in delimited values.
For example:
Suppose that the delimited file format is as follows: |ID|Country|City|Pin|
Suppose i provide following line in file: |1|India|
As you can see the above line does not contain information for City and Pin. Therefore, I expect FieldSet object should contain Null value for these two fiels (City and Pin) instead of empty string. I don't want empty value as Null will help me to know if that field was actually present in file or not.
How can I achieve this ? Do I need to extend DelimitedLineTokenizer which I am using for tokenizing ? Or this is a simple way to do this ?
Any help will be appreciated.
From FieldSetMapper javadoc
To customize the way that FieldSet values are converted to the desired
type for injecting into the prototype there are several choices. You
can inject PropertyEditor instances directly through the customEditors
property, or you can override the createBinder(Object) and
initBinder(DataBinder) methods, or you can provide a custom FieldSet
implementation.
Depending on type of your target bean conversion is done using default Spring convention. If you need other type of logic write your own.

How to set value to property through Dozer mapping file?

I am using Dozer mapping. i have two pojo1 and pojo2. pojo1 values to be mapped to pojo2. Pojo1 has 3 properties and Pojo2 has 4 properties. i am able to map 3 properties form pojo1 to pojo2 but to map fourth property i dont have property in pojo1. to map fourth property i cannot take value from pojo1, directly i need to give the value by taking from Enum. Please help me is it possible to give value to any property through mapping file?
value from enum directly not from pojo1
fourth property
Thanks!
As far as I know this is not possible in a convenient way. The only way to do this atm is by either having a custom converter, or by modifying one of the POJOs.
With a custom converter you could just map pojo1.field3 to pojo2.field4. The converter completely ignores pojo1.field3, and just sets the pojo2.field4 to your enum value.
Another solution is to just modify pojo1 and add a field4 which always returns the enum value.
And the third solution is to modify pojo2, and just set field4 in the default constructor. If you can't modify the default constructor, you can use a custom create method or a custom bean factory to achieve the same.
I've been doing dozer mappings a lot, and would like some more convenient solution for this too. Unfortunately I don't think there is any atm.
Let me know how it works out for you!