SlideShare a Scribd company logo
1 of 41
Download to read offline
DivConq Framework’s Schema and Structures
DivConq Design Goal
Linux Box
 Windows
                              Java App w/ DivConq                      MUMPS
  User w/
Web Browser                                                            MUMPS
                              Your                                     Process
                                             DivConq
                            Application
                                             Database
                              Code                                     MUMPS
                                             Interface
  External                                                             Process
  App on
                        DivConq                                        MUMPS
   Linux
                       Web Server      DivConq Schema                  Process
                       (HTTP + Web
                         Sockets)



There are many reasons to “why JSON?” – one of the best is interoperability with
web apps and other external applications. Through HTTP or WebSocket calls
JSON parameters can be sent and JSON results can be returned. To minimize
interoperability hassles DivConq favors JSON-like structures throughout.
Java App w/ DivConq

                        dcDB

                                          dcRPC
                                                           dcSchema
       Your
     Application      dcScripts
                                                            (“JSON”
       Code
                                          dcServiceBus     Validation)

                       dcWeb




Many of the features of the framework use DivConq Schema to validate data
structures. When you learn how to use these structures you can use these
features. dcDB, dcWeb and dcServiceBus are especially important for most
developers using the framework.
JSON.org Term             DivConq Term      DivConq Class
     Object                    Record            RecordStruct
     Array                     List              ListStruct
     Value                     Scalar            ScalarStruct

     (also)
     Pair                      Field             FieldStruct
     Members                   Fields
     Elements                  Items




Although DivConq uses different terms, it matches up with JSON very well (see
www.json.org).
JSON.org Type               DivConq Name      DivConq Class
     String                      String            StringStruct
     Number                      Integer           IntegerStruct (64 bit)
     "                           BigInteger        BigIntegerStruct (unlimited)
     "                           Decimal           DecimalStruct (unlimited)
     "                           BigDecimal        "
     true                        Boolean           BooleanStruct
     false                       "                 "
     null                        Null              NullStruct
     -                           Any               AnyStruct
     -                           Binary            BinaryStruct
     -                           DateTime          DateTimeStruct
     -                           BigDateTime       BigDateTimeStruct


DivConq supports the same value types, plus a few more. JSON to DivConq
conversions are simple. String becomes string, number tries to fit into Integer or
BigInteger, but otherwise falls to Decimal. A true or false becomes a Boolean. A
null becomes a “null” in Java (though NullStruct could be used instead).
DivConq Name       DivConq Class
     Binary             BinaryStruct
     DateTime           DateTimeStruct
     BigDateTime        BigDateTimeStruct


Converting from DivConq to JSON is fairly obvious for most of the types, except
those above.

Binary in DivConq is byte array data and JSON does not support byte arrays. So
when Binary is converted to JSON it becomes a base64 encoded string.

DateTime is also not in JSON (there are some adaptations though). When
DateTime is converted to JSON it becomes an ISO 8601 formatted string using
UTC (Z) timezone.

BigDateTime is a topic on to itself, it supports dates billions of years past and
future. The very short summary, format is: ‘t’YYYYYYYYYYYMMDDhhmmss
Classes for JSON-Like structures
Example

     RecordStruct params = new RecordStruct();
     params.setField("MinAge", 3);
     params.setField("MaxAge", 8);

     QueryRequest request = new QueryRequest("dctListPeople", params);




When working with the DivConq Struct classes we usually have a goal in mind.
In the example above we mean to create some parameters for a database query
request.

However, in the following examples we’ll create structures just for the sake of
learning, without the context of how they are used. Look for presentations on the
dcDb or dcServiceBus for specific examples of how Structs are used.
JSON
     { "Code": 5, "Message": "Problem with coolant system." }


     Java
     RecordStruct ex1 = new RecordStruct();
     ex1.setField("Code", 5);
     ex1.setField("Message", "Problem with coolant system.");




Scalar types are automatically inferred from java native types. When setting the
Code field above, 5 becomes an IntegerStruct and the message string becomes a
StringStruct.
JSON
     { "Code": 5, "Message": "Problem with coolant system." }


     Java
     RecordStruct ex1 = new RecordStruct();
     ex1.setField("Code", new IntegerScalar(5));
     ex1.setField("Message", new StringScalar("Problem with coolant system."));




You can be explicit, as above, but most of the time there is no need.
OK, you made a record – and presumably passed it to a service (or other
feature). How does that service access the data in the record?

Before answering, keep in mind the service may run in the same JVM as the
caller, or another JVM on running on a computer a thousand miles away. Either
way, DivConq is capable of delivering the data (as it was assembled in the last
side) if you use the built-in data types (except Any which has special handling).
There are no additional requirements or efforts for serialization.
RecordStruct ex1 = [as delivered to the service]

     System.out.println("Code: " + ex1.getFieldAsString("Code"));

     long code = ex1.getFieldAsInteger("Code");

     System.out.println("Code Is Priority Level: " + (code < 3));



