本文整理汇总了Python中pyasm.search.SearchType.get_db_resource_by_search_type方法的典型用法代码示例。如果您正苦于以下问题:Python SearchType.get_db_resource_by_search_type方法的具体用法?Python SearchType.get_db_resource_by_search_type怎么用?Python SearchType.get_db_resource_by_search_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.search.SearchType
的用法示例。
在下文中一共展示了SearchType.get_db_resource_by_search_type方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check
# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_db_resource_by_search_type [as 别名]
def check(self):
self.search_type = self.kwargs.get("search_type")
self.values = self.kwargs.get("values")
self.db_resource = SearchType.get_db_resource_by_search_type(self.search_type)
self.database = self.db_resource.get_database()
self.search_type_obj = SearchType.get(self.search_type)
if self.database != Project.get_project_code() and self.database !='sthpw':
raise TacticException('You are not allowed to delete the sType [%s] from another project [%s].' %(self.search_type, self.database))
return False
return True
示例2: check
# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_db_resource_by_search_type [as 别名]
def check(my):
my.search_type = my.kwargs.get("search_type")
my.values = my.kwargs.get("values")
my.db_resource = SearchType.get_db_resource_by_search_type(my.search_type)
my.database = my.db_resource.get_database()
my.search_type_obj = SearchType.get(my.search_type)
if my.database != Project.get_project_code() and my.database !='sthpw':
raise TacticException('You are not allowed to delete the sType [%s] from another project [%s].' %(my.search_type, my.database))
return False
return True
示例3: on_insert
# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_db_resource_by_search_type [as 别名]
def on_insert(my):
'''Function that should be run on insert/update. It's already automatically called during insert.
On update, the caller needs to call this explicitly. It checks the search type
this pipeline is associated with and if there is no pipeline code
column, then update it. It updates the process table also.'''
search_type = my.get_value('search_type')
my.update_process_table(search_type=search_type)
# don't do anything for task sType
if search_type =='sthpw/task':
return
if not search_type:
return
if ProdSetting.get_value_by_key('autofill_pipeline_code') != 'false':
try:
columns = SearchType.get_columns(search_type)
if not 'pipeline_code' in columns:
# add the pipeline code column
from pyasm.command import ColumnAddCmd
cmd = ColumnAddCmd(search_type, "pipeline_code", "varchar")
cmd.execute()
except SqlException, e:
print "Error creating column [pipeline_code] for %" %search_type
pass
# go through all of the sobjects and set all the empty ones
# to the new pipeline
search = Search(search_type)
search.add_op("begin")
search.add_filter("pipeline_code", "NULL", op='is', quoted=False)
search.add_filter("pipeline_code", "")
search.add_op("or")
sobject_ids = search.get_sobject_ids()
if sobject_ids:
# this is much faster and memory efficient
db_resource = SearchType.get_db_resource_by_search_type(search_type)
sql = DbContainer.get(db_resource)
tbl = search.get_table()
sobject_ids = [str(x) for x in sobject_ids]
pipeline_code = my.get_value("code")
sql.do_update('''UPDATE "%s" SET "pipeline_code" = '%s' WHERE id in (%s) ''' %(tbl, pipeline_code, ','.join(sobject_ids)))
"""
示例4: dump_to_tactic
# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_db_resource_by_search_type [as 别名]
def dump_to_tactic(my, path=None, mode='sql'):
from pyasm.search import SearchType, Sql, DbContainer
search_type_obj = SearchType.get(my.search_type)
database = search_type_obj.get_database()
table = search_type_obj.get_table()
db_resource = SearchType.get_db_resource_by_search_type(my.search_type)
sql = DbContainer.get(db_resource)
exists = sql.table_exists(table)
if not exists:
return
info = sql.get_column_info(table)
impl = sql.get_database_impl()
columns = info.keys()
columns.sort()
# if the table does not exist, there are no columns
if not columns:
return
if path:
import os
f = codecs.getwriter('utf8')(open(path, 'ab'))
else:
import sys
f = sys.stdout
if not my.delimiter:
my.delimiter = "--"
my.end_delimiter = my.delimiter
f.write( "%s\n" % my.delimiter )
if mode == 'sobject':
f.write("table = CreateTable('%s')\n" % my.search_type)
else:
f.write("table = CreateTable()\n")
f.write("table.set_table('%s')\n" % table)
# Hard code this - all search types have id as the primary key at the
# moment
primary_key_col = 'id'
for column in columns:
if column in my.ignore_columns:
continue
col_info = info[column]
#print col_info
space = " "*(25-len(column))
data_type = col_info['data_type']
is_nullable = col_info['nullable']
if column == "id":
# A dump will output a database independent serial
#data_type = impl.get_serial() <--- Database depenedent
data_type = 'serial'
f.write("table.add('%s',%s'%s', primary_key=True)\n" % (column, space, data_type) )
continue
elif data_type in ['varchar','char','nvarchar']:
size = col_info.get('size')
if size == -1:
size = 'max'
if not size:
size = 256
if is_nullable:
f.write("table.add('%s',%s'%s', length='%s' )\n" % (column, space, data_type, size))
else:
f.write("table.add('%s',%s'%s', length='%s', not_null=True )\n" % (column, space, data_type, size))
continue
if is_nullable:
f.write("table.add('%s',%s'%s' )\n" % (column, space, data_type))
else:
f.write("table.add('%s',%s'%s', not_null=True )\n" % (column, space, data_type))
# add the constraints
constraints = impl.get_constraints(db_resource, table)
for constraint in constraints:
name = constraint.get("name")
columns = constraint.get("columns")
mode = constraint.get("mode")
if not name:
name = "%s_%s_idx" % (name, "_".join(columns))
f.write('''table.add_constraint(%s, mode="%s")\n''' % (columns, mode))
#def add_constraint(my, columns, mode="UNIQUE"):
#f.write("table.set_primary_key('id')\n")
# Disable commit for now
#.........这里部分代码省略.........
示例5: resolve_relationship_attrs
# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_db_resource_by_search_type [as 别名]
def resolve_relationship_attrs(self, attrs, search_type, search_type2):
if attrs.get("relationship") not in ("search_type","search_code","search_id"):
return attrs
search_type_obj = SearchType.get(search_type)
search_type_obj2 = SearchType.get(search_type2)
my_is_from = attrs['from'] == search_type_obj.get_base_key()
db_resource = SearchType.get_db_resource_by_search_type(search_type)
db_resource2 = SearchType.get_db_resource_by_search_type(search_type2)
db_impl = db_resource.get_database_impl()
db_impl2 = db_resource2.get_database_impl()
# <connect from="sthpw/note" to="*"
# type='hierarchy' relationship='search_type'/>
prefix = attrs.get("prefix")
if prefix:
prefix = "%s_" % prefix
else:
prefix = ""
if my_is_from:
if db_impl2.get_database_type() == "MongoDb":
attrs['from_col'] = '%ssearch_code' % prefix
attrs['to_col'] = db_impl2.get_id_col(db_resource2,search_type2)
attrs['relationship'] = 'search_code'
else:
code_column = "%ssearch_code" % prefix
has_code = SearchType.column_exists(search_type, code_column)
if has_code:
attrs['from_col'] = '%ssearch_code' % prefix
attrs['to_col'] = 'code'
attrs['relationship'] = 'search_code'
else:
attrs['from_col'] = '%ssearch_id' % prefix
attrs['to_col'] = db_impl2.get_id_col(db_resource2,search_type2)
attrs['relationship'] = 'search_id'
else:
if db_impl.get_database_type() == "MongoDb":
attrs['to_col'] = '%ssearch_code' % prefix
attrs['from_col'] = db_impl.get_id_col(db_resource,search_type)
attrs['relationship'] = 'search_code'
else:
code_column = "%ssearch_code" % prefix
has_code = SearchType.column_exists(search_type2, code_column)
if has_code:
attrs['from_col'] = 'code'
attrs['to_col'] = '%ssearch_code' % prefix
attrs['relationship'] = 'search_code'
else:
attrs['from_col'] = db_impl.get_id_col(db_resource,search_type)
attrs['to_col'] = '%ssearch_id' % prefix
attrs['relationship'] = 'search_id'
return attrs