Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Static Private Attributes
Archetypes.SQLStorage.PostgreSQLStorage Class Reference
Inheritance diagram for Archetypes.SQLStorage.PostgreSQLStorage:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.SQLStorage.PostgreSQLStorage:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def table_exists
def map_object
def unmap_object
def map_datetime
def map_fixedpoint
def unmap_fixedpoint
def map_lines
def unmap_lines
def map_boolean
def map_reference
def unmap_boolean
def is_initialized
def initializeField
def is_cleaned
def cleanupField
def initializeInstance
def get
def set
def cleanupInstance

Static Public Attributes

tuple query_create
tuple query_select
tuple query_insert
tuple query_update
tuple query_delete
dictionary db_type_map
tuple query_drop = ('drop table <dtml-var table>')
dictionary sqlm_type_map = {'integer':'int'}

Static Private Attributes

 __implements__ = BaseSQLStorage.__implements__

Detailed Description

Definition at line 402 of file SQLStorage.py.


Member Function Documentation

def Archetypes.SQLStorage.BaseSQLStorage.cleanupField (   self,
  instance,
  field 
) [inherited]

Definition at line 116 of file SQLStorage.py.

00116 
00117     def cleanupField(self, instance, field):
00118         pass

def Archetypes.SQLStorage.BaseSQLStorage.cleanupInstance (   self,
  instance,
  item = None,
  container = None 
) [inherited]

Definition at line 232 of file SQLStorage.py.

00232 
00233     def cleanupInstance(self, instance, item=None, container=None):
00234         if (self.is_cleaned(instance) or
00235             getattr(instance, '_at_is_fake_instance', None)):
00236             # duh, we don't need to be cleaned twice
00237             return
00238         # the object is being deleted. remove data from sql.  but
00239         # first, made a temporary copy of the field values in case we
00240         # are being moved
00241         fields = instance.Schema().fields()
00242         fields = [f for f in fields if IObjectField.isImplementedBy(f) \
00243                   and f.getStorage().__class__ is self.__class__]
00244         temps = {}
00245         for f in fields:
00246             temps[f.getName()] = f.get(instance)
00247         setattr(instance, '_v_%s_temps' % self.getName(), temps)
00248         # now, remove data from sql
00249         c_tool = getToolByName(instance, TOOL_NAME)
00250         connection_id = c_tool.getConnFor(instance)
00251         args = {}
00252         args['table'] = instance.portal_type
00253         args['UID'] = instance.UID()
00254         #args['db_encoding']=kwargs.get('db_encoding',None)
00255         method = SQLMethod(instance)
00256         method.edit(connection_id, ' '.join(args.keys()), self.query_delete)
00257         try:
00258             query, result = method(test__=1, **args)
00259         except ConflictError:
00260             raise
00261         except:
00262             # dunno what could happen here raise
00263             # SQLCleanupException(msg)
00264             raise BeforeDeleteException
00265         try:
00266             instance.__cleaned += (self.getName(),)
00267         except AttributeError:
00268             instance.__cleaned = (self.getName(),)
00269         try:
00270             del instance.__initialized
00271         except (AttributeError, KeyError):
00272             pass

Here is the call graph for this function:

def Archetypes.SQLStorage.BaseSQLStorage.get (   self,
  name,
  instance,
  kwargs 
) [inherited]

Definition at line 184 of file SQLStorage.py.

00184 
00185     def get(self, name, instance, **kwargs):
00186         if not self.is_initialized(instance):
00187             # ignore all calls before we're initialized - some
00188             # manage_afterAdd() methods try to get and set fields and
00189             # we can't allow that to break
00190             return None
00191         field = kwargs.get('field', instance.getField(name))
00192         args = {}
00193         args['table'] = instance.portal_type
00194         args['UID'] = instance.UID()
00195         args['db_encoding']=kwargs.get('db_encoding',None)
00196         args['field'] = name
00197         result = self._query(instance, self.query_select, args)
00198         result = result[0][0]
00199         mapper = getattr(self, 'unmap_' + field.type, None)
00200         if mapper is not None:
00201             result = mapper(field, result)
00202         return result

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.SQLStorage.BaseSQLStorage.initializeField (   self,
  instance,
  field 
) [inherited]

