%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/
Upload File :
Create Path :
Current File : //proc/self/root/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyo

�
��4]c@s�dZddlmZddlmZddlmZddlmZddgZdefd��YZ	d	e
fd
��YZdefd��YZdS(
sHorizontal sharding support.

Defines a rudimental 'horizontal sharding' system which allows a Session to
distribute queries and persistence operations across multiple databases.

For a usage example, see the :ref:`examples_sharding` example included in
the source distribution.

i(tinspect(tutil(tQuery(tSessiontShardedSessiontShardedQuerycBsGeZd�Zd�Zd�Zd�Zddd�Zdd�ZRS(cOsDtt|�j||�|jj|_|jj|_d|_dS(N(tsuperRt__init__tsessiont
id_choosert
query_choosertNonet	_shard_id(tselftargstkwargs((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyRscCs|j�}||_|S(s�return a new query, limited to a single shard ID.

        all subsequent operations with the returned query will
        be against the single shard regardless of other state.
        (t_cloneR(R
tshard_idtq((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyt	set_shard"s	cs���fd�}�jdk	r.|�j�S�jdk	rJ|�j�Sg}x*�j��D]}|j||��q`Wt|�SdS(NcsT|�jd<�_�jd�j�d|�j�j�j�}�j|��S(NRtmapper(t
attributestidentity_tokent_connection_from_sessiont_bind_mappertexecutet	statementt_paramst	instances(Rtresult(tcontextR
(sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pytiter_for_shard.s
	(RRRR
textendtiter(R
RRtpartialR((RR
sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyt_execute_and_instances-s

cs����fd�}�jdk	r1|�j�Sd}g}x=�j��D],}||�}||j7}|j|�qMWt||�SdS(Nc	s=�jd�d|d�dt�}|j��j�}|S(NRRtclausetclose_with_result(RtTrueRR(RtconnR(RR
tstmt(sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pytexec_for_shardCs		i(RRR
trowcounttappendt
ShardedResult(R
R(RR)R*tresultsRR((RR
R(sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyt
_execute_crudBs


c	Ks�|dk	r.tt|�j||d||�S|jj|�}|rX|j|�}nxN|j||�D]:}tt|�j||d||�}|dk	rk|SqkWdSdS(s�override the default Query._identity_lookup method so that we
        search for a given non-token primary key identity across all
        possible identity tokens (e.g. shard ids).

        RN(RRRt_identity_lookupRtqueryt_set_lazyload_fromR	(	R
Rtprimary_key_identityRtlazy_loaded_fromtkwRRtobj((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR/YscsX��fd�}|dkr9�jdk	r9�j}ntt��j||d|�S(s�Override the default Query._get_impl() method so that we emit
        a query to the DB for each possible identity token, if we don't
        have one already.

        cs~�jdk	r��|�Stj|�}xL�j�|�D]4}�j|�}�||�}|dk	r>|Sq>WdSdS(N(RRRtto_listR	R(R0R2tidentRRto(t
db_load_fnR
(sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyt_db_load_fn�s
RN(RRRRt	_get_impl(R
R2R9RR:((R9R
sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR;{s
N(	t__name__t
__module__RRR#R.RR/R;(((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyRs				R,cBs,eZdZdZd�Zed��ZRS(s�A value object that represents multiple :class:`.ResultProxy` objects.

    This is used by the :meth:`.ShardedQuery._execute_crud` hook to return
    an object that takes the place of the single :class:`.ResultProxy`.

    Attribute include ``result_proxies``, which is a sequence of the
    actual :class:`.ResultProxy` objects, as well as ``aggregate_rowcount``
    or ``rowcount``, which is the sum of all the individual rowcount values.

    .. versionadded::  1.3
    tresult_proxiestaggregate_rowcountcCs||_||_dS(N(R>R?(R
R>R?((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR�s	cCs|jS(N(R?(R
((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR*�s(R>R?(R<R=t__doc__t	__slots__RtpropertyR*(((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR,�s	cBsMeZded�Zd�Zdddd�Zdddd�Zd�ZRS(cKs�tt|�jd||�||_||_||_i|_|j|_|dk	r�x%|D]}|j
|||�q_WndS(sConstruct a ShardedSession.

        :param shard_chooser: A callable which, passed a Mapper, a mapped
          instance, and possibly a SQL clause, returns a shard ID.  This id
          may be based off of the attributes present within the object, or on
          some round-robin scheme. If the scheme is based on a selection, it
          should set whatever state on the instance to mark it in the future as
          participating in that shard.

        :param id_chooser: A callable, passed a query and a tuple of identity
          values, which should return a list of shard ids where the ID might
          reside.  The databases will be queried in the order of this listing.

        :param query_chooser: For a given Query, returns the list of shard_ids
          where the query should be issued.  Results from all shards returned
          will be combined together into a single listing.

        :param shards: A dictionary of string shard names
          to :class:`~sqlalchemy.engine.Engine` objects.

        t	query_clsN(RRRt
shard_chooserR	R
t_ShardedSession__bindst
connectiontconnection_callableRt
bind_shard(R
RDR	R
tshardsRCRtk((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR�s				
cKsv|dk	rEt|�}|jr2|jd}|S|jrE|jSn|j|||�}|dk	rr||_n|S(Ni(RRtkeyRRD(R
RtinstanceR4tstatettokenR((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyt_choose_shard_and_assign�s	
	
cKsl|dkr!|j||�}n|jdk	rF|jj|d|�S|j|d|d|�j|�SdS(NRRL(RROttransactionRFtget_bindt_contextual_connect(R
RRLRR((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyRF�scKs2|dkr'|j||d|�}n|j|S(NR$(RRORE(R
RRRLR$R4((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyRQ�scCs||j|<dS(N(RE(R
Rtbind((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyRHsN(	R<R=RRRRORFRQRH(((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR�s"	N(
R@tRRt	orm.queryRtorm.sessionRt__all__RtobjectR,R(((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyt<module>s�

Zerion Mini Shell 1.0