Figure 10: Generated ONM code for data access.
stores one entity of the schema. An entity is com-
posed by one root class, that represent the root docu-
ment of the collection and it could have other classes
that represent nested documents. For example, pack-
age mf.model.nosql.categories stores a single class to
represent the document structure of Categories col-
lection and package mf.model.nosql.products stores
three classes to represent the document structure of
collection Products, where Products is the root class
and Categories and Inventory classes are the nested
documents.
MfCodeGenerator generates code that conforms
to the NoSQL schema, adding attributes to estab-
lish relationships between classes. Figures 11, 12
and 13 present the code generated by MfCodeGener-
ator, highlighting the ONM annotations added in the
classes. For the sake of simplicity, we only show iden-
tifier fields and relationship fields, suppressing other
fields and getter and setter methods. The Categories
entity is not presented because the code is similar to
Customers and it does not bring new aspects to high-
light.
/ / SPRING DATA
@Document ( c o l l e c t i o n =” Cu s t o m e r s ” )
p u b l i c c l a s s C u s t o m e r s {
@Id
p r i v a t e S t r i n g i d ;
p r i v a t e I n t e g e r i d c u s t o m e r ;
@R e ad O nl y Pr o pe r ty
@Do cumen tR efe re nce ( l o o k u p =
” { ’ c u s t o m e r i d ’ : ? # { # s e l f . i d c u s t o m e r }} ” )
p r i v a t e L i s t<Orde r s> o r d e r s ;
}
/ /DATA NUCLEUS a nd IMPETUS KUNDERA
@E n t ity ( name = ” C u s t o m e r s ” )
p u b l i c c l a s s C u s t o m e r s {
@Id
p r i v a t e I n t e g e r i d c u s t o m e r ;
@OneToMany( mappedBy = ” c u s t o m e r i d ” )
p r i v a t e L i s t<Orde r s> o r d e r s ;
}
Figure 11: Customers code generated for all ONMs.
4.2 ONM Code Customization
It is worth noting the use of @AttributeOverride an-
notation in Products class for Data Nucleus (Figure
12). The annotation defines the attributes name of the
/ / DATA NUCLEUS
@E n t ity ( name=” P r o d u c t s ” )
p u b l i c c l a s s P r o d u c t s {
@Id
p r i v a t e I n t e g e r i d p r o d ;
@Embedded
@ A t t r i b u t e O v e r r i d e ( name=
” p r o d i d ” , c ol umn =
@Column( name= ” p r o d i d ” ) )
@ A t t r i b u t e O v e r r i d e ( name=
” q u a n s t o c k ” , column=
@Column( name= ” q u a n s t o c k ” ) )
@ A t t r i b u t e O v e r r i d e ( name=
” s a l e s ” , colu mn =
@Column( name= ” s a l e s ” ) )
p r i v a t e I n v e n t o r y i n v e n t o r y ;
@Embedded
@ A t t r i b u t e O v e r r i d e ( name=
” i d c a t e g o r y ” , colu mn =
@Column( name= ” i d c a t e g o r y ” ) )
@ A t t r i b u t e O v e r r i d e ( name=
” ca t e g o r y n a m e ” , colu mn =
@Column( name= ” ca t g o r y n a m e ” ) )
p r i v a t e C a t e g o r i e s c a t s ;
@OneToMany( mappedBy=
” p r o d i d ” )
p r i v a t e L i s t<O r d e r l i n e s >
o l i n e s ;
}
/ / IMPETUS KUNDERA
@E n t ity ( name=” P r o d u c t s ” )
p u b l i c c l a s s P r o d u c t s {
@Id
p r i v a t e I n t e g e r i d
p r o d ;
@Embedded
p r i v a t e I n v e n t o r y i n v e n t o r y ;
@Embedded
p r i v a t e C a t e g o r i e s c a t s ;
p r i v a t e L i s t<O r d e r l i n e s >
o l i n e s ;
}
/ / DATA NUCLEUS a nd
IMPETUS KUNDERA
@Embeddable
p u b l i c c l a s s C a t e g o r i e s {
I n t e g e r i d c a t e g o r y ;
S t r i n g c a t e g o r y n a m e ;
}
@Embeddable
p u b l i c c l a s s I n v e n t o r y {
I n t e g e r p r o d i d ;
I n t e g e r q u a n i n s t o c k ;
I n t e g e r s a l e s ;
}
/ / SPRING DATA
@Document ( c o l l e c t i o n =
” P r o d u c t s ” )
p u b l i c c l a s s P r o d u c t s {
@Id
p r i v a t e S t r i n g i d ;
p r i v a t e I n t e g e r i d p r o d ;
p r i v a t e I n v e n t o r y
i n v e n t o r y ;
p r i v a t e C a t e g o r i e s c a t s ;
p r i v a t e L i s t<O r d e r l i n e s >
o l i n e s ;
}
p u b l i c c l a s s C a t e g o r i e s {
I n t e g e r i d c a t e g o r y ;
S t r i n g c a t e g o r y n a m e ;
}
p u b l i c c l a s s I n v e n t o r y {
I n t e g e r p r o d i d ;
I n t e g e r q u a n i n s t o c k ;
I n t e g e r s a l e s ;
}
Figure 12: Products, Categories and Inventory code gener-
ated for all ONMs. Getters and setters are omitted.
/ / DATA NUCLEUS
@E n t ity ( name = ” O r d e r s ” )
p u b l i c c l a s s O r d e r s {
@Id
p r i v a t e I n t e g e r i d o r d e r ;
@Embedded
p r i v a t e L i s t<O r d e r l i n e s >
o l i n e s ;
@ManyToOne
p r i v a t e C u s t o m e r s cu s t om ;
}
@Embeddable
p u b l i c c l a s s O r d e r l i n e s {
p r i v a t e I n t e g e r o l i n e i d ;
p r i v a t e I n t e g e r o r d e r i d ;
p r i v a t e I n t e g e r p r o d i d ;
p r i v a t e I n t e g e r q u a n t i t y ;
p r i v a t e D at e o l i n e d a t e ;
@ManyToOne
p r i v a t e P r o d u c t s p r o d u c t s ;
}
/ / IMPETUS KUNDERA
@E n t ity ( name=” Or d e r s ” )
p u b l i c c l a s s O r d e r s {
@Id
p r i v a t e I n t e g e r i d
o r d e r ;
@ E l e m e n t C o l l e c t i o n
p r i v a t e L i s t<O r d e r l i n e s >
o l i n e s ;
@ManyToOne
@JoinColumn ( name=
” cu s t o m e r i d ” )
p r i v a t e C u s t o m e r s cu s t om ;
}
@Embeddable
p u b l i c c l a s s O r d e r l i n e s {
p r i v a t e I n t e g e r o l i n e i d ;
p r i v a t e I n t e g e r o r d e r i d ;
p r i v a t e I n t e g e r p r o d i d ;
p r i v a t e I n t e g e r q u a n t i t y ;
p r i v a t e D at e o l i n e d a t e ;
p r i v a t e P r o d u c t s p r o d u c t s ;
}
/ / SPRING DATA
@Document ( c o l l e c t i o n =
” O r d e r s ” )
p u b l i c c l a s s O r d e r s {
@Id
p r i v a t e S t r i n g i d ;
p r i v a t e I n t e g e r i d o r d e r ;
p r i v a t e L i s t<O r d e r l i n e s >
o l i n e s ;
@Do cumen tR efe re nce ( l o o k u p =
” { ’ i d c u s t o m e r ’ : ? # { c u s t o m e r i d
}} ” )
p r i v a t e C u s t o m e r s cu s t om ;
}
p u b l i c c l a s s O r d e r l i n e s {
p r i v a t e I n t e g e r o l i n e i d ;
p r i v a t e I n t e g e r o r d e r i d ;
p r i v a t e I n t e g e r p r o d i d ;
p r i v a t e I n t e g e r q u a n t i t y ;
p r i v a t e D at e o l i n e d a t e ;
@Do cumen tR efe re nce ( l o o k u p =
” { ’ i d p r o d ’ : ? # { p r o d i d }} ” )
p r i v a t e P r o d u c t s p r o d u c t s ;
}
Figure 13: Orders and Orderlines code generated for all
ONMs.
MfCodeGenerator: A Code Generation Tool for NoSQL Data Access with ONM Support
237