Definition at line 107 of file SQLStorage.py.

00107 
00108     def initializeField(self, instance, field):
00109         pass

def Archetypes.SQLStorage.BaseSQLStorage.initializeInstance (   self,
  instance,
  item = None,
  container = None 
) [inherited]

Definition at line 127 of file SQLStorage.py.

00127 
00128     def initializeInstance(self, instance, item=None, container=None):
00129         if (self.is_initialized(instance) or
00130             getattr(instance, '_at_is_fake_instance', None)):
00131             # duh, we don't need to be initialized twice
00132             return
00133         factory = getToolByName(instance,'portal_factory')
00134         if factory.isTemporary(instance):
00135           return
00136               
00137         fields = instance.Schema().fields()
00138         fields = [f for f in fields if IObjectField.isImplementedBy(f) \
00139                   and f.getStorage().__class__ is self.__class__]
00140         columns = []
00141         args = {}
00142         for field in fields:
00143             type = self.db_type_map.get(field.type, field.type)
00144             name = field.getName()
00145             # MySQL supports escape for columns names!
00146             if self.__class__.__name__ == 'MySQLSQLStorage':
00147                 columns.append('`%s` %s' % (name, type))
00148             else:
00149                 columns.append('%s %s' % (name, type))
00150         parent = container or aq_parent(aq_inner(instance))
00151         args['PARENTUID'] = getattr(aq_base(parent), 'UID', lambda: None)()
00152         args['table'] = instance.portal_type
00153         args['UID'] = instance.UID()
00154         #args['db_encoding']=kwargs.get('db_encoding',None)
00155         args['columns'] = ', ' + ', '.join(columns)
00156         if not self.table_exists(instance):
00157             self._query(instance, self.query_create, args)
00158             log('created table %s\n' % args['table'])
00159         try:
00160             self._query(instance, self.query_insert, args)
00161         except ConflictError:
00162             raise
00163         except:
00164             # usually, duplicate key
00165             # raise SQLInitException(msg)
00166             raise
00167         try:
00168             instance.__initialized += (self.getName(),)
00169         except AttributeError:
00170             instance.__initialized = (self.getName(),)
00171         # now, if we find an attribute called _v_$classname_temps, it
00172         # means the object was moved and we can initialize the fields
00173         # with those values
00174         temps_var = '_v_%s_temps' % self.getName()
00175         if hasattr(aq_base(instance), temps_var):
00176             temps = getattr(instance, temps_var)
00177             for key, value in temps.items():
00178                 instance.Schema()[key].set(instance, value)
00179             delattr(instance, temps_var)
00180         try:
00181             del instance.__cleaned
00182         except (AttributeError, KeyError):
00183             pass

Here is the call graph for this function:

def Archetypes.SQLStorage.BaseSQLStorage.is_cleaned (   self,
  instance 
) [inherited]

Definition at line 110 of file SQLStorage.py.

00110 
00111     def is_cleaned(self, instance):
00112         try:
00113             return self.getName() in instance.__cleaned
00114         except AttributeError:
00115             return None

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.SQLStorage.BaseSQLStorage.is_initialized (   self,
  instance 
) [inherited]

Definition at line 101 of file SQLStorage.py.

00101 
00102     def is_initialized(self, instance):
00103         try:
00104             return self.getName() in instance.__initialized
00105         except AttributeError:
00106             return None

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.SQLStorage.BaseSQLStorage.map_boolean (   self,
  field,
  value 
) [inherited]

Definition at line 79 of file SQLStorage.py.

