java hibernate criteria issue - java

I did the following code I have the error duplicate field : owner.
I tried to create an alias, but it's the same for country, ...
And when i create an alias for each I have this error :
could not resolve property: country of: com.something.test.bo.impl.Link
Code:
if (link.getOwner() != null) {
if (link.getOwner().getSiteName().trim().length() > 0 ) {
criteria.createCriteria("owner").add(Restrictions.like("siteName", link.getOwner().getSiteName()));
}
if (link.getOwner().getCountry().getName().trim().length() > 0 ) {
criteria.createCriteria("owner").createCriteria("country").add(Restrictions.like("name", link.getOwner().getCountry().getName()));
}
if (link.getOwner().getCountry().getZone().getName().trim().length() > 0 ) {
criteria.createCriteria("owner").createCriteria("country").createCriteria("zone").add(Restrictions.like("name", link.getOwner().getCountry().getZone().getName()));
}
if (link.getOwner().getCountry().getZone().getRegion().getCode().trim().length() > 0 ) {
criteria.createCriteria("owner").createCriteria("country").createCriteria("zone").createCriteria("region").add(Restrictions.like("code", link.getOwner().getCountry().getZone().getRegion().getCode()));
}
}
Does anybody have an idea to make this search ?

I think you should be using "if else". As I don't find any ambiguity in your criteria creation.

Related

Problem with NullValueCheckStrategy.ALWAYS (mapstruct 1.3.1)

After upgrading mapstruct from 1.2.0 to 1.3.1 I noticed that the annotation #Mapper(nullValueCheckStrategy=NullValueCheckStrategy.ALWAYS) in not in effect.
Is it a bug of new mapstruct version?
Example:
The code below:
String id = getTestId( testId);
if ( id != null ) {
testCase.setTestCaseId( id );
}
else {
testCase.setTestCaseId( null );
}
while the right is:
String id = getTestId( testId);
if ( id != null ) {
testCase.setTestCaseId( id );
}
The behaviour has been made more consequent with the advent of NullValuePropertyMapping. I think that was mentioned in the release notes as well. Checkout the documentation:
1: update methods (#MappingTarget)
https://mapstruct.org/documentation/stable/reference/html/#mapping-result-for-null-properties
2: regular (non update) methods
https://mapstruct.org/documentation/stable/reference/html/#checking-source-property-for-null-arguments

Improving mongo query Performance(using Sub query )

Two documents can have same IMAGE_CONTENT_INSTANCE_HANDLE and state can be BOOKED or RELEASED
but I want all image instances handles which are only RELEASED state,
Currently I am doing this by firing two queries it introduced performance issues.
{
"state" : "RELEASED"
}
with projection { "imageContentInstance.handle" : 1}
i am iterating through the result which is coming out from this query
and firing another query as below and excluding the handles which are also in BOOKED state from adding to the list.So i gets handles only in the RELEASED state
while (cursor.hasNext()) {
ICI ici = objectMapper.readValue(result, ICI_COLLECTION_TYPE_REF);
String result = JSON.serialize(cursor.next());
try {
queryDocument = { "imageContentInstance.handle" : ici.getImageContentInstance().getHandle() , "state" : "BOOKED"}
Document bookedDoc = iciDAO.findOne(queryDocument);
if (null != bookedDoc)
LOGGER.debug("Calling continue and skipping booked state ");
continue;
}
iciHandles.add(ici.getImageContentInstance().getHandle().toString());
LOGGER.debug("ImageInstanceHandle is added to the lisr and the lise is "+iciHandles.size());
}
I want to achieve this in a single mongo query as an example query written in sql to increase performance .I really appreciate your comments .
SELECT *
FROM ici i
WHERE i.state = 'RELEASED'
AND NOT EXISTS
(SELECT * FROM ici ic WHERE ic.handle = i.handle AND ic.state = 'BOOKED'
);
example :
Suppose the documents are as below
{
"_id" : ObjectId("58c9f524fa8cd6a517cf5ddf"),
"imageContentInstance" : {
"handle" : "ICI:1234",
"key" : null,
}
"instanceHandle" : "LCI:RNBM12",
"state" : "BOOKED",
}
{
"_id" : ObjectId("58c9f524fa8cd6a517cf5ddf"),
"imageContentInstance" : {
"handle" : "ICI:1234",
"key" : null,
}
"instanceHandle" : "LCI:RNBM13",
"state" : "RELEASED",
}
{
"_id" : ObjectId("58c9f524fa8cd6a517cf5ddf"),
"imageContentInstance" : {
"handle" : "ICI:456",
"key" : null,
}
"instanceHandle" : "LCI:RNBM14",
"state" : "RELEASED"
}
My query should return the handle of the last document alone .ie, document with the status only with the RELEASED status .i am stuck, I really appreciate your ideas to improve this.
From Your question,i understand that you want all state ='Released' ans state!= 'BOOKED' which i think you have written little incorrect.
MongoDB query:
db.inventory.find({'state' : 'RELEASED'}})
Also go through mognodb docs
I hope it will help.I am also new to mongodb,if there is an error please make it correct.

