Presentation is loading. Please wait.

Presentation is loading. Please wait.

Perst Query-by-Example. Customized Searches  When using relational SQL-style databases, you define a search using a query string  Specify columns 

Similar presentations


Presentation on theme: "Perst Query-by-Example. Customized Searches  When using relational SQL-style databases, you define a search using a query string  Specify columns "— Presentation transcript:

1 Perst Query-by-Example

2 Customized Searches  When using relational SQL-style databases, you define a search using a query string  Specify columns  Specify constraints  When using a Object-Oriented Database like Perst you use Query-by-Example  Use an object (or two) to represent your search criteria

3 Perst Index types  Perst uses two main Index types  Regular Index instances are good when searching against a single criteria  i.e. Search against the key itself  Multi-dimensional Index  Query-by-Example style  Allows for searching against any number of criteria

4 Query-by-Example  A Query-by-Example (QBE) is a technique used in OODBMS’s to do a search  A “search object” of the same type as the objects being scanned is initialized with the values you want to find  QBEs can also be used to search for ranges of values (upper and lower bounds)

5 Query-by-Example  Query-by-Example is specified by  Defining a “blank” object instance  Setting the properties of the blank to values you are searching for  E.g. to search a database of Car objects for a cars with a brand “Ferrari” Car car = new Car() car.setType(“Ferrari”) // pass this to the database search function

6 MultidimensionalIndex  MultiDimensionalIndex  Use Storage createMultidimensionalIndex ()  Specify which field names are to be used for searching using an array  Java will use its reflection mechanism to check if the field exists or not  Specify if numeric defaults (0/0.0) are considered undefined for searches  Required since Java numeric primitive types all have default values

7 Example MultidimensionalIndex index = db. createMultidimensionalIndex( Quote.class, // class of index elements new String[] { // list of searchable fields "low", "high", "open", "close", "volume" }, false); // do not treat 0 as undefined value class Quote extends Persistent { int timestamp; float low; float high; float open; float close; int volume; }

8 Caveats  Here it is essential to specify boundaries for all scalar and boolean fields (encompassing all potential allowed values, not just the ones used in this query) or to set a minimum/maximum value for this type.  If this is inconvenient, the default field value can be excluded from the search conditions. The default value for numeric (integer and floating point) types is 0.  The last parameter treatZeroAsUndefinedValue of createMultidimensionalIndex makes it possible to ignore all fields of numeric type with a 0 value.  NOTE: non-numeric field ranges still have to be specified.

9 Searching  Once you have created your search object use either of the following MultiDimensionalIndex methods  queryByExample(searchObject)  Returns an ArrayList  iterator(searchObject)  Returns an Iterator

10 Bounded QBE  You can also specify a QBE search that defines a range/bound  Upper and lower limits  Examples:  Searching for all Appointments from Date X to Date Y

11 Searching  Once you have created your two bound objects use either of the following MultiDimensionalIndex methods  queryByExample(lowerBound, upperBound)  Returns an ArrayList  iterator(lowerBound, upperBound)  Returns an Iterator

12 Example  Note the use of Integer.MAX_VALUE and MIN_VALUE to indicate that no bound is required Car low = new Car(); // no lower boundary for this field low.mileage = Integer.MIN_VALUE; low.price = 1000; // no lower boundary for this field low.productionYear = Integer.MIN_VALUE; low.airCondition = true; // air condition is required Car high = new Car(); high.mileage = 100000; high.price = 2000; // no upper boundary for this field high.productionYear = Integer.MAX_VALUE; high.airCondition = true;// air condition is required high.automatic = true; // full range: [false,true] high.navigationSystem = true; // full range: [false,true] ArrayList cars = index.queryByExample(low, high); class Car { String model; String make; String color; int mileage; int price; int productionYear; boolean airCondition; boolean automatic; boolean navigationSystem;

13 As always there is more!  We have only touched the surface of what Perst can do  Perst has several features that can be used for different purposes  Compressed database files  Use of SD card for database files  Spatial Index, PatriciaTrie, Thick Index  Check out the tutorial.pdf that comes with Perst to use these features


Download ppt "Perst Query-by-Example. Customized Searches  When using relational SQL-style databases, you define a search using a query string  Specify columns "

Similar presentations


Ads by Google