00079 
00080     def map_boolean(self, field, value):
00081         __traceback_info__ = repr(value)
00082         if not value:
00083             return 0
00084         else:
00085             return 1
        
def Archetypes.SQLStorage.BaseSQLStorage.map_datetime (   self,
  field,
  value 
) [inherited]

Reimplemented in Archetypes.SQLStorage.GadflySQLStorage.

Definition at line 50 of file SQLStorage.py.

00050 
00051     def map_datetime(self, field, value):
00052         # we don't want to lose even 0.001 second
00053         try:
00054             return value.ISO()[:-2] + str(value.second())
00055         except:
00056             return None

def Archetypes.SQLStorage.BaseSQLStorage.map_fixedpoint (   self,
  field,
  value 
) [inherited]

Definition at line 57 of file SQLStorage.py.

00057 
00058     def map_fixedpoint(self, field, value):
00059         __traceback_info__ = repr(value)
00060         template = '%%d%%0%dd' % field.precision
00061         return template % value

def Archetypes.SQLStorage.BaseSQLStorage.map_lines (   self,
  field,
  value 
) [inherited]

Definition at line 71 of file SQLStorage.py.

00071 
00072     def map_lines(self, field, value):
00073         __traceback_info__ = repr(value)
00074         return '\n'.join(value)

def Archetypes.SQLStorage.BaseSQLStorage.map_object (   self,
  field,
  value 
) [inherited]

Definition at line 38 of file SQLStorage.py.

00038 
00039     def map_object(self, field, value):
00040         if value is None:
00041             return 'None'
00042         else:
00043             return value

def Archetypes.SQLStorage.BaseSQLStorage.map_reference (   self,
  field,
  value 
) [inherited]

Definition at line 86 of file SQLStorage.py.

00086 
00087     def map_reference(self, field, value):
00088         __traceback_info__ = repr(value)
00089 
00090         return ','.join(value)
    
def Archetypes.SQLStorage.BaseSQLStorage.set (   self,
  name,
  instance,
  value,
  kwargs 
) [inherited]

Definition at line 203 of file SQLStorage.py.

00203 
00204     def set(self, name, instance, value, **kwargs):
00205         if not self.is_initialized(instance):
00206             # ignore all calls before we're initialized - some
00207             # manage_afterAdd() methods try to get and set fields and
00208             # we can't allow that to break
00209             return None
00210         field = kwargs.get('field', instance.getField(name))
00211         mapper = getattr(self, 'map_' + field.type, None)
00212         if mapper is not None:
00213             value = mapper(field, value)
00214         type = type_map.get(field.type, 'string')
00215         sql_type = self.sqlm_type_map.get(field.type, 'string')
00216         default = field.default
00217         args = {}
00218         args['table'] = instance.portal_type
00219         args['UID'] = instance.UID()
00220         #args['db_encoding']=kwargs.get('db_encoding',None)
00221         field_name = '%s:%s' % (name, type)
00222         if default:
00223             if type == 'string':
00224                 default = "'%s'" % default
00225             field_name =  "%s=%s" % (name, default)
00226         args[field_name] = name
00227         args['field'] = name
00228         if value is not None:
00229             # omiting it causes dtml-sqlvar to insert NULL
00230             args['value'] = value
00231         self._query(instance, self.query_update % sql_type, args)

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from Archetypes.SQLStorage.BaseSQLStorage.

Definition at line 430 of file SQLStorage.py.

00430 
00431     def table_exists(self, instance):
00432         return self._query(instance,
00433                            ('select relname from pg_class where '
00434                             '<dtml-sqltest relname op="eq" type="string">'),
00435                            {'relname': instance.portal_type.lower()})

Here is the call graph for this function:

def Archetypes.SQLStorage.BaseSQLStorage.unmap_boolean (   self,
  field,
  value 
) [inherited]

Definition at line 91 of file SQLStorage.py.

