Module: DAO

Included in:
Muml_Class
Defined in:
lib/ontomde-java/jpa/jpa.rb,
lib/ontomde-java/crank/crankJpa.rb

Constant Summary collapse

DAOInterface =
"GenericDao"
DAOQualifiedInterface =
"org.crank.crud.GenericDao"

Instance Method Summary collapse

Instance Method Details

#jpa_addDAO!Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/ontomde-java/jpa/jpa.rb', line 118

def jpa_addDAO!
  return if db_isDAO?
  return if java_ignoreMe?


  if !context[:db_autonomousDAO,false]
    self.java_DAOClass=self
    self.java_persistentClass=self
  else
    
    log.debug { "adding dao for #{self}" }
    p=umlx_package

    #p=self
    p=p.umlx_getOrCreatePackage(context[:dbDAOsubPackage,"dao"],p)
    c=p.umlx_createAndAddClass(rdf_uri+"_dao")
    c.db_isDAO=RDF_TRUE
    c.db_isTransient=RDF_TRUE
    self.java_DAOClass=c
    c.java_persistentClass=self
    c.uml_name=uml_name_one+"Dao"

    #log.debug { "DAO added: #{c.uml_name} in #{c.umlx_package.uml_name}"}
    java_DAOClass_one.jpa_addEntityManager!()
    java_DAOClass_one.jpa_addStdImports!
#      jpa_addGetDao!()
  end
  jpa_addPersist!
  jpa_addMerge!
  jpa_addRemove!
  jpa_addFindByPrimaryKey!(java_DAOClass_one)
  jpa_addFindAll!(java_DAOClass_one)
end

#jpa_addGetDao!Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/ontomde-java/jpa/jpa.rb', line 151

def jpa_addGetDao!()
  return if uml_isAbstract?
  umlx_classifier_generalization_indirect.each {|c|
    return unless c.uml_isAbstract?
  }
  m=umlx_createAndAddOperation(rdf_uri+"_getdao")
  m.uml_name="dao"
  m.uml_class=self
  m.uml_visibility=Cuml_VisibilityKind::Public
  m.uml_isStatic=RDF_TRUE
  #m.db_isTransient=RDF_TRUE

  #em=m.umlx_createAndAddParameter(m.rdf_uri+"_entityManager","entityManager")
  #em.uml_type=umlx_getOrCreateClass(DB::EntityManager)
  #em.uml_direction=Cuml_ParameterDirectionKind::In
  #em.uml_upperValue=umlx_literal(1)
  #em.uml_lowerValue=umlx_literal(1)

  rp=m.umlx_createAndAddParameter(m.rdf_uri+"_ret_param","return")
  rp.uml_direction=Cuml_ParameterDirectionKind::Return
  rp.uml_upperValue=umlx_literal(1)
  rp.uml_lowerValue=umlx_literal(1)
  rp.uml_type=java_DAOClass_one
  m.java_code="return new #{java_DAOClass_one.java_qualifiedName}();"
  return m
end

#jpa_addMerge!Object



107
108
109
110
111
112
# File 'lib/ontomde-java/jpa/jpa.rb', line 107

def jpa_addMerge!
  c=umlx_createAndAddOperation(rdf_uri+"_merge","merge")
  c.java_code="return (#{self.java_qualifiedName})getEntityManager().merge(this);"
  r=c.umlx_createAndAddReturnParameter("#{c.rdf_uri}_ret")
  r.uml_type=self
end

#jpa_addNamedQueryObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/ontomde-java/crank/crankJpa.rb', line 125

def jpa_addNamedQuery
  namedQuery = "@javax.persistence.NamedQueries( {\n"
  namedQuery << "    @javax.persistence.NamedQuery( name = \"#{self.java_Name}.readPopulated\",\n"
  namedQuery << "      query = \"select distinct #{self.java_Name.downcase} from #{self.java_Name} #{self.java_Name.downcase} "
  umlx_ownedAndInheritedAttribute.sort  { |a,b| a.java_Name.to_s <=> b.java_Name.to_s }.each { |a|
    next if a.uml_type_one.db_isTransient? 
    next if a.uml_isDerived?
    if !a.umlx_isAttribute? 
      namedQuery << jpa_addNamedQueryToAssociation!(a)
    end
  }
  namedQuery <<  " where #{self.java_Name.downcase}.id=?\" )"
  
  namedQuery += "})"    
  self.java_annotation_add(namedQuery)
end

#jpa_addNamedQueryToAssociation!(a) ⇒ Object



142
143
144
# File 'lib/ontomde-java/crank/crankJpa.rb', line 142

def jpa_addNamedQueryToAssociation!(a)
   return "left outer join fetch #{self.java_Name.downcase}.#{a.java_Name} "
end

#jpa_addPersist!Object



103
104
105
106
# File 'lib/ontomde-java/jpa/jpa.rb', line 103

def jpa_addPersist!
  c=umlx_createAndAddOperation(rdf_uri+"_persist","persist")
  c.java_code="getEntityManager().persist(this);"
end

#jpa_addPersistenceContext!Object



101
102
# File 'lib/ontomde-java/jpa/jpa.rb', line 101

def jpa_addPersistenceContext!
end

#jpa_addRemove!Object



114
115
116
117
# File 'lib/ontomde-java/jpa/jpa.rb', line 114

def jpa_addRemove!
  c=umlx_createAndAddOperation(rdf_uri+"_remove","remove")
  c.java_code="getEntityManager().remove(this);"
end

#super_jpa_addDAO!Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ontomde-java/crank/crankJpa.rb', line 74

def jpa_addDAO!
  return if db_isDAO?
  return if java_ignoreMe?


  if !context[:db_autonomousDAO,false]
    self.java_DAOClass=self
    self.java_persistentClass=self
  else
    
    log.debug { "adding dao for #{self}" }
    p=umlx_package

    #p=self
    p=p.umlx_getOrCreatePackage(context[:dbDAOsubPackage,"dao"],p)
    c=p.umlx_createAndAddClass(rdf_uri+"_dao")
    c.db_isDAO=RDF_TRUE
    c.db_isTransient=RDF_TRUE
    self.java_DAOClass=c
    c.java_persistentClass=self
    c.uml_name=uml_name_one+"Dao"

    #log.debug { "DAO added: #{c.uml_name} in #{c.umlx_package.uml_name}"}
    java_DAOClass_one.jpa_addEntityManager!()
    java_DAOClass_one.jpa_addStdImports!
#      jpa_addGetDao!()
  end
  jpa_addPersist!
  jpa_addMerge!
  jpa_addRemove!
  jpa_addFindByPrimaryKey!(java_DAOClass_one)
  jpa_addFindAll!(java_DAOClass_one)
end