Presentation is loading. Please wait.

Presentation is loading. Please wait.

KRAD Data Layer A Data Access and Persistence Architecture for KRAD Eric Westfall February 2013.

Similar presentations


Presentation on theme: "KRAD Data Layer A Data Access and Persistence Architecture for KRAD Eric Westfall February 2013."— Presentation transcript:

1 KRAD Data Layer A Data Access and Persistence Architecture for KRAD Eric Westfall February 2013

2 Introducing the krad-data module ( Encapsulate ) and and Simplify Simplify

3 What we have today KRAD still using KNS data and persistence architecture Originally written for OJB Overly complex!

4

5 YES! That’s more than 10 services that all support our current data and persistence layer in KRAD.

6 The current abstraction is leaky

7 Take all those services and throw them in the trash! Because we can do it with just one!

8 DataObjectService Focus on what the KRAD framework needs to get it’s job done. Basic CRUD Metadata Data Validation

9 Keep It Simple! An attempt to create the ultimate general-purpose abstraction on top of any ORM or persistence technology would be doomed to failure.

10 Instead, we need to push the complexity down. Instead, we need to push the complexity down. Application code can still use ORM-specific APIs if need arises.

11 Hold On! What is all this nonsense? I thought we were just adding JPA support? JPA Roolz!

12 Yes, but first we need to fix our foundation!

13 Otherwise…

14 …and it wouldn’t hurt to plan for the future a bit.

15 But let’s be honest…

16 However… There are already use cases within our community for non-traditional data stores Example: OLE Document Store The future is now

17 Data from Anywhere By keeping things simple, we open up the possibility to interface with nearly any backend data store or persistence technology OJBJPAJDBCSpring-DataNoSQL Web Services

18

19 Architecture

20 DataObjectService Design find find findMatching findMatching save save delete delete validate validate getDataDictionary getDataDictionary

21 Flexible Data Types

22 DataObjectType<T> public class DataObjectType { public static DataObjectType create( Class dataObjectClass, String discriminator) {... } public static DataObjectType forClass( Class dataObjectClass) {... } // discriminator is null... } public interface DataObjectService { T find(DataObjectType type, Object id); T find(Class type, Object id); // for convenience... }

23 Example of a Static Data Type DataObjectService dos =...; DataObjectType accountType = DataObjectType.forClass(Account.class); Account acct = dos.find(accountType, “123”); System.out.println(acct.getNbr()); // prints “123”

24 Example of a Dynamic Data Type DataObjectService dos =...; DataObjectType jsonAccountType = DataObjectType.create(Json.class, “account”); Json accountJson = new Json(jsonAccountType, “{ ‘nbr’ : ‘123’,... }”); dos.save(accountJson); // assume we have implemented save Json json = dos.find(jsonAccountType, “123”); json.getType().equals(jsonAccountType); // true System.out.println(json.getJson()); // { ‘nbr’ : ‘123’,... }

25 Working with Dynamic Types Allows for a flexible design that could facilitate tasks on the roadmap such as rewriting eDocLite to use KRAD Metadata would need to be available for these dynamic types as well Properties could also be accessed in a syntax similar to Java (dot-notation) with pluggable property accessors for dynamic types.

26 Provider Framework An SPI will be used to allow for custom data providers Can be registered with a ProviderRegistry or loaded via a ModuleConfiguration Three different types of providers: PersistenceProviderMetadataProviderValidationProvider

27 PersistenceProvider Implements basic CRUD operations Can be responsible for one or more data object types For a given data object type, there should be only one valid PersistenceProvider OJB and JPA implementations will be provided out-of-the box with the krad-data module

28 MetadataProvider Loads metadata into the data dictionary for a set of data object types Metadata for a given data object type can be combined from multiple providers into one Reasonable defaults should be applied when possible! LabelsValidationEtc.

29 The Metadata Pipeline

30 Splitting the DataDictionary The DataDictionary becomes the authoritative source for all metadata in KRAD What is currently called the “Data Dictionary” is split into: Data Dictionary – data object metadata View Dictionary – KRAD UIF view configuration Document Dictionary – document framework configuration The “new” DataDictionary becomes part of krad-data module

31 ValidationProvider Allows for simple data object validation Data validation executed automatically upon save Can be disabled by passing a flag to save method Meant for simple, data-focussed validation Required-ness Max/min length Proper format Default provider will be applied in most cases which will leverage constraints defined in Data Dictionary

32 Externalizable Business Objects EBO’s were tacked-on to the KNS Implementation is a mess and very brittle Through the use of custom PersistenceProviders, the goal is the render the current incarnation of EBOs obsolete …and deprecate the ExternalizableBusinessObject marker interface

33 Transaction Management Transaction management will still occur above the data layer Not all data stores support transactions It will be up to the provider implementation to be written in a “transaction aware” fashion if transactions are supported JPA and OJB providers will both be transaction-aware In KRAD, will work to discontinue the practice of course- grained transactions automatically initiated on entry into any controller Instead, controller methods which should be transactional, will initiate transactions when appropriate/necessary

34 Impact Goal is to leave legacy KNS untouched as much as possible Existing KRAD applications will have impact if they are currently using BusinessObjectService and it’s friends

35 The Old-School Way Create database table(s) Create java object, implements PersistableBusinessObject Map Java object to Database using ORM Create Data Dictionary XML file for business object Configure all attributes in Data Dictionary file Inject data dictionary files in module configuration Use BusinessObjectService to load and persist object

36 The New-And-Improved Way Create database table(s) Create POJO Map Java object to Database using ORM Inject ORM provider into module configuration Use DataObjectService to load and persist data object Mapping the data object in an XML Data Dictionary file is optional! Intelligent defaults will be applied and all metadata sources will be leveraged wherever possible.

37 Advantages Metadata pipeline will derive dictionary info when possible Natural language derivation for labels (for example: accountNumber -> “Account Number”) Max Length derived from database metadata Required-ness derived from database metadata Intelligent convention-based defaults whenever possible DataDictionary XML can be used to refine metadata, but is ultimately optional Data Validation is built into the data layer and sourced from metadata in Data Dictionary Data Dictionary is simplified to just data object metadata

38

39 The Development Plan Data and Provider Layer implementation OJB Persistence and Metadata Providers DataDictionary refactoring Isolation of legacy KNS Refactoring of KRAD to utilize new service(s) JPA Persistence and Metadata Providers JPA Implementation Support Classes Conversion/Migration Scripts

40 Still Working On… How best to handle linking and refreshing Detailed design on EBO Work through issues on how to handle data dictionary split and modularity. Is proposed definition of DataObjectService enough? Method to create a new instance of a data object? Helpers for property accessors/modifiers? How, exactly, to do all of this without breaking legacy KNS?

41 Next Time Design of OJB implementation Design of JPA implementation JPA-specific considerations and challenges

42


Download ppt "KRAD Data Layer A Data Access and Persistence Architecture for KRAD Eric Westfall February 2013."

Similar presentations


Ads by Google