NoraUI - "Cannot infer Type argument" error using Result.Warning<> in a custom step

I need to raise a warning during one of my scenario but i don't stop to have this error appearing : "Cannot infer type arguments for Result.Warning<>"
I actually tried to raise the Warning the same way i was raising Failure until now :
new Result.Warning<>(targetKey, Messages.format(TaroMessages.WARNING_RESOURCES_VALUE_DIFFERENCE_AFTER_REAFFECTATION, existing_value, new_value), true, oscarAccesClientPage.getCallBack());
The custom step i am using it inside is the following : I'm trying to go over a list of Element and checking that the existing value of them is the same or not as the one saved before.
protected void checkXyResourcesValue(Integer xyIterator, List<WebElement> elements, String keyParameter) throws TechnicalException, FailureException {
try {
Integer resIterator = 1;
for(WebElement element : elements) {
String targetKey = "XY" + xyIterator + "RES" + resIterator + keyParameter;
String new_value = element.getAttribute(VALUE) != null ? element.getAttribute(VALUE) : element.getText();
String existing_value = Context.getValue(targetKey) != null ? Context.getValue(targetKey) : targetKey;
if (new_value != existing_value) {
new Result.Warning<>(targetKey, Messages.format(TaroMessages.WARNING_RESOURCES_VALUE_DIFFERENCE_AFTER_REAFFECTATION, existing_value, new_value), true, oscarAccesClientPage.getCallBack());
}
resIterator++;
}
} catch (Exception e) {
new Result.Failure<>(e.getMessage(), Messages.format(TaroMessages.FAIL_MESSAGE_ACCES_CLIENT_XY_CHECK_RESOURCES_VALUE, keyParameter, xyIterator), true, oscarAccesClientPage.getCallBack());
}
}
For the method to check and saved value I actually inspired myself for the piece of code from NoraUI to save a value on Context or read it from.
I'm using Eclipse Luna 4.4.2 and i try to compile using JDK1.8.0_131.
It may be more related to me not knowing how this work in Java than a real problem so thank you in advance for your help or insights. Don't hesitate to ask if you need more information on the piece of code or the context.
new Result.Warning<>(targetKey, Messages.format(TaroMessages.WARNING_RESOURCES_VALUE_DIFFERENCE_AFTER_REAFFECTATION, existing_value, new_value), true, 0);
use 0 if you do not use any Model (data serialized) or use id of your Object in the serial.

AllRowsReader class with token range

