ÿØÿàJFIFÿþ ÿÛC       ÿÛC ÿÀÿÄÿÄ"#QrÿÄÿÄ&1!A"2qQaáÿÚ ?Øy,æ/3JæÝ¹È߲؋5êXw²±ÉyˆR”¾I0ó2—PI¾IÌÚiMö¯–þrìN&"KgX:Šíµ•nTJnLK„…@!‰-ý ùúmë;ºgµŒ&ó±hw’¯Õ@”Ü— 9ñ-ë.²1<yà‚¹ïQÐU„ہ?.’¦èûbß±©Ö«Âw*VŒ) `$‰bØÔŸ’ëXÖ-ËTÜíGÚ3ð«g Ÿ§¯—Jx„–’U/ÂÅv_s(Hÿ@TñJÑãõçn­‚!ÈgfbÓc­:él[ðQe 9ÀPLbÃãCµm[5¿ç'ªjglå‡Ûí_§Úõl-;"PkÞÞÁQâ¼_Ñ^¢SŸx?"¸¦ùY騐ÒOÈ q’`~~ÚtËU¹CڒêV  I1Áß_ÿÙ 4]c@sdZddlmZddlmZddlmZddlmZddgZdefdYZ d e fd YZ defd 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 ShardedQuerycBsGeZdZdZdZdZdddZddZRS(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(sreturn 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  csfd}jdk r.|jSjdk rJ|jSg}x*jD]}|j||q`Wt|SdS(NcsT|jd<_jdjd|jjj}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  (RR R R textendtiter(R RRtpartialR((RR sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyt_execute_and_instances-s  csfd}jdk r1|jSd}g}x=jD],}||}||j7}|j|qMWt||SdS(Nc s=jdd|ddt}|jj}|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 R R 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(soverride 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(R RRt_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  csXfd}|dkr9jdk r9j}nttj||d|S(sOverride 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|}xLj|D]4}j|}||}|dk r>|Sq>WdSdS(N(R R Rtto_listR R(R0R2tidentRRto(t db_load_fnR (sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyt _db_load_fns  RN(R R 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.R R/R;(((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyRs    R,cBs,eZdZdZdZedZRS(sA 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.pyRs 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  cBsMeZdedZdZddddZddddZdZRS(cKstt|jd||||_||_||_i|_|j|_|dk rx%|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_callableR t bind_shard(R RDR R tshardsRCRtk((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyRs       cKs|dk rWt|}|jrD|jd}|dk s@t|S|jrW|jSn|j|||}|dk r||_n|S(Ni(R RtkeytAssertionErrorRRD(R RtinstanceR4tstatettokenR((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyt_choose_shard_and_assigns        cKsl|dkr!|j||}n|jdk rF|jj|d|S|j|d|d|j|SdS(NRRM(R RPt transactionRFtget_bindt_contextual_connect(R RRMRR((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyRFs cKs2|dkr'|j||d|}n|j|S(NR$(R RPRE(R RRRMR$R4((sR/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyRRs cCs||j|s