iBatis to myBatis conversion related issue - mybatis

I have been trying to migrate from ibatis to mybatis. what is the converted equivalent to isEmpty tag of ibatis in mybatis
for isNotEmpty it is
is this is correct fot isEmpty tag

<if test='str=null or str=""'>
you may even try something like:
<if test='org.apache.commons.lang.StringUtils.isEmpty(str)'>

Related

Aggregation works unexpectedly after spring-data-mongo-db library update

Today I updated Spring Boot from version 2.2.2.RELEASE to 2.5.2. After that aggregations started to behave differently. Here is an example query (in kotlin language):
val aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("_id").isEqualTo(ObjectId("6faa215a23cfcf1524cc4a4b"))),
Aggregation.project().andExclude("_id").andExpression("\$\$ROOT").`as`("user"),
Aggregation.lookup("user", "user._id", "_id", "sameUser")
)
return reactiveMongoTemplate.aggregate(aggregation, "user", UserTestAgggr::class.java)
data class UserTestAgggrUserTestAgggr(
val user: User,
val sameUser: User
)
For 2.2.2.RELEASE version this code worked. However in version 2.5.2 API requires sameUser param to be a list (otherwise it throws an exception).
I would like to avoid modifying my queries or objects (because I've got too many of those).
So I guess my question is: is there a way to make most recent API behave like before without a downgrade?
So my answer was to create my own MappingMongoConverter, which was a nightmare, because it had to extend MappingMongoConverter (some spring classes inject MappingMongoConverter directly instead of using MongoConverter interface). Had to write it in java as well (so I could rely on MappingMongoConverter original implementation). Not fun at all, but solved the issue for me.

Trouble with SqlParser using Anorm

I'm trying to parse some SQL and save it as PushMessage (which is a class, not a case class - don't know if that matters). Following the Anorm documentation I have
implicit val parser: RowParser[PushMessage] = Macro.namedParser[PushMessage]
val result = db.withConnection { implicit connection: Connection =>
SQL"select * from PUSH_MESSAGES where VENDOR_ID=$requestedVendorId;".as(parser.*)
}
However, I'm getting a problem as IntelliJ tells me that Macro.namedParser[PushMessage] returns an Any, and not a RowParser[PushMessage]. I tried removing the declaration type, but then I couldn't run the parser using the .as(parser.*) syntax.
How do I get this to return a RowParser?
Thanks in advance,
I guess you are using an Anorm version before 2.5.1 (April 2016), when the macros have been updated to use whitebox context. In such case, your IDE cannot properly infer the return type.
Note that Anorm 2.5.2 has just been released.

Squeryl, inhibitWhen function doesnt seems to work

Im using Squeryl with the function inhibitWhen to ignore a Where clause when a scala value is Empty. I tried this code but Squeryl still checking for the where clause that i want to ignore!
(l.book_id in params.get("book_id").toList.flatMap(_.split(",")).map(_.toInt)).inhibitWhen(params.get("book_id").map(_.isEmpty) == Some(true))
So what i need to do is when book_id has some values (1,4,6) it use the in clause but when it's empty the in clause should be ignored !

how to test if a string DON'T match using protractor

I'm migrating my karma-ng-scenario tests suite to protractor. I would like to do something like
// karma-ng-scenario
expect(element('legend').text()).not().toBe("LOGIN_CONNECT");
in the protractor way. But it seems there isn't a not() function.
I'm using angular-translate to bind the LONGIN_CONNECT string into multiple languages and I want to test if the string is translated.
More globally, is there a a way test if something is different ? ... don't have a class, don't exists on the page, is not selected, ...
It is definitely worth looking at the API docs. I have these open pretty much all the time.
There are lots of Web Driver functions you can use like isEnabled(), isDisplayed(), isSelected() etc. Protractor uses Jasmine syntax so you can use '.toBe(false)' to assert things are false.
To check for classes, you can do something like:
expect(myElement.getAttribute('class')).toContain('my-class-name');
To compare strings and assert that they do NOT match you could use .not. Jasmine docs
say:
Every matcher's criteria can be inverted by prepending .not:
expect(x).not.toEqual(y); compares objects or primitives x and y and
passes if they are not equivalent
You can use something like:
expect(model.getText()).not.toContain('abcdef');
There is a .not property nowadays.
I'm using the following to check for NOT matching:
expect(element('legend').text() === "LOGIN_CONNECT").toBe(false);

Imported function in Entity Framework Where clause?

Is it possible to use a function import in a where clause in entity framework? I have tried the following, but I get a rather cryptic exception to which I cannot find any information about:
var q = MyContext.MyEntities.Where("MyContext.MyFunction(it.ID)")
(The function is set to return a Boolean)
System.Data.EntitySqlException: 'MyContext.MyFunction' cannot be resolved into a valid type constructor or function., near WHERE predicate, line 6, column 21..
Regards
Lee
The query you are trying to write is composing a call to a FunctionImport with a query over an EntitySet.
But because FunctionImports are wrappers around StoredProcedures, which are non-composable, this just won't work.
In order for something like this to work, theoretically the function would need to be a wrapper around something composable like a TVF (Table Value Function). But unfortunately TVFs aren't supported in the Entity Framework today.
Alex
I don't think you want to pass this expression as a string. You want a proper lambda expression like:
MyContext.MyEntities.Where( entity => MyContext.MyFunction(entity.ID ) );