Gosu (Guidewire) - guidewire

If we need to consider two states of claim (e.g - Draft & Closed state) for temporary claim, then how can we use these state using Query?
I tried with -
var claims = Query.startswith("ClaimNumber", "TMP", false)
.compareIn(Claim#State, {ClaimState.TC_DRAFT, ClaimState.TC_CLOSED}.toArray())
.select()
The above line throws null pointer error . Could anyone help on this ?

I believe the Claim Entity has enough data to be queried.
Also i see the "make" statement is missing in the code given by you.
Try the below query in your Gosu Scratchpad,
uses gw.api.database.Query
var claims = Query.make(Claim)
.startsWith("ClaimNumber","TMP",false)
.compareIn(Claim#State, {ClaimState.TC_DRAFT, ClaimState.TC_CLOSED} as ClaimState[])
.select()
for(claim in claims){
print(claim.ClaimNumber)
}
If you still face any issues, please provide the exception that you get.
Please mark the answer as correct if my info solved your issue.

Try with or block,
uses gw.api.database.Query
var queryCliamState= Query.make(entity.Claim)
.compare("ClaimNumber", Equals, "12345")
.or(\orCondition -> {
orCondition.compare("State" , Equals,typekey.ClaimState.TC_DRAFT)
orCondition.compare("State" , Equals,typekey.ClaimState.TC_CLOSED)
}) .select()
-When you are comparing make sure the state is equal to the database field.

Looks like you are missing the make sentence:
var claims = Query.make(Claim).startsWith("ClaimNumber", "TMP", false)
.compareIn(Claim#State, {ClaimState.TC_DRAFT, ClaimState.TC_CLOSED}.toArray())
.select()
It should work after that.

Related

How to set timeout for NHibernate LINQ statement

I am using Fluent NHibernate for my ORM. In doing so I am trying to use the NHibernate LINQ syntax to fetch a set of data with the power of LINQ. The code I have works and executes correctly with the exception being that a timeout is thrown if it takes longer than roughly 30 seconds to run. The question I have is how do I extend the default 30 second timeout for LINQ statements via NHibernate?
I have already seen the posts here, here, and here but the first two refer to setting the DataContext's Timeout property, which does not apply here, and the third refers to setting the timeout in XML, which also does not apply because I am using Fluent NHibernate to generate the XML on the fly. Not only that but the post is 2 years old and Fluent NHibernate has changed since.
With the ICriteria objects and even HQL I can specify the timeout, however that is not the goal here. I would like to know how to set that same timeout and use LINQ.
Example code:
using (var session = SessionFactory.OpenSession())
using (var transaction = session.BeginTransaction())
{
var query = (from mem in session.Query<Member>()
select mem);
query = query.Where({where statement});
int start = (currentPage - 1) * max);
if (start > 0)
query = query.Skip(start).Take(max);
else
query = query.Take(max);
var list = query.ToList();
transaction.Commit();
return list;
}
This code (where statement does not matter) works for all purposes except where a timeout occurs.
Any help is appreciated. Thanks in advance!
I ended up setting the command timeout for the Configuration for Fluent NHibernate. The downside to this is that it sets the timeout for ALL of my data access calls and not just the one.
Example code:
.ExposeConfiguration(c => c.SetProperty("command_timeout", (TimeSpan.FromMinutes(10).TotalSeconds).ToString()))
I found this suggestion from this website.
Nhibernate has extended the IQueryable and added a few methods https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate/Linq/LinqExtensionMethods.cs
var query = (from c in Session.Query<Puppy>()).Timeout(12);
or
var query = (from c in Session.Query<Puppy>());
query.Timeout(456);
I've just spent fair amount of time fighting with this and hopefully this will save someone else some time.
You should use the .Timeout(120) method call at the very last moment to make sure it is used. TBH I'm not 100% sure on why this is but here are some examples:
WILL WORK
query = query.Where(x => x.Id = 123);
var result = query.Timeout(120).ToList();
DOESN'T WORK
query.Timeout(120);
query = query.Where(x => x.Id = 123);
var result = query.ToList();
If done like the second (DOESN'T WORK) example, it seems to fall back to the default System.Transaction.TransactionManager.DefaultTimeout.
Just in case anyone is still looking for this and finds this old thread too...
Query.Timeout is deprecated.
You should use WithOptions instead:
.WithOptions(o => o.SetTimeout(databaseTimeoutInSeconds))

Kohana 3.2 ORM Does not contain model info

I'm working with Kohana 3.2 and have the following code in my controller.
$Blog_Post = new Model_Blogpost();
$Blog_Post->where('id', '=', 1);
$Blog_Post->find();
$content = $Blog_Post->content;
I Currently have 3 records in my db with id's 1, 2, and 3.
$Blog_Post->content, or any other field return null. and I'm not sure why.
Use ORM::factory('blogpost', $id) or new Model_Blogpost($id) if you need an object with PK == $id.
Check your model after loading.
if $Blog_Post->loaded()
{
// it works!
}
else
{
// record not found
}
If record not found, you can see last DB query with $Blog_Post->last_query()
UPD. From comments. Your model will not work with this modifications. Note that ORM data stored in $_object property, and $Blog_Post->content is just a shortcut for $Blog_Post->_object['content'] via __get() method. Of course, if you define public $content property, $Blog_Post->content will return NULL value instead of using DB data.
There is no reason for defining model fields as properties. If you need IDE hints, just use PHPDOC.
At the firm I work for we were looking into upgrading to 3.2 very recently. However, in our evaluation I don't recall seeing a difference in ORM handling methods.
Yours above looks like it should be something like this:
$Blog_Post = ORM::factory('blogpost')->where('id', '=', 1)->find();
$content = $Blog_Post->content;
Assuming your table is called blogposts, of course. I may be wrong about that and if I am, can you link to the documentation that shows this kind of model interaction?

Nhibernate linq where clause with boolean value

If I try to add a where clause, containing a lambda filter on a boolean field, to a nhibernate linq query, the filter seems to be ignored:
var result = Session.Linq().Where(x=> x.Approved);
Session is an iSession and Newspaper is a simple object with the fields NewspaperId int, Name - varchar(50) and Approved - bit.
When I run this the following sql is generated:
SELECT this_.NewspaperId as Newspape1_33_0_, this_.Name as Name33_0_, this_.Approved as Approved33_0_, FROM Newspapers this_
it seems to ignore the lambda if it is for a boolean field.
It works fine for the name field, ie:
var result = Session.Linq().Where(x=> x.Name == "The Times");
results in:
exec sp_executesql N'SELECT this_.NewspaperId as Newspape1_33_0_, this_.Name as Name33_0_, this_.Approved as Approved33_0_ FROM Newspapers this_ WHERE this_.Name = #p0',N'#p0 nvarchar(9)',#p0=N'The Times'
Anybody know why I can't query on a boolean value?
Any help is greatly appreciated
I am using NHibernate 2.1 with linq
It's been a while so you've probably got your answer somewhere else a long time ago. But to answer your question: I can't see a reason why this wouldn't work. Actually I've tried it out in both NH2.1.2 and NH3.0.0. It works in both (verified by looking at the query with SQL Profiler). So it would be interesting to see the mapping you used, perhapse there's something wrong there.

How to use the GetChanges method of SiteData WebService

Can anyone elaborate on the parameter values to be supplied for GetChanges method of SiteData Web Service?
Basically I am not able to understand what value should we supply for startChangeID and EndChangeID and from where can we get these values?
Any help on this would be greatly appreciated.
Thanks.
Try calling GetContent first with
string result = mysiteDataServiceInstance.GetContent(SiteDataService.ObjectType.ContentDatabase,
myContentDbGuid.ToString(), "", "", false, false, ref lastChangeID);
Where lastChangeID is an empty string. This should give back results like
<ContentDatabase><Metadata ChangeId="1;0;146b129e-4f56-4701-ada2-b370744f2ca3;633896405160170000;168811216" ID="{146b129e-4f56-4701-ada2-b370744f2ca3}" /></ContentDatabase>
Where 146b129e-4f56-4701-ada2-b370744f2ca3 is the guid of my ContentDb
The ChangeId mentioned here can be used in place of the lastChangeId and currentChangeId.
My results appeared like
<SPContentDatabase Change="Unchanged" ItemCount="0">
<ContentDatabase><Metadata ChangeId="1;0;146b129e-4f56-4701-ada2-b370744f2ca3;633896953296070000;30349699" ID="{146b129e-4f56-4701-ada2-b370744f2ca3}" /></ContentDatabase></SPContentDatabase>
The process is exactly the same when using SiteDataService.ObjectType.Site

Subsonic Delete multiple records

I have a table which has a two fields, userid and degreeid. A user can have multiple degreeds in this table. When a user select their degree I want to delete any degree id already in the database but un-selected by user. How should do it? I try to use something like this with no luck.
repo.DeleteMany(x=>x.MeetingAttendeeUserID==userID && x.EducationDegreeID userDegreeList)
Thanks,
Lewis
Could you do something like this?
repo.DeleteMany(x =>
x.MeetingAttendeeUserId == userID &&
x.EducationDegreeID != selectedDegreeId
);
Edit: Or this.
repo.DeleteMany(x =>
x.MeetingAttendeeUserId == userID &&
userDegreeList.Contains(x.EducationDegreeID))
);
I have tried
SubSonicRepository<ReportDatum> repo = new SubSonicRepository<ReportDatum>(db);
repo.DeleteMany(x => x.ReportID == Convert.ToInt32(reportID));
and it does nothing, not even an error.
Addendum for someone that comes across this:
don't convert in the delete call, convert your variables beforehand.
int deleteKey = Convert.ToInt32(reportID)
SubSonicRepository<ReportDatum> repo = new SubSonicRepository<ReportDatum>(db);
repo.DeleteMany(x => x.ReportID == deleteKey);
and it fired fine.
I would recommend if you dont know Lamda expression. Create your own stored procedure and call use it.
This will not restrict you using lamda expression if you don't have time to learn it.
Ultimately you wanted to done your job.

Resources