6 """Class add optional comment on given entry in a given table\n
9 """Input: coral schema handle.
17 """Check if entry comment table exists
20 transaction=self.__session.transaction()
21 transaction.start(
True)
22 schema = self.__session.nominalSchema()
23 result=schema.existsTable(CommonUtils.commentTableName())
27 transaction.rollback()
28 raise Exception, str(er)
32 """Create entry comment able.Existing table will be deleted.
35 transaction=self.__session.transaction()
37 schema = self.__session.nominalSchema()
38 schema.dropIfExistsTable(CommonUtils.commentTableName())
39 description = coral.TableDescription()
40 description.setName(CommonUtils.commentTableName())
41 for columnName, columnType
in self.__entryCommentTableColumns.items():
42 description.insertColumn(columnName,columnType)
44 description.setNotNullConstraint(columnName,
True)
46 tablehandle=schema.createTable(description)
47 tablehandle.privilegeManager().grantToPublic(coral.privilege_Select)
50 transaction.rollback()
51 raise Exception, str(e)
53 """insert comment on the given entry of given table
55 transaction=self.__session.transaction()
57 transaction.start(
False)
58 tabrowValueDict={
'entryid':entryid,
'tablename':tablename,
'comment':comment}
59 schema = self.__session.nominalSchema()
64 transaction.rollback()
65 raise Exception, str(e)
67 """bulk insert comments for a given table
68 bulkinput [{'entryid':unsigned long, 'tablename':string,'comment':string}]
70 transaction=self.__session.transaction()
72 transaction.start(
False)
73 schema = self.__session.nominalSchema()
78 transaction.rollback()
79 raise Exception, str(e)
82 """get comment for given id in given table
84 transaction=self.__session.transaction()
87 transaction.start(
True)
88 schema = self.__session.nominalSchema()
89 query = schema.tableHandle(CommonUtils.commentTableName()).newQuery()
90 condition=
'entryid = :entryid AND tablename = :tablename'
91 conditionbindDict=coral.AttributeList()
92 conditionbindDict.extend(
'entryid',
'unsigned long')
93 conditionbindDict.extend(
'tablename',
'string')
94 conditionbindDict[
'entryid'].setData(entryid)
95 conditionbindDict[
'tablename'].setData(tableName)
96 query.addToOutputList(
'comment')
97 query.setCondition(condition,conditionbindDict)
98 cursor=query.execute()
100 comment=cursor.currentRow()[
'comment'].
data()
106 transaction.rollback()
107 raise Exception, str(e)
109 """get all comments for given table
110 result=[(entryid,comment)]
112 transaction=self.__session.transaction()
116 transaction.start(
True)
117 schema = self.__session.nominalSchema()
118 query = schema.tableHandle(CommonUtils.commentTableName()).newQuery()
119 condition=
'tablename = :tablename'
120 conditionbindDict=coral.AttributeList()
121 conditionbindDict.extend(
'tablename',
'string')
122 conditionbindDict[
'tablename'].setData(tableName)
123 query.addToOutputList(
'entryid')
124 query.addToOutputList(
'comment')
125 query.setCondition(condition,conditionbindDict)
126 cursor=query.execute()
128 comment=cursor.currentRow()[
'comment'].
data()
129 entryid=cursor.currentRow()[
'entryid'].
data()
130 result.append((entryid,comment))
136 transaction.rollback()
137 raise Exception, str(e)
140 """replace comment for given entry for given table
142 transaction=self.__session.transaction()
144 transaction.start(
False)
145 editor = self.__session.nominalSchema().tableHandle(CommonUtils.commentTableName()).dataEditor()
146 inputData = coral.AttributeList()
147 inputData.extend(
'newcomment',
'string')
148 inputData.extend(
'entryid',
'unsigned long')
149 inputData.extend(
'tablename',
'string')
150 inputData[
'newcomment'].setData(newcomment)
151 inputData[
'entryid'].setData(entryid)
152 inputData[
'tablename'].setData(tableName)
153 editor.updateRows(
"comment = :newcomment",
"entryid = :entryid AND tablename = :tablename", inputData )
156 transaction.rollback()
157 raise Exception, str(e)
159 def replaceId( self, tableName, oldentryid, newentryid ):
160 """replace entryid in given table
162 transaction=self.__session.transaction()
164 transaction.start(
False)
165 editor = self.__session.nominalSchema().tableHandle(CommonUtils.commentTableName()).dataEditor()
166 inputData = coral.AttributeList()
167 inputData.extend(
'newentryid',
'unsigned long')
168 inputData.extend(
'oldentryid',
'unsigned long')
169 inputData.extend(
'tablename',
'string')
170 inputData[
'newentryid'].setData(newentryid)
171 inputData[
'oldentryid'].setData(oldentryid)
172 inputData[
'tablename'].setData(tableName)
173 editor.updateRows(
"entryid = :newentryid",
"entryid = :oldentryid AND tablename = :tablename", inputData )
176 transaction.rollback()
177 raise Exception, str(e)
180 """delete selected comment entry
182 transaction=self.__session.transaction()
184 transaction.start(
False)
186 condition=
'tablename = :tablename AND entryid = :entryid'
187 conditionbindDict=coral.AttributeList()
188 conditionbindDict.extend(
'tablename',
'string')
189 conditionbindDict.extend(
'entryid',
'unsigned long')
190 conditionbindDict[
'tablename'].setData(tablename)
191 conditionbindDict[
'entryid'].setData(entryid)
192 dbop.deleteRows(CommonUtils.commentTableName(),condition,conditionbindDict)
195 transaction.rollback()
196 raise Exception, str(e)
199 """delete all entries related with given table
201 transaction=self.__session.transaction()
203 transaction.start(
False)
205 condition=
'tablename = :tablename'
206 conditionbindDict=coral.AttributeList()
207 conditionbindDict.extend(
'tablename',
'string')
208 conditionbindDict[
'tablename'].setData(tablename)
209 dbop.deleteRows(CommonUtils.commentTableName(),condition,conditionbindDict)
212 transaction.rollback()
213 raise Exception, str(e)
216 if __name__ ==
"__main__":
217 svc = coral.ConnectionService()
218 session = svc.connect(
'sqlite_file:testentryComment.db',
219 accessMode = coral.access_Update )
222 print "test create entrycomment table"
223 entrycomment.createEntryCommentTable()
224 print "test insert one comment"
225 entrycomment.insertComment(CommonUtils.inventoryTableName(),12,
'comment1')
226 entrycomment.insertComment(CommonUtils.treeTableName(
'ABCTREE'),12,
'comment1')
227 print "test bulk insert"
229 bulkinput.append({
'entryid':21,
'tablename':CommonUtils.inventoryTableName(),
'comment':
'mycomment'})
230 bulkinput.append({
'entryid':22,
'tablename':CommonUtils.inventoryTableName(),
'comment':
'mycomment2'})
231 bulkinput.append({
'entryid':23,
'tablename':CommonUtils.inventoryTableName(),
'comment':
'mycomment3'})
232 bulkinput.append({
'entryid':24,
'tablename':CommonUtils.inventoryTableName(),
'comment':
'mycomment4'})
233 entrycomment.bulkinsertComments(CommonUtils.inventoryTableName(),bulkinput)
234 print "test getCommentsForTable ",CommonUtils.inventoryTableName()
235 results=entrycomment.getCommentsForTable(CommonUtils.inventoryTableName())
237 result=entrycomment.getCommentForId(CommonUtils.inventoryTableName(),23)
239 entrycomment.modifyCommentForId(CommonUtils.inventoryTableName(),23,
'mynewcomment' )
240 print entrycomment.getCommentForId(CommonUtils.inventoryTableName(),23)
241 print 'test replaceid'
242 entrycomment.replaceId(CommonUtils.inventoryTableName(),23,33 )
243 print entrycomment.getCommentForId(CommonUtils.inventoryTableName(),33)
244 print 'test deletecomment for id'
245 entrycomment.deleteCommentForId(CommonUtils.inventoryTableName(), 24)
246 print entrycomment.getCommentsForTable(CommonUtils.inventoryTableName())
247 print 'clearAllEntriesForTable'
248 entrycomment.clearAllEntriesForTable(CommonUtils.inventoryTableName())
249 print entrycomment.getCommentsForTable(CommonUtils.inventoryTableName())
252 print "Failed in unit test"
char data[epos_bytes_allocation]