Esempio n. 1
0
    def delColumn(sqlmeta,
                  column,
                  changeSchema=False,
                  connection=None,
                  childUpdate=False):
        if childUpdate:
            soClass = sqlmeta.soClass
            unmakeProperties(soClass)
            makeProperties(soClass)

            if isinstance(column, str):
                name = column
            else:
                name = column.name
            delattr(soClass, name)
            delattr(soClass.q, name)
            return

        super(InheritableSQLMeta, sqlmeta).delColumn(column, changeSchema,
                                                     connection)

        # DSM: Update each child class if needed
        # DSM: and delete properties for this column
        for c in sqlmeta.childClasses.values():
            c.sqlmeta.delColumn(column,
                                changeSchema=changeSchema,
                                connection=connection,
                                childUpdate=True)
Esempio n. 2
0
    def addJoin(sqlmeta, joinDef, childUpdate=False):
        soClass = sqlmeta.soClass
        # DSM: Try to add parent properties to the current class
        # DSM: Only do this once if possible at object creation and once for
        # DSM: each new dynamic join to refresh the current class
        if sqlmeta.parentClass:
            for join in sqlmeta.parentClass.sqlmeta.joins:
                jname = join.joinMethodName
                jarn = join.addRemoveName
                setattr(soClass, getterName(jname),
                        eval('lambda self: self._parent.%s' % jname))
                if hasattr(join, 'remove'):
                    setattr(
                        soClass, 'remove' + jarn,
                        eval('lambda self,o: self._parent.remove%s(o)' % jarn))
                if hasattr(join, 'add'):
                    setattr(
                        soClass, 'add' + jarn,
                        eval('lambda self,o: self._parent.add%s(o)' % jarn))
            if childUpdate:
                makeProperties(soClass)
                return

        if joinDef:
            super(InheritableSQLMeta, sqlmeta).addJoin(joinDef)

        # DSM: Update each child class if needed and existing (only for new
        # DSM: dynamic join as no child classes exists at object creation)
        for c in sqlmeta.childClasses.values():
            c.sqlmeta.addJoin(joinDef, childUpdate=True)
Esempio n. 3
0
    def addJoin(sqlmeta, joinDef, childUpdate=False):
        soClass = sqlmeta.soClass
        # DSM: Try to add parent properties to the current class
        # DSM: Only do this once if possible at object creation and once for
        # DSM: each new dynamic join to refresh the current class
        if sqlmeta.parentClass:
            for join in sqlmeta.parentClass.sqlmeta.joins:
                jname = join.joinMethodName
                jarn = join.addRemoveName
                setattr(
                    soClass, getterName(jname),
                    eval('lambda self: self._parent.%s' % jname))
                if hasattr(join, 'remove'):
                    setattr(
                        soClass, 'remove' + jarn,
                        eval('lambda self,o: self._parent.remove%s(o)' % jarn))
                if hasattr(join, 'add'):
                    setattr(
                        soClass, 'add' + jarn,
                        eval('lambda self,o: self._parent.add%s(o)' % jarn))
            if childUpdate:
                makeProperties(soClass)
                return

        if joinDef:
            super(InheritableSQLMeta, sqlmeta).addJoin(joinDef)

        # DSM: Update each child class if needed and existing (only for new
        # DSM: dynamic join as no child classes exists at object creation)
        for c in sqlmeta.childClasses.values():
            c.sqlmeta.addJoin(joinDef, childUpdate=True)
Esempio n. 4
0
    def addColumn(sqlmeta,
                  columnDef,
                  changeSchema=False,
                  connection=None,
                  childUpdate=False):
        soClass = sqlmeta.soClass
        # DSM: Try to add parent properties to the current class
        # DSM: Only do this once if possible at object creation and once for
        # DSM: each new dynamic column to refresh the current class
        if sqlmeta.parentClass:
            for col in sqlmeta.parentClass.sqlmeta.columnList:
                cname = col.name
                if cname == 'childName':
                    continue
                if cname.endswith("ID"):
                    cname = cname[:-2]
                setattr(soClass, getterName(cname),
                        eval('lambda self: self._parent.%s' % cname))
                if not col.immutable:

                    def make_setfunc(cname):
                        def setfunc(self, val):
                            if not self.sqlmeta._creating and \
                               not getattr(self.sqlmeta,
                                           "row_update_sig_suppress", False):
                                self.sqlmeta.send(events.RowUpdateSignal, self,
                                                  {cname: val})

                            setattr(self._parent, cname, val)

                        return setfunc

                    setfunc = make_setfunc(cname)
                    setattr(soClass, setterName(cname), setfunc)
            if childUpdate:
                makeProperties(soClass)
                return

        if columnDef:
            super(InheritableSQLMeta,
                  sqlmeta).addColumn(columnDef, changeSchema, connection)

        # DSM: Update each child class if needed and existing (only for new
        # DSM: dynamic column as no child classes exists at object creation)
        if columnDef and hasattr(soClass, "q"):
            q = getattr(soClass.q, columnDef.name, None)
        else:
            q = None
        for c in sqlmeta.childClasses.values():
            c.sqlmeta.addColumn(columnDef,
                                connection=connection,
                                childUpdate=True)
            if q:
                setattr(c.q, columnDef.name, q)