So back to the question – how do you access data? The answer – the way you
want it. As seen in the example above, you can access the field Code either as a
String or as an Integer. RecordStruct will attempt to return a value in the data
type you request, if it cannot then it returns null.
JSON
     { "Code": "5", "Message": "Problem with coolant system." }


     Java
     RecordStruct ex1 = new RecordStruct();
     ex1.setField("Code", "5");
     ex1.setField("Message", "Problem with coolant system.");




Note that in this example, the field Code contains a string not a number. But the
service’s code “long code = ex1.getFieldAsInteger("Code");” will still work. Again,
all the getFieldAs* methods attempt to deliver the data the way you need it,
regardless of the original type.
public   Long getFieldAsInteger(String name)
     public   BigInteger getFieldAsBigInteger(String name)
     public   BigDecimal getFieldAsDecimal(String name)
     public   Boolean getFieldAsBoolean(String name)
     public   DateTime getFieldAsDateTime(String name)
     public   BigDateTime getFieldAsBigDateTime(String name)
     public   LocalDate getFieldAsDate(String name)
     public   LocalTime getFieldAsTime(String name)
     public   String getFieldAsString(String name)
     public   Memory getFieldAsBinary(String name)
     public   RecordStruct getFieldAsRecord(String name)
     public   ListStruct getFieldAsList(String name)
     public   CompositeStruct getFieldAsComposite(String name)
     public   Struct getFieldAsStruct(String name)
     public   XElement getFieldAsXml(String name)


These are the primary ways of accessing field values.
public boolean isEmpty()
              - are there no fields in this record
     public Iterable<FieldStruct> getFields()
              - loop all fields
     public int getFieldCount()
              - get number of fields
     public Struct getField(String name)
              - get the Struct for the field (e.g. StringStruct)
     public Object getFieldAsAny(String name)
              - return the value, no mater what type it is
     public boolean hasField(String name)
              - check if field is present
     public boolean isFieldEmpty(String name)
              - check that field is not null, if field is a string also check
                that it contains something other than whitespace




These methods also help with data access.
JSON
     [ 0, 20, 50, 90, 140 ]


     Java
     ListStruct ex2 = new ListStruct();
     ex2.addItem(0);
     ex2.addItem(20);
     ex2.addItem(50);
     ex2.addItem(90);
     ex2.addItem(140);


One way to make a list.
for (int i = 0; i < ex2.getSize(); i++) {
        long code = ex2.getItemAsInteger(i);

         System.out.println("Code " + code
               + " is priority level: " + (code < 73));
     }




Just like the “getFieldAs” methods, there is a “getItemAs” method for all the types
recognized by DivConq.
JSON
      [
                {
                         "Code": 5,
                         "Message": "Problem with coolant system."
                },
                {
                         "Code": 53,
                         "Message": “Fan blade nicked."
                }
      ]




We can combine list and records – a field of one record can hold a list or a record
for the value just like JSON. An item in a list may be a scalar or it may be another
list or a record. This example is a list of records.
Java (DivConq)
      ListStruct ex3 = new ListStruct();

      RecordStruct m1 = new RecordStruct();
      m1.setField("Code", 5);
      m1.setField("Message", "Problem with coolant system.");

      ex3.addItem(m1);

      RecordStruct m2 = new RecordStruct();
      m2.setField("Code", 53);
      m2.setField("Message", "Fan blade nicked.");

      ex3.addItem(m2);



The equivalent in DivConq.
for (int i = 0; i < ex3.getSize(); i++) {
         RecordStruct msg = ex3.getItemAsRecord(i);

          System.out.println("Message #" + i);

          System.out.println("   Code: " +
              msg.getFieldAsString("Code"));

          System.out.println("   Text: " +
              msg.getFieldAsString("Message"));
      }



Use the getItemAsRecord method to access the record.
Example 1
      ListStruct ex2 = new ListStruct(0, 20, 50, 90, 140);

      Example 2
      ListStruct ex3 = new ListStruct(
         new RecordStruct(
               new FieldStruct("Code", 5),
               new FieldStruct("Message", "Problem with coolant system.")
         ),
         new RecordStruct(
               new FieldStruct("Code", 53),
               new FieldStruct("Message", "Fan blade nicked.")
         )
      );


To make it easier to compose a complex structure, you can pass values right into
the constructor of ListStruct and RecordStruct.
Structure declaration and data validation
The code you have seen so far all works. Your application is not required to have
a declaration for all (or any) of your JSON-Like data structures you plan to use.
But it sure can help to have a shared reference for a data structure, especially if
you plan on exposing the data via a service (some services are also available as
web services).