00091 
00092     def unmap_boolean(self, field, value):
00093         __traceback_info__ = repr(value)
00094         if not value or value == '0':   # Gadfly return integers as strings
00095             return 0
00096         else:
00097             return 1

def Archetypes.SQLStorage.BaseSQLStorage.unmap_fixedpoint (   self,
  field,
  value 
) [inherited]

Definition at line 62 of file SQLStorage.py.

00062 
00063     def unmap_fixedpoint(self, field, value):
00064         __traceback_info__ = repr(value)
00065         if value is None or value == '':
00066             return (0, 0)
00067         if type(value) == type(''):   # Gadfly return integers as strings
00068             value = int(value)
00069         split = 10 ** field.precision
00070         return (value / split), (value % split)

def Archetypes.SQLStorage.BaseSQLStorage.unmap_lines (   self,
  field,
  value 
) [inherited]

Reimplemented in Archetypes.SQLStorage.GadflySQLStorage.

Definition at line 75 of file SQLStorage.py.

00075 
00076     def unmap_lines(self, field, value):
00077         __traceback_info__ = repr(value)
00078         return value.split('\n')

def Archetypes.SQLStorage.BaseSQLStorage.unmap_object (   self,
  field,
  value 
) [inherited]

Definition at line 44 of file SQLStorage.py.

00044 
00045     def unmap_object(self, field, value):
00046         if value == 'None':
00047             return None
00048         else:
00049             return value


Member Data Documentation

Reimplemented from Archetypes.SQLStorage.BaseSQLStorage.

Definition at line 404 of file SQLStorage.py.

Initial value:
{'object'     : 'text',
                   'string'     : 'text',
                   'datetime'   : 'timestamp',
                   'fixedpoint' : 'integer',
                   'lines'      : 'text',
                   'reference'  : 'text',
                   }

Reimplemented from Archetypes.SQLStorage.BaseSQLStorage.

Definition at line 422 of file SQLStorage.py.

Initial value:
('create table <dtml-var table> '
                    '(UID text primary key not null, '
                    'PARENTUID text <dtml-var columns>)')

Reimplemented from Archetypes.SQLStorage.BaseSQLStorage.

Definition at line 406 of file SQLStorage.py.

Initial value:
('delete from <dtml-var table> '
                    'where <dtml-sqltest UID op="eq" type="string">')

Reimplemented from Archetypes.SQLStorage.BaseSQLStorage.

Definition at line 419 of file SQLStorage.py.

tuple Archetypes.SQLStorage.BaseSQLStorage.query_drop = ('drop table <dtml-var table>') [static, inherited]

Definition at line 21 of file SQLStorage.py.

Initial value:
('insert into <dtml-var table> '
                    '(UID, PARENTUID) values '
                    '(<dtml-sqlvar UID type="string">, '
                    '<dtml-sqlvar PARENTUID type="string">)')

Reimplemented from Archetypes.SQLStorage.BaseSQLStorage.

Definition at line 411 of file SQLStorage.py.

Initial value:
('select <dtml-var field> from <dtml-var table> '
                    'where <dtml-sqltest UID op="eq" type="string">')

Reimplemented from Archetypes.SQLStorage.BaseSQLStorage.

Definition at line 409 of file SQLStorage.py.

Initial value:
('update <dtml-var table> set '
                    '<dtml-var field>=<dtml-sqlvar value '
                    'type="%s" optional> where '
                    '<dtml-sqltest UID op="eq" type="string">')

Reimplemented from Archetypes.SQLStorage.BaseSQLStorage.

Definition at line 415 of file SQLStorage.py.

dictionary Archetypes.SQLStorage.BaseSQLStorage.sqlm_type_map = {'integer':'int'} [static, inherited]

Reimplemented in Archetypes.SQLStorage.GadflySQLStorage.

Definition at line 34 of file SQLStorage.py.


The documentation for this class was generated from the following file: