Exemple #1
0
 def __init__(self, parent, child, key_type, name, cascade, child_only, public, static) :
     rel_base.Relationship.__init__(self, parent, child, name, cascade, child_only, public, static)
     self.key_type = key_type
     self.addChildField(name + parent.__name__ + "Key", key_type)
     self.addParentArrayField(name + child.__name__ + "Table", child, 0, public = False)
     self.addParentField(name + child.__name__ + "TableMin", dbtypes.StdUInt, public = False)
     self.addParentField(name + child.__name__ + "TableMax", dbtypes.StdUInt, public = False)
     self.addParentField(name + child.__name__ + "TableSize", dbtypes.StdUInt, public = False, initial_value = "DEFAULT_HASH_TABLE_SIZE")
     self.addParentField("Num" + name + child.__name__ + "s", dbtypes.StdUInt, public = True)
     rel_list.createList(parent, child, "TableList", cascade = cascade, child_only = True, public = False)
Exemple #2
0
def prepareClass(the_class) :
    ## Создание пустого списка для методов класса
    the_class.methods = []
    prepareClassUserMethods(the_class)
    if dbtypes.HSDB.logger_enabled :
        the_class.methods.append(RegisterMethod())
    the_class.methods.append(InitMethod(the_class))
    #the_class.methods.append(toStringMethod(the_class))
    if the_class.save_data :
        the_class.methods.append(SaveMethod(the_class))
        the_class.methods.append(LoadMethod(the_class))
        the_class.methods.append(OnSaveHandler(the_class))
        the_class.methods.append(OnLoadHandler(the_class))
    ## Создание системных полей для несинглтон класса (создается счетчик выделенных объектов Used и флаг существования объекта Exists)
    if not the_class.singleton :
        the_class.methods.append(ResetMethod(the_class))
        rel_stack.createStack(the_class, the_class, "Free", False, True, False, True)
        the_class.__dict__["Used"] = fields.Field(field_type = dbtypes.StdUInt, 
                                                  static = True, 
                                                  privacy = fields.PRIVATE_FIELD, 
                                                  initial_value = 0,
                                                  comment = "The number of instances that was already been created at least one")
        the_class.__dict__["Exists"] = fields.Field(field_type = dbtypes.Bool, privacy = fields.PRIVATE_FIELD, initial_value = "true",
                                                    comment = "Flag indicating object is exists now (was created but not destroyed yet)")

    the_class.__field_names__ = [name for name in sorted(the_class.__dict__.keys()) if util.inherits(the_class.__dict__[name], fields.Field)]
    ## Cоздание дополнительных полей для динамических массивов
    for name in the_class.__field_names__ :
        field = the_class.__dict__[name]
        privacy_val = fields.READONLY_FIELD
        if field.privacy == fields.PRIVATE_FIELD :
            privacy_val = fields.PRIVATE_FIELD
        if field.array and field.array_size == 0 :
            the_class.__dict__[name + "Len"] = fields.Field(field_type = dbtypes.StdUInt, privacy = privacy_val, initial_value = 0,
                                                            comment = "The length of '{0}' array field of a given class instance".format(name))
            if not the_class.singleton :
                the_class.__dict__[name + "Used"] = fields.Field(field_type = dbtypes.StdUInt, 
                                                                 static = True, 
                                                                 privacy = fields.PRIVATE_FIELD, 
                                                                 initial_value = 0,
                                                                 comment = "The number of buffer elements that is already in use by class objects")
                the_class.__dict__[name + "Index"] = fields.Field(field_type = dbtypes.StdUInt, privacy = fields.PRIVATE_FIELD, initial_value = "Null",
                                                                  comment = "Index of the first array field element in array buffer of given class instance")
                rel_list.createList(the_class, the_class, "__" + name + "Block" + "__", static = True, public = False)

    the_class.__field_names__ = [name for name in sorted(the_class.__dict__.keys()) if util.inherits(the_class.__dict__[name], fields.Field)]
    ## Создание методов для несинглтон классов
    if not the_class.singleton :
        the_class.methods.append(CreateClassMethod(the_class))
        the_class.methods.append(ExtendedCreateClassMethod(the_class))
        the_class.methods.append(DestroyMethod(the_class))
        the_class.methods.append(OnCreateHandler(the_class))
        the_class.methods.append(OnDestroyHandler(the_class))

    if the_class.singleton :
        for name in the_class.__field_names__ :
            the_class.__dict__[name].static = True
    ## Экстракция пользовательских методов, объявленных в описании БД
    for name in the_class.__field_names__ :
        the_class.methods = the_class.methods + the_class.__dict__[name].getMethods(name, the_class.memory_type)
    ## Экстракция методов из отношений класса
    for rel in dbtypes.HSDB.relationships :
        if rel.parent == the_class :
            the_class.methods = the_class.methods + rel.getParentMethods()
        if rel.child == the_class :
            the_class.methods = the_class.methods + rel.getChildMethods()

    for method in the_class.methods :
        method.parent = the_class
        if the_class.singleton :
            method.static = True