The schema file is where you declare the structures you want to validate and
share. When building your application you’ll need your own schema file – more
importantly you’ll need your own package folder. These examples are part of the
“dcTest” package. If you are following along in the code, look in the dcTest
package.

You may find the schema file here:

divconq/template/packages/dcTest/all/schema
<Schema>
         ... Ignore Database and other elements, look for

         <Shared>
               <Record Id="Schema1Ex1">
                         <Field Name="Code" Type="Integer" />
                         <Field Name="Message" Type="String" />
               </Record>
         </Shared>

         ...
      </Schema>



Shared is the element within Schema where you’ll put many of your structure
definitions. It is the common denominator, types defined here may be used by
stored procedures or services.
<Record Id="Schema1Ex1">
             <Field Name="Code" Type="Integer" />
             <Field Name="Message" Type="String" />
      </Record>


Within the Shared element expect to see either List or Record elements. The
children of Shared will all have an Id attribute, this is the name by which the
structure is known within Java code.

Within a Record element expect to see a list of Field elements, each with a Type
attribute or a child Record or List element.

Before looking at some of the options, lets consider a simple validation.
RecordStruct ex1 = new RecordStruct();
      ex1.setField("Code", 5);
      ex1.setField("Message", "Problem with coolant system.");

      System.out.println(ex1.validate("Schema1Ex1").toString());




Build a record and then validate by calling “validate” method and use the name of
the data type. Validate returns info about the success of the validation, a quick
way to see the results is to use “toString” to print all the validation messages.
RecordStruct ex1 = new RecordStruct();
      ex1.setField("Code", "5");
      ex1.setField("Message", "Problem with coolant system.");

      System.out.println(ex1.validate("Schema1Ex1").toString());




Back to the case where “Code” is a string. This will work because the validation
methods check to see if the data can be accessed as the validating type – in this
case AsInteger. Since it can be accessed that way then all is fine.
RecordStruct ex1 = new RecordStruct();
      ex1.setField("Code", "abc");
      ex1.setField("Message", "Problem with coolant system.");

      System.out.println(ex1.validate("Schema1Ex1").toString());




However, in this case AsInteger returns null. The schema demands that this field
be accessible as an Integer, since it is not, an error is returned.
RecordStruct ex1 = new RecordStruct();
      ex1.setField("Message", "Problem with coolant system.");

      System.out.println(ex1.validate("Schema1Ex1").toString());




Code is not marked as a required field in the Schema, so the above will pass
even though no Code field is present.
Schema
      <Record Id="Schema1Ex2">
                <Field Name="Code" Type="Integer" Required="True" />
                <Field Name="Message" Type="String" />
      </Record>


      Java
      RecordStruct ex1 = new RecordStruct();
      ex1.setField("Message", "Problem with coolant system.");

      System.out.println(ex1.validate("Schema1Ex2").toString());


Adding the Required attribute makes the field required. Now we get an error
message when we validate. Note the new schema Id – using “Ex2” not “Ex1”.
RecordStruct ex1 = new RecordStruct();
      ex1.setField("Code", 5);
      ex1.setField("Message", "Problem with coolant system.");

      System.out.println(ex1.validate("Schema1Ex2").toString());




And now it validates without messages.
Schema
--- common examples ---

<List Id="str" Type="String" />

<List Id="int" Type="Integer" />

--- but lets consider ---

<Record Id="Schema1Ex2">
          <Field Name="Code" Type="Integer" Required="True" />
          <Field Name="Message" Type="String" />
</Record>

<List Id="Schema1Ex3" Type="Schema1Ex2" />
Schema
--- could also be written as ---

<List Id="Schema1Ex3">
   <Record>
         <Field Name="Code" Type="Integer" Required="True" />
         <Field Name="Message" Type="String" />
   </Record>
</List>
ListStruct ex3 = new ListStruct(
            new RecordStruct(
                      new FieldStruct("Code", 5),
                      new FieldStruct("Message", "Problem with coolant system.")
            ),
            new RecordStruct(
                      new FieldStruct("Message", "Fan belt cracked.")
            ),
            new RecordStruct(
                      new FieldStruct("Code", 53),
                      new FieldStruct("Message", "Fan blade nicked.")
            ),
            new RecordStruct(
                      new FieldStruct("Code", "abc"),
                      new FieldStruct("Message", "Fan bearing worn.")
            )
   );

   System.out.println(ex3.validate("Schema1Ex3").toString());


