0% found this document useful (0 votes)
663 views27 pages

Gosu Query Basics and Examples

The document outlines a lesson on Gosu queries within Guidewire applications, focusing on query objects, restrictions, and result processing. It provides step-by-step instructions for creating and executing queries, as well as methods for filtering and sorting results. Additionally, it covers advanced topics such as handling null values and counting results.

Uploaded by

abhi879
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
663 views27 pages

Gosu Query Basics and Examples

The document outlines a lesson on Gosu queries within Guidewire applications, focusing on query objects, restrictions, and result processing. It provides step-by-step instructions for creating and executing queries, as well as methods for filtering and sorting results. Additionally, it covers advanced topics such as handling null values and counting results.

Uploaded by

abhi879
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Gosu Queries

May 25, 2016

© Guidewire Software, Inc. 2001-2016. All rights reserved.


Do not distribute without permission.
Lesson objectives
• By the end of this lesson, you should be able to:
- Describe a query object
- Identify various types of query restrictions
- Write Gosu queries to retrieve objects from a Guidewire application
- Iterate through the results of query

This lesson uses the notes section for additional explanation and information.
To view the notes in PowerPoint, select View → Normal or View → Notes Page.
When printing notes, select Note Pages and Print hidden slides.
© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 2
Lesson outline

• Gosu query basics

• Working with queries

• Working with result sets

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 3
Gosu queries
• A Gosu query specifies the
entity and criteria associated with the entity
to retrieve from the Guidewire application
• Use Gosu queries to retrieve
one or more objects
- Referenced by foreign key relationships
- NOT in an array relationship

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 4
Objects for querying database
Query object Results object

ab_abcontact

• Query object specifies the • Results object is set of


query criteria entity instances fetched
- Which entity to query from the Guidewire
- What restrictions to apply application
- How many?
- How to order?
© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 5
Steps to execute a basic query
1. Create the query object using the make() method
2. Create the results object using the select() method
3. Process the results of the query as needed

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 6
Step 1: Create the query object
1 uses [Link]
2
3 var output = ""
4 var queryObj = [Link]([Link])

• Query is a class in the [Link] package


• make(EntityName) is a method that requires a named
entity type
• Line 4: creates the query object for the ABContact entity
type

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 7
Step 2: Create the results object
1 uses [Link]
2
3 var output = ""
4 var queryObj = [Link]([Link])
5 var resultsObj = [Link]()

• Create the result object with select()


- However, results are not fetched

• Lines 5 : creates the results object

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 8
Step 3: Process results
1 uses [Link]
2
3 var output = ""
4 var queryObj = [Link]([Link])
5 var resultsObj = [Link]()
6
7 for (anABContact in resultsObj) {
8 output += [Link] + "\n"
9 }
10 print(output)

• Use a for loop to iterate


through the result set
• Lines 7-9: fetches the Stan Newton
result objects Bo Simpson
Bo Simpson
• Line 10: prints to console William Weeks
William William

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 9
Viewing approximation of SQL query
1 uses [Link]
2
3 var output = ""
4 var queryObj = [Link]([Link]).withLogSQL(true)
5 output += [Link]())
6 var resultsObj = [Link]()
7
8 for (anABContact in resultsObj) {
9 output += [Link] + "\n"
10 }
11 print(output)

• For real SQL, use withLogSQL(true)


INFO Executing sql = SELECT /* KeyTable:ab_abcontact; */
[Link] col0, [Link] col1 FROM ab_abcontact gRoot WHERE
[Link] = 0 []

• For SQL approximation, use [Link]()


SELECT FROM ab_abcontact gRoot WHERE [Link] = 0

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 10
Lesson outline

• Gosu query basics

• Working with queries

• Working with result sets

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 11
Restricting queries: compare() method
1 uses [Link]
2 uses [Link]
3
4 var output = ""
5 var queryObj = [Link](ABPerson)
6 [Link]("LastName", [Link], "Andy")
7 var resultsObj = [Link]()
8 for (anABContact in resultsObj) {
9 output += [Link] + "\n"
10 }
11 print(output)

