#	entity.tcl -- entity Tcl Command for QeTcl package
#****************************
proc entity {c args} {
   upvar #0 $c data
   eval tclInt_CreateCommand $c entityClass EntityClass $args
   return $c
}

proc entityClass::CreateClassRec {} {
   global entityClass
   # OPTIONS
   set entityClass(rootOptions)   {}
   set entityClass(options)       {}
   # DEFAULT VALUES
   # METHODS
   set entityClass(methods)   { name list_of_fields list_of_primary \
                                list_of_foreign in_relations out_relations\
                                list_of_indexes list_of_constraints get_path\
                                driver  pk_index update is_xbase}
}

proc entityClass::ConstructCommand {c} {
   upvar #0 $c data
   # initialization stuff
}
#*************************
proc entityClass::list_of_fields {c args} {
   upvar  #0 $c data
   upvar  #0 $data(class) class
   return [$data(source)::fl_list $c]
}

#*************************
proc entityClass::list_of_indexes {c args} {
   upvar  #0 $c data
   upvar  #0 $data(class) class
   return [$data(source)::index_list $c]
}

#*************************
proc entityClass::list_of_primary {c args} {
   upvar  #0 $c data
   upvar  #0 $data(class) class
   return [$data(source)::prlist $c $args]
}

#*************************
proc entityClass::list_of_foreign {c args} {
   upvar  #0 $c data
   upvar  #0 $data(class) class
   global  fieldClass
   return [$data(source)::fklist $c $args]
}

#*************************
proc entityClass::out_relations {c args} {
   upvar  #0 $c data
   upvar  #0 $data(class) class
   return [$data(source)::relations_out $c]
}

#*************************
proc entityClass::in_relations {c args} {
   upvar  #0 $c data
   upvar  #0 $data(class) class
   return [$data(source)::relations_in $c]
}
#*************************
proc entityClass::name {c args} {
  upvar  #0 $c data
  return [$data(source)::get_ent_name $c]
}
proc entityClass::get_path {c args} {
  upvar  #0 $c data
  return [$data(source)::get_ent_path $c]
}
proc entityClass::driver {c args} {
  upvar  #0 $c data
  return [$data(source)::get_ent_driver $c]
}
proc entityClass::pk_index {c args} {
  upvar  #0 $c data
  return [$data(source)::ent_pk_index $c]
}
proc entityClass::update { c attr_name value } {
  upvar  #0 $c data
  entity_$data(source)::update $c $attr_name $value
  # update the cache
  update_attribute $c $attr_name $value
}

proc entityClass::is_xbase {c args} {
  upvar  #0 $c data
  return [$data(source)::ent_is_xbase $c]
}