The second and fourth records will fail the validation.
ListStruct ex3 = new ListStruct(
         new RecordStruct(
                   new FieldStruct("Code", 5),
                   new FieldStruct("Message", "Problem with coolant system.")
         ),
         new RecordStruct(
                   new FieldStruct("Code", 52),
                   new FieldStruct("Message", "Fan belt cracked.")
         ),
         new RecordStruct(
                   new FieldStruct("Code", 53),
                   new FieldStruct("Message", "Fan blade nicked.")
         ),
         new RecordStruct(
                   new FieldStruct("Code", 54),
                   new FieldStruct("Message", "Fan bearing worn.")
         )
);

System.out.println(ex3.validate("Schema1Ex3").toString());
Primitive Type Validation
<StringType Id="ResultLevel">
               <StringRestriction Enum="Error,Warn,Info,Exit" />
      </StringType>

      <Record Id="Schema1Ex4">
                <Field Name="Code" Type="Integer" Required="True" />
                <Field Name="Level" Type="ResultLevel" />
                <Field Name="Message" Type="String" />
      </Record>

      ------------------
      RecordStruct ex1 = new RecordStruct();
      ex1.setField("Code", 5);
      ex1.setField("Level", "Warn");
      ex1.setField("Message", "Problem with coolant system.");

      System.out.println(ex1.validate("Schema1Ex4").toString());


With StringType element (child of Shared like Record and List) you can create an
enumeration. In Schema1Ex4 we use that enum for the field Level.
<StringType Id="dcSmallString">
              <StringRestriction MaxLength="250" />
     </StringType>

     <Record Id="Schema1Ex5">
               <Field Name="Code" Type="Integer" Required="True" />
               <Field Name="Level" Type="ResultLevel" />
               <Field Name="Message" Type="dcSmallString" />
     </Record>




A StringType element may also have a max or min length. In Schema1Ex5 we
updated the Message field to have a max of 250 characters.
<StringType Id="dcHubId">
               <StringRestriction Pattern="d{5}" />
      </StringType>

      <StringType Id="BigDateTime">
               <StringRestriction Pattern="td{11,21}" />
      </StringType>

      <StringType Id="Id">
               <StringRestriction Pattern="d{5}_d{15}" />
      </StringType>


A StringType element may also have a pattern restriction. Above, the first must
be 5 digits (e.g. “00202”), the second must be a “t” literal followed by 11 to 21
digits, the third must be 5 digits followed by a “_” literal followed by 15 digits.
dcSchema is powerful, yet reasonably simple, way to validate JSON-Like data
structures in DivConq. Tables, stored procedures, services, scripts and many
other DivConq features rely on the schema for validation of parameters and
return values.

More Related Content

What's hot

Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpaStaples
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know Norberto Leite
 
Real-Time Integration Between MongoDB and SQL Databases
Real-Time Integration Between MongoDB and SQL DatabasesReal-Time Integration Between MongoDB and SQL Databases
Real-Time Integration Between MongoDB and SQL DatabasesEugene Dvorkin
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)MongoDB
 
Wed 1630 greene_robert_color
Wed 1630 greene_robert_colorWed 1630 greene_robert_color
Wed 1630 greene_robert_colorDATAVERSITY
 
NoSQL @ CodeMash 2010
NoSQL @ CodeMash 2010NoSQL @ CodeMash 2010
NoSQL @ CodeMash 2010Ben Scofield
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLMongoDB
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 80 of 202
The Ring programming language version 1.8 book - Part 80 of 202The Ring programming language version 1.8 book - Part 80 of 202
The Ring programming language version 1.8 book - Part 80 of 202Mahmoud Samir Fayed
 
Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)MongoSF
 
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...Donny Wals
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329Douglas Duncan
 
The Ring programming language version 1.5.4 book - Part 73 of 185
The Ring programming language version 1.5.4 book - Part 73 of 185The Ring programming language version 1.5.4 book - Part 73 of 185
The Ring programming language version 1.5.4 book - Part 73 of 185Mahmoud Samir Fayed
 

What's hot (18)

Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpa
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
Real-Time Integration Between MongoDB and SQL Databases
Real-Time Integration Between MongoDB and SQL DatabasesReal-Time Integration Between MongoDB and SQL Databases
Real-Time Integration Between MongoDB and SQL Databases
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
 
Mongo indexes
Mongo indexesMongo indexes
Mongo indexes
 
Wed 1630 greene_robert_color
Wed 1630 greene_robert_colorWed 1630 greene_robert_color
Wed 1630 greene_robert_color
 
sqlmap internals
sqlmap internalssqlmap internals
sqlmap internals
 
NoSQL @ CodeMash 2010
NoSQL @ CodeMash 2010NoSQL @ CodeMash 2010
NoSQL @ CodeMash 2010
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQL
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84
 