• Compare() applies
restrictions to query object
William Andy
• Line 7: restricts to Eric Andy
ABPersons with last name as
"Andy"
© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 12
Compare() method syntax
4 var queryObj = [Link]([Link])
5
6 // String
7 [Link]("LastName"), [Link], "William")
8
9 // Feature Literal
10 [Link](ABPerson#LastName, [Link], "Andy")

• Comparison predicates are columns in SQL Where clause


• When applied to character fields, the values in the field
must match exactly the comparison value
• compare() method is overloaded, meaning it has one or
more method signatures
• Line 7: String reference for column Name
• Line 10: Property Name using feature literal syntax

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 13
Feature literals for property reference
• Statically refer to the features of a given type in the Gosu
type system with feature literals
• Various kinds of feature references
- Property
- Method

• Syntax : type#Feature
- ABContact#Address
- ABContact#addContactNote()
When it
needs to be
• Uses
- Bind feature literal to instance
type safe,
- Bind argument values in method reference use feature
- Directly invoke/get/set
literals!
- Supports chaining
- Covert method references to blocks
© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 14
compare() method examples (1)
4 var queryObj = [Link]([Link])
5
6 // compare string
7 [Link](ABPerson#LastName, [Link], "Andy")
8
9 // compare integer
10 [Link](ABPerson#NumDependents, [Link], 0)
11
12 // compare boolean
13 [Link](ABPerson#PrefersContactByEmail, [Link],
true)

• Line 7: String literals require quotes

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 15
compare() method examples (2)
4 var queryObj = [Link]([Link])
5
6 // compare date
7 [Link](ABPerson#CreateTime, [Link],
"2010-09-10" as [Link])
8
9 // compare typekey
10 [Link](ABPerson#TaxStatus, [Link],
[Link].TC_UNCONFIRMED)
11
12 // compare null
13 [Link](ABPerson#Score, [Link], null)

• Line 7: Cast date values that are strings to


[Link]
• Line 10: Use typekey reference syntax for typecode
comparisons
• A null value signifies the absence of or void of a value
© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 16
Null values for query restrictions
…3 var queryNull= [Link]([Link])
4 var queryNotNull= [Link]([Link])
5
6 // ABPerson where Score IS NULL
7 [Link](ABPerson#Score, [Link], null)
8
9 // ABPerson where Score IS NOT NULL
10 [Link](ABPerson#Score, [Link], null)

• Entities can have elements that allow for null values


• If there is no value, the database leaves the field as null
unless the element specifies a default value
• Restriction queries can compare for null or not null values

[Link] ANSI SQL


compare([Link], Equals, null) where [Link] IS NULL

compare([Link], NotEquals, null) where [Link] IS NOT NULL

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 17
Multiple restrictions ANDed together
1 uses [Link]
2 uses [Link]
3
4 var output = ""
5 var queryObj = [Link](ABPerson)
6 // Last name
7 [Link](ABPerson#LastName, [Link], "Andy")
8 // First name
9 [Link](ABPerson#FirstName, [Link], "William")
10
11 var resultsObj = [Link]()
12 for (anABContact in resultsObj) {
13 output += [Link] + "\n"
14 }
15 print(output)

• Restrictions are inherently ANDed together


• Line 7 + 9: Restricts ABPersons to last name equal to
"Andy" and the first name not equal to "William"
© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 18
Multiple restrictions ORed together
1 uses [Link]
2 uses [Link]
3
4 var output = ""
5 var queryObj = [Link](ABPerson)
6 // Last name or First name
7 [Link](\ criteria -> {
8 [Link](ABPerson#LastName, [Link], "Andy" )
9 [Link](ABPerson#FirstName, [Link], "William")
10 } )
11 var resultsObj = [Link]()
12 for (anABContact in resultsObj) {
13 output += [Link] + "\n"
14 }
15 print(output)

• or() requires block that specifies criteria to OR together


• Line 7-10: or() block consists of a criteria element that
represents the query object
© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 19
Additional restriction options
• See the
Predicate Methods
Reference
in the
Gosu Reference Guide
- between()
- compareIgnore()
- contains()
- subselect()
- startsWith()

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 20
Lesson outline

• Gosu query basics

• Working with queries

• Working with result sets

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 21
Counting results
1 uses [Link]
2
3 var output = ""
4 var queryObj = [Link](ABPerson)
5 var resultsObj = [Link]()
6 var count = [Link]
7 output += "Result count: " + count + "\n"
8 print(output)

• Count property returns


the number of result objects
• Line 6: [Link]
retrieves the number objects Result count: 116

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 22
Sorting results
1 uses [Link]
2
3 var output = ""
4 var queryObj = [Link](ABPerson)
5 var resultsObj = [Link]()
6 [Link]( \ row -> [Link])
7 for (anABContact in resultsObj) {
8 output += [Link] + "\n"
9 }
10 print(output)

• orderBy() requires block that specifies sort column


• orderByDescending()
specifies descending order
James Andersen
• Line 6: Samantha Andrews
[Link]() William Andy
Eric Andy
specifies the LastName William Dan
as the ascending sort column
© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 23
Querying for one result
1 uses [Link]
2
3 var output = ""
4 var queryObj = [Link](ABCompany)
5 [Link](ABCompany#Name, [Link], "Albertson's")
6 var resultsObj = [Link]().AtMostOneRow
7 output += resultsObj.EmailAddress1
8 print(output)

• AtMostOneRow is a property that…


- If a single item exists, returns that single row
- If no item exists, returns null
- If multiple items exist,
throws exception
info@[Link]
• Line 6: AtMostOneRow
returns one row, null,
or throws exception
© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 24
Lesson objectives review
• You should now be able to:
- Describe a query object
- Identify various types of query restrictions
- Write Gosu queries to retrieve objects from a Guidewire application
- Iterate through the results of query

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 25
Review questions
1. Name two ways for viewing the SQL for a query object?
2. What is the difference between a query object and results
object?
3. What is an example of an AND restriction?
4. What is an example of an OR restriction?
5. How do you order query results in descending order?
6. If you use the AtMostOneRow property for a query object,
and the query returns more than one row, what happens?

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 26
Notices
Copyright © 2001-2016 Guidewire Software, Inc. All rights reserved.

Guidewire, Guidewire Software, Guidewire ClaimCenter, Guidewire PolicyCenter, Guidewire


BillingCenter, Guidewire Reinsurance Management, Guidewire ContactManager, Guidewire Vendor Data
Management, Guidewire Client Data Management, Guidewire Rating Management, Guidewire
InsuranceSuite, Guidewire ContactCenter, Guidewire Studio, Guidewire Product Designer, Guidewire
Live, Guidewire DataHub, Guidewire InfoCenter, Guidewire Standard Reporting, Guidewire
ExampleCenter, Guidewire Account Manager Portal, Guidewire Claim Portal, Guidewire Policyholder
Portal, ClaimCenter, BillingCenter, PolicyCenter, InsuranceSuite, Gosu, Deliver Insurance Your Way, and
the Guidewire logo are trademarks, service marks, or registered trademarks of Guidewire Software, Inc.
in the United States and/or other countries.

All other trademarks are the property of their respective owners.

This material is confidential and proprietary to Guidewire and subject to the


confidentiality terms in the applicable license agreement and/or separate
nondisclosure agreement.

This file and the contents herein are the property of Guidewire Software, Inc. Use of this course material
is restricted to students officially registered in this specific Guidewire-instructed course, or for other use
expressly authorized by Guidewire. Replication or distribution of this course material in electronic, paper,
or other format is prohibited without express permission from Guidewire.

Guidewire products are protected by one or more United States patents.

© Guidewire Software, Inc. 2001-2016. All rights reserved. Do not distribute without permission. 27

You might also like