This is an example of using AllRowsReader class from Astyanax recipes:
reader = new AllRowsReader.Builder<>(keyspace, columnFamily)
.withPageSize(1000)
.withConcurrencyLevel(10)
.withPartitioner(null)
.withConsistencyLevel(ConsistencyLevel.CL_ONE)
.withIncludeEmptyRows(false)
.withTokenRange(startToken, endToken)
.forEachRow(new Function<Row<String, String>, Boolean>() {
#Override
public Boolean apply(#Nullable Row<String, String> row) {
startToken = keyspace.getPartitioner().getTokenForKey(row.getRawKey());
// some other statements
return true;
}
})
.build();
reader.call();
where
startToken = keyspace.getPartitioner().getMinToken();
lastToken = keyspace.getPartitioner().getMaxToken();
If to run AllRowsReader without "withTokenRange(startToken, endToken)" then all works fine. But with "withTokenRange(startToken, endToken)" not all rows are fetched during column family reading.
AllRowsReader's source has this code:
if (this.concurrencyLevel != null || startToken != null|| endToken != null) {
List<TokenRange> tokens = partitioner.splitTokenRange(
startToken == null ? partitioner.getMinToken() : startToken,
endToken == null ? partitioner.getMinToken() : endToken,
this.concurrencyLevel == null ? 1 : this.concurrencyLevel);
for (TokenRange range : tokens) {
subtasks.add(makeTokenRangeTask(range.getStartToken(), range.getEndToken()));
}
}
Later partitioner.getMinToken() reverts to maxToken. So I don't understand what is the difference from my approach? Why AllRowsReader with minToken/maxToken works differnt from AllRowsReader without them?
If operation is teminated, I execute it again with the last startToken (so it must be a shift). But in this case I see some rows were fetched before. And this is confusing me too...
P.S. Astyanax automatically determines Murmur3Partitioner.
Thanks for any help.
Links:
AllRowsReader source,
Murmur3Partitioner source
Dmitry,
Treat the token range as a ring,as the circle completes start will be equal to end.Thats why in astyanax code there are setting the same token as min and max.
startToken == null ? partitioner.getMinToken() : startToken,
endToken == null ? partitioner.getMinToken() : endToken
I hope this clarifies your answer.Let me know if you have doubts

Why equals might not return true

I have this string: "no_questions_by_user" in a variable named result.
than I do this check:
if ( result != null && result.equals( "no_user_id" ) )
{
Log.d( "Post execute: " , "NOOOT OKKKK - no user id" );
}
else
if ( result != null && result.equals( "database_error" ) )
{
Log.d( "Post execute: " , "NOOOT OKKKK - database error" );
}
else
if ( result != null && result.equals( "no_questions_by_user" ) )
{
Log.d( "Post execute: " , "NOOOT OKKKK - no questions by user so far" );
}
else
{
Log.d( "MyQuestionsActivity" , "In JSON parsing area.." );
}
and it always goes to the last else. But in my understanding it should really go to the block which checks result.equals( "no_questions_by_user" )
any idea why that block does not get executed?
Thanks!!
The code looks good. Your variable result must have another value.
My guess is that there are some whitespaces at the end or beginning of your result string.
Personally, I think this code is a hot mess.
I'd write one method that took in a result and looked up a message in a Map. All those if tests are making my eyes bleed:
private static final Map<String, String> LOG_MESSAGE_MAP;
static {
LOG_MESSAGE_MAP = new HashMap<String, String>();
// put all your result, message pairs in here
}
public void logResultDependentMessage(String result) {
log.debug(LOG_MESSAGE_MAP.get(result));
}
Now adding new result, message pairs just means inserting into the map. If you're using something like Spring you can do it in configuration and not touch the code.
Try:
result.trim().equals( "no_questions_by_user" )
Did you see "no_questions_by_user" in a debbugger ?
You can try to trim it before the test, as spaces are hard to detect in debuggers.
Make sure there are no white spaces in the value of the "result" variable.
Before entering the if statements, you can do a print line like this one.
System.out.println("The Value of result variable is=\"" + result + "\"");
You might as well do this
if ( result != null && result.trim().equals( "no_questions_by_user" ) )
{
Log.d( "Post execute: " , "NOOOT OKKKK - no questions by user so far" );
}
I advise you to use some static variables to store your strings, so you avoid typing errors.

Categories

Resources