2 exporter(sourceSession,destSession[,rowCachesize])
3 Input parameter sourceSession : session proxy for source schema providing logical service name & access mode
4 Input parameter destSession : session proxy for destination schema providing logical service name & access mode
5 Input parameter rowCachesize : the number of rows to be cached at the client side, default value =100
6 Output paramter : the exporter object
13 from multivaluedict
import mseqdict
14 from listobjects
import listobjects,listschema,listtables,listtableset
17 "exporter class for CoralTools"
22 def __init__( self,sourceSession,destSession,rowCachesize=100 ):
29 self.m_sourceSession.transaction().
start()
30 self.m_destSession.transaction().
start()
33 raise Exception(
"Error in Initializer: " + str(e))
39 listsourceTable=
listschema( self.m_sourceSession.nominalSchema() )
40 listdestTable=
listobjects( self.m_destSession.nominalSchema() )
43 for key,value
in listsourceTable.items():
48 self.m_destSession.transaction().commit()
49 self.m_sourceSession.transaction().commit()
50 print "copyschema SUCCESS"
55 self.m_destSession.transaction().rollback()
56 self.m_sourceSession.transaction().commit()
57 raise Exception (
"Error in copyschema method: " + str(e))
64 self.m_sourceSession.transaction().
start()
65 self.m_destSession.transaction().
start()
67 listsourceTable=
listschema( self.m_sourceSession.nominalSchema() )
68 listdestTable=
listobjects( self.m_destSession.nominalSchema() )
72 selectionparameters=coral.AttributeList()
73 for key,value
in listsourceTable.items():
78 self.
_copydatalayout(iTable,selectionclause,selectionparameters,currentCount,rowCount)
80 self.m_destSession.transaction().commit()
81 self.m_sourceSession.transaction().commit()
82 print "copydata SUCCESS"
86 self.m_destSession.transaction().rollback()
87 self.m_sourceSession.transaction().commit()
88 raise Exception (
"Error in copydata method: " + str(e))
96 listsourceTable=
listtables( self.m_sourceSession.nominalSchema(),tablename )
97 listdestTable=
listtables(self.m_destSession.nominalSchema(),tablename )
100 for key,value
in listsourceTable.items():
105 self.m_destSession.transaction().commit()
106 self.m_sourceSession.transaction().commit()
107 print "copytableschema SUCCESS"
111 self.m_destSession.transaction().rollback()
112 self.m_sourceSession.transaction().commit()
113 raise Exception (
"Error in copytableschema method: " + str(e)+
" : "+iTable)
117 def copytabledata(self,tablename,selectionclause,selectionparameters,rowCount=-1 ):
121 listsourceTable=
listtables( self.m_sourceSession.nominalSchema(),tablename )
122 listdestTable=
listtables( self.m_destSession.nominalSchema(),tablename )
125 for key,value
in listsourceTable.items():
128 tableexists = self.
_checkdata(iTable,listdestTable)
133 self.
_copydatalayout(iTable,selectionclause,selectionparameters,currentCount,rowCount)
135 self.m_destSession.transaction().commit()
136 self.m_sourceSession.transaction().commit()
137 print "copytabledata SUCCESS"
141 self.m_destSession.transaction().rollback()
142 self.m_sourceSession.transaction().commit()
143 raise Exception (
"Error in copytabledata method: " + str(e)+
" : " + iTable)
151 listsourceTable=
listtableset( self.m_sourceSession.nominalSchema(),tableset )
152 listdestTable=
listtableset( self.m_destSession.nominalSchema(),tableset )
155 for key,value
in listsourceTable.items():
160 self.m_destSession.transaction().commit()
161 self.m_sourceSession.transaction().commit()
162 print "copytablelistschema SUCCESS"
166 self.m_destSession.transaction().rollback()
167 self.m_sourceSession.transaction().commit()
168 raise Exception (
"Error in copytablelistschema method: " + str(e)+
" : "+iTable)
177 for table
in tablelist:
179 for parameter
in table:
181 tableset.append(parameter)
184 listsourceTable=
listtableset( self.m_sourceSession.nominalSchema(),tableset )
185 listdestTable=
listtableset( self.m_destSession.nominalSchema(),tableset )
186 for key,value
in listsourceTable.items():
191 selectionparameters=coral.AttributeList()
192 for table
in tablelist:
194 for parameter
in table:
199 selectionclause = parameter
201 selectionparameters = parameter
204 tableexists = self.
_checkdata(iTable,listdestTable)
209 self.
_copydatalayout(iTable,selectionclause,selectionparameters,currentCount,rowCount)
211 self.m_destSession.transaction().commit()
212 self.m_sourceSession.transaction().commit()
213 print "copytablelistdata SUCCESS"
217 self.m_destSession.transaction().rollback()
218 self.m_sourceSession.transaction().commit()
219 raise Exception (
"Error in copytablelistdata method: " + str(e) +
" : "+ iTable)
226 description = self.m_sourceSession.nominalSchema().tableHandle( iTable ).
description()
227 table = self.m_destSession.nominalSchema().createTable( description )
232 raise Exception (
" " + str(e))
236 def _copydatalayout(self,iTable,selectionclause,selectionparameters,currentCount,rowCount ):
238 data=coral.AttributeList()
239 sourceEditor = self.m_sourceSession.nominalSchema().tableHandle( iTable ).dataEditor()
240 destEditor = self.m_destSession.nominalSchema().tableHandle( iTable ).dataEditor()
242 sourceEditor.rowBuffer(data)
243 sourcequery = self.m_sourceSession.nominalSchema().tableHandle( iTable ).newQuery()
244 sourcequery.setCondition(selectionclause,selectionparameters)
246 sourcequery.defineOutput(data)
250 cursor=sourcequery.execute()
253 currentCount = currentCount+1
254 bulkOperation.processNextIteration()
255 if currentCount == rowCount:
256 bulkOperation.flush()
257 self.m_destSession.transaction().commit()
258 self.m_destSession.transaction().
start()
260 bulkOperation.flush()
267 raise Exception (
" " + str(e))
274 for key,value
in listsourceTable.items():
276 for key,value
in listdestTable.items():
278 raise Exception(
"Table exists in Destination Schema : " )
283 raise Exception (
" " + str(e) + table)
292 for key,value
in listdestTable.items():
296 query = self.m_destSession.nominalSchema().tableHandle( iTable ).newQuery()
297 cursor = query.execute()
308 raise Exception (
" " + str(e) + iTable)