def _mappings(self, ctx): Mappings.includes(ctx, self.mappings) mappings = [mapping.copy() for mapping in self.mappings] for mapping in mappings: if (not "entity" in mapping): mapping["entity"] = self.entity for attribute in self.entity.attributes: # Add dimension attributes as fields for the mapper if not existing mapping = {"name": attribute["name"], "entity": self.entity} if ("type" in attribute and attribute["type"] != None): mapping["type"] = attribute["type"] if not attribute["name"] in [m["name"] for m in mappings]: if not (self.entity.name + "_" + attribute["name"]) in self._automapping_warning: logger.debug( "Automatically adding mapping for attribute '%s' of %s since no mapping was defined for that attribute." % (attribute["name"], self.entity)) self._automapping_warning.append( (self.entity.name + "_" + attribute["name"])) self._extend_mappings(ctx, mappings, [mapping]) self._ensure_mappings(ctx, mappings) return mappings
def initialize(self, ctx): super(TableMapper, self).initialize(ctx) ctx.comp.initialize(self.entity) ctx.comp.initialize(self.connection) self._sqltable = CachedSQLTable() self._sqltable.name = self.table self._sqltable.connection = self.connection Mappings.includes(ctx, self.mappings) for mapping in self.mappings: if (not "entity" in mapping): mapping["entity"] = self.entity mappings = self._mappings(ctx) for mapping in mappings: self._sqltable.columns.append({ "name": mapping["column"] , "type": mapping["type"], "pk": mapping["pk"] }) # If lookup_cols is a string, split by commas if (isinstance(self.lookup_cols, basestring)): self.lookup_cols = [ key.strip() for key in self.lookup_cols.split(",") ] # If no key, use pk() if (self.lookup_cols == None): pk = self.pk(ctx) if ((pk == None) or (pk["type"] == "AutoIncrement")): raise Exception ("No lookup cols defined for %s " % self) self.lookup_cols = [ pk["name"] ] ctx.comp.initialize(self._sqltable)
def initialize(self, ctx): super(TableMapper, self).initialize(ctx) if self._uses_table: if (self.entity == None): raise Exception("No entity defined for %s" % self) if (self.connection == None): raise Exception("No connection defined for %s" % self) ctx.comp.initialize(self.entity) ctx.comp.initialize(self.connection) self._sqltable = CachedSQLTable() self._sqltable.name = self.table self._sqltable.connection = self.connection # Assert that the sqltable is clean #if (len(self._sqltable.columns) != 0): raise AssertionError("SQLTable '%s' columns shall be empty!" % self._sqltable.name) # If lookup_cols is a string, split by commas if (isinstance(self.lookup_cols, basestring)): self.lookup_cols = [ key.strip() for key in self.lookup_cols.split(",") ] Mappings.includes(ctx, self.mappings) for mapping in self.mappings: try: if (not "entity" in mapping): mapping["entity"] = self.entity except TypeError as e: raise Exception( "Could not initialize mapping '%s' of '%s': %s" % (mapping, self, e)) if self._uses_table: mappings = self._mappings(ctx) for mapping in mappings: logger.debug("%s adding column from OLAP mapping: %s" % (self, mapping)) self._sqltable.columns.append({ "name": mapping["column"], "type": mapping["type"], "pk": mapping["pk"] }) # If no key, use pk() if (self.lookup_cols == None): pk = self.pk(ctx) if ((pk == None) or (pk["type"] == "AutoIncrement")): raise Exception( "No lookup cols defined for %s (use lookup_cols=[...])" % self) self.lookup_cols = [pk["name"]] ctx.comp.initialize(self._sqltable)
def initialize(self, ctx): super(TableMapper, self).initialize(ctx) if self._uses_table: if (self.entity == None): raise Exception("No entity defined for %s" % self) if (self.connection == None): raise Exception("No connection defined for %s" % self) ctx.comp.initialize(self.entity) ctx.comp.initialize(self.connection) self._sqltable = CachedSQLTable() self._sqltable.name = self.table self._sqltable.connection = self.connection # Assert that the sqltable is clean #if (len(self._sqltable.columns) != 0): raise AssertionError("SQLTable '%s' columns shall be empty!" % self._sqltable.name) # If lookup_cols is a string, split by commas if (isinstance(self.lookup_cols, basestring)): self.lookup_cols = [ key.strip() for key in self.lookup_cols.split(",") ] Mappings.includes(ctx, self.mappings) for mapping in self.mappings: try: if (not "entity" in mapping): mapping["entity"] = self.entity except TypeError as e: raise Exception("Could not initialize mapping '%s' of '%s': %s" % (mapping, self, e)) if self._uses_table: mappings = self._mappings(ctx) for mapping in mappings: logger.debug("%s adding column from OLAP mapping: %s" % (self, mapping)) self._sqltable.columns.append({ "name": mapping["column"] , "type": mapping["type"], "pk": mapping["pk"] }) # If no key, use pk() if (self.lookup_cols == None): pk = self.pk(ctx) if ((pk == None) or (pk["type"] == "AutoIncrement")): raise Exception ("No lookup cols defined for %s (use lookup_cols=[...])" % self) self.lookup_cols = [ pk["name"] ] ctx.comp.initialize(self._sqltable)
def _mappings(self, ctx): Mappings.includes(ctx, self.mappings) mappings = [mapping.copy() for mapping in self.mappings] for mapping in mappings: if (not "entity" in mapping): mapping["entity"] = self.entity for attribute in self.entity.attributes: # Add dimension attributes as fields for the mapper if not existing mapping = { "name": attribute["name"], "entity": self.entity } if ("type" in attribute and attribute["type"] != None): mapping["type"] = attribute["type"] if not attribute["name"] in [m["name"] for m in mappings]: if not (self.entity.name + "_" + attribute["name"]) in self._automapping_warning: logger.debug("Automatically adding mapping for attribute '%s' of %s since no mapping was defined for that attribute." % (attribute["name"], self.entity)) self._automapping_warning.append((self.entity.name + "_" + attribute["name"])) self._extend_mappings(ctx, mappings, [ mapping ]) self._ensure_mappings(ctx, mappings) return mappings