The Ring programming language version 1.8 book - Part 80 of 202
The Ring programming language version 1.8 book - Part 80 of 202The Ring programming language version 1.8 book - Part 80 of 202
The Ring programming language version 1.8 book - Part 80 of 202
 
Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)
 
Advanced queuinginternals
Advanced queuinginternalsAdvanced queuinginternals
Advanced queuinginternals
 
Java 7
Java 7Java 7
Java 7
 
Getting Started with MongoDB
Getting Started with MongoDBGetting Started with MongoDB
Getting Started with MongoDB
 
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329
 
The Ring programming language version 1.5.4 book - Part 73 of 185
The Ring programming language version 1.5.4 book - Part 73 of 185The Ring programming language version 1.5.4 book - Part 73 of 185
The Ring programming language version 1.5.4 book - Part 73 of 185
 

Similar to Data Types/Structures in DivConq

Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)lennartkats
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020Thodoris Bais
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2Haroon Idrees
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorialKat Roque
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices -  Michael HacksteinNoSQL meets Microservices -  Michael Hackstein
NoSQL meets Microservices - Michael Hacksteindistributed matters
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsFulvio Corno
 
Js info vis_toolkit
Js info vis_toolkitJs info vis_toolkit
Js info vis_toolkitnikhilyagnic
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Andrii Lashchenko
 
WebSocket JSON Hackday
WebSocket JSON HackdayWebSocket JSON Hackday
WebSocket JSON HackdaySomay Nakhal
 
Hazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSHazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSuzquiano
 
Cassandra Java APIs Old and New – A Comparison
Cassandra Java APIs Old and New – A ComparisonCassandra Java APIs Old and New – A Comparison
Cassandra Java APIs Old and New – A Comparisonshsedghi
 
Oleksandr Valetskyy - DI vs. IoC
Oleksandr Valetskyy - DI vs. IoCOleksandr Valetskyy - DI vs. IoC
Oleksandr Valetskyy - DI vs. IoCOleksandr Valetskyy
 

Similar to Data Types/Structures in DivConq (20)

Green dao
Green daoGreen dao
Green dao
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
 
.Net 3.5
.Net 3.5.Net 3.5
.Net 3.5
 
Lecture17
Lecture17Lecture17
Lecture17
 
Data access
Data accessData access
Data access
 
GraphQL 101
GraphQL 101GraphQL 101
GraphQL 101
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices -  Michael HacksteinNoSQL meets Microservices -  Michael Hackstein
NoSQL meets Microservices - Michael Hackstein
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applications
 
Js info vis_toolkit
Js info vis_toolkitJs info vis_toolkit
Js info vis_toolkit
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.
 
WebSocket JSON Hackday
WebSocket JSON HackdayWebSocket JSON Hackday
WebSocket JSON Hackday
 
Jdbc[1]
Jdbc[1]Jdbc[1]
Jdbc[1]
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
 
Reversing JavaScript
Reversing JavaScriptReversing JavaScript
Reversing JavaScript
 
Hazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSHazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMS
 
Cassandra Java APIs Old and New – A Comparison
Cassandra Java APIs Old and New – A ComparisonCassandra Java APIs Old and New – A Comparison
Cassandra Java APIs Old and New – A Comparison
 
Oleksandr Valetskyy - DI vs. IoC
Oleksandr Valetskyy - DI vs. IoCOleksandr Valetskyy - DI vs. IoC
Oleksandr Valetskyy - DI vs. IoC
 

