コード例 #1
0
ファイル: table.py プロジェクト: pridawn/spacetime
 def take_control(self, obj):
     oid = obj.__r_oid__
     self.object_table[oid] = dict()
     for dimname, dim_obj in self.obj_type.__r_meta__.dimmap.items():
         if hasattr(obj, dimname):
             self.object_table[oid][dimname] = convert(
                 dim_obj.dim_type, getattr(obj, dimname))
コード例 #2
0
ファイル: table.py プロジェクト: pridawn/spacetime
    def set(self, oid, dimname, dim_obj, value):
        if not isinstance(value, dim_obj.dim_type):
            # No ducktyping :D
            raise TypeError("{0} is not of type {1}".format(
                repr(value), dim_obj.dim_type.__name__))
        if oid is None:
            # setting up a random uuid as oid
            oid = str(uuid4())
            self.object_table[oid] = dict()

        converted = convert(dim_obj.dim_type, value)
        if oid in self.store_as_temp:
            self.store_as_temp[oid][dimname] = converted

        # Write to local state map.
        self.object_table[oid][dimname] = convert(dim_obj.dim_type, value)
        return oid
コード例 #3
0
ファイル: table.py プロジェクト: pridawn/spacetime
    def set_primarykey(self, oid, dimname, dim_obj, value):
        if not isinstance(value, dim_obj.dim_type):
            # No ducktyping :D
            raise TypeError("{0} is not of type {1}".format(
                repr(value), dim_obj.dim_type.__name__))

        if oid is None and value is None:
            raise RuntimeError("Primary key cannot be None.")

        if oid is not None:
            # Oid is being reset, but the object is not controlled by the dataframe.
            self.object_table[oid][dimname] = convert(dim_obj.dim_type, value)
            self.object_table[value] = self.object_table[oid]
            del self.object_table[oid]
        else:
            # oid is being assigned for the first time.
            self.object_table[value] = dict()
            self.object_table[value][dimname] = convert(
                dim_obj.dim_type, value)
        return value
コード例 #4
0
 def prop(self, value):
     cls = type(self)
     oid = self.__r_oid__ if hasattr(self, "__r_oid__") else None
     df_attached = hasattr(self, "__r_df__") and self.__r_df__ is not None
     if dim_obj.is_primary:
         if df_attached:
             self.__r_df__.reset_primary_key(
                 cls, oid, dimname, convert(dim_obj.dim_type, value))
         else:
             cls.__r_table__.set_primarykey(oid, dimname, dim_obj, value)
         self.__r_oid__ = value
     else:
         if df_attached:
             if oid is None:
                 raise RuntimeError("Objhect primarykey has not been"
                                    " set but dataframe is attached.")
             self.__r_df__.write_dimension(cls, oid, dimname,
                                           convert(dim_obj.dim_type, value))
         else:
             self.__r_oid__ = cls.__r_table__.set(oid, dimname, dim_obj,
                                                  value)
     if hasattr(self, "__r_temp__") and self.__r_temp__ is not None:
         self.__r_temp__[dimname] = convert(dim_obj.dim_type, value)
コード例 #5
0
ファイル: pcc_set.py プロジェクト: Mondego/spacetime
 def prop(self, value):
     oid = self.__r_oid__ if hasattr(self, "__r_oid__") else None
     df_attached = hasattr(self, "__r_df__") and self.__r_df__ is not None
     if dim_obj.is_primary:
         if df_attached:
             self.__r_df__.reset_primary_key(
                 cls, oid, dimname, convert(dim_obj.dim_type, value))
         else:
             cls.__r_table__.set_primarykey(
                 oid, dimname, dim_obj, value)
         self.__r_oid__ = value
     else:
         if df_attached:
             if oid is None:
                 raise RuntimeError(
                     "Objhect primarykey has not been"
                     " set but dataframe is attached.")
             self.__r_df__.write_dimension(
                 cls, oid, dimname, convert(dim_obj.dim_type, value))
         else:
             self.__r_oid__ = cls.__r_table__.set(
                 oid, dimname, dim_obj, value)
     if hasattr(self, "__r_temp__") and self.__r_temp__ is not None:
         self.__r_temp__[dimname] = convert(dim_obj.dim_type, value)