Esempio n. 5
0
    def delJoin(sqlmeta, joinDef, childUpdate=False):
        if childUpdate:
            soClass = sqlmeta.soClass
            unmakeProperties(soClass)
            makeProperties(soClass)
            return

        super(InheritableSQLMeta, sqlmeta).delJoin(joinDef)

        # DSM: Update each child class if needed
        # DSM: and delete properties for this join
        for c in sqlmeta.childClasses.values():
            c.sqlmeta.delJoin(joinDef, childUpdate=True)
Esempio n. 6
0
    def delJoin(sqlmeta, joinDef, childUpdate=False):
        if childUpdate:
            soClass = sqlmeta.soClass
            unmakeProperties(soClass)
            makeProperties(soClass)
            return

        super(InheritableSQLMeta, sqlmeta).delJoin(joinDef)

        # DSM: Update each child class if needed
        # DSM: and delete properties for this join
        for c in sqlmeta.childClasses.values():
            c.sqlmeta.delJoin(joinDef, childUpdate=True)
Esempio n. 7
0
    def addColumn(sqlmeta, columnDef, changeSchema=False, connection=None,
                  childUpdate=False):
        soClass = sqlmeta.soClass
        # DSM: Try to add parent properties to the current class
        # DSM: Only do this once if possible at object creation and once for
        # DSM: each new dynamic column to refresh the current class
        if sqlmeta.parentClass:
            for col in sqlmeta.parentClass.sqlmeta.columnList:
                cname = col.name
                if cname == 'childName':
                    continue
                if cname.endswith("ID"):
                    cname = cname[:-2]
                setattr(soClass, getterName(cname), eval(
                    'lambda self: self._parent.%s' % cname))
                if not col.immutable:
                    def make_setfunc(cname):
                        def setfunc(self, val):
                            if not self.sqlmeta._creating and \
                               not getattr(self.sqlmeta,
                                           "row_update_sig_suppress", False):
                                self.sqlmeta.send(events.RowUpdateSignal, self,
                                                  {cname: val})

                            setattr(self._parent, cname, val)
                        return setfunc

                    setfunc = make_setfunc(cname)
                    setattr(soClass, setterName(cname), setfunc)
            if childUpdate:
                makeProperties(soClass)
                return

        if columnDef:
            super(InheritableSQLMeta, sqlmeta).addColumn(columnDef,
                                                         changeSchema,
                                                         connection)

        # DSM: Update each child class if needed and existing (only for new
        # DSM: dynamic column as no child classes exists at object creation)
        if columnDef and hasattr(soClass, "q"):
            q = getattr(soClass.q, columnDef.name, None)
        else:
            q = None
        for c in sqlmeta.childClasses.values():
            c.sqlmeta.addColumn(columnDef, connection=connection,
                                childUpdate=True)
            if q:
                setattr(c.q, columnDef.name, q)
Esempio n. 8
0
    def delColumn(sqlmeta, column, changeSchema=False, connection=None, childUpdate=False):
        if childUpdate:
            soClass = sqlmeta.soClass
            unmakeProperties(soClass)
            makeProperties(soClass)

            if isinstance(column, str):
                name = column
            else:
                name = column.name
            delattr(soClass, name)
            delattr(soClass.q, name)
            return

        super(InheritableSQLMeta, sqlmeta).delColumn(column, changeSchema, connection)

        # DSM: Update each child class if needed
        # DSM: and delete properties for this column
        for c in sqlmeta.childClasses.values():
            c.sqlmeta.delColumn(column, changeSchema=changeSchema, connection=connection, childUpdate=True)