Recently uploaded

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Data Types/Structures in DivConq

  • 3. Linux Box Windows Java App w/ DivConq MUMPS User w/ Web Browser MUMPS Your Process DivConq Application Database Code MUMPS Interface External Process App on DivConq MUMPS Linux Web Server DivConq Schema Process (HTTP + Web Sockets) There are many reasons to “why JSON?” – one of the best is interoperability with web apps and other external applications. Through HTTP or WebSocket calls JSON parameters can be sent and JSON results can be returned. To minimize interoperability hassles DivConq favors JSON-like structures throughout.
  • 4. Java App w/ DivConq dcDB dcRPC dcSchema Your Application dcScripts (“JSON” Code dcServiceBus Validation) dcWeb Many of the features of the framework use DivConq Schema to validate data structures. When you learn how to use these structures you can use these features. dcDB, dcWeb and dcServiceBus are especially important for most developers using the framework.
  • 5. JSON.org Term DivConq Term DivConq Class Object Record RecordStruct Array List ListStruct Value Scalar ScalarStruct (also) Pair Field FieldStruct Members Fields Elements Items Although DivConq uses different terms, it matches up with JSON very well (see www.json.org).
  • 6. JSON.org Type DivConq Name DivConq Class String String StringStruct Number Integer IntegerStruct (64 bit) " BigInteger BigIntegerStruct (unlimited) " Decimal DecimalStruct (unlimited) " BigDecimal " true Boolean BooleanStruct false " " null Null NullStruct - Any AnyStruct - Binary BinaryStruct - DateTime DateTimeStruct - BigDateTime BigDateTimeStruct DivConq supports the same value types, plus a few more. JSON to DivConq conversions are simple. String becomes string, number tries to fit into Integer or BigInteger, but otherwise falls to Decimal. A true or false becomes a Boolean. A null becomes a “null” in Java (though NullStruct could be used instead).
  • 7. DivConq Name DivConq Class Binary BinaryStruct DateTime DateTimeStruct BigDateTime BigDateTimeStruct Converting from DivConq to JSON is fairly obvious for most of the types, except those above. Binary in DivConq is byte array data and JSON does not support byte arrays. So when Binary is converted to JSON it becomes a base64 encoded string. DateTime is also not in JSON (there are some adaptations though). When DateTime is converted to JSON it becomes an ISO 8601 formatted string using UTC (Z) timezone. BigDateTime is a topic on to itself, it supports dates billions of years past and future. The very short summary, format is: ‘t’YYYYYYYYYYYMMDDhhmmss
  • 9. Example RecordStruct params = new RecordStruct(); params.setField("MinAge", 3); params.setField("MaxAge", 8); QueryRequest request = new QueryRequest("dctListPeople", params); When working with the DivConq Struct classes we usually have a goal in mind. In the example above we mean to create some parameters for a database query request. However, in the following examples we’ll create structures just for the sake of learning, without the context of how they are used. Look for presentations on the dcDb or dcServiceBus for specific examples of how Structs are used.
  • 10. JSON { "Code": 5, "Message": "Problem with coolant system." } Java RecordStruct ex1 = new RecordStruct(); ex1.setField("Code", 5); ex1.setField("Message", "Problem with coolant system."); Scalar types are automatically inferred from java native types. When setting the Code field above, 5 becomes an IntegerStruct and the message string becomes a StringStruct.
  • 11. JSON { "Code": 5, "Message": "Problem with coolant system." } Java RecordStruct ex1 = new RecordStruct(); ex1.setField("Code", new IntegerScalar(5)); ex1.setField("Message", new StringScalar("Problem with coolant system.")); You can be explicit, as above, but most of the time there is no need.
  • 12. OK, you made a record – and presumably passed it to a service (or other feature). How does that service access the data in the record? Before answering, keep in mind the service may run in the same JVM as the caller, or another JVM on running on a computer a thousand miles away. Either way, DivConq is capable of delivering the data (as it was assembled in the last side) if you use the built-in data types (except Any which has special handling). There are no additional requirements or efforts for serialization.
  • 13. RecordStruct ex1 = [as delivered to the service] System.out.println("Code: " + ex1.getFieldAsString("Code")); long code = ex1.getFieldAsInteger("Code"); System.out.println("Code Is Priority Level: " + (code < 3)); So back to the question – how do you access data? The answer – the way you want it. As seen in the example above, you can access the field Code either as a String or as an Integer. RecordStruct will attempt to return a value in the data type you request, if it cannot then it returns null.
  • 14. JSON { "Code": "5", "Message": "Problem with coolant system." } Java RecordStruct ex1 = new RecordStruct(); ex1.setField("Code", "5"); ex1.setField("Message", "Problem with coolant system."); Note that in this example, the field Code contains a string not a number. But the service’s code “long code = ex1.getFieldAsInteger("Code");” will still work. Again, all the getFieldAs* methods attempt to deliver the data the way you need it, regardless of the original type.
  • 15. public Long getFieldAsInteger(String name) public BigInteger getFieldAsBigInteger(String name) public BigDecimal getFieldAsDecimal(String name) public Boolean getFieldAsBoolean(String name) public DateTime getFieldAsDateTime(String name) public BigDateTime getFieldAsBigDateTime(String name) public LocalDate getFieldAsDate(String name) public LocalTime getFieldAsTime(String name) public String getFieldAsString(String name) public Memory getFieldAsBinary(String name) public RecordStruct getFieldAsRecord(String name) public ListStruct getFieldAsList(String name) public CompositeStruct getFieldAsComposite(String name) public Struct getFieldAsStruct(String name) public XElement getFieldAsXml(String name) These are the primary ways of accessing field values.
  • 16. public boolean isEmpty() - are there no fields in this record public Iterable<FieldStruct> getFields() - loop all fields public int getFieldCount() - get number of fields public Struct getField(String name) - get the Struct for the field (e.g. StringStruct) public Object getFieldAsAny(String name) - return the value, no mater what type it is public boolean hasField(String name) - check if field is present public boolean isFieldEmpty(String name) - check that field is not null, if field is a string also check that it contains something other than whitespace These methods also help with data access.
  • 17. JSON [ 0, 20, 50, 90, 140 ] Java ListStruct ex2 = new ListStruct(); ex2.addItem(0); ex2.addItem(20); ex2.addItem(50); ex2.addItem(90); ex2.addItem(140); One way to make a list.
  • 18. for (int i = 0; i < ex2.getSize(); i++) { long code = ex2.getItemAsInteger(i); System.out.println("Code " + code + " is priority level: " + (code < 73)); } Just like the “getFieldAs” methods, there is a “getItemAs” method for all the types recognized by DivConq.
  • 19. JSON [ { "Code": 5, "Message": "Problem with coolant system." }, { "Code": 53, "Message": “Fan blade nicked." } ] We can combine list and records – a field of one record can hold a list or a record for the value just like JSON. An item in a list may be a scalar or it may be another list or a record. This example is a list of records.
  • 20. Java (DivConq) ListStruct ex3 = new ListStruct(); RecordStruct m1 = new RecordStruct(); m1.setField("Code", 5); m1.setField("Message", "Problem with coolant system."); ex3.addItem(m1); RecordStruct m2 = new RecordStruct(); m2.setField("Code", 53); m2.setField("Message", "Fan blade nicked."); ex3.addItem(m2); The equivalent in DivConq.
  • 21. for (int i = 0; i < ex3.getSize(); i++) { RecordStruct msg = ex3.getItemAsRecord(i); System.out.println("Message #" + i); System.out.println(" Code: " + msg.getFieldAsString("Code")); System.out.println(" Text: " + msg.getFieldAsString("Message")); } Use the getItemAsRecord method to access the record.
  • 22. Example 1 ListStruct ex2 = new ListStruct(0, 20, 50, 90, 140); Example 2 ListStruct ex3 = new ListStruct( new RecordStruct( new FieldStruct("Code", 5), new FieldStruct("Message", "Problem with coolant system.") ), new RecordStruct( new FieldStruct("Code", 53), new FieldStruct("Message", "Fan blade nicked.") ) ); To make it easier to compose a complex structure, you can pass values right into the constructor of ListStruct and RecordStruct.
  • 23. Structure declaration and data validation
  • 24. The code you have seen so far all works. Your application is not required to have a declaration for all (or any) of your JSON-Like data structures you plan to use. But it sure can help to have a shared reference for a data structure, especially if you plan on exposing the data via a service (some services are also available as web services). The schema file is where you declare the structures you want to validate and share. When building your application you’ll need your own schema file – more importantly you’ll need your own package folder. These examples are part of the “dcTest” package. If you are following along in the code, look in the dcTest package. You may find the schema file here: divconq/template/packages/dcTest/all/schema
  • 25. <Schema> ... Ignore Database and other elements, look for <Shared> <Record Id="Schema1Ex1"> <Field Name="Code" Type="Integer" /> <Field Name="Message" Type="String" /> </Record> </Shared> ... </Schema> Shared is the element within Schema where you’ll put many of your structure definitions. It is the common denominator, types defined here may be used by stored procedures or services.
  • 26. <Record Id="Schema1Ex1"> <Field Name="Code" Type="Integer" /> <Field Name="Message" Type="String" /> </Record> Within the Shared element expect to see either List or Record elements. The children of Shared will all have an Id attribute, this is the name by which the structure is known within Java code. Within a Record element expect to see a list of Field elements, each with a Type attribute or a child Record or List element. Before looking at some of the options, lets consider a simple validation.
  • 27. RecordStruct ex1 = new RecordStruct(); ex1.setField("Code", 5); ex1.setField("Message", "Problem with coolant system."); System.out.println(ex1.validate("Schema1Ex1").toString()); Build a record and then validate by calling “validate” method and use the name of the data type. Validate returns info about the success of the validation, a quick way to see the results is to use “toString” to print all the validation messages.
  • 28. RecordStruct ex1 = new RecordStruct(); ex1.setField("Code", "5"); ex1.setField("Message", "Problem with coolant system."); System.out.println(ex1.validate("Schema1Ex1").toString()); Back to the case where “Code” is a string. This will work because the validation methods check to see if the data can be accessed as the validating type – in this case AsInteger. Since it can be accessed that way then all is fine.
  • 29. RecordStruct ex1 = new RecordStruct(); ex1.setField("Code", "abc"); ex1.setField("Message", "Problem with coolant system."); System.out.println(ex1.validate("Schema1Ex1").toString()); However, in this case AsInteger returns null. The schema demands that this field be accessible as an Integer, since it is not, an error is returned.
  • 30. RecordStruct ex1 = new RecordStruct(); ex1.setField("Message", "Problem with coolant system."); System.out.println(ex1.validate("Schema1Ex1").toString()); Code is not marked as a required field in the Schema, so the above will pass even though no Code field is present.
  • 31. Schema <Record Id="Schema1Ex2"> <Field Name="Code" Type="Integer" Required="True" /> <Field Name="Message" Type="String" /> </Record> Java RecordStruct ex1 = new RecordStruct(); ex1.setField("Message", "Problem with coolant system."); System.out.println(ex1.validate("Schema1Ex2").toString()); Adding the Required attribute makes the field required. Now we get an error message when we validate. Note the new schema Id – using “Ex2” not “Ex1”.
  • 32. RecordStruct ex1 = new RecordStruct(); ex1.setField("Code", 5); ex1.setField("Message", "Problem with coolant system."); System.out.println(ex1.validate("Schema1Ex2").toString()); And now it validates without messages.
  • 33. Schema --- common examples --- <List Id="str" Type="String" /> <List Id="int" Type="Integer" /> --- but lets consider --- <Record Id="Schema1Ex2"> <Field Name="Code" Type="Integer" Required="True" /> <Field Name="Message" Type="String" /> </Record> <List Id="Schema1Ex3" Type="Schema1Ex2" />
  • 34. Schema --- could also be written as --- <List Id="Schema1Ex3"> <Record> <Field Name="Code" Type="Integer" Required="True" /> <Field Name="Message" Type="String" /> </Record> </List>
  • 35. ListStruct ex3 = new ListStruct( new RecordStruct( new FieldStruct("Code", 5), new FieldStruct("Message", "Problem with coolant system.") ), new RecordStruct( new FieldStruct("Message", "Fan belt cracked.") ), new RecordStruct( new FieldStruct("Code", 53), new FieldStruct("Message", "Fan blade nicked.") ), new RecordStruct( new FieldStruct("Code", "abc"), new FieldStruct("Message", "Fan bearing worn.") ) ); System.out.println(ex3.validate("Schema1Ex3").toString()); The second and fourth records will fail the validation.
  • 36. ListStruct ex3 = new ListStruct( new RecordStruct( new FieldStruct("Code", 5), new FieldStruct("Message", "Problem with coolant system.") ), new RecordStruct( new FieldStruct("Code", 52), new FieldStruct("Message", "Fan belt cracked.") ), new RecordStruct( new FieldStruct("Code", 53), new FieldStruct("Message", "Fan blade nicked.") ), new RecordStruct( new FieldStruct("Code", 54), new FieldStruct("Message", "Fan bearing worn.") ) ); System.out.println(ex3.validate("Schema1Ex3").toString());
  • 38. <StringType Id="ResultLevel"> <StringRestriction Enum="Error,Warn,Info,Exit" /> </StringType> <Record Id="Schema1Ex4"> <Field Name="Code" Type="Integer" Required="True" /> <Field Name="Level" Type="ResultLevel" /> <Field Name="Message" Type="String" /> </Record> ------------------ RecordStruct ex1 = new RecordStruct(); ex1.setField("Code", 5); ex1.setField("Level", "Warn"); ex1.setField("Message", "Problem with coolant system."); System.out.println(ex1.validate("Schema1Ex4").toString()); With StringType element (child of Shared like Record and List) you can create an enumeration. In Schema1Ex4 we use that enum for the field Level.
  • 39. <StringType Id="dcSmallString"> <StringRestriction MaxLength="250" /> </StringType> <Record Id="Schema1Ex5"> <Field Name="Code" Type="Integer" Required="True" /> <Field Name="Level" Type="ResultLevel" /> <Field Name="Message" Type="dcSmallString" /> </Record> A StringType element may also have a max or min length. In Schema1Ex5 we updated the Message field to have a max of 250 characters.
  • 40. <StringType Id="dcHubId"> <StringRestriction Pattern="d{5}" /> </StringType> <StringType Id="BigDateTime"> <StringRestriction Pattern="td{11,21}" /> </StringType> <StringType Id="Id"> <StringRestriction Pattern="d{5}_d{15}" /> </StringType> A StringType element may also have a pattern restriction. Above, the first must be 5 digits (e.g. “00202”), the second must be a “t” literal followed by 11 to 21 digits, the third must be 5 digits followed by a “_” literal followed by 15 digits.
  • 41. dcSchema is powerful, yet reasonably simple, way to validate JSON-Like data structures in DivConq. Tables, stored procedures, services, scripts and many other DivConq features rely on the schema for validation of parameters and return values.