1 /* @source ensattribute *******************************************************
2 **
3 ** Ensembl Attribute functions
4 **
5 ** @author Copyright (C) 1999 Ensembl Developers
6 ** @author Copyright (C) 2006 Michael K. Schuster
7 ** @version $Revision: 1.42 $
8 ** @modified 2009 by Alan Bleasby for incorporation into EMBOSS core
9 ** @modified $Date: 2013/02/17 13:02:10 $ by $Author: mks $
10 ** @@
11 **
12 ** This library is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU Lesser General Public
14 ** License as published by the Free Software Foundation; either
15 ** version 2.1 of the License, or (at your option) any later version.
16 **
17 ** This library is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** Lesser General Public License for more details.
21 **
22 ** You should have received a copy of the GNU Lesser General Public
23 ** License along with this library; if not, write to the Free Software
24 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 ** MA 02110-1301, USA.
26 **
27 ******************************************************************************/
28
29 /* ========================================================================= */
30 /* ============================= include files ============================= */
31 /* ========================================================================= */
32
33 #include "ensattribute.h"
34 #include "ensgene.h"
35 #include "ensoperon.h"
36 #include "enstable.h"
37 #include "enstranscript.h"
38 #include "enstranslation.h"
39
40
41
42
43 /* ========================================================================= */
44 /* =============================== constants =============================== */
45 /* ========================================================================= */
46
47 /* @conststatic attributetypeadaptorKTablenames *******************************
48 **
49 ** Array of Ensembl Attribute Type Adaptor SQL table names
50 **
51 ******************************************************************************/
52
53 static const char *const attributetypeadaptorKTablenames[] =
54 {
55 "attrib_type",
56 (const char *) NULL
57 };
58
59
60
61
62 /* @conststatic attributetypeadaptorKColumnnames ******************************
63 **
64 ** Array of Ensembl Attribute Type Adaptor SQL column names
65 **
66 ******************************************************************************/
67
68 static const char *const attributetypeadaptorKColumnnames[] =
69 {
70 "attrib_type.attrib_type_id",
71 "attrib_type.code",
72 "attrib_type.description",
73 "attrib_type.name",
74 (const char *) NULL
75 };
76
77
78
79
80 /* ========================================================================= */
81 /* =========================== global variables ============================ */
82 /* ========================================================================= */
83
84
85
86
87 /* ========================================================================= */
88 /* ============================= private data ============================== */
89 /* ========================================================================= */
90
91
92
93
94 /* ========================================================================= */
95 /* =========================== private constants =========================== */
96 /* ========================================================================= */
97
98
99
100
101 /* ========================================================================= */
102 /* =========================== private variables =========================== */
103 /* ========================================================================= */
104
105
106
107
108 /* ========================================================================= */
109 /* =========================== private functions =========================== */
110 /* ========================================================================= */
111
112 static AjBool attributeadaptorFetchAllbyStatement(
113 EnsPAttributeadaptor aa,
114 const AjPStr statement,
115 AjPList attributes);
116
117 static AjBool attributetypeadaptorFetchAllbyStatement(
118 EnsPBaseadaptor ba,
119 const AjPStr statement,
120 EnsPAssemblymapper am,
121 EnsPSlice slice,
122 AjPList ats);
123
124 static AjBool attributetypeadaptorCacheInit(EnsPAttributetypeadaptor ata);
125
126 static AjBool attributetypeadaptorCacheInsert(EnsPAttributetypeadaptor ata,
127 EnsPAttributetype *Pat);
128
129 static void attributetypeadaptorFetchAll(const void *key,
130 void **Pvalue,
131 void *cl);
132
133
134
135
136 /* ========================================================================= */
137 /* ======================= All functions by section ======================== */
138 /* ========================================================================= */
139
140
141
142
143 /* @filesection ensattribute **************************************************
144 **
145 ** @nam1rule ens Function belongs to the Ensembl library
146 **
147 ******************************************************************************/
148
149
150
151
152 /* @datasection [EnsPAttribute] Ensembl Attribute *****************************
153 **
154 ** @nam2rule Attribute Functions for manipulating Ensembl Attribute objects
155 **
156 ** @cc Bio::EnsEMBL::Attribute
157 ** @cc CVS Revision: 1.14
158 ** @cc CVS Tag: branch-ensembl-68
159 **
160 ******************************************************************************/
161
162
163
164
165 /* @section constructors ******************************************************
166 **
167 ** All constructors return a new Ensembl Attribute by pointer.
168 ** It is the responsibility of the user to first destroy any previous
169 ** Attribute. The target pointer does not need to be initialised to
170 ** NULL, but it is good programming practice to do so anyway.
171 **
172 ** @fdata [EnsPAttribute]
173 **
174 ** @nam3rule New Constructor
175 ** @nam4rule Cpy Constructor with existing object
176 ** @nam4rule Ini Constructor with initial values
177 ** @nam4rule Ref Constructor by incrementing the reference counter
178 **
179 ** @argrule Cpy attribute [const EnsPAttribute] Ensembl Attribute
180 ** @argrule Ini at [EnsPAttributetype] Ensembl Attribute Type
181 ** @argrule Ini value [AjPStr] Value
182 ** @argrule Ref attribute [EnsPAttribute] Ensembl Attribute
183 **
184 ** @valrule * [EnsPAttribute] Ensembl Attribute or NULL
185 **
186 ** @fcategory new
187 ******************************************************************************/
188
189
190
191
192 /* @func ensAttributeNewCpy ***************************************************
193 **
194 ** Object-based constructor function, which returns an independent object.
195 **
196 ** @param [r] attribute [const EnsPAttribute] Ensembl Attribute
197 **
198 ** @return [EnsPAttribute] Ensembl Attribute or NULL
199 **
200 ** @release 6.4.0
201 ** @@
202 ******************************************************************************/
203
ensAttributeNewCpy(const EnsPAttribute attribute)204 EnsPAttribute ensAttributeNewCpy(const EnsPAttribute attribute)
205 {
206 EnsPAttribute pthis = NULL;
207
208 AJNEW0(pthis);
209
210 pthis->Attributetype = ensAttributetypeNewRef(attribute->Attributetype);
211
212 if (attribute->Value)
213 pthis->Value = ajStrNewRef(attribute->Value);
214
215 pthis->Use = 1U;
216
217 return pthis;
218 }
219
220
221
222
223 /* @func ensAttributeNewIni ***************************************************
224 **
225 ** Ensembl Attribute constructor with initial values.
226 **
227 ** @cc Bio::EnsEMBL::Attribute::new
228 ** @param [u] at [EnsPAttributetype] Ensembl Attribute Type
229 ** @param [u] value [AjPStr] Value
230 **
231 ** @return [EnsPAttribute] Ensembl Attribute or NULL
232 **
233 ** @release 6.4.0
234 ** @@
235 ******************************************************************************/
236
ensAttributeNewIni(EnsPAttributetype at,AjPStr value)237 EnsPAttribute ensAttributeNewIni(EnsPAttributetype at,
238 AjPStr value)
239 {
240 EnsPAttribute attribute = NULL;
241
242 AJNEW0(attribute);
243
244 attribute->Attributetype = ensAttributetypeNewRef(at);
245
246 if (value)
247 attribute->Value = ajStrNewRef(value);
248
249 attribute->Use = 1U;
250
251 return attribute;
252 }
253
254
255
256
257 /* @func ensAttributeNewRef ***************************************************
258 **
259 ** Ensembl Object referencing function, which returns a pointer to the
260 ** Ensembl Object passed in and increases its reference count.
261 **
262 ** @param [u] attribute [EnsPAttribute] Ensembl Attribute
263 **
264 ** @return [EnsPAttribute] Ensembl Attribute or NULL
265 **
266 ** @release 6.2.0
267 ** @@
268 ******************************************************************************/
269
ensAttributeNewRef(EnsPAttribute attribute)270 EnsPAttribute ensAttributeNewRef(EnsPAttribute attribute)
271 {
272 if (!attribute)
273 return NULL;
274
275 attribute->Use++;
276
277 return attribute;
278 }
279
280
281
282
283 /* @section destructors *******************************************************
284 **
285 ** Destruction destroys all internal data structures and frees the memory
286 ** allocated for an Ensembl Attribute object.
287 **
288 ** @fdata [EnsPAttribute]
289 **
290 ** @nam3rule Del Destroy (free) an Ensembl Attribute
291 **
292 ** @argrule * Pattribute [EnsPAttribute*] Ensembl Attribute address
293 **
294 ** @valrule * [void]
295 **
296 ** @fcategory delete
297 ******************************************************************************/
298
299
300
301
302 /* @func ensAttributeDel ******************************************************
303 **
304 ** Default destructor for an Ensembl Attribute.
305 **
306 ** @param [d] Pattribute [EnsPAttribute*] Ensembl Attribute address
307 **
308 ** @return [void]
309 **
310 ** @release 6.2.0
311 ** @@
312 ******************************************************************************/
313
ensAttributeDel(EnsPAttribute * Pattribute)314 void ensAttributeDel(EnsPAttribute *Pattribute)
315 {
316 EnsPAttribute pthis = NULL;
317
318 if (!Pattribute)
319 return;
320
321 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
322 if (ajDebugTest("ensAttributeDel"))
323 {
324 ajDebug("ensAttributeDel\n"
325 " *Pattribute %p\n",
326 *Pattribute);
327
328 ensAttributeTrace(*Pattribute, 1);
329 }
330 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
331
332 if (!(pthis = *Pattribute) || --pthis->Use)
333 {
334 *Pattribute = NULL;
335
336 return;
337 }
338
339 ensAttributetypeDel(&pthis->Attributetype);
340
341 ajStrDel(&pthis->Value);
342
343 ajMemFree((void **) Pattribute);
344
345 return;
346 }
347
348
349
350
351 /* @section member retrieval **************************************************
352 **
353 ** Functions for returning members of an Ensembl Attribute object.
354 **
355 ** @fdata [EnsPAttribute]
356 **
357 ** @nam3rule Get Return Ensembl Attribute attribute(s)
358 ** @nam4rule Attributetype Return the Ensembl Attribute Type
359 ** @nam4rule Value Return the value
360 **
361 ** @argrule * attribute [const EnsPAttribute] Ensembl Attribute
362 **
363 ** @valrule Attributetype [EnsPAttributetype] Ensembl Attribute Type or NULL
364 ** @valrule Value [AjPStr] Value or NULL
365 **
366 ** @fcategory use
367 ******************************************************************************/
368
369
370
371
372 /* @func ensAttributeGetAttributetype *****************************************
373 **
374 ** Get the Ensembl Attribute Type member of an Ensembl Attribute.
375 **
376 ** @cc Bio::EnsEMBL::Attribute::code
377 ** @cc Bio::EnsEMBL::Attribute::description
378 ** @cc Bio::EnsEMBL::Attribute::name
379 ** @param [r] attribute [const EnsPAttribute] Ensembl Attribute
380 **
381 ** @return [EnsPAttributetype] Ensembl Attribute Type or NULL
382 **
383 ** @release 6.4.0
384 ** @@
385 ******************************************************************************/
386
ensAttributeGetAttributetype(const EnsPAttribute attribute)387 EnsPAttributetype ensAttributeGetAttributetype(const EnsPAttribute attribute)
388 {
389 return (attribute) ? attribute->Attributetype : NULL;
390 }
391
392
393
394
395 /* @func ensAttributeGetValue *************************************************
396 **
397 ** Get the value member of an Ensembl Attribute.
398 **
399 ** @cc Bio::EnsEMBL::Attribute::value
400 ** @param [r] attribute [const EnsPAttribute] Ensembl Attribute
401 **
402 ** @return [AjPStr] Value or NULL
403 **
404 ** @release 6.2.0
405 ** @@
406 ******************************************************************************/
407
ensAttributeGetValue(const EnsPAttribute attribute)408 AjPStr ensAttributeGetValue(const EnsPAttribute attribute)
409 {
410 return (attribute) ? attribute->Value : NULL;
411 }
412
413
414
415
416 /* @section debugging *********************************************************
417 **
418 ** Functions for reporting of an Ensembl Attribute object.
419 **
420 ** @fdata [EnsPAttribute]
421 **
422 ** @nam3rule Trace Report Ensembl Attribute members to debug file
423 **
424 ** @argrule Trace attribute [const EnsPAttribute] Ensembl Attribute
425 ** @argrule Trace level [ajuint] Indentation level
426 **
427 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
428 **
429 ** @fcategory misc
430 ******************************************************************************/
431
432
433
434
435 /* @func ensAttributeTrace ****************************************************
436 **
437 ** Trace an Ensembl Attribute.
438 **
439 ** @param [r] attribute [const EnsPAttribute] Ensembl Attribute
440 ** @param [r] level [ajuint] Indentation level
441 **
442 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
443 **
444 ** @release 6.2.0
445 ** @@
446 ******************************************************************************/
447
ensAttributeTrace(const EnsPAttribute attribute,ajuint level)448 AjBool ensAttributeTrace(const EnsPAttribute attribute, ajuint level)
449 {
450 AjPStr indent = NULL;
451
452 if (!attribute)
453 return ajFalse;
454
455 indent = ajStrNew();
456
457 ajStrAppendCountK(&indent, ' ', level * 2);
458
459 ajDebug("%SensAttributeTrace %p\n"
460 "%S Attributetype %p\n"
461 "%S Value '%S'\n"
462 "%S Use %u\n",
463 indent, attribute,
464 indent, attribute->Attributetype,
465 indent, attribute->Value,
466 indent, attribute->Use);
467
468 ensAttributetypeTrace(attribute->Attributetype, level + 1);
469
470 ajStrDel(&indent);
471
472 return ajTrue;
473 }
474
475
476
477
478 /* @section calculate *********************************************************
479 **
480 ** Functions for calculating information from an Ensembl Attribute object.
481 **
482 ** @fdata [EnsPAttribute]
483 **
484 ** @nam3rule Calculate Calculate Ensembl Attribute information
485 ** @nam4rule Memsize Calculate the memory size in bytes
486 **
487 ** @argrule * attribute [const EnsPAttribute] Ensembl Attribute
488 **
489 ** @valrule Memsize [size_t] Memory size in bytes or 0
490 **
491 ** @fcategory misc
492 ******************************************************************************/
493
494
495
496
497 /* @func ensAttributeCalculateMemsize *****************************************
498 **
499 ** Calclate the memory size in bytes of an Ensembl Attribute.
500 **
501 ** @param [r] attribute [const EnsPAttribute] Ensembl Attribute
502 **
503 ** @return [size_t] Memory size in bytes or 0
504 **
505 ** @release 6.4.0
506 ** @@
507 ******************************************************************************/
508
ensAttributeCalculateMemsize(const EnsPAttribute attribute)509 size_t ensAttributeCalculateMemsize(const EnsPAttribute attribute)
510 {
511 size_t size = 0;
512
513 if (!attribute)
514 return 0;
515
516 size += sizeof (EnsOAttribute);
517
518 size += ensAttributetypeCalculateMemsize(attribute->Attributetype);
519
520 if (attribute->Value)
521 {
522 size += sizeof (AjOStr);
523
524 size += ajStrGetRes(attribute->Value);
525 }
526
527 return size;
528 }
529
530
531
532
533 /* @section convenience functions *********************************************
534 **
535 ** Ensembl Attribute convenience functions
536 **
537 ** @fdata [EnsPAttribute]
538 **
539 ** @nam3rule Get Get member(s) of associated objects
540 ** @nam4rule Code Get the code member of the Ensembl Attribute Type
541 ** linked to an Ensembl Attribute
542 ** @nam4rule Description Get the description member of an
543 ** Ensembl Attribute Type linked to an Ensembl Attribute
544 ** @nam4rule Name Get the name member of an Ensembl Attribute Type
545 ** linked to an Ensembl Attribute
546 **
547 ** @argrule * attribute [const EnsPAttribute] Ensembl Attribute
548 **
549 ** @valrule Code [AjPStr] Code or NULL
550 ** @valrule Description [AjPStr] Description or NULL
551 ** @valrule Name [AjPStr] Name or NULL
552 **
553 ** @fcategory use
554 ******************************************************************************/
555
556
557
558
559 /* @func ensAttributeGetCode **************************************************
560 **
561 ** Get the code member of an Ensembl Attribute Type
562 ** linked to an Ensembl Attribute.
563 **
564 ** @cc Bio::EnsEMBL::Attribute::code
565 ** @param [r] attribute [const EnsPAttribute] Ensembl Attribute
566 **
567 ** @return [AjPStr] Code or NULL
568 **
569 ** @release 6.2.0
570 ** @@
571 ******************************************************************************/
572
ensAttributeGetCode(const EnsPAttribute attribute)573 AjPStr ensAttributeGetCode(const EnsPAttribute attribute)
574 {
575 return (attribute) ?
576 ensAttributetypeGetCode(attribute->Attributetype) : NULL;
577 }
578
579
580
581
582 /* @func ensAttributeGetDescription *******************************************
583 **
584 ** Get the description member of an Ensembl Attribute Type
585 ** linked to an Ensembl Attribute.
586 **
587 ** @cc Bio::EnsEMBL::Attribute::description
588 ** @param [r] attribute [const EnsPAttribute] Ensembl Attribute
589 **
590 ** @return [AjPStr] Description or NULL
591 **
592 ** @release 6.2.0
593 ** @@
594 ******************************************************************************/
595
ensAttributeGetDescription(const EnsPAttribute attribute)596 AjPStr ensAttributeGetDescription(const EnsPAttribute attribute)
597 {
598 return (attribute) ?
599 ensAttributetypeGetDescription(attribute->Attributetype) : NULL;
600 }
601
602
603
604
605 /* @func ensAttributeGetName **************************************************
606 **
607 ** Get the name member of an Ensembl Attribute Type
608 ** linked to an Ensembl Attribute.
609 **
610 ** @cc Bio::EnsEMBL::Attribute::name
611 ** @param [r] attribute [const EnsPAttribute] Ensembl Attribute
612 **
613 ** @return [AjPStr] Name or NULL
614 **
615 ** @release 6.2.0
616 ** @@
617 ******************************************************************************/
618
ensAttributeGetName(const EnsPAttribute attribute)619 AjPStr ensAttributeGetName(const EnsPAttribute attribute)
620 {
621 return (attribute) ?
622 ensAttributetypeGetName(attribute->Attributetype) : NULL;
623 }
624
625
626
627
628 /* @datasection [EnsPAttributeadaptor] Ensembl Attribute Adaptor **************
629 **
630 ** @nam2rule Attributeadaptor Functions for manipulating
631 ** Ensembl Attribute Adaptor objects
632 **
633 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor
634 ** @cc CVS Revision: 1.29
635 ** @cc CVS Tag: branch-ensembl-68
636 **
637 ******************************************************************************/
638
639
640
641
642 /* @funcstatic attributeadaptorFetchAllbyStatement ****************************
643 **
644 ** Run a SQL statement against an Ensembl Database Adaptor and consolidate the
645 ** results into an AJAX List of Ensembl Attribute objects.
646 **
647 ** The caller is responsible for deleting the Ensembl Attribute objects before
648 ** deleting the AJAX List.
649 **
650 ** @param [u] aa [EnsPAttributeadaptor] Ensembl Attribute Adaptor
651 ** @param [r] statement [const AjPStr] SQL statement
652 ** @param [u] attributes [AjPList] AJAX List of Ensembl Attribute objects
653 **
654 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
655 **
656 ** @release 6.4.0
657 ** @@
658 ******************************************************************************/
659
attributeadaptorFetchAllbyStatement(EnsPAttributeadaptor aa,const AjPStr statement,AjPList attributes)660 static AjBool attributeadaptorFetchAllbyStatement(
661 EnsPAttributeadaptor aa,
662 const AjPStr statement,
663 AjPList attributes)
664 {
665 ajuint atid = 0U;
666
667 AjPSqlstatement sqls = NULL;
668 AjISqlrow sqli = NULL;
669 AjPSqlrow sqlr = NULL;
670
671 AjPStr value = NULL;
672
673 EnsPAttribute attribute = NULL;
674
675 EnsPAttributetype at = NULL;
676 EnsPAttributetypeadaptor ata = NULL;
677
678 EnsPDatabaseadaptor dba = NULL;
679
680 if (!aa)
681 return ajFalse;
682
683 if (!statement)
684 return ajFalse;
685
686 if (!attributes)
687 return ajFalse;
688
689 dba = ensAttributeadaptorGetDatabaseadaptor(aa);
690
691 ata = ensRegistryGetAttributetypeadaptor(dba);
692
693 sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
694
695 sqli = ajSqlrowiterNew(sqls);
696
697 while (!ajSqlrowiterDone(sqli))
698 {
699 atid = 0;
700 value = ajStrNew();
701
702 sqlr = ajSqlrowiterGet(sqli);
703
704 ajSqlcolumnToUint(sqlr, &atid);
705 ajSqlcolumnToStr(sqlr, &value);
706
707 ensAttributetypeadaptorFetchByIdentifier(ata, atid, &at);
708
709 attribute = ensAttributeNewIni(at, value);
710
711 ajListPushAppend(attributes, (void *) attribute);
712
713 ensAttributetypeDel(&at);
714
715 ajStrDel(&value);
716 }
717
718 ajSqlrowiterDel(&sqli);
719
720 ensDatabaseadaptorSqlstatementDel(dba, &sqls);
721
722 return ajTrue;
723 }
724
725
726
727
728 /* @section member retrieval **************************************************
729 **
730 ** Functions for returning members of an Ensembl Attribute Adaptor object.
731 **
732 ** @fdata [EnsPAttributeadaptor]
733 **
734 ** @nam3rule Get Return Ensembl Attribute Adaptor attribute(s)
735 ** @nam4rule Databaseadaptor Return the Ensembl Database Adaptor
736 **
737 ** @argrule * ata [EnsPAttributeadaptor] Ensembl Attribute Adaptor
738 **
739 ** @valrule Databaseadaptor [EnsPDatabaseadaptor] Ensembl Database Adaptor
740 **
741 ** @fcategory use
742 ******************************************************************************/
743
744
745
746
747 /* @func ensAttributeadaptorGetDatabaseadaptor ********************************
748 **
749 ** Get the Ensembl Database Adaptor member of an Ensembl Attribute Adaptor.
750 ** The Ensembl Attribute Adaptor is just an alias for the
751 ** Ensembl Database Adaptor.
752 **
753 ** @param [u] ata [EnsPAttributeadaptor] Ensembl Attribute Adaptor
754 **
755 ** @return [EnsPDatabaseadaptor] Ensembl Database Adaptor or NULL
756 **
757 ** @release 6.3.0
758 ** @@
759 ******************************************************************************/
760
ensAttributeadaptorGetDatabaseadaptor(EnsPAttributeadaptor ata)761 EnsPDatabaseadaptor ensAttributeadaptorGetDatabaseadaptor(
762 EnsPAttributeadaptor ata)
763 {
764 return ata;
765 }
766
767
768
769
770 /* @section object retrieval **************************************************
771 **
772 ** Functions for fetching Ensembl Attribute objects from an
773 ** Ensembl SQL database.
774 **
775 ** @fdata [EnsPAttributeadaptor]
776 **
777 ** @nam3rule Fetch Fetch Ensembl Attribute object(s)
778 ** @nam4rule All Fetch all Ensembl Attribute objects
779 ** @nam4rule Allby Fetch all Ensembl Attribute objects matching criteria
780 ** @nam5rule Gene Fetch all by an Ensembl Gene
781 ** @nam5rule Operon Fetch all by an Ensembl Operon
782 ** @nam5rule Operontranscript Fetch all by an Ensembl Operon Transcript
783 ** @nam5rule Seqregion Fetch all by an Ensembl Sequence Region
784 ** @nam5rule Slice Fetch all by an Ensembl Slice
785 ** @nam5rule Transcript Fetch all by an Ensembl Transcript
786 ** @nam5rule Translation Fetch all by an Ensembl Translation
787 ** @nam4rule By Fetch one Ensembl Attribute object matching criteria
788 **
789 ** @argrule * ata [EnsPAttributeadaptor] Ensembl Attribute Adaptor
790 ** @argrule AllbyGene gene [const EnsPGene] Ensembl Gene
791 ** @argrule AllbyGene code [const AjPStr] Ensembl Attribute code
792 ** @argrule AllbyOperon operon [const EnsPOperon] Ensembl Operon
793 ** @argrule AllbyOperon code [const AjPStr] Ensembl Attribute code
794 ** @argrule AllbyOperontranscript ot [const EnsPOperontranscript]
795 ** Ensembl Operon Transcript
796 ** @argrule AllbyOperontranscript code [const AjPStr] Ensembl Attribute code
797 ** @argrule AllbySeqregion sr [const EnsPSeqregion] Ensembl Sequence Region
798 ** @argrule AllbySeqregion code [const AjPStr] Ensembl Attribute code
799 ** @argrule AllbySlice slice [const EnsPSlice] Ensembl Slice
800 ** @argrule AllbySlice code [const AjPStr] Ensembl Attribute code
801 ** @argrule AllbyTranscript transcript [const EnsPTranscript]
802 ** Ensembl Transcript
803 ** @argrule AllbyTranscript code [const AjPStr] Ensembl Attribute code
804 ** @argrule AllbyTranslation translation [const EnsPTranslation]
805 ** Ensembl Translation
806 ** @argrule AllbyTranslation code [const AjPStr] Ensembl Attribute code
807 ** @argrule Allby attributes [AjPList]
808 ** AJAX List of Ensembl Attribute objects
809 **
810 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
811 **
812 ** @fcategory use
813 ******************************************************************************/
814
815
816
817
818 /* @func ensAttributeadaptorFetchAllbyGene ************************************
819 **
820 ** Fetch all Ensembl Attribute objects via an Ensembl Gene.
821 **
822 ** The caller is responsible for deleting the Ensembl Attribute objects before
823 ** deleting the AJAX List.
824 **
825 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::AUTOLOAD
826 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::fetch_all_by_
827 ** @param [u] ata [EnsPAttributeadaptor] Ensembl Attribute Adaptor
828 ** @param [r] gene [const EnsPGene] Ensembl Gene
829 ** @param [r] code [const AjPStr] Ensembl Attribute code
830 ** @param [u] attributes [AjPList] AJAX List of Ensembl Attribute objects
831 **
832 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
833 **
834 ** @release 6.4.0
835 ** @@
836 ******************************************************************************/
837
ensAttributeadaptorFetchAllbyGene(EnsPAttributeadaptor ata,const EnsPGene gene,const AjPStr code,AjPList attributes)838 AjBool ensAttributeadaptorFetchAllbyGene(
839 EnsPAttributeadaptor ata,
840 const EnsPGene gene,
841 const AjPStr code,
842 AjPList attributes)
843 {
844 char *txtcode = NULL;
845
846 AjBool result = AJFALSE;
847
848 AjPStr statement = NULL;
849
850 if (!ata)
851 return ajFalse;
852
853 if (!gene)
854 return ajFalse;
855
856 if (!attributes)
857 return ajFalse;
858
859 statement = ajFmtStr(
860 "SELECT "
861 "gene_attrib.attrib_type_id, "
862 "gene_attrib.value "
863 "FROM "
864 "attrib_type, "
865 "gene_attrib "
866 "WHERE "
867 "attrib_type.attrib_type_id = "
868 "gene_attrib.attrib_type_id "
869 "AND "
870 "gene_attrib.gene_id = %u",
871 ensGeneGetIdentifier(gene));
872
873 if (code && ajStrGetLen(code))
874 {
875 ensDatabaseadaptorEscapeC(
876 ensAttributeadaptorGetDatabaseadaptor(ata),
877 &txtcode,
878 code);
879
880 ajFmtPrintAppS(&statement, " AND attrib_type.code = '%s'", txtcode);
881
882 ajCharDel(&txtcode);
883 }
884
885 result = attributeadaptorFetchAllbyStatement(ata, statement, attributes);
886
887 ajStrDel(&statement);
888
889 return result;
890 }
891
892
893
894
895 /* @func ensAttributeadaptorFetchAllbyOperon **********************************
896 **
897 ** Fetch all Ensembl Attribute objects via an Ensembl Operon.
898 **
899 ** The caller is responsible for deleting the Ensembl Attribute objects before
900 ** deleting the AJAX List.
901 **
902 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::AUTOLOAD
903 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::fetch_all_by_
904 ** @param [u] ata [EnsPAttributeadaptor] Ensembl Attribute Adaptor
905 ** @param [r] operon [const EnsPOperon] Ensembl Operon
906 ** @param [r] code [const AjPStr] Ensembl Attribute code
907 ** @param [u] attributes [AjPList] AJAX List of Ensembl Attribute objects
908 **
909 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
910 **
911 ** @release 6.4.0
912 ** @@
913 ******************************************************************************/
914
ensAttributeadaptorFetchAllbyOperon(EnsPAttributeadaptor ata,const EnsPOperon operon,const AjPStr code,AjPList attributes)915 AjBool ensAttributeadaptorFetchAllbyOperon(
916 EnsPAttributeadaptor ata,
917 const EnsPOperon operon,
918 const AjPStr code,
919 AjPList attributes)
920 {
921 char *txtcode = NULL;
922
923 AjBool result = AJFALSE;
924
925 AjPStr statement = NULL;
926
927 if (!ata)
928 return ajFalse;
929
930 if (!operon)
931 return ajFalse;
932
933 if (!attributes)
934 return ajFalse;
935
936 statement = ajFmtStr(
937 "SELECT "
938 "operon_attrib.attrib_type_id, "
939 "operon_attrib.value "
940 "FROM "
941 "attrib_type, "
942 "operon_attrib "
943 "WHERE "
944 "attrib_type.attrib_type_id = "
945 "operon_attrib.attrib_type_id "
946 "AND "
947 "operon_attrib.operon_id = %u",
948 ensOperonGetIdentifier(operon));
949
950 if (code && ajStrGetLen(code))
951 {
952 ensDatabaseadaptorEscapeC(
953 ensAttributeadaptorGetDatabaseadaptor(ata),
954 &txtcode,
955 code);
956
957 ajFmtPrintAppS(&statement, " AND attrib_type.code = '%s'", txtcode);
958
959 ajCharDel(&txtcode);
960 }
961
962 result = attributeadaptorFetchAllbyStatement(ata, statement, attributes);
963
964 ajStrDel(&statement);
965
966 return result;
967 }
968
969
970
971
972 /* @func ensAttributeadaptorFetchAllbyOperontranscript ************************
973 **
974 ** Fetch all Ensembl Attribute objects via an Ensembl Operon Transcript.
975 **
976 ** The caller is responsible for deleting the Ensembl Attribute objects before
977 ** deleting the AJAX List.
978 **
979 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::AUTOLOAD
980 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::fetch_all_by_
981 ** @param [u] ata [EnsPAttributeadaptor] Ensembl Attribute Adaptor
982 ** @param [r] ot [const EnsPOperontranscript] Ensembl Operon Transcript
983 ** @param [r] code [const AjPStr] Ensembl Attribute code
984 ** @param [u] attributes [AjPList] AJAX List of Ensembl Attribute objects
985 **
986 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
987 **
988 ** @release 6.4.0
989 ** @@
990 ******************************************************************************/
991
ensAttributeadaptorFetchAllbyOperontranscript(EnsPAttributeadaptor ata,const EnsPOperontranscript ot,const AjPStr code,AjPList attributes)992 AjBool ensAttributeadaptorFetchAllbyOperontranscript(
993 EnsPAttributeadaptor ata,
994 const EnsPOperontranscript ot,
995 const AjPStr code,
996 AjPList attributes)
997 {
998 char *txtcode = NULL;
999
1000 AjBool result = AJFALSE;
1001
1002 AjPStr statement = NULL;
1003
1004 if (!ata)
1005 return ajFalse;
1006
1007 if (!ot)
1008 return ajFalse;
1009
1010 if (!attributes)
1011 return ajFalse;
1012
1013 statement = ajFmtStr(
1014 "SELECT "
1015 "operon_transcript_attrib.attrib_type_id, "
1016 "operon_transcript_attrib.value "
1017 "FROM "
1018 "attrib_type, "
1019 "operon_transcript_attrib "
1020 "WHERE "
1021 "attrib_type.attrib_type_id = "
1022 "operon_transcript_attrib.attrib_type_id "
1023 "AND "
1024 "operon_transcript_attrib.operon_transcript_id = %u",
1025 ensOperontranscriptGetIdentifier(ot));
1026
1027 if (code && ajStrGetLen(code))
1028 {
1029 ensDatabaseadaptorEscapeC(
1030 ensAttributeadaptorGetDatabaseadaptor(ata),
1031 &txtcode,
1032 code);
1033
1034 ajFmtPrintAppS(&statement, " AND attrib_type.code = '%s'", txtcode);
1035
1036 ajCharDel(&txtcode);
1037 }
1038
1039 result = attributeadaptorFetchAllbyStatement(ata, statement, attributes);
1040
1041 ajStrDel(&statement);
1042
1043 return result;
1044 }
1045
1046
1047
1048
1049 /* @func ensAttributeadaptorFetchAllbySeqregion *******************************
1050 **
1051 ** Fetch all Ensembl Attribute objects via an Ensembl Sequence Region.
1052 **
1053 ** The caller is responsible for deleting the Ensembl Attribute objects before
1054 ** deleting the AJAX List.
1055 **
1056 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::AUTOLOAD
1057 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::fetch_all_by_
1058 ** @param [u] ata [EnsPAttributeadaptor] Ensembl Attribute Adaptor
1059 ** @param [r] sr [const EnsPSeqregion] Ensembl Sequence Region
1060 ** @param [r] code [const AjPStr] Ensembl Attribute code
1061 ** @param [u] attributes [AjPList] AJAX List of Ensembl Attribute objects
1062 **
1063 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1064 **
1065 ** @release 6.4.0
1066 ** @@
1067 ******************************************************************************/
1068
ensAttributeadaptorFetchAllbySeqregion(EnsPAttributeadaptor ata,const EnsPSeqregion sr,const AjPStr code,AjPList attributes)1069 AjBool ensAttributeadaptorFetchAllbySeqregion(
1070 EnsPAttributeadaptor ata,
1071 const EnsPSeqregion sr,
1072 const AjPStr code,
1073 AjPList attributes)
1074 {
1075 char *txtcode = NULL;
1076
1077 AjBool result = AJFALSE;
1078
1079 AjPStr statement = NULL;
1080
1081 if (!ata)
1082 return ajFalse;
1083
1084 if (!sr)
1085 return ajFalse;
1086
1087 if (!attributes)
1088 return ajFalse;
1089
1090 statement = ajFmtStr(
1091 "SELECT "
1092 "seq_region_attrib.attrib_type_id, "
1093 "seq_region_attrib.value "
1094 "FROM "
1095 "attrib_type, "
1096 "seq_region_attrib "
1097 "WHERE "
1098 "attrib_type.attrib_type_id = "
1099 "seq_region_attrib.attrib_type_id "
1100 "AND "
1101 "seq_region_attrib.seq_region_id = %u",
1102 ensSeqregionGetIdentifier(sr));
1103
1104 if (code && ajStrGetLen(code))
1105 {
1106 ensDatabaseadaptorEscapeC(
1107 ensAttributeadaptorGetDatabaseadaptor(ata),
1108 &txtcode,
1109 code);
1110
1111 ajFmtPrintAppS(&statement, " AND attrib_type.code = '%s'", txtcode);
1112
1113 ajCharDel(&txtcode);
1114 }
1115
1116 result = attributeadaptorFetchAllbyStatement(ata, statement, attributes);
1117
1118 ajStrDel(&statement);
1119
1120 return result;
1121 }
1122
1123
1124
1125
1126 /* @func ensAttributeadaptorFetchAllbySlice ***********************************
1127 **
1128 ** Fetch all Ensembl Attribute objects via an Ensembl Slice.
1129 **
1130 ** The caller is responsible for deleting the Ensembl Attribute objects before
1131 ** deleting the AJAX List.
1132 **
1133 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::AUTOLOAD
1134 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::fetch_all_by_
1135 ** @param [u] ata [EnsPAttributeadaptor] Ensembl Attribute Adaptor
1136 ** @param [r] slice [const EnsPSlice] Ensembl Slice
1137 ** @param [r] code [const AjPStr] Ensembl Attribute code
1138 ** @param [u] attributes [AjPList] AJAX List of Ensembl Attribute objects
1139 **
1140 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1141 **
1142 ** @release 6.4.0
1143 ** @@
1144 ******************************************************************************/
1145
ensAttributeadaptorFetchAllbySlice(EnsPAttributeadaptor ata,const EnsPSlice slice,const AjPStr code,AjPList attributes)1146 AjBool ensAttributeadaptorFetchAllbySlice(
1147 EnsPAttributeadaptor ata,
1148 const EnsPSlice slice,
1149 const AjPStr code,
1150 AjPList attributes)
1151 {
1152 EnsPSeqregion sr = NULL;
1153
1154 if (!ata)
1155 return ajFalse;
1156
1157 if (!slice)
1158 return ajFalse;
1159
1160 if (!attributes)
1161 return ajFalse;
1162
1163 sr = ensSliceGetSeqregion(slice);
1164
1165 if (!sr)
1166 {
1167 ajDebug("ensAttributeadaptorFetchAllbySlice cannot get "
1168 "Ensembl Attribute objects for an Ensembl Slice without an "
1169 "Ensembl Sequence Region.\n");
1170
1171 return ajFalse;
1172 }
1173
1174 return ensAttributeadaptorFetchAllbySeqregion(
1175 ata,
1176 sr,
1177 code,
1178 attributes);
1179 }
1180
1181
1182
1183
1184 /* @func ensAttributeadaptorFetchAllbyTranscript ******************************
1185 **
1186 ** Fetch all Ensembl Attribute objects via an Ensembl Transcript.
1187 **
1188 ** The caller is responsible for deleting the Ensembl Attribute objects before
1189 ** deleting the AJAX List.
1190 **
1191 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::AUTOLOAD
1192 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::fetch_all_by_
1193 ** @param [u] ata [EnsPAttributeadaptor] Ensembl Attribute Adaptor
1194 ** @param [r] transcript [const EnsPTranscript] Ensembl Transcript
1195 ** @param [r] code [const AjPStr] Ensembl Attribute code
1196 ** @param [u] attributes [AjPList] AJAX List of Ensembl Attribute objects
1197 **
1198 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1199 **
1200 ** @release 6.4.0
1201 ** @@
1202 ******************************************************************************/
1203
ensAttributeadaptorFetchAllbyTranscript(EnsPAttributeadaptor ata,const EnsPTranscript transcript,const AjPStr code,AjPList attributes)1204 AjBool ensAttributeadaptorFetchAllbyTranscript(
1205 EnsPAttributeadaptor ata,
1206 const EnsPTranscript transcript,
1207 const AjPStr code,
1208 AjPList attributes)
1209 {
1210 char *txtcode = NULL;
1211
1212 AjBool result = AJFALSE;
1213
1214 AjPStr statement = NULL;
1215
1216 if (!ata)
1217 return ajFalse;
1218
1219 if (!transcript)
1220 return ajFalse;
1221
1222 if (!attributes)
1223 return ajFalse;
1224
1225 statement = ajFmtStr(
1226 "SELECT "
1227 "transcript_attrib.attrib_type_id, "
1228 "transcript_attrib.value "
1229 "FROM "
1230 "attrib_type, "
1231 "transcript_attrib "
1232 "WHERE "
1233 "attrib_type.attrib_type_id = "
1234 "transcript_attrib.attrib_type_id "
1235 "AND "
1236 "transcript_attrib.transcript_id = %u",
1237 ensTranscriptGetIdentifier(transcript));
1238
1239 if (code && ajStrGetLen(code))
1240 {
1241 ensDatabaseadaptorEscapeC(
1242 ensAttributeadaptorGetDatabaseadaptor(ata),
1243 &txtcode,
1244 code);
1245
1246 ajFmtPrintAppS(&statement, " AND attrib_type.code = '%s'", txtcode);
1247
1248 ajCharDel(&txtcode);
1249 }
1250
1251 result = attributeadaptorFetchAllbyStatement(ata, statement, attributes);
1252
1253 ajStrDel(&statement);
1254
1255 return result;
1256 }
1257
1258
1259
1260
1261 /* @func ensAttributeadaptorFetchAllbyTranslation *****************************
1262 **
1263 ** Fetch all Ensembl Attribute objects via an Ensembl Translation.
1264 **
1265 ** The caller is responsible for deleting the Ensembl Attribute objects before
1266 ** deleting the AJAX List.
1267 **
1268 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::AUTOLOAD
1269 ** @cc Bio::EnsEMBL::DBSQL::AttributeAdaptor::fetch_all_by_
1270 ** @param [u] ata [EnsPAttributeadaptor] Ensembl Attribute Adaptor
1271 ** @param [r] translation [const EnsPTranslation] Ensembl Translation
1272 ** @param [r] code [const AjPStr] Ensembl Attribute code
1273 ** @param [u] attributes [AjPList] AJAX List of Ensembl Attribute objects
1274 **
1275 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1276 **
1277 ** @release 6.4.0
1278 ** @@
1279 ******************************************************************************/
1280
ensAttributeadaptorFetchAllbyTranslation(EnsPAttributeadaptor ata,const EnsPTranslation translation,const AjPStr code,AjPList attributes)1281 AjBool ensAttributeadaptorFetchAllbyTranslation(
1282 EnsPAttributeadaptor ata,
1283 const EnsPTranslation translation,
1284 const AjPStr code,
1285 AjPList attributes)
1286 {
1287 char *txtcode = NULL;
1288
1289 AjBool result = AJFALSE;
1290
1291 AjPStr statement = NULL;
1292
1293 if (!ata)
1294 return ajFalse;
1295
1296 if (!translation)
1297 return ajFalse;
1298
1299 if (!attributes)
1300 return ajFalse;
1301
1302 statement = ajFmtStr(
1303 "SELECT "
1304 "translation_attrib.attrib_type_id, "
1305 "translation_attrib.value "
1306 "FROM "
1307 "attrib_type, "
1308 "translation_attrib "
1309 "WHERE "
1310 "attrib_type.attrib_type_id = "
1311 "translation_attrib.attrib_type_id "
1312 "AND "
1313 "translation_attrib.translation_id = %u",
1314 ensTranslationGetIdentifier(translation));
1315
1316 if (code && ajStrGetLen(code))
1317 {
1318 ensDatabaseadaptorEscapeC(
1319 ensAttributeadaptorGetDatabaseadaptor(ata),
1320 &txtcode,
1321 code);
1322
1323 ajFmtPrintAppS(&statement, " AND attrib_type.code = '%s'", txtcode);
1324
1325 ajCharDel(&txtcode);
1326 }
1327
1328 result = attributeadaptorFetchAllbyStatement(ata, statement, attributes);
1329
1330 ajStrDel(&statement);
1331
1332 return result;
1333 }
1334
1335
1336
1337
1338 /* @datasection [EnsPAttributetype] Ensembl Attribute Type ********************
1339 **
1340 ** @nam2rule Attributetype Functions for manipulating
1341 ** Ensembl Attribute Type objects
1342 **
1343 ** @cc Split out of Bio::EnsEMBL::Attribute
1344 **
1345 ******************************************************************************/
1346
1347
1348
1349
1350 /* @section constructors ******************************************************
1351 **
1352 ** All constructors return a new Ensembl Attribute Type by pointer.
1353 ** It is the responsibility of the user to first destroy any previous
1354 ** Attribute Type. The target pointer does not need to be initialised to
1355 ** NULL, but it is good programming practice to do so anyway.
1356 **
1357 ** @fdata [EnsPAttributetype]
1358 **
1359 ** @nam3rule New Constructor
1360 ** @nam4rule Cpy Constructor with existing object
1361 ** @nam4rule Ini Constructor with initial values
1362 ** @nam4rule Ref Constructor by incrementing the reference counter
1363 **
1364 ** @argrule Cpy at [const EnsPAttributetype] Ensembl Attribute Type
1365 ** @argrule Ini ata [EnsPAttributetypeadaptor]
1366 ** Ensembl Attribute Type Adaptor
1367 ** @argrule Ini identifier [ajuint] SQL database-internal identifier
1368 ** @argrule Ini code [AjPStr] Code
1369 ** @argrule Ini name [AjPStr] Name
1370 ** @argrule Ini description [AjPStr] Description
1371 ** @argrule Ref at [EnsPAttributetype] Ensembl Attribute Type
1372 **
1373 ** @valrule * [EnsPAttributetype] Ensembl Attribute Type or NULL
1374 **
1375 ** @fcategory new
1376 ******************************************************************************/
1377
1378
1379
1380
1381 /* @func ensAttributetypeNewCpy ***********************************************
1382 **
1383 ** Object-based constructor function, which returns an independent object.
1384 **
1385 ** @param [r] at [const EnsPAttributetype] Ensembl Attribute Type
1386 **
1387 ** @return [EnsPAttributetype] Ensembl Attribute Type or NULL
1388 **
1389 ** @release 6.4.0
1390 ** @@
1391 ******************************************************************************/
1392
ensAttributetypeNewCpy(const EnsPAttributetype at)1393 EnsPAttributetype ensAttributetypeNewCpy(const EnsPAttributetype at)
1394 {
1395 EnsPAttributetype pthis = NULL;
1396
1397 AJNEW0(pthis);
1398
1399 pthis->Use = 1U;
1400 pthis->Identifier = at->Identifier;
1401 pthis->Adaptor = at->Adaptor;
1402
1403 if (at->Code)
1404 pthis->Code = ajStrNewRef(at->Code);
1405
1406 if (at->Name)
1407 pthis->Name = ajStrNewRef(at->Name);
1408
1409 if (at->Description)
1410 pthis->Description = ajStrNewRef(at->Description);
1411
1412 return pthis;
1413 }
1414
1415
1416
1417
1418 /* @func ensAttributetypeNewIni ***********************************************
1419 **
1420 ** Ensembl Attribute Type constructor with initial values.
1421 **
1422 ** @cc Bio::EnsEMBL::Storable::new
1423 ** @param [u] ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
1424 ** @param [r] identifier [ajuint] SQL database-internal identifier
1425 ** @cc Bio::EnsEMBL::AttributeType::new
1426 ** @param [u] code [AjPStr] Code
1427 ** @param [u] name [AjPStr] Name
1428 ** @param [u] description [AjPStr] Description
1429 **
1430 ** @return [EnsPAttributetype] Ensembl Attribute Type or NULL
1431 **
1432 ** @release 6.4.0
1433 ** @@
1434 ******************************************************************************/
1435
ensAttributetypeNewIni(EnsPAttributetypeadaptor ata,ajuint identifier,AjPStr code,AjPStr name,AjPStr description)1436 EnsPAttributetype ensAttributetypeNewIni(EnsPAttributetypeadaptor ata,
1437 ajuint identifier,
1438 AjPStr code,
1439 AjPStr name,
1440 AjPStr description)
1441 {
1442 EnsPAttributetype at = NULL;
1443
1444 AJNEW0(at);
1445
1446 at->Use = 1U;
1447 at->Adaptor = ata;
1448 at->Identifier = identifier;
1449
1450 if (code)
1451 at->Code = ajStrNewRef(code);
1452
1453 if (name)
1454 at->Name = ajStrNewRef(name);
1455
1456 if (description)
1457 at->Description = ajStrNewRef(description);
1458
1459 return at;
1460 }
1461
1462
1463
1464
1465 /* @func ensAttributetypeNewRef ***********************************************
1466 **
1467 ** Ensembl Object referencing function, which returns a pointer to the
1468 ** Ensembl Object passed in and increases its reference count.
1469 **
1470 ** @param [u] at [EnsPAttributetype] Ensembl Attribute Type
1471 **
1472 ** @return [EnsPAttributetype] Ensembl Attribute Type or NULL
1473 **
1474 ** @release 6.4.0
1475 ** @@
1476 ******************************************************************************/
1477
ensAttributetypeNewRef(EnsPAttributetype at)1478 EnsPAttributetype ensAttributetypeNewRef(EnsPAttributetype at)
1479 {
1480 if (!at)
1481 return NULL;
1482
1483 at->Use++;
1484
1485 return at;
1486 }
1487
1488
1489
1490
1491 /* @section destructors *******************************************************
1492 **
1493 ** Destruction destroys all internal data structures and frees the memory
1494 ** allocated for an Ensembl Attribute Type object.
1495 **
1496 ** @fdata [EnsPAttributetype]
1497 **
1498 ** @nam3rule Del Destroy (free) an Ensembl Attribute Type
1499 **
1500 ** @argrule * Pat [EnsPAttributetype*] Ensembl Attribute Type address
1501 **
1502 ** @valrule * [void]
1503 **
1504 ** @fcategory delete
1505 ******************************************************************************/
1506
1507
1508
1509
1510 /* @func ensAttributetypeDel **************************************************
1511 **
1512 ** Default destructor for an Ensembl Attribute Type.
1513 **
1514 ** @param [d] Pat [EnsPAttributetype*] Ensembl Attribute Type address
1515 **
1516 ** @return [void]
1517 **
1518 ** @release 6.4.0
1519 ** @@
1520 ******************************************************************************/
1521
ensAttributetypeDel(EnsPAttributetype * Pat)1522 void ensAttributetypeDel(EnsPAttributetype *Pat)
1523 {
1524 EnsPAttributetype pthis = NULL;
1525
1526 if (!Pat)
1527 return;
1528
1529 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
1530 if (ajDebugTest("ensAttributetypeDel"))
1531 {
1532 ajDebug("ensAttributetypeDel\n"
1533 " *Pat %p\n",
1534 *Pat);
1535
1536 ensAttributetypeTrace(*Pat, 1);
1537 }
1538 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
1539
1540 if (!(pthis = *Pat) || --pthis->Use)
1541 {
1542 *Pat = NULL;
1543
1544 return;
1545 }
1546
1547 ajStrDel(&pthis->Code);
1548 ajStrDel(&pthis->Name);
1549 ajStrDel(&pthis->Description);
1550
1551 ajMemFree((void **) Pat);
1552
1553 return;
1554 }
1555
1556
1557
1558
1559 /* @section member retrieval **************************************************
1560 **
1561 ** Functions for returning members of an Ensembl Attribute Type object.
1562 **
1563 ** @fdata [EnsPAttributetype]
1564 **
1565 ** @nam3rule Get Return Ensembl Attribute Type attribute(s)
1566 ** @nam4rule Adaptor Return the Ensembl Attribute Type Adaptor
1567 ** @nam4rule Code Return the code
1568 ** @nam4rule Description Return the description
1569 ** @nam4rule Identifier Return the SQL database-internal identifier
1570 ** @nam4rule Name Return the name
1571 **
1572 ** @argrule * at [const EnsPAttributetype] Ensembl Attribute Type
1573 **
1574 ** @valrule Adaptor [EnsPAttributetypeadaptor]
1575 ** Ensembl Attribute Type Adaptor or NULL
1576 ** @valrule Code [AjPStr] Code or NULL
1577 ** @valrule Description [AjPStr] Description or NULL
1578 ** @valrule Identifier [ajuint] SQL database-internal identifier or 0U
1579 ** @valrule Name [AjPStr] Name or NULL
1580 **
1581 ** @fcategory use
1582 ******************************************************************************/
1583
1584
1585
1586
1587 /* @func ensAttributetypeGetAdaptor *******************************************
1588 **
1589 ** Get the Ensembl Attribute Type Adaptor member of an
1590 ** Ensembl Attribute Type.
1591 **
1592 ** @cc Bio::EnsEMBL::Storable::adaptor
1593 ** @param [r] at [const EnsPAttributetype] Ensembl Attribute Type
1594 **
1595 ** @return [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor or NULL
1596 **
1597 ** @release 6.4.0
1598 ** @@
1599 ******************************************************************************/
1600
ensAttributetypeGetAdaptor(const EnsPAttributetype at)1601 EnsPAttributetypeadaptor ensAttributetypeGetAdaptor(
1602 const EnsPAttributetype at)
1603 {
1604 return (at) ? at->Adaptor : NULL;
1605 }
1606
1607
1608
1609
1610 /* @func ensAttributetypeGetCode **********************************************
1611 **
1612 ** Get the code member of an Ensembl Attribute Type.
1613 **
1614 ** @cc Bio::EnsEMBL::Attribute::code
1615 ** @param [r] at [const EnsPAttributetype] Ensembl Attribute Type
1616 **
1617 ** @return [AjPStr] Code or NULL
1618 **
1619 ** @release 6.4.0
1620 ** @@
1621 ******************************************************************************/
1622
ensAttributetypeGetCode(const EnsPAttributetype at)1623 AjPStr ensAttributetypeGetCode(
1624 const EnsPAttributetype at)
1625 {
1626 return (at) ? at->Code : NULL;
1627 }
1628
1629
1630
1631
1632 /* @func ensAttributetypeGetDescription ***************************************
1633 **
1634 ** Get the description member of an Ensembl Attribute Type.
1635 **
1636 ** @cc Bio::EnsEMBL::Attribute::description
1637 ** @param [r] at [const EnsPAttributetype] Ensembl Attribute Type
1638 **
1639 ** @return [AjPStr] Description or NULL
1640 **
1641 ** @release 6.4.0
1642 ** @@
1643 ******************************************************************************/
1644
ensAttributetypeGetDescription(const EnsPAttributetype at)1645 AjPStr ensAttributetypeGetDescription(
1646 const EnsPAttributetype at)
1647 {
1648 return (at) ? at->Description : NULL;
1649 }
1650
1651
1652
1653
1654 /* @func ensAttributetypeGetIdentifier ****************************************
1655 **
1656 ** Get the SQL database-internal identifier member of an
1657 ** Ensembl Attribute Type.
1658 **
1659 ** @cc Bio::EnsEMBL::Storable::dbID
1660 ** @param [r] at [const EnsPAttributetype] Ensembl Attribute Type
1661 **
1662 ** @return [ajuint] SQL database-internal identifier or 0U
1663 **
1664 ** @release 6.4.0
1665 ** @@
1666 ******************************************************************************/
1667
ensAttributetypeGetIdentifier(const EnsPAttributetype at)1668 ajuint ensAttributetypeGetIdentifier(
1669 const EnsPAttributetype at)
1670 {
1671 return (at) ? at->Identifier : 0U;
1672 }
1673
1674
1675
1676
1677 /* @func ensAttributetypeGetName **********************************************
1678 **
1679 ** Get the name member of an Ensembl Attribute Type.
1680 **
1681 ** @cc Bio::EnsEMBL::Attribute::name
1682 ** @param [r] at [const EnsPAttributetype] Ensembl Attribute Type
1683 **
1684 ** @return [AjPStr] Name or NULL
1685 **
1686 ** @release 6.4.0
1687 ** @@
1688 ******************************************************************************/
1689
ensAttributetypeGetName(const EnsPAttributetype at)1690 AjPStr ensAttributetypeGetName(
1691 const EnsPAttributetype at)
1692 {
1693 return (at) ? at->Name : NULL;
1694 }
1695
1696
1697
1698
1699 /* @section member assignment *************************************************
1700 **
1701 ** Functions for assigning members of an Ensembl Attribute Type object.
1702 **
1703 ** @fdata [EnsPAttributetype]
1704 **
1705 ** @nam3rule Set Set one member of an Ensembl Attribute Type
1706 ** @nam4rule Adaptor Set the Ensembl Attribute Type Adaptor
1707 ** @nam4rule Code Set the code
1708 ** @nam4rule Description Set the description
1709 ** @nam4rule Identifier Set the SQL database-internal identifier
1710 ** @nam4rule Name Set the name
1711 **
1712 ** @argrule * at [EnsPAttributetype] Ensembl Attribute Type object
1713 ** @argrule Adaptor ata [EnsPAttributetypeadaptor]
1714 ** Ensembl Attribute Type Adaptor
1715 ** @argrule Code code [AjPStr] Code
1716 ** @argrule Description description [AjPStr] Description
1717 ** @argrule Identifier identifier [ajuint] SQL database-internal identifier
1718 ** @argrule Name name [AjPStr] Name
1719 **
1720 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1721 **
1722 ** @fcategory modify
1723 ******************************************************************************/
1724
1725
1726
1727
1728 /* @func ensAttributetypeSetAdaptor *******************************************
1729 **
1730 ** Set the Ensembl Attribute Type Adaptor member of an
1731 ** Ensembl Attribute Type.
1732 **
1733 ** @cc Bio::EnsEMBL::Storable::adaptor
1734 ** @param [u] at [EnsPAttributetype] Ensembl Attribute Type
1735 ** @param [u] ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
1736 **
1737 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1738 **
1739 ** @release 6.4.0
1740 ** @@
1741 ******************************************************************************/
1742
ensAttributetypeSetAdaptor(EnsPAttributetype at,EnsPAttributetypeadaptor ata)1743 AjBool ensAttributetypeSetAdaptor(EnsPAttributetype at,
1744 EnsPAttributetypeadaptor ata)
1745 {
1746 if (!at)
1747 return ajFalse;
1748
1749 at->Adaptor = ata;
1750
1751 return ajTrue;
1752 }
1753
1754
1755
1756
1757 /* @func ensAttributetypeSetCode **********************************************
1758 **
1759 ** Set the code member of an Ensembl Attribute Type.
1760 **
1761 ** @cc Bio::EnsEMBL::Attribute::code
1762 ** @param [u] at [EnsPAttributetype] Ensembl Attribute Type
1763 ** @param [u] code [AjPStr] Code
1764 **
1765 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1766 **
1767 ** @release 6.4.0
1768 ** @@
1769 ******************************************************************************/
1770
ensAttributetypeSetCode(EnsPAttributetype at,AjPStr code)1771 AjBool ensAttributetypeSetCode(EnsPAttributetype at,
1772 AjPStr code)
1773 {
1774 if (!at)
1775 return ajFalse;
1776
1777 ajStrDel(&at->Code);
1778
1779 at->Code = ajStrNewRef(code);
1780
1781 return ajTrue;
1782 }
1783
1784
1785
1786
1787 /* @func ensAttributetypeSetDescription ***************************************
1788 **
1789 ** Set the description member of an Ensembl Attribute Type.
1790 **
1791 ** @cc Bio::EnsEMBL::Attribute::description
1792 ** @param [u] at [EnsPAttributetype] Ensembl Attribute Type
1793 ** @param [u] description [AjPStr] Description
1794 **
1795 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1796 **
1797 ** @release 6.4.0
1798 ** @@
1799 ******************************************************************************/
1800
ensAttributetypeSetDescription(EnsPAttributetype at,AjPStr description)1801 AjBool ensAttributetypeSetDescription(EnsPAttributetype at,
1802 AjPStr description)
1803 {
1804 if (!at)
1805 return ajFalse;
1806
1807 ajStrDel(&at->Description);
1808
1809 at->Description = ajStrNewRef(description);
1810
1811 return ajTrue;
1812 }
1813
1814
1815
1816
1817 /* @func ensAttributetypeSetIdentifier ****************************************
1818 **
1819 ** Set the SQL database-internal identifier member of an
1820 ** Ensembl Attribute Type.
1821 **
1822 ** @cc Bio::EnsEMBL::Storable::dbID
1823 ** @param [u] at [EnsPAttributetype] Ensembl Attribute Type
1824 ** @param [r] identifier [ajuint] SQL database-internal identifier
1825 **
1826 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1827 **
1828 ** @release 6.4.0
1829 ** @@
1830 ******************************************************************************/
1831
ensAttributetypeSetIdentifier(EnsPAttributetype at,ajuint identifier)1832 AjBool ensAttributetypeSetIdentifier(EnsPAttributetype at,
1833 ajuint identifier)
1834 {
1835 if (!at)
1836 return ajFalse;
1837
1838 at->Identifier = identifier;
1839
1840 return ajTrue;
1841 }
1842
1843
1844
1845
1846 /* @func ensAttributetypeSetName **********************************************
1847 **
1848 ** Set the name member of an Ensembl Attribute Type.
1849 **
1850 ** @cc Bio::EnsEMBL::Attribute::name
1851 ** @param [u] at [EnsPAttributetype] Ensembl Attribute Type
1852 ** @param [u] name [AjPStr] Name
1853 **
1854 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1855 **
1856 ** @release 6.4.0
1857 ** @@
1858 ******************************************************************************/
1859
ensAttributetypeSetName(EnsPAttributetype at,AjPStr name)1860 AjBool ensAttributetypeSetName(EnsPAttributetype at,
1861 AjPStr name)
1862 {
1863 if (!at)
1864 return ajFalse;
1865
1866 ajStrDel(&at->Name);
1867
1868 at->Name = ajStrNewRef(name);
1869
1870 return ajTrue;
1871 }
1872
1873
1874
1875
1876 /* @section debugging *********************************************************
1877 **
1878 ** Functions for reporting of an Ensembl Attribute Type object.
1879 **
1880 ** @fdata [EnsPAttributetype]
1881 **
1882 ** @nam3rule Trace Report Ensembl Attribute Type members to debug file
1883 **
1884 ** @argrule Trace at [const EnsPAttributetype] Ensembl Attribute Type
1885 ** @argrule Trace level [ajuint] Indentation level
1886 **
1887 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
1888 **
1889 ** @fcategory misc
1890 ******************************************************************************/
1891
1892
1893
1894
1895 /* @func ensAttributetypeTrace ************************************************
1896 **
1897 ** Trace an Ensembl Attribute Type.
1898 **
1899 ** @param [r] at [const EnsPAttributetype] Ensembl Attribute Type
1900 ** @param [r] level [ajuint] Indentation level
1901 **
1902 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
1903 **
1904 ** @release 6.4.0
1905 ** @@
1906 ******************************************************************************/
1907
ensAttributetypeTrace(const EnsPAttributetype at,ajuint level)1908 AjBool ensAttributetypeTrace(const EnsPAttributetype at, ajuint level)
1909 {
1910 AjPStr indent = NULL;
1911
1912 if (!at)
1913 return ajFalse;
1914
1915 indent = ajStrNew();
1916
1917 ajStrAppendCountK(&indent, ' ', level * 2);
1918
1919 ajDebug("%SensAttributetypeTrace %p\n"
1920 "%S Use %u\n"
1921 "%S Identifier %u\n"
1922 "%S Adaptor %p\n"
1923 "%S Code '%S'\n"
1924 "%S Name '%S'\n"
1925 "%S Description '%S'\n",
1926 indent, at,
1927 indent, at->Use,
1928 indent, at->Identifier,
1929 indent, at->Adaptor,
1930 indent, at->Code,
1931 indent, at->Name,
1932 indent, at->Description);
1933
1934 ajStrDel(&indent);
1935
1936 return ajTrue;
1937 }
1938
1939
1940
1941
1942 /* @section calculate *********************************************************
1943 **
1944 ** Functions for calculating information from an Ensembl Attribute Type object.
1945 **
1946 ** @fdata [EnsPAttributetype]
1947 **
1948 ** @nam3rule Calculate Calculate Ensembl Attribute Type information
1949 ** @nam4rule Memsize Calculate the memory size in bytes
1950 **
1951 ** @argrule * at [const EnsPAttributetype] Ensembl Attribute Type
1952 **
1953 ** @valrule Memsize [size_t] Memory size in bytes or 0
1954 **
1955 ** @fcategory misc
1956 ******************************************************************************/
1957
1958
1959
1960
1961 /* @func ensAttributetypeCalculateMemsize *************************************
1962 **
1963 ** Calclate the memory size in bytes of an Ensembl Attribute Type.
1964 **
1965 ** @param [r] at [const EnsPAttributetype] Ensembl Attribute Type
1966 **
1967 ** @return [size_t] Memory size in bytes or 0
1968 **
1969 ** @release 6.4.0
1970 ** @@
1971 ******************************************************************************/
1972
ensAttributetypeCalculateMemsize(const EnsPAttributetype at)1973 size_t ensAttributetypeCalculateMemsize(const EnsPAttributetype at)
1974 {
1975 size_t size = 0;
1976
1977 if (!at)
1978 return 0;
1979
1980 size += sizeof (EnsOAttributetype);
1981
1982 if (at->Code)
1983 {
1984 size += sizeof (AjOStr);
1985
1986 size += ajStrGetRes(at->Code);
1987 }
1988
1989 if (at->Name)
1990 {
1991 size += sizeof (AjOStr);
1992
1993 size += ajStrGetRes(at->Name);
1994 }
1995
1996 if (at->Description)
1997 {
1998 size += sizeof (AjOStr);
1999
2000 size += ajStrGetRes(at->Description);
2001 }
2002
2003 return size;
2004 }
2005
2006
2007
2008
2009 /* @datasection [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor *****
2010 **
2011 ** @nam2rule Attributetypeadaptor Functions for manipulating
2012 ** Ensembl Attribute Type Adaptor objects
2013 **
2014 ** @cc Split out of Bio::EnsEMBL::DBSQL::AttributeAdaptor
2015 **
2016 ******************************************************************************/
2017
2018
2019
2020
2021 /* @funcstatic attributetypeadaptorFetchAllbyStatement ************************
2022 **
2023 ** Run a SQL statement against an Ensembl Database Adaptor and consolidate the
2024 ** results into an AJAX List of Ensembl Attribute Type objects.
2025 **
2026 ** The caller is responsible for deleting the Ensembl Attribute Type objects
2027 ** before deleting the AJAX List.
2028 **
2029 ** @param [u] ba [EnsPBaseadaptor] Ensembl Base Adaptor
2030 ** @param [r] statement [const AjPStr] SQL statement
2031 ** @param [uN] am [EnsPAssemblymapper] Ensembl Assembly Mapper
2032 ** @param [uN] slice [EnsPSlice] Ensembl Slice
2033 ** @param [u] ats [AjPList] AJAX List of Ensembl Attribute Type objects
2034 **
2035 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2036 **
2037 ** @release 6.4.0
2038 ** @@
2039 ******************************************************************************/
2040
attributetypeadaptorFetchAllbyStatement(EnsPBaseadaptor ba,const AjPStr statement,EnsPAssemblymapper am,EnsPSlice slice,AjPList ats)2041 static AjBool attributetypeadaptorFetchAllbyStatement(
2042 EnsPBaseadaptor ba,
2043 const AjPStr statement,
2044 EnsPAssemblymapper am,
2045 EnsPSlice slice,
2046 AjPList ats)
2047 {
2048 ajuint identifier = 0U;
2049
2050 AjPSqlstatement sqls = NULL;
2051 AjISqlrow sqli = NULL;
2052 AjPSqlrow sqlr = NULL;
2053
2054 AjPStr code = NULL;
2055 AjPStr name = NULL;
2056 AjPStr description = NULL;
2057
2058 EnsPAttributetype at = NULL;
2059 EnsPAttributetypeadaptor ata = NULL;
2060
2061 EnsPDatabaseadaptor dba = NULL;
2062
2063 if (ajDebugTest("attributetypeadaptorFetchAllbyStatement"))
2064 ajDebug("attributetypeadaptorFetchAllbyStatement\n"
2065 " ba %p\n"
2066 " statement %p\n"
2067 " am %p\n"
2068 " slice %p\n"
2069 " ats %p\n",
2070 ba,
2071 statement,
2072 am,
2073 slice,
2074 ats);
2075
2076 if (!ba)
2077 return ajFalse;
2078
2079 if (!statement)
2080 return ajFalse;
2081
2082 if (!ats)
2083 return ajFalse;
2084
2085 dba = ensBaseadaptorGetDatabaseadaptor(ba);
2086
2087 ata = ensRegistryGetAttributetypeadaptor(dba);
2088
2089 sqls = ensDatabaseadaptorSqlstatementNew(dba, statement);
2090
2091 sqli = ajSqlrowiterNew(sqls);
2092
2093 while (!ajSqlrowiterDone(sqli))
2094 {
2095 identifier = 0;
2096 code = ajStrNew();
2097 name = ajStrNew();
2098 description = ajStrNew();
2099
2100 sqlr = ajSqlrowiterGet(sqli);
2101
2102 ajSqlcolumnToUint(sqlr, &identifier);
2103 ajSqlcolumnToStr(sqlr, &code);
2104 ajSqlcolumnToStr(sqlr, &name);
2105 ajSqlcolumnToStr(sqlr, &description);
2106
2107 at = ensAttributetypeNewIni(ata, identifier, code, name, description);
2108
2109 ajListPushAppend(ats, (void *) at);
2110
2111 ajStrDel(&code);
2112 ajStrDel(&name);
2113 ajStrDel(&description);
2114 }
2115
2116 ajSqlrowiterDel(&sqli);
2117
2118 ensDatabaseadaptorSqlstatementDel(dba, &sqls);
2119
2120 return ajTrue;
2121 }
2122
2123
2124
2125
2126 /* @section constructors ******************************************************
2127 **
2128 ** All constructors return a new Ensembl Attribute Type Adaptor by pointer.
2129 ** It is the responsibility of the user to first destroy any previous
2130 ** Attribute Type Adaptor. The target pointer does not need to be initialised
2131 ** to NULL, but it is good programming practice to do so anyway.
2132 **
2133 ** @fdata [EnsPAttributetypeadaptor]
2134 **
2135 ** @nam3rule New Constructor
2136 **
2137 ** @argrule New dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
2138 **
2139 ** @valrule * [EnsPAttributetypeadaptor]
2140 ** Ensembl Attribute Type Adaptor or NULL
2141 **
2142 ** @fcategory new
2143 ******************************************************************************/
2144
2145
2146
2147
2148 /* @func ensAttributetypeadaptorNew *******************************************
2149 **
2150 ** Default constructor for an Ensembl Attribute Type Adaptor.
2151 **
2152 ** Ensembl Object Adaptors are singleton objects in the sense that a single
2153 ** instance of an Ensembl Object Adaptor connected to a particular database is
2154 ** sufficient to instantiate any number of Ensembl Objects from the database.
2155 ** Each Ensembl Object will have a weak reference to the Object Adaptor that
2156 ** instantiated it. Therefore, Ensembl Object Adaptors should not be
2157 ** instantiated directly, but rather obtained from the Ensembl Registry,
2158 ** which will in turn call this function if neccessary.
2159 **
2160 ** @see ensRegistryGetDatabaseadaptor
2161 ** @see ensRegistryGetAttributetypeadaptor
2162 **
2163 ** @param [u] dba [EnsPDatabaseadaptor] Ensembl Database Adaptor
2164 **
2165 ** @return [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor or NULL
2166 **
2167 ** @release 6.4.0
2168 ** @@
2169 ******************************************************************************/
2170
ensAttributetypeadaptorNew(EnsPDatabaseadaptor dba)2171 EnsPAttributetypeadaptor ensAttributetypeadaptorNew(
2172 EnsPDatabaseadaptor dba)
2173 {
2174 EnsPAttributetypeadaptor ata = NULL;
2175
2176 if (!dba)
2177 return NULL;
2178
2179 if (ajDebugTest("ensAttributetypeadaptorNew"))
2180 ajDebug("ensAttributetypeadaptorNew\n"
2181 " dba %p\n",
2182 dba);
2183
2184 AJNEW0(ata);
2185
2186 ata->Adaptor = ensBaseadaptorNew(
2187 dba,
2188 attributetypeadaptorKTablenames,
2189 attributetypeadaptorKColumnnames,
2190 (const EnsPBaseadaptorLeftjoin) NULL,
2191 (const char *) NULL,
2192 (const char *) NULL,
2193 &attributetypeadaptorFetchAllbyStatement);
2194
2195 /*
2196 ** NOTE: The cache cannot be initialised here because the
2197 ** attributetypeadaptorCacheInit function calls
2198 ** ensBaseadaptorFetchAllbyConstraint,
2199 ** which calls attributetypeadaptorFetchAllbyStatement, which calls
2200 ** ensRegistryGetAttributetypeadaptor. At that point, however, the
2201 ** Ensembl Attribute Type Adaptor has not been stored in the Registry.
2202 ** Therefore, each ensAttributetypeadaptorFetch function has to test the
2203 ** presence of the adaptor-internal cache and eventually initialise before
2204 ** accessing it.
2205 **
2206 ** attributetypeadaptorCacheInit(ata);
2207 */
2208
2209 return ata;
2210 }
2211
2212
2213
2214
2215 /* @section cache *************************************************************
2216 **
2217 ** Functions for maintaining the Ensembl Attribute Type Adaptor-internal
2218 ** cache of Ensembl Attribute Type objects.
2219 **
2220 ** @fdata [EnsPAttributetypeadaptor]
2221 **
2222 ** @nam3rule Cache Process an Ensembl Attribute Type Adaptor-internal cache
2223 ** @nam4rule Clear Clear the Ensembl Attribute Type Adaptor-internal cache
2224 **
2225 ** @argrule * ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
2226 **
2227 ** @valrule * [AjBool] True on success, ajFalse otherwise
2228 **
2229 ** @fcategory use
2230 ******************************************************************************/
2231
2232
2233
2234
2235 /* @funcstatic attributetypeadaptorCacheInit **********************************
2236 **
2237 ** Initialise the internal Attribute Type cache of an
2238 ** Ensembl Attribute Type Adaptor.
2239 **
2240 ** @param [u] ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
2241 **
2242 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2243 **
2244 ** @release 6.4.0
2245 ** @@
2246 ******************************************************************************/
2247
attributetypeadaptorCacheInit(EnsPAttributetypeadaptor ata)2248 static AjBool attributetypeadaptorCacheInit(EnsPAttributetypeadaptor ata)
2249 {
2250 AjBool result = AJFALSE;
2251
2252 AjPList ats = NULL;
2253
2254 EnsPAttributetype at = NULL;
2255
2256 if (ajDebugTest("attributetypeadaptorCacheInit"))
2257 ajDebug("attributetypeadaptorCacheInit\n"
2258 " ata %p\n",
2259 ata);
2260
2261 if (!ata)
2262 return ajFalse;
2263
2264 if (ata->CacheByIdentifier)
2265 return ajFalse;
2266 else
2267 {
2268 ata->CacheByIdentifier = ajTableuintNew(0U);
2269
2270 ajTableSetDestroyvalue(
2271 ata->CacheByIdentifier,
2272 (void (*)(void **)) &ensAttributetypeDel);
2273 }
2274
2275 if (ata->CacheByCode)
2276 return ajFalse;
2277 else
2278 {
2279 ata->CacheByCode = ajTablestrNew(0U);
2280
2281 ajTableSetDestroyvalue(
2282 ata->CacheByCode,
2283 (void (*)(void **)) &ensAttributetypeDel);
2284 }
2285
2286 ats = ajListNew();
2287
2288 result = ensBaseadaptorFetchAll(
2289 ensAttributetypeadaptorGetBaseadaptor(ata),
2290 ats);
2291
2292 while (ajListPop(ats, (void **) &at))
2293 {
2294 attributetypeadaptorCacheInsert(ata, &at);
2295
2296 /*
2297 ** Both caches hold internal references to the
2298 ** Ensembl attribute Type objects.
2299 */
2300
2301 ensAttributetypeDel(&at);
2302 }
2303
2304 ajListFree(&ats);
2305
2306 return result;
2307 }
2308
2309
2310
2311
2312 /* @funcstatic attributetypeadaptorCacheInsert ********************************
2313 **
2314 ** Insert an Ensembl Attribute Type into the
2315 ** Ensembl Attribute Type Adaptor-internal cache.
2316 ** If an Ensembl Attribute Type with the same code member is already present
2317 ** in the adaptor cache, the Ensembl Attribute Type is deleted and a pointer
2318 ** to the cached Ensembl Attribute Type is returned.
2319 **
2320 ** @param [u] ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
2321 ** @param [u] Pat [EnsPAttributetype*] Ensembl Attribute Type address
2322 **
2323 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2324 **
2325 ** @release 6.4.0
2326 ** @@
2327 ******************************************************************************/
2328
attributetypeadaptorCacheInsert(EnsPAttributetypeadaptor ata,EnsPAttributetype * Pat)2329 static AjBool attributetypeadaptorCacheInsert(EnsPAttributetypeadaptor ata,
2330 EnsPAttributetype *Pat)
2331 {
2332 ajuint *Pidentifier = NULL;
2333
2334 EnsPAttributetype at1 = NULL;
2335 EnsPAttributetype at2 = NULL;
2336
2337 if (!ata)
2338 return ajFalse;
2339
2340 if (!ata->CacheByIdentifier)
2341 return ajFalse;
2342
2343 if (!ata->CacheByCode)
2344 return ajFalse;
2345
2346 if (!Pat)
2347 return ajFalse;
2348
2349 if (!*Pat)
2350 return ajFalse;
2351
2352 /* Search the identifer cache. */
2353
2354 at1 = (EnsPAttributetype) ajTableFetchmodV(
2355 ata->CacheByIdentifier,
2356 (const void *) &((*Pat)->Identifier));
2357
2358 /* Search the code cache. */
2359
2360 at2 = (EnsPAttributetype) ajTableFetchmodS(
2361 ata->CacheByCode,
2362 (*Pat)->Code);
2363
2364 if ((!at1) && (!at2))
2365 {
2366 /* Insert into the identifier cache. */
2367
2368 AJNEW0(Pidentifier);
2369
2370 *Pidentifier = (*Pat)->Identifier;
2371
2372 ajTablePut(ata->CacheByIdentifier,
2373 (void *) Pidentifier,
2374 (void *) ensAttributetypeNewRef(*Pat));
2375
2376 /* Insert into the code cache. */
2377
2378 ajTablePut(ata->CacheByCode,
2379 (void *) ajStrNewS((*Pat)->Code),
2380 (void *) ensAttributetypeNewRef(*Pat));
2381 }
2382
2383 if (at1 && at2 && (at1 == at2))
2384 {
2385 ajDebug("attributetypeadaptorCacheInsert replaced "
2386 "Ensembl Attribute Type %p with "
2387 "one already cached %p.\n",
2388 *Pat, at1);
2389
2390 ensAttributetypeDel(Pat);
2391
2392 ensAttributetypeNewRef(at1);
2393
2394 Pat = &at1;
2395 }
2396
2397 if (at1 && at2 && (at1 != at2))
2398 ajDebug("attributetypeadaptorCacheInsert detected "
2399 "Ensembl Attribute Type objects in the "
2400 "identifier and code cache with identical codes "
2401 "('%S' and '%S') but different addresses (%p and %p).\n",
2402 at1->Code, at2->Code, at1, at2);
2403
2404 if (at1 && (!at2))
2405 ajDebug("attributetypeadaptorCacheInsert detected an "
2406 "Ensembl Attribute Type object in the identifier, "
2407 "but not in the code cache.\n");
2408
2409 if ((!at1) && at2)
2410 ajDebug("attributetypeadaptorCacheInsert detected an "
2411 "Ensembl Attribute Type object in the code, "
2412 "but not in the identifier cache.\n");
2413
2414 return ajTrue;
2415 }
2416
2417
2418
2419
2420 #if AJFALSE
2421 /* @funcstatic attributetypeadaptorCacheRemove ********************************
2422 **
2423 ** Remove an Ensembl Attribute Type from the
2424 ** Ensembl Attribute Type Adaptor-internal cache.
2425 **
2426 ** @param [u] ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
2427 ** @param [u] at [EnsPAttributetype] Ensembl Attribute Type
2428 **
2429 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2430 **
2431 ** @release 6.4.0
2432 ** @@
2433 ******************************************************************************/
2434
attributetypeadaptorCacheRemove(EnsPAttributetypeadaptor ata,EnsPAttributetype at)2435 static AjBool attributetypeadaptorCacheRemove(EnsPAttributetypeadaptor ata,
2436 EnsPAttributetype at)
2437 {
2438 EnsPAttributetype at1 = NULL;
2439 EnsPAttributetype at2 = NULL;
2440
2441 if (!ata)
2442 return ajFalse;
2443
2444 if (!at)
2445 return ajFalse;
2446
2447 at1 = (EnsPAttributetype) ajTableRemove(
2448 ata->CacheByIdentifier,
2449 (const void *) &at->Identifier);
2450
2451 at2 = (EnsPAttributetype) ajTableRemove(
2452 ata->CacheByCode,
2453 (const void *) at->Code);
2454
2455 if (at1 && (!at2))
2456 ajWarn("attributetypeadaptorCacheRemove could remove "
2457 "Ensembl Attribute Type with "
2458 "identifier %u and code '%S' only from the identifier cache.\n",
2459 at->Identifier,
2460 at->Code);
2461
2462 if ((!at1) && at2)
2463 ajWarn("attributetypeadaptorCacheRemove could remove "
2464 "Ensembl Attribute Type with "
2465 "identifier %u and code '%S' only from the code cache.\n",
2466 at->Identifier,
2467 at->Code);
2468
2469 ensAttributetypeDel(&at1);
2470 ensAttributetypeDel(&at2);
2471
2472 return ajTrue;
2473 }
2474
2475 #endif /* AJFALSE */
2476
2477
2478
2479
2480 /* @func ensAttributetypeadaptorCacheClear ************************************
2481 **
2482 ** Clear the Ensembl Attribute Type Adaptor-internal cache of
2483 ** Ensembl Attribute Type objects.
2484 **
2485 ** @param [u] ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
2486 **
2487 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2488 **
2489 ** @release 6.4.0
2490 ** @@
2491 ******************************************************************************/
2492
ensAttributetypeadaptorCacheClear(EnsPAttributetypeadaptor ata)2493 AjBool ensAttributetypeadaptorCacheClear(EnsPAttributetypeadaptor ata)
2494 {
2495 if (!ata)
2496 return ajFalse;
2497
2498 ajTableDel(&ata->CacheByIdentifier);
2499 ajTableDel(&ata->CacheByCode);
2500
2501 return ajTrue;
2502 }
2503
2504
2505
2506
2507 /* @section destructors *******************************************************
2508 **
2509 ** Destruction destroys all internal data structures and frees the memory
2510 ** allocated for an Ensembl Attribute Type Adaptor object.
2511 **
2512 ** @fdata [EnsPAttributetypeadaptor]
2513 **
2514 ** @nam3rule Del Destroy (free) an Ensembl Attribute Type Adaptor
2515 **
2516 ** @argrule * Pata [EnsPAttributetypeadaptor*]
2517 ** Ensembl Attribute Type Adaptor address
2518 **
2519 ** @valrule * [void]
2520 **
2521 ** @fcategory delete
2522 ******************************************************************************/
2523
2524
2525
2526
2527 /* @func ensAttributetypeadaptorDel *******************************************
2528 **
2529 ** Default destructor for an Ensembl Attribute Type Adaptor.
2530 **
2531 ** This function also clears the internal caches.
2532 **
2533 ** Ensembl Object Adaptors are singleton objects that are registered in the
2534 ** Ensembl Registry and weakly referenced by Ensembl Objects that have been
2535 ** instantiated by it. Therefore, Ensembl Object Adaptors should never be
2536 ** destroyed directly. Upon exit, the Ensembl Registry will call this function
2537 ** if required.
2538 **
2539 ** @param [d] Pata [EnsPAttributetypeadaptor*]
2540 ** Ensembl Attribute Type Adaptor address
2541 **
2542 ** @return [void]
2543 **
2544 ** @release 6.4.0
2545 ** @@
2546 ******************************************************************************/
2547
ensAttributetypeadaptorDel(EnsPAttributetypeadaptor * Pata)2548 void ensAttributetypeadaptorDel(EnsPAttributetypeadaptor *Pata)
2549 {
2550 EnsPAttributetypeadaptor pthis = NULL;
2551
2552 if (!Pata)
2553 return;
2554
2555 #if defined(AJ_DEBUG) && AJ_DEBUG >= 1
2556 if (ajDebugTest("ensAttributetypeadaptorDel"))
2557 ajDebug("ensAttributetypeadaptorDel\n"
2558 " *Pata %p\n",
2559 *Pata);
2560 #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */
2561
2562 if (!(pthis = *Pata))
2563 return;
2564
2565 ajTableDel(&pthis->CacheByIdentifier);
2566 ajTableDel(&pthis->CacheByCode);
2567
2568 ensBaseadaptorDel(&pthis->Adaptor);
2569
2570 ajMemFree((void **) Pata);
2571
2572 return;
2573 }
2574
2575
2576
2577
2578 /* @section member retrieval **************************************************
2579 **
2580 ** Functions for returning members of an
2581 ** Ensembl Attribute Type Adaptor object.
2582 **
2583 ** @fdata [EnsPAttributetypeadaptor]
2584 **
2585 ** @nam3rule Get Return Ensembl Attribute Type Adaptor attribute(s)
2586 ** @nam4rule Baseadaptor Return the Ensembl Base Adaptor
2587 ** @nam4rule Databaseadaptor Return the Ensembl Database Adaptor
2588 **
2589 ** @argrule * ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
2590 **
2591 ** @valrule Baseadaptor [EnsPBaseadaptor]
2592 ** Ensembl Base Adaptor or NULL
2593 ** @valrule Databaseadaptor [EnsPDatabaseadaptor]
2594 ** Ensembl Database Adaptor or NULL
2595 **
2596 ** @fcategory use
2597 ******************************************************************************/
2598
2599
2600
2601
2602 /* @func ensAttributetypeadaptorGetBaseadaptor ********************************
2603 **
2604 ** Get the Ensembl Base Adaptor member of an
2605 ** Ensembl Attribute Type Adaptor.
2606 **
2607 ** @param [u] ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
2608 **
2609 ** @return [EnsPBaseadaptor] Ensembl Base Adaptor or NULL
2610 **
2611 ** @release 6.4.0
2612 ** @@
2613 ******************************************************************************/
2614
ensAttributetypeadaptorGetBaseadaptor(EnsPAttributetypeadaptor ata)2615 EnsPBaseadaptor ensAttributetypeadaptorGetBaseadaptor(
2616 EnsPAttributetypeadaptor ata)
2617 {
2618 return (ata) ? ata->Adaptor : NULL;
2619 }
2620
2621
2622
2623
2624 /* @func ensAttributetypeadaptorGetDatabaseadaptor ****************************
2625 **
2626 ** Get the Ensembl Database Adaptor member of an
2627 ** Ensembl Attribute Type Adaptor.
2628 **
2629 ** @param [u] ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
2630 **
2631 ** @return [EnsPDatabaseadaptor] Ensembl Database Adaptor or NULL
2632 **
2633 ** @release 6.4.0
2634 ** @@
2635 ******************************************************************************/
2636
ensAttributetypeadaptorGetDatabaseadaptor(EnsPAttributetypeadaptor ata)2637 EnsPDatabaseadaptor ensAttributetypeadaptorGetDatabaseadaptor(
2638 EnsPAttributetypeadaptor ata)
2639 {
2640 return ensBaseadaptorGetDatabaseadaptor(
2641 ensAttributetypeadaptorGetBaseadaptor(ata));
2642 }
2643
2644
2645
2646
2647 /* @section object retrieval **************************************************
2648 **
2649 ** Functions for fetching Ensembl Attribute Type objects from an
2650 ** Ensembl SQL database.
2651 **
2652 ** @fdata [EnsPAttributetypeadaptor]
2653 **
2654 ** @nam3rule Fetch Fetch Ensembl Attribute Type object(s)
2655 ** @nam4rule All Fetch all Ensembl Attribute Type objects
2656 ** @nam4rule Allby
2657 ** Fetch all Ensembl Attribute Type objects matching a criterion
2658 ** @nam4rule By Fetch one Ensembl Attribute Type object matching a criterion
2659 ** @nam5rule Code Fetch by a code
2660 ** @nam5rule Identifier Fetch by an SQL database internal identifier
2661 **
2662 ** @argrule * ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
2663 ** @argrule All ats [AjPList] AJAX List of Ensembl Attribute Type objects
2664 ** @argrule ByCode code [const AjPStr] Ensembl Attribute Type code
2665 ** @argrule ByCode Pat [EnsPAttributetype*] Ensembl Attribute Type address
2666 ** @argrule ByIdentifier identifier [ajuint] SQL database-internal identifier
2667 ** @argrule ByIdentifier Pat [EnsPAttributetype*]
2668 ** Ensembl Attribute Type address
2669 **
2670 ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
2671 **
2672 ** @fcategory use
2673 ******************************************************************************/
2674
2675
2676
2677
2678 /* @funcstatic attributetypeadaptorFetchAll ***********************************
2679 **
2680 ** An ajTableMap "apply" function to return all Ensembl Attribute Type objects
2681 ** from the Ensembl Attribute Type Adaptor-internal cache.
2682 **
2683 ** @param [u] key [const void*] AJAX unsigned integer key data address
2684 ** @param [u] Pvalue [void**] Ensembl Attribute Type value data address
2685 ** @param [u] cl [void*]
2686 ** AJAX List of Ensembl Attribute Type objects, passed in via ajTableMap
2687 ** @see ajTableMap
2688 **
2689 ** @return [void]
2690 **
2691 ** @release 6.4.0
2692 ** @@
2693 ******************************************************************************/
2694
attributetypeadaptorFetchAll(const void * key,void ** Pvalue,void * cl)2695 static void attributetypeadaptorFetchAll(const void *key,
2696 void **Pvalue,
2697 void *cl)
2698 {
2699 if (!key)
2700 return;
2701
2702 if (!Pvalue)
2703 return;
2704
2705 if (!*Pvalue)
2706 return;
2707
2708 if (!cl)
2709 return;
2710
2711 ajListPushAppend((AjPList) cl,
2712 (void *) ensAttributetypeNewRef(
2713 *((EnsPAttributetype *) Pvalue)));
2714
2715 return;
2716 }
2717
2718
2719
2720
2721 /* @func ensAttributetypeadaptorFetchAll **************************************
2722 **
2723 ** Fetch all Ensembl Attribute Type objects.
2724 **
2725 ** The caller is responsible for deleting the Ensembl Attribute Type objects
2726 ** before deleting the AJAX List object.
2727 **
2728 ** @param [u] ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
2729 ** @param [u] ats [AjPList] AJAX List of Ensembl Attribute Type objects
2730 **
2731 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2732 **
2733 ** @release 6.4.0
2734 ** @@
2735 ******************************************************************************/
2736
ensAttributetypeadaptorFetchAll(EnsPAttributetypeadaptor ata,AjPList ats)2737 AjBool ensAttributetypeadaptorFetchAll(EnsPAttributetypeadaptor ata,
2738 AjPList ats)
2739 {
2740 if (!ata)
2741 return ajFalse;
2742
2743 if (!ats)
2744 return ajFalse;
2745
2746 if (!ata->CacheByIdentifier)
2747 attributetypeadaptorCacheInit(ata);
2748
2749 ajTableMap(ata->CacheByIdentifier,
2750 &attributetypeadaptorFetchAll,
2751 (void *) ats);
2752
2753 return ajTrue;
2754 }
2755
2756
2757
2758
2759 /* @func ensAttributetypeadaptorFetchByCode ***********************************
2760 **
2761 ** Fetch an Ensembl Attribute Type by its code.
2762 **
2763 ** The caller is responsible for deleting the Ensembl Attribute Type.
2764 **
2765 ** @param [u] ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
2766 ** @param [r] code [const AjPStr] Ensembl Attribute Type code
2767 ** @param [wP] Pat [EnsPAttributetype*] Ensembl Attribute Type address
2768 **
2769 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2770 **
2771 ** @release 6.4.0
2772 ** @@
2773 ******************************************************************************/
2774
ensAttributetypeadaptorFetchByCode(EnsPAttributetypeadaptor ata,const AjPStr code,EnsPAttributetype * Pat)2775 AjBool ensAttributetypeadaptorFetchByCode(EnsPAttributetypeadaptor ata,
2776 const AjPStr code,
2777 EnsPAttributetype *Pat)
2778 {
2779 char *txtcode = NULL;
2780
2781 AjBool result = AJFALSE;
2782
2783 AjPList ats = NULL;
2784
2785 AjPStr constraint = NULL;
2786
2787 EnsPAttributetype at = NULL;
2788
2789 EnsPBaseadaptor ba = NULL;
2790
2791 if (!ata)
2792 return ajFalse;
2793
2794 if (!(code && ajStrGetLen(code)))
2795 return ajFalse;
2796
2797 if (!Pat)
2798 return ajFalse;
2799
2800 /*
2801 ** Initially, search the name cache.
2802 ** For any object returned by the AJAX Table the reference counter needs
2803 ** to be incremented manually.
2804 */
2805
2806 if (!ata->CacheByCode)
2807 attributetypeadaptorCacheInit(ata);
2808
2809 *Pat = (EnsPAttributetype) ajTableFetchmodV(ata->CacheByCode,
2810 (const void *) code);
2811
2812 if (*Pat)
2813 {
2814 ensAttributetypeNewRef(*Pat);
2815
2816 return ajTrue;
2817 }
2818
2819 /* In case of a cache miss, re-query the database. */
2820
2821 ba = ensAttributetypeadaptorGetBaseadaptor(ata);
2822
2823 ensBaseadaptorEscapeC(ba, &txtcode, code);
2824
2825 constraint = ajFmtStr("attrib_type.code = '%s'", txtcode);
2826
2827 ajCharDel(&txtcode);
2828
2829 ats = ajListNew();
2830
2831 result = ensBaseadaptorFetchAllbyConstraint(
2832 ba,
2833 constraint,
2834 (EnsPAssemblymapper) NULL,
2835 (EnsPSlice) NULL,
2836 ats);
2837
2838 if (ajListGetLength(ats) > 1)
2839 ajWarn("ensAttributetypeadaptorFetchByCode got more than one "
2840 "Ensembl Attribute Type for (UNIQUE) code '%S'.\n",
2841 code);
2842
2843 ajListPop(ats, (void **) Pat);
2844
2845 attributetypeadaptorCacheInsert(ata, Pat);
2846
2847 while (ajListPop(ats, (void **) &at))
2848 {
2849 attributetypeadaptorCacheInsert(ata, &at);
2850
2851 ensAttributetypeDel(&at);
2852 }
2853
2854 ajListFree(&ats);
2855
2856 ajStrDel(&constraint);
2857
2858 return result;
2859 }
2860
2861
2862
2863
2864 /* @func ensAttributetypeadaptorFetchByIdentifier *****************************
2865 **
2866 ** Fetch an Ensembl Attribute Type by its SQL database-internal identifier.
2867 ** The caller is responsible for deleting the Ensembl Attribute Type.
2868 **
2869 ** @param [u] ata [EnsPAttributetypeadaptor] Ensembl Attribute Type Adaptor
2870 ** @param [r] identifier [ajuint] SQL database-internal identifier
2871 ** @param [wP] Pat [EnsPAttributetype*] Ensembl Attribute Type address
2872 **
2873 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
2874 **
2875 ** @release 6.4.0
2876 ** @@
2877 ******************************************************************************/
2878
ensAttributetypeadaptorFetchByIdentifier(EnsPAttributetypeadaptor ata,ajuint identifier,EnsPAttributetype * Pat)2879 AjBool ensAttributetypeadaptorFetchByIdentifier(EnsPAttributetypeadaptor ata,
2880 ajuint identifier,
2881 EnsPAttributetype *Pat)
2882 {
2883 AjBool result = AJFALSE;
2884
2885 if (!ata)
2886 return ajFalse;
2887
2888 if (!identifier)
2889 return ajFalse;
2890
2891 if (!Pat)
2892 return ajFalse;
2893
2894 /*
2895 ** Initially, search the identifier cache.
2896 ** For any object returned by the AJAX Table the reference counter needs
2897 ** to be incremented manually.
2898 */
2899
2900 if (!ata->CacheByIdentifier)
2901 attributetypeadaptorCacheInit(ata);
2902
2903 *Pat = (EnsPAttributetype) ajTableFetchmodV(ata->CacheByIdentifier,
2904 (const void *) &identifier);
2905
2906 if (*Pat)
2907 {
2908 ensAttributetypeNewRef(*Pat);
2909
2910 return ajTrue;
2911 }
2912
2913 /* For a cache miss re-query the database. */
2914
2915 result = ensBaseadaptorFetchByIdentifier(
2916 ensAttributetypeadaptorGetBaseadaptor(ata),
2917 identifier,
2918 (void **) Pat);
2919
2920 attributetypeadaptorCacheInsert(ata, Pat);
2921
2922 return result;
2923 }
2924