*** empty log message ***

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@14993 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Mirko Viviani 2002-11-15 22:57:05 +00:00
commit bf5ba60b07
165 changed files with 62782 additions and 0 deletions

4
AUTHORS Normal file
View file

@ -0,0 +1,4 @@
Mirko Viviani <mirko.viviani@rccr.cremona.it>
Gerald Siebke <gerald@turbocat.de>
Manuel Guesdon <mguesdon@orange-concept.com>
David Ayers <d.ayers@inode.at>

481
COPYING.LIB Normal file
View file

@ -0,0 +1,481 @@
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, while the latter only
works together with the library.
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

751
ChangeLog Normal file
View file

@ -0,0 +1,751 @@
2002-11-14 Manuel Guesdon <mguesdon@orange-concept.com>
* EOAcces/EODatabaseDataSource.m:
o corrected bug in -description
* EOAdaptors/Postgres95/Postgres95SQLExpression.m
o change in +formatValue:forAttribute: to handle string value for dates
2002-11-14 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAdaptors/*, EOAccess/*, EOControl/*: removed some warnings.
2002-11-13 Manuel Guesdon <mguesdon@orange-concept.com>
* EOAcces/EODatabaseContext.m:
o corrected bug
o logs
* EOAccess/EODatabaseOperation.m:
o -setDatabaseOperator: change to not update deleted objetcs
* EOAccess/EOEntity.m:
o -_attributesToFetch added exception handling
* EOAccess/EOSQLExpression:
o use sqlExpressionWithEntity instead of alloc/init
* EOControl/EOEditingContext.m:
o _processOwnedObjectsUsingChangeTable:deleteTable:
bug correction in new/existing value handling
o doc
* EOControl/EOGenericRecord.m:
o log changes
* EOControl/EOKeyValueCoding.m:
o added -takeStoredValue:forKeyPath:
o added -storedValuesForKeyPaths:
o corrected bug in NSArray -valueForKey:
o corrected bugs in NSArray -valueForKeyPath:
* EOAccess/EOUtilities.m
o handle nil value in rawRowsMatchingValue:forKey:entityNamed:
o handle nil value in objectsMatchingValue:forKey:entityNamed:
o handle nil value in objectWithPrimaryKeyValue:entityNamed:
* EOAccess/EOAttribute.m
o destroy docComment in -dealloc
* EOAdaptors/Postgres98/Postgres95Values.m:
o comment
o use stringWithCString.. instead of alloc/init/release
* EOControl/EOMultipleKnownKeyDictionary.h
o added -debugDescription
* EOControl/EONull.m:
o added -NSNull -valueForKey:
* EOAccess/EOQualifier.m:
o in getKey: autorelease key
o in -qualifierWithQualifierFormat:varargList:
user [NSMutableArray array] instead [NSMutableArray new]/DESTROY
to avoid memory leak if an exception is raised
2002-11-04 David Ayers <d.ayers@inode.at>
* EOControl/EOSortOrdering.m:
o changed -sortedArrayUsingKeyOrderArray:
* EOControl/EOQualifier.m:
o improved -qualifierWithQualifierFormat: parsing
2002-10-31 David Ayers <d.ayers@inode.at>
* EOControl/EOQualifier.m:
o improved -qualifierWithQualifierFormat: parsing
o added NSNumber -initWithString as EOQualiferExtra
* EOControl/EOKeyValueQualifier.m:
o changed -description
* EOControl/EOKeyComparisonQualifier.m:
o changed -description
2002-09-22 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* Makefile.postamble: install gdl2.make.
2002-09-22 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* configure.ac: added adaptors configuration.
* config/postgres.m4: check for postgres db.
* EOAdaptors/Postgres95/GNUmakefile.in: new file.
* EOAdaptors/Postgres95/Makefile.preamble.in: new file.
2002-09-20 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* configure.ac: new file.
* gdl2.make.in: new file.
* config.h.in: new file.
2002-09-20 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* Indented all the sources and removed many warnings.
* Moved EOCheapArray.m|h, EONSAddOns.m|h and EODebug.m|h to EOControl.
* Moved EOUtilities.m|h to EOAccess.
* Moved EOQualifierSQLGeneration in EOAccess/EOSQLQualifier
2002-06-03 Manuel Guesdon <mguesdon@orange-concept.com>
* EOAdaptors/Postgres95/Postgres95SQLExpression.m:
o NSWarn -> NSWarnLog
* EOControl/EOKeyValueArchiver.m:
o added -isThereValueForKey: in EOKeyValueUnarchiver
* EOControl/EOKeyValueArchiver.h:
o added -isThereValueForKey: in EOKeyValueUnarchiver
* EOControl/EOSQLExpression.m:
o changes for usesDistincts
o logs
* EOAccess/EODatabaseChannel.m:
o fix for refetched objects
* EOAccess/EODatabaseContext.m:
o fixes in recordChangesInEditingContext
* EOAccess/EODatabaseDataSource.m:
o logs
* EOAccess/EONSAddOns.h/.m
o added NSArray -arrayExcludingObject:
o added NSArray -containsIdenticalObjectsWithArray:
* EOAccess/EORelationship.h/.m:
o added isBidirectional: and associated methods (for use with smartTakeValue:forKey:)
* EOControl/EOClassDescription.h/.m:
o added -relationshipNamed:
o added -anyRelationshipNamed:
* EOControl/EOGenericRecord.m:
o added -smartTakeValue:forKey:
* EOControl/EOObjectStoreCoordinator.m:
o logs
2002-05-14 Manuel Guesdon <mguesdon@orange-concept.com>
* EOControl/EOEditingContext.m:
o changes in -saveChangesInEditingContext: to avoid return in the middle of the method
o logs
* EOAccess/EODatabaseContext.m:
o add rollbackChanges on exception in -saveChangesInEditingContext:
o corrected bug in initializeObject:row:entity:editingContext:
o logs
* EOControl/EOKeyValueQualifier.m:
o implementation of flatten case in -schemaBasedQualifierWithRootEntity:
o logs
* EOControl/EODetailDataSource.m
o correct bugs by using -decodeObjectForKey: in -initWithKeyValueUnarchiver:
o changed _masterEntityName to _masterClassDescriptionName
o added -classDescriptionForObjects
o logs
* EOControl/EODetailDataSource.h:
o changed _masterEntityName to _masterClassDescriptionName
o added -classDescriptionForObjects
* EOControl/EODataSource.m:
o logs
* EOControl/EOGenericRecord.m:
o added -willChange call in _setValueForKey:object:selector:type:size:offset:
* EOControl/EOMutableKnownKeyDictionary.m:
o corrected bug in -containsObjectsNotIdenticalTo:
o logs
* EOAccess/EOSQLExpression.m:
o logs
* EOAdaptors/Postgres95/Postgres95SQLExpression.m:
o logs
o corrected bugs for empty strings in +formatValue:forAttribute:
* EOAccess/EODatabaseDataSource.m
o logs
* EOAccess/EOEntity.m
o logs
* EOControl/EOQualifier.m:
o logs
* EOControl/EOOrQualifier.m:
o logs
* EOControl/EOAndQualifier.m:
o logs
* EOControl/EOObserver.m:
o logs
* EOAccess/EODatabase.m:
o logs
o avoid fault access in -entityForObject:
2002-04-15 Manuel Guesdon <mguesdon@orange-concept.com>
* EOAccess/EOFetchSpecification.m:
o changed -fetchSpecification into +fetchSpecification
* EOAccess/EOKeyValueCoding.m:
o logs
o corrected bug: added special case "count" in NSArray -valueForKeyPath:
* EOAccess/EOGenericRecord.m:
o logs
* EOControl/EODetailDataSource.h:
o added -initWithKeyValueUnarchiver:
* EOControl/EODetailDataSource.m:
o added -initWithKeyValueUnarchiver:
* EOControl/EOKeyValueArcher.m:
o added EOKeyValueArchivingContainer +keyValueArchivingContainer
o corrected not autorelease bug in -_objectForPropertyList:
o logs
* EOControl/EODatabaseDataSource.m:
o logs
2002-04-01 Manuel Guesdon <mguesdon@orange-concept.com>
* EOAccess/EOModel.h:
o added +version
* EOAccess/EOStoredProcedure.h:
o added +storedProcedureWithPropertyList:owner:
* EOAccess/EOEntity.h:
o added +entityWithPropertyList:owner:
o added -setDocComment:
o added +entityClassDescriptionWithEntity:
* EOAccess/EOEntity.m:
o corrected bug in _keyMapForIdenticalKeyRelationshipPath: (dictionary construction)
* EOAccess/EOEntityPriv.h:
o retyped -_parseDescription:isFormat:arguments:;
* EOAccess/EORelationship.h:
o added +relationshipWithPropertyList:owner:
* EOAccess/EOAttribute.h:
o added +attributeWithPropertyList:owner:
o added -setInternalInfo:
o added -_normalizeDefinition:path:
* EOAccess/EOAttribute.m:
o use an id instead of a string for userInfo,...
o added -setInternalInfo:
* EOAccess/EOExpressionArray.h:
o added -valueForSQLExpression:
2002-04-01 Manuel Guesdon <mguesdon@orange-concept.com>
* EOControl/EODetailDataSource.h/.m:
o added +detailDataSourceWithMasterDataSource:detailKey:
* EOAccess/EODatbaseDataSource.m:
o changed allocations
* EOAccess/EODatabase.m:
o changed allocations
* EOAccess/EOEntity.m:
o changed allocations
o corrected not autorelease bug in EOEntity -classDescriptionForInstances
* EOControl/EOGlobalID.h/.m:
o added EOTemporaryGlobalID +temporaryGlobalID
* EOControl/EIEditingContext.m:
o changed allocations
* EOControl/EOKeyValueQualifier.m:
o changed allocations
* EOControl/EOObjectStoreCoordinator.m:
o changed allocations
* EOKeyComparisonQualifier.m:
o added +qualifierWithLeftKey:operatorSelector:rightKey:
* EONotQualifier.m:
o added +qualifierWithQualifier:
* EOQualifier.m:
o changed allocations
* EOAccess/EOAdaptorContext.h/.m:
o added +adaptorContextWithAdaptor:
* EOAdaptors/Postgres95/Postgres9Adaptor.m:
o changed allocations
* EOAdaptors/Postgres95/Postgres9Channel.m:
o changed allocations
* EOAdaptors/Postgres95/Postgres9Context.m:
o changed allocations
* EOAccess/EOModel.h/.m:
o added +model
* EOAccess/EOAdaptorChannel.h/.m
o added +adaptorChannelWithAdaptorContext:
* EOAdaptors/Postgres95/Postgres9Values.m:
o changed allocations
2002-03-29 Manuel Guesdon <mguesdon@orange-concept.com>
* EOAccess/EODatabaseOperation.m
o logs
* EOAccess/EODatabaseContext.h/.m
o logs
o added +databaseContextWithDatabase:
o change allocations
* EOAccess/EORelationship.m
o logs
o corrected not autorelease bug in _foreignKeyForSourceRow:
o added +relationshipWithPropertyList:owner:
* EOAccess/EOJoin.h/.m:
o added +joinWithSourceAttribute:destinationAttribute:
* EOAccess/EOSQLExpression.m:
o added +sqlExpressionWithEntity:
* EOAccess/EOAttribute.m:
o added +attributeWithPropertyList:owner:
* EOAdaptors/Postgres95/Postgres95Channel.m
o logs
* EOAccess/EODatabaseChannel.m
o logs
o added +databaseChannelWithDatabaseContext:
* EOAccess/EOFault.m:
o logs
* EOAccess/EOFetchSpecification.m/.h
o added +fetchSpecification
* EOControl/EOUtilities.m:
o corrected not autorelease bug in -objectsMatchingValues:entityNamed:
o change qualifiers allocations
* EOAccess/EOAndQualifier.m:
o added EOAndQualifier +qualifierWithQualifierArray:
o added EOAndQualifier +qualifierWithQualifiers:
* EOAccess/EOOrQualifier.m:
o added EOOrQualifier +qualifierWithQualifierArray:
* EOAccess/EOQualifier.h
o added EOAndQualifier +qualifierWithQualifierArray:
o added EOOrQualifier +qualifierWithQualifierArray:
* EOAccess/EOEntity.m:
o changed EOMutableKnownKeyDictionary allocation in -_dictionaryForProperties
* EOAccess/EOMutableKnownKeyDictionary.h/.m:
o added +dictionaryFromDictionary:subsetMapping:
* EOAccess/EOModel.h/.m
o added +modelWithContentsOfFile:
o corrected not autorelease bug
o allocation changes
* EOAccess/EOModelGroup.m:
o Changed EOModel allocation
* EOAccess/EODatabase.h/.m:
o added +databaseWithModel:
* EOAccess/EOAccessFault.h/.m
o added EOAccessFaultHandler +accessFaultHandlerWithGlobalID:databaseContext:editingContext:
o added EOAccessArrayFaultHandler
+accessArrayFaultHandlerWithSourceGlobalID:relationshipName:databaseContext:editingContext:
* EOAccess/EODatabaseOperation.h/.m:
o added EODatabaseOperation +databaseOperationWithGlobalID:object:entity:
* EOAccess/EOAdaptorOperation.h/.m:
o added EOAdaptorOperation +adaptorOperationWithEntity:
* EOAccess/EODatabaseDataSource.m:
o allocation changes
* EOAccess/EOStoredProcedure.m:
o corrected not autorelease bug in -initWithPropertyList:owner:
2002-03-28 Manuel Guesdon <mguesdon@orange-concept.com>
* EOAccess/EODatabaseChannel.m
o removed logs
o changed logs
* EOAdaptors/Postgres95/Postgres95Channel.m
o removed logs
* EOAccess/EORelationship.m:
o NSAssert
o added _docComment and associated methods
* EOAccess/EORelationship.h:
o added _docComment and associated methods
* EOAccess/EOSQLExpression.m:
o NSAssert
o logs
* EOAccess/EOEntity.m:
o doc
o logs
o added _docComment and associated methods
* EOAccess/EOEntity.h:
o added _docComment and associated methods
* EOAccess/EOModel.h/.m:
o added -adaptorClassname
o added _version and -version
o added _docComment and associated methods
* EOAccess/EOAttribute.h/.m:
o added _docComment and associated methods
* EOAccess/EOAdaptorChannel.m
o logs
* EOAdaptors/Postgres95/Postgres95SQLExpression.m:
o corrected bug in formatValue:forAttribute:
* added Tools/
2002-03-25 Manuel Guesdon <mguesdon@orange-concept.com>
* EOAccess/GNUmakefile:
o removed -SystemProjects System
o added -Declared EOAccess
* EOControl/GNUmakefile:
o removed -SystemProjects System
o added -Declared EOControl
* EOAdaptors/Postgres95/GNUmakefile:
o removed -SystemProjects System
o added -Declared EOAdaptors/PostgreSQL
* EOControl/EOGenericRecord.m: logs
* EOAccess/EODebug.h: added EOFLOGClassFnStartCond EOFLOGClassFnStopCond
* EOAccess/EODatabaseChannel.m: logs
* EOAccess/EORelationship.m:
o setDefinition
o corrected bug in _makeFlattenedInverseRelationship
* EOAccess/EOEntity.m
o logs
* EOControl/EOQualifier.h
o added qualifierWithKey:operatorSelector:value:
* EOControl/EOKeyValueQualifier.m:
o added qualifierWithKey:operatorSelector:value:
* EOAccess/EOModel.m:
o removed assert for non EOGenericRecord class in -_classDescriptionNeeded:
2002-03-07 Manuel Guesdon <mguesdon@orange-concept.com>
Too much changes
2001-04-10 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EOSQLExpression.m ([EOSQLExpression
+foreignKeyConstraintStatementsForRelationship:]): implemented.
2001-04-07 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOControl/EOKeyValueCoding.m: import EOControl.h
* EOControl/EONull.m: likewise.
* EOAccess/EOModel.m ([EOModel -writeToFile:]): implemented.
([EOModel -encodeTableOfContentsInfoPropertyList:]): implemented.
* EOAccess/EORelationship.m ([EORelationship -setEntity:]): remove self
from previous entity.
([EORelationship -setDefinition:]): remove joins.
2001-01-12 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOModeler: new library.
* EOModeler/EOModelExtensions.m/.h: EOModeler categories needed by
eogenerator.
* EOControl/EOKeyValueCoding.m ([NSArray -valueForKey:]): fixed @x key.
2001-01-06 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOControl/EOControl.h: defined FOUNDATION_HAS_KVC to use Foundation
key value coding.
* EOAccess/EOAttribute.m ([EOAttribute
-adaptorValueByConvertingAttributeValue:]): use EONull null object.
* EOAccess/EOSQLExpression.m ([EOSQLExpression -sqlStringForSelector:
value:]): likewise.
* EOControl/EOKeyValueCoding.m ([NSObject -takeValuesFromDictionary:]):
([NSObject -takeStoredValuesFromDictionary:]): likewise.
defined FOUNDATION_HAS_KVC to use Foundation key value coding.
2001-01-03 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EODatabaseContext.m ([EODatabaseContext
-faultForGlobalID:editingContext:]): use the correct class property
array.
2000-12-23 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EOEntity.m ([EOEntity -isPrimaryKeyValidInObject:]): fixed.
Do not returns from inside an exception handler.
* EOAccess/EODatabaseContext.m ([EODatabaseContext
-prepareForSaveWithCoordinator:editingContext:]): bug fix. Do not
release an autoreleased object.
* EOAccess/EODatabaseDataSource.m ([EODatabaseDataSource
-fetchSpecificationForFetch]): fixed fetch qualifier.
* EOControl/EOKeyValueQualifier.m ([EOKeyValueQualifier
-copyWithZone:]): do not copy _value.
* EOControl/EOAndQualifier.m ([EOAndQualifier -copyWithZone:]): use
correct zone.
* EOControl/EOOrQualifier.m ([EOOrQualifier -copyWithZone:]): likewise.
* EOControl/EOKeyComparisonQualifier.m ([EOKeyComparisonQualifier
-copyWithZone:]): likewise.
2000-12-20 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EODatabaseContext.m ([EODatabaseContext
-_recordChangesForObjects:operator:]): create dbOperation with the
correct entity for to-many relationship objects.
2000-12-11 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EOModel.m ([EOModel -_registerClassDescForClass:]):
check for NULL _entitiesByClass
([EOModel -dealloc]): release _entitiesByClass
([EOModel -removeEntity:]): bug fix.
* EOAdaptors/Postgres95/Postgres95Channel.m ([Postgres
-_evaluateCommandsUntilAFetch]): raise an exception on error.
2000-12-10 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOControl/EOKeyValueCoding.m (newGetStoredBinding): fixed value of
class variable.
2000-12-09 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EOModel.m ([EOModel -_registerClassDescForClass:]): fixed
class description registration.
([EOModel -_registerClassDescForEntityName:]): likewise.
([EOModel -addEntity:]), ([EOModel -removeEntity:]): save EOEntity in
_entitiesByClass.
2000-12-08 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EODatabaseContext.m ([EODatabaseContext
-prepareForSaveWithCoordinator:editingContext:]): get the object value
if the key is a class property.
Added code to handle propagatesPrimaryKey for to many relationships.
Fixed code that merges pk values.
* EOControl/EOClassDescription.m ([EOClassDescription -awakeObject:
fromInsertionInEditingContext:]): use NSMutableArray for to many
relationships.
2000-12-08 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EODatabaseContext.m ([EODatabaseContext -faultForGlobalID:
editingContext:]): set only class property's object values.
([EODatabaseContext -faultForRawRow:entityNamed:editingContext:]):
likewise.
([EODatabaseContext -_recordChangesForObjects:operator:]): likewise.
([EODatabaseContext -batchFetchRelationship:forSourceObjects:
editingContext:]): get key value from snapshot rather than in the
object.
2000-12-06 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOControl/EOKeyValueCoding.m ([NSObject
-handleQueryWithUnboundKey:]): raise an EOUnknownKeyException with
the correct userInfo.
([NSObject -handleTakeValue:forUnboundKey:]): likewise.
* EOAccess/EOEntity.m ([EOEntity -isPrimaryKeyValidInObject:]):
check valueForKey: exception.
* EOControl/EOClassDescription.m ([NSObject -changesFromSnapshot:]):
check for EONull values as toMany relationship array.
* EOControl/EOEditingContext.m ([EOEditingContext
-processRecentChanges]): check for EONull values in dictionary.
* EOAccess/EOModel.m ([EOModel -initWithPropertyList:owner:]): check
for an exception in the entity awakeWithPropertyList method.
* EOAccess/EOJoin.m ([EOJoin -initWithSourceAttribute:
destinationAttribute:]): raise exception if source or destination is
nil.
2000-12-05 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EODatabaseChannel.m ([EODatabaseChannel -fetchObject]):
fixed refreshing objects.
* EOControl/EOKeyValueCoding.m ([NSArray -valueForKey:]): fixed array
and string selector.
* EOAccess/EOUtilities.m ([EOEditingContext -objectsForEntityNamed:]):
([EOEditingContext -primaryKeyForObject:]), ([EOEditingContext
-entityForObject:]): implemented.
* EOAccess/EODatabaseContext.m ([EODatabaseContext
-prepareForSaveWithCoordinator:editingContext:]): lock the database
context.
([EODatabaseContext -commitChanges]), ([EODatabaseContext
-rollbackChanges]): unlock the database context
([EODatabaseContext -registerLockedObjectWithGlobalID:]): fixed zone
size.
2000-12-04 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EODatabaseContext.m ([EODatabaseContext
-_recordChangesForObjects:operator:]): when updating relationship keys
look also in the object snapshot.
2000-12-03 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EOSQLExpression.m ([EOSQLExpression
-sqlStringForKeyValueQualifier:]): bug fix.
* EOAccess/EOUtilities.m ([EOEditingContext -objectsMatchingValue:
forKey:entityNamed:]): implemented.
2000-12-01 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EOUtilities.m/.h: new files.
* EOAccess/EOAccess.h: addes EOUtilities.h
2000-11-23 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOControl/EOEditingContext.m ([EOEditingContext
-initializeObject:withGlobalID:editingContext:]): ensure that the next
'willChange' notification will be processed for the initialized object.
* EOAccess/EOEntity.m ([EOEntity -globalIDForRow:]): fixed globalID
values order for compound PKs.
2000-11-22 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAccess/EODatabaseOperationPriv.h: new file.
* EOAccess/EODatabaseOperation.m ([EODatabaseOperation
-_setGlobalID:]): new method.
* EOAccess/EODatabaseContext.m ([EODatabaseContext
-prepareForSaveWithCoordinator:editingContext:]): fixed propagates
primary key code.
([EODatabaseContext -_recordChangesForObjects:operator:]): in toOne rel
discard PK to PK joins. Discard 'empty' toOne rels.
([EODatabaseContext -_setGlobalID:forDatabaseOperation:): new method.
It replaces the globalID for the gived operation.
* EOAccess/EORelationship.m ([EORelationship
-initWithPropertyList:owner:]): check for 'propagatesPrimaryKey'.
* EOAccess/EOSQLExpression.m ([EOSQLExpression
-addOrderByAttributeOrdering:]): use compare selector defines. Call
-sqlStringForAttributeNamed: for the sortOrdering key.
2000-11-19 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOControl/EOFault.m ([EOFault +makeObjectIntoFault:withHandler:]):
do not turn into fault the nil object.
* EOControl/EOEditingContext.m ([EOEditingContext
-refaultObject:withGlobalID:editingContext:]): does nothing if objects
is nil.
* EOAccess/EODatabaseContext.m ([EODatabaseContext
-refaultObject:withGlobalID:editingContext:]): likewise.
([EODatabaseContext -refaultObject:withGlobalID:editingContext:]): does
not remove the snapshot.
([EODatabaseChannel -fetchObject]): fix for refreshing object.
* EOControl/EOSortOrdering.m ([NSMutableArray
-_sortUsingKeyOrder:fromIndex:count:]): use defined value for compare
selectors. Fix when aValue or bValue are nil.
([EONull -compareAscending:]), ([EONull -compareDescending:]),
([EONull -compareCaseInsensitiveAscending:]): ([EONull
-compareCaseInsensitiveDescending:]): if value to be compared is be
treat it as EONull.
2000-11-18 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOControl/EOEditingContext.m ([EOEditingContext
-processRecentChanges]): get toOne and toMany keys from object instead
of the editingContext.
* EOAccess/EODatabaseContext.m ([EODatabaseContext
-_recordChangesForObjects:operator:]): new method. Fixed foreign key
update for inserted objects of toOne relationships. Fixed dictionary
and foreign key update for toMany relationships.
([EODatabaseContext -recordChangesInEditingContext]): moved code into
-_recordChangesForObjects:operator: and check changes also in inserted
objects.
([EODatabaseContext -_dbOperationWithObject:operator:]): new method.
Find db operation for the given object and operator.
([EODatabaseContext -commitChanges]), ([EODatabaseContext
-rollbackChanges]): reset ivars if no transaction in progress.
2000-11-16 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOControl/EOEditingContext.m ([EOEditingContext
-_handleObjectsChangedInStoreNotification:]): refault updated objects.
* EOAccess/EODatabaseChannel.m ([EODatabaseChannel -fetchObject]):
fixed notification for refreshed objects.
* EOAccess/EOSQLExpression.m ([EOSQLExpression
-sqlStringForAttribute:]): fix id attribute is derived.
* EOAccess/EOEntity.m ([EOEntity -setAttributesUsedForLocking:]): fix
release of the array when no valid attributes are found.
([EOEntity -setPrimaryKeyAttributes:]): likewise.
* EOAccess/EODatabase.m ([EODatabase -forgetSnapshotsForGlobalIDs:]):
([EODatabase -forgetSnapshotForGlobalID:]): use defined userInfo string
instead of an hardcoded one.
2000-11-05 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOControl/EOSortOrdering.m ([NSArray
-sortedArrayUsingKeyOrderArray:]): implemented.
([NSMutableArray -sortUsingKeyOrderArray:]): not fully implemented.
([NSMutableArray -_sortUsingKeyOrder:fromIndex:count:]): modified
gnustep-base shell sort.
([EOSortOrdering -initWithCoder:]): fixed.
([EONull -compareAscending:]): implemented.
([EONull -compareDescending:]): implemented.
([EONull -compareCaseInsensitiveAscending:]): implemented.
([EONull -compareCaseInsensitiveDescending:]): implemented.
* EOAdaptors/Postgres95/Postgres95Channel.m ([Postgres
-_describeResults]): does not coerce attribute className.
* EOAdaptors/Postgres95/Postgres95Values.m: fixed pg calendar format.
* EOAdaptors/Postgres95/Postgres95SQLExpression.m ([Postgres -assembleSelectStatementWithAttributes:lock:qualifier:fetchOrder:selectString:columnList:tableList:whereClause:joinClause:orderByClause:lockClause:]): does not return
mutableCopy of the string.
([Postgres +formatValue:forAttribute:]): implemented. Added code from
Turbocat's development.
* EOAccess/EOSQLExpression.m: does not return mutableCopy of a string.
([EOSQLExpression +formatValue:forAttribute:]): return value unchanged.
([EOSQLExpression -sqlStringForValue:attributeNamed:]): bug fix ?
moved code from +[formatValue:forAttribute:]
* EOControl/EOAndQualifier.m ([EOAndQualifier
-sqlStringForSQLExpression:]): doesn't return mutableCopy of a string.
* EOControl/EOOrQualifier.m ([EOOrQualifier
-sqlStringForSQLExpression:]): likewise.
* EOControl/EODetailDataSource.m ([EODetailDataSource
-initWithMasterClassDescription:detailKey:]): set
masterClassDescription.
* EOAccess/EOSQLExpression.m
([EOSQLExpression -addCreateClauseForAttribute:]):
([EOSQLExpression -allowsNullClauseForConstraint:]):
([EOSQLExpression -columnTypeStringForAttribute:]):
([EOSQLExpression +dropTableStatementsForEntityGroup:]):
([EOSQLExpression +createTableStatementsForEntityGroup:]):
([EOSQLExpression +primaryKeyConstraintStatementsForEntityGroup:]):
([EOSQLExpression +primaryKeySupportStatementsForEntityGroup:]):
([EOSQLExpression +dropPrimaryKeySupportStatementsForEntityGroup:]):
([EOSQLExpression +createTableStatementsForEntityGroups:]):
([EOSQLExpression +dropTableStatementsForEntityGroups:]):
([EOSQLExpression +primaryKeyConstraintStatementsForEntityGroups:]):
([EOSQLExpression +primaryKeySupportStatementsForEntityGroups:]):
([EOSQLExpression +dropPrimaryKeySupportStatementsForEntityGroups:]):
([EOSQLExpression +appendExpression:toScript:]):
([EOSQLExpression +schemaCreationScriptForEntities:options:]):
([EOSQLExpression +schemaCreationStatementsForEntities:options:]):
([EOSQLExpression -prepareConstraintStatementForRelationship:
sourceColumns:destinationColumns:]):
([EOSQLExpression +createDatabaseStatementsForConnectionDictionary:
administrativeConnectionDictionary:]):
([EOSQLExpression +dropDatabaseStatementsForConnectionDictionary:
administrativeConnectionDictionary:]):
([EOSQLExpression +selectStatementForContainerOptions]): implemented.
* EOAccess/EOEntity.m ([EOEntity -primaryKeyRootName]): bug fix: calls
-primaryKeyRootName on the _parent entity instead of -externalName.
* EOAccess/EOSchemaGeneration.h: new file.
* EOAccess/EOAccess.h: added EOSchemaGeneration.h
* EOAccess/EOModel.m ([EOModel -initWithContentsOfFile:]):,
([EOModel -initWithTableOfContentsPropertyList:path:]): fixed _name and
_path.
([EOModel -initWithPropertyList:owner:]): use _path instead of _name.
* EOAccess/EOModelGroup.m ([EOModelGroup +globalModelGroup]): search
models in bundles and frameworks.
* EOAccess/EOAdaptor.m ([EOAdaptor +adaptorWithName:]): changed adaptor
from bundle to framework. Looks for <name>EOAdaptor.framework
([EOAdaptor -createDatabaseWithAdministrativeConnectionDictionary:]):
([EOAdaptor -dropDatabaseWithAdministrativeConnectionDictionary:]):
new methods.
* EOAccess/EOAdaptor.h: added include file
* EOAccess/GNUmakefile: added LIBRARIES_DEPEND_UPON
* EOControl/GNUmakefile: Likewise.
2000-10-05 Manuel Guesdon <mguesdon@orange-concept.com>
* EOAccess/EODatabaseChannel.m: added NSDebugMLog and NSAssert
* EOAccess/EODatabaseDataSource.m: added NSDebugMLog and NSAssert
* EOAccess/EOEntity.m: added NSDebugMLog and NSAssert
* EOAccess/EOModel.m: modified -init
* EOControl/EOFetchSpecification.h/.m: added EOKeyValueUnarchiver support
* EOControl/EOKeyValueArchiver.h/.m: implemented EOKeyValueUnarchiver
* EOControl/GNUmakefile: added EOKeyValueArchiver
2000-09-28 Manuel Guesdon <mguesdon@orange-concept.com>
* EOAccess/EODatabaseContext.m: added NSDebugMLog and NSAssert
* EOAccess/EODatabaseChannel.m: added NSDebugMLog and NSAssert
* EOAdaptors/Postgres95/Postgres95Channel.m : added NSDebugMLog
and NSAssert
* EOAccess/EODatabase.m: added NSDebugMLog and NSAssert
2000-09-24 Manuel Guesdon <mguesdon@orange-concept.com>
* config.mak: added include directories in POSTGRES95_CFLAGS
2000-09-23 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOControl/EOQualifier.m (getKey): fixed pointer in key-value parsing.
2000-09-17 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* EOAdaptors/Postgres95/GNUmakefile: remove Postgres95Exceptions.h
2000-09-17 Mirko Viviani <mirko.viviani@rccr.cremona.it>
Patches by David Wetzel <dave@turbocat.de>
* EOAccess/EOAdaptorContext.m ([EOAdaptorContext -initWithAdaptor:]):
set default debug.
* EOAccess/EOModel.m ([EOModel +findPathForModelNamed:]): look also
in the current dir.
* EOControl/EOObjectStoreCoordinator.m ([EOObjectStoreCoordinator
-objectStoreForGlobalID:]), ([EOObjectStoreCoordinator
-objectStoreForObject:]), ([EOObjectStoreCoordinator
-objectStoreForFetchSpecification:]): bug fix: changed notification
object.

73
EOAccess/EOAccess.h Normal file
View file

@ -0,0 +1,73 @@
/*
EOAccess.h
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOAccess_h__
#define __EOAccess_h__
#import <extensions/objc-runtime.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSCharacterSet.h>
#import <Foundation/NSData.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h>
#import <Foundation/NSNotification.h>
#import <Foundation/NSObjCRuntime.h>
#import <Foundation/NSObject.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSRange.h>
#import <Foundation/NSScanner.h>
#import <Foundation/NSString.h>
#import <Foundation/NSUtilities.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSZone.h>
#import <Foundation/NSCoder.h>
#import <Foundation/NSArchiver.h>
#import <EOAccess/EOAdaptor.h>
#import <EOAccess/EOAdaptorContext.h>
#import <EOAccess/EOAdaptorChannel.h>
#import <EOAccess/EOAttribute.h>
#import <EOAccess/EODatabase.h>
#import <EOAccess/EODatabaseChannel.h>
#import <EOAccess/EODatabaseContext.h>
#import <EOAccess/EOEntity.h>
#import <EOAccess/EOJoin.h>
#import <EOAccess/EOModel.h>
#import <EOAccess/EOModelGroup.h>
#import <EOAccess/EORelationship.h>
#import <EOAccess/EOStoredProcedure.h>
#import <EOAccess/EOSQLExpression.h>
#import <EOAccess/EOSQLQualifier.h>
#import <EOAccess/EODatabaseDataSource.h>
#import <EOAccess/EOSchemaGeneration.h>
#import <EOAccess/EOUtilities.h>
#endif /* __EOAccess_h__ */

114
EOAccess/EOAccessFault.h Normal file
View file

@ -0,0 +1,114 @@
/*
EOAccessFault.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: June 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOAccessFault_h__
#define __EOAccessFault_h__
#import <EOControl/EOControl.h>
@class EODatabaseContext;
@class EOKeyGlobalID;
@interface EOAccessGenericFaultHandler:EOFaultHandler
{
unsigned int _generation;
EOAccessGenericFaultHandler *_next;
EOAccessGenericFaultHandler *_prev;
}
- (void)linkAfter: (EOAccessGenericFaultHandler *)faultHandler
usingGeneration: (unsigned int)gen;
- (EOAccessGenericFaultHandler *)next;
- (EOAccessGenericFaultHandler *)previous;
- (unsigned int)generation;
@end
@interface EOAccessFaultHandler:EOAccessGenericFaultHandler
{
EOKeyGlobalID *gid;
EODatabaseContext *databaseContext;
EOEditingContext *editingContext;
}
+ (EOAccessFaultHandler *)accessFaultHandlerWithGlobalID: (EOKeyGlobalID *)globalID
databaseContext: (EODatabaseContext *)dbcontext
editingContext: (EOEditingContext *)ec;
- initWithGlobalID: (EOKeyGlobalID *)globalID
databaseContext: (EODatabaseContext *)dbcontext
editingContext: (EOEditingContext *)ec;
- (EOKeyGlobalID *)globalID;
- (EODatabaseContext *)databaseContext;
- (EOEditingContext *)editingContext;
@end
@interface EOAccessArrayFaultHandler:EOAccessGenericFaultHandler
{
EOKeyGlobalID *sgid;
NSString *relationshipName;
EODatabaseContext *databaseContext;
EOEditingContext *editingContext;
id copy;
}
+ (EOAccessArrayFaultHandler *)accessArrayFaultHandlerWithSourceGlobalID: (EOKeyGlobalID *)sourceGID
relationshipName: (NSString *)relationshipName
databaseContext: (EODatabaseContext *)dbcontext
editingContext: (EOEditingContext *)ec;
- initWithSourceGlobalID: (EOKeyGlobalID *)sourceGID
relationshipName: (NSString *)relationshipName
databaseContext: (EODatabaseContext *)dbcontext
editingContext: (EOEditingContext *)ec;
- (EOKeyGlobalID *)sourceGlobalID;
- (NSString *)relationshipName;
- (EODatabaseContext *)databaseContext;
- (EOEditingContext *)editingContext;
@end
@interface NSObject (EOAccessFaultUnableToFaultToOne)
- (void)unableToFaultObject:(id)object
databaseContext:(EODatabaseContext *)context;
@end
extern NSString *EOAccessFaultObjectNotAvailableException;
#endif

324
EOAccess/EOAccessFault.m Normal file
View file

@ -0,0 +1,324 @@
/**
EOAccessFault.m <title>EOAccessFault Class</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: June 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSObjCRuntime.h>
#import <EOAccess/EOAccessFault.h>
#import <EOAccess/EODatabaseContext.h>
#import <EOAccess/EODatabaseContextPriv.h>
#import <EOControl/EOCheapArray.h>
NSString *EOAccessFaultObjectNotAvailableException = @"EOAccessFaultObjectNotAvailableException";
@implementation EOAccessGenericFaultHandler
- (void)linkAfter: (EOAccessGenericFaultHandler *)faultHandler
usingGeneration: (unsigned int)gen
{
_generation = gen;
_prev = faultHandler;
_next = faultHandler->_next;
faultHandler->_next = self;
if(_next)
_next->_prev = self;
}
- (void)_linkNext: (EOAccessGenericFaultHandler *)next
{
if(_next)
_next->_prev = nil;
_next = next;
if(next)
next->_prev = self;
}
- (void)_linkPrev: (EOAccessGenericFaultHandler *)prev
{
if(_prev)
_prev->_next = nil;
_prev = prev;
if(prev)
prev->_next = self;
}
- (EOAccessGenericFaultHandler *)next
{
return _next;
}
- (EOAccessGenericFaultHandler *)previous
{
return _prev;
}
- (unsigned int)generation
{
return _generation;
}
- (void)faultWillFire: (id)object
{
//TODO change le prev, met à 0
}
@end
@implementation EOAccessFaultHandler
- (id) init
{
if ((self = [super init]))
{
}
return self;
}
+ (EOAccessFaultHandler *)accessFaultHandlerWithGlobalID: (EOKeyGlobalID *)globalID
databaseContext: (EODatabaseContext *)dbcontext
editingContext: (EOEditingContext *)ec
{
return [[[self alloc] initWithGlobalID: globalID
databaseContext: dbcontext
editingContext: ec] autorelease];
}
- (id) initWithGlobalID: (EOKeyGlobalID *)globalID
databaseContext: (EODatabaseContext *)dbcontext
editingContext: (EOEditingContext *)ec
{
if ((self = [self init]))
{
EOFLOGObjectFnStartOrCond(@"EOAccesFaultHandler");
ASSIGNCOPY(gid, globalID);
ASSIGN(databaseContext, dbcontext);
ASSIGN(editingContext, ec);
}
return self;
}
- (void)dealloc
{
EOFLOGObjectFnStopOrCond(@"EOAccesFaultHandler");
DESTROY(gid);
DESTROY(databaseContext);
DESTROY(editingContext);
}
- (EOKeyGlobalID *)globalID
{
#ifdef DEBUG
EOFLOGObjectFnStartOrCond(@"EOAccesFaultHandler");
EOFLOGObjectFnStopOrCond(@"EOAccesFaultHandler");
#endif
return gid;
}
- (EODatabaseContext *)databaseContext
{
return databaseContext;
}
- (EOEditingContext *)editingContext
{
return editingContext;
}
- (void)completeInitializationOfObject:(id)anObject
{
EOFLOGObjectFnStart();
[databaseContext _fireFault: anObject];
//MIRKO: replaced
/*
[databaseContext _batchToOne:anObject
withHandler:self];
*/
if ([EOFault isFault: anObject] == YES)
{
NSDebugMLLog(@"error", @"UnableToFaultObject: %p of class %@",
anObject,
[EOFault targetClassForFault: anObject]);
[self unableToFaultObject: anObject
databaseContext: databaseContext];
}
EOFLOGObjectFnStop();
}
- (BOOL)shouldPerformInvocation: (NSInvocation *)invocation
{
return YES;
}
@end
@implementation NSObject (EOAccessFaultUnableToFaultToOne)
- (void)unableToFaultObject: (id)object
databaseContext: (EODatabaseContext *)context
{
EOFaultHandler *handler = [EOFault handlerForFault:object];
EOGlobalID *globalID = nil;
if ([handler respondsToSelector: @selector(globalID)])
globalID = [(EOAccessFaultHandler *)handler globalID];
NSDebugMLLog(@"gsdb", @"Fault Handler=%@ (%@)", handler, [handler class]);
[NSException raise: EOAccessFaultObjectNotAvailableException
format: @"%@ -- %@ 0x%x: cannot fault to-one for object %@ of class %@ databaseContext %@ handler %@ (globalID=%@)",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
object,
[EOFault targetClassForFault: object],
context,
handler,
globalID];
}
@end
@implementation EOAccessArrayFaultHandler
+ (EOAccessArrayFaultHandler *)accessArrayFaultHandlerWithSourceGlobalID: (EOKeyGlobalID *)sourceGID
relationshipName: (NSString *)aRelationshipName
databaseContext: (EODatabaseContext *)dbcontext
editingContext: (EOEditingContext *)ec
{
return [[[self alloc] initWithSourceGlobalID: sourceGID
relationshipName: aRelationshipName
databaseContext: dbcontext
editingContext: ec] autorelease];
}
- initWithSourceGlobalID: (EOKeyGlobalID *)sourceGID
relationshipName: (NSString *)relName
databaseContext: (EODatabaseContext *)dbcontext
editingContext: (EOEditingContext *)ec
{
if ((self = [self init]))
{
ASSIGN(sgid, sourceGID);
ASSIGN(relationshipName, relName);
ASSIGN(databaseContext, dbcontext);
ASSIGN(editingContext, ec);
}
return self;
}
- (void)dealloc
{
DESTROY(sgid);
DESTROY(relationshipName);
DESTROY(databaseContext);
DESTROY(editingContext);
[super dealloc];
}
- (EOKeyGlobalID *)sourceGlobalID
{
return sgid;
}
- (NSString *)relationshipName
{
return relationshipName;
}
- (EODatabaseContext *)databaseContext
{
return databaseContext;
}
- (EOEditingContext *)editingContext
{
return editingContext;
}
- (void)completeInitializationOfObject: (id)anObject
{
EOFLOGObjectFnStart();
[databaseContext _fireArrayFault: anObject];
[(EOCheapCopyMutableArray *)anObject _setCopy: NO];
NSDebugMLLog(@"gsdb", @"anObject %p=%@", anObject, anObject);
EOFLOGObjectFnStop();
/*MIRKO replaced
[databaseContext _batchToMany:anObject
withHandler:self];
*/
}
- (id) descriptionForObject: (id)object
{
//OK
return [NSString stringWithFormat: @"<ArrayFault(%p) source: %@ relationship: %@>",
object,
sgid,
relationshipName];
}
- (BOOL)shouldPerformInvocation: (NSInvocation *)invocation
{
return YES;
}
@end

View file

@ -0,0 +1,37 @@
/*
EOAccessFaultPriv.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOAccessFaultPriv_h__
#define __EOAccessFaultPriv_h__
@interface EOAccessGenericFaultHandler (EOAccessFaultPrivate)
- (void)_linkNext: (EOAccessGenericFaultHandler *)next;
- (void)_linkPrev: (EOAccessGenericFaultHandler *)prev;
@end
#endif

172
EOAccess/EOAdaptor.h Normal file
View file

@ -0,0 +1,172 @@
/*
EOAdaptor.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOAdaptor_h__
#define __EOAdaptor_h__
#import <Foundation/NSObject.h>
@class NSMutableArray;
@class NSDictionary;
@class NSString;
@class NSNumber;
@class EOModel;
@class EOAttribute;
@class EOAdaptorContext;
@class EOLoginPanel;
@class EOEntity;
extern NSString *EOGeneralAdaptorException;
@interface EOAdaptor : NSObject
{
EOModel *_model;//Not in EOFD
NSString *_name;
NSDictionary *_connectionDictionary;
NSMutableArray *_contexts; // values with contexts
NSString *_expressionClassName;
Class _expressionClass;
id _delegate; // not retained
struct {
unsigned processValue:1;
} _delegateRespondsTo;
}
/* Creating an EOAdaptor */
+ (EOAdaptor *)adaptorWithModel: (EOModel *)model;
+ (EOAdaptor *)adaptorWithName: (NSString *)name;
+ (void)setExpressionClassName: (NSString *)sqlExpressionClassName
adaptorClassName: (NSString *)adaptorClassName;
+ (EOLoginPanel *)sharedLoginPanelInstance;
+ (NSArray *)availableAdaptorNames;
+ (NSArray *)prototypes;
- initWithName:(NSString *)name;
/* Getting an adaptor's name */
- (NSString *)name;
/* Creating and removing an adaptor context */
- (EOAdaptorContext *)createAdaptorContext;
- (NSArray *)contexts;
/* Setting the model */
- (void)setModel: (EOModel*)aModel;//Not in EOFD
- (EOModel*)model;//Not in EOFD
/* Checking connection status */
- (BOOL)hasOpenChannels;
/* Getting adaptor-specific information */
- (Class)expressionClass;
- (Class)defaultExpressionClass;
/* Reconnection to database */
- (void)handleDroppedConnection;
- (BOOL)isDroppedConnectionException: (NSException *)exception;
/* Setting connection information */
- (void)setConnectionDictionary: (NSDictionary*)aDictionary;
- (NSDictionary *)connectionDictionary;
- (void)assertConnectionDictionaryIsValid;
- (BOOL)canServiceModel: (EOModel *)model;
- (NSStringEncoding)databaseEncoding;
- (id)fetchedValueForValue: (id)value
attribute: (EOAttribute *)attribute;
- (NSString *)fetchedValueForStringValue: (NSString *)value
attribute: (EOAttribute *)attribute;
- (NSNumber *)fetchedValueForNumberValue: (NSNumber *)value
attribute: (EOAttribute *)attribute;
- (NSCalendarDate *)fetchedValueForDateValue: (NSCalendarDate *)value
attribute: (EOAttribute *)attribute;
- (NSData *)fetchedValueForDataValue: (NSData *)value
attribute: (EOAttribute *)attribute;
/* Setting the delegate */
- (id)delegate;
- (void)setDelegate: delegate;
@end /* EOAdaptor */
@interface EOAdaptor (EOAdaptorLoginPanel)
- (BOOL)runLoginPanelAndValidateConnectionDictionary;
- (NSDictionary *)runLoginPanel;
@end
@interface EOAdaptor (EOExternalTypeMapping)
+ (NSString *)internalTypeForExternalType: (NSString *)extType
model: (EOModel *)model;
+ (NSArray *)externalTypesWithModel: (EOModel *)model;
+ (void)assignExternalTypeForAttribute: (EOAttribute *)attribute;
+ (void)assignExternalInfoForAttribute: (EOAttribute *)attribute;
+ (void)assignExternalInfoForEntity: (EOEntity *)entity;
+ (void)assignExternalInfoForEntireModel: (EOModel *)model;
@end
@interface EOAdaptor (EOSchemaGenerationExtensions)
- (void)dropDatabaseWithAdministrativeConnectionDictionary: (NSDictionary *)administrativeConnectionDictionary;
- (void)createDatabaseWithAdministrativeConnectionDictionary: (NSDictionary *)administrativeConnectionDictionary;
@end
@interface EOLoginPanel : NSObject
- (NSDictionary *)runPanelForAdaptor: (EOAdaptor *)adaptor validate: (BOOL)yn;
- (NSDictionary *)administraticeConnectionDictionaryForAdaptor: (EOAdaptor *)adaptor;
@end
@interface NSObject (EOAdaptorDelegate)
- (id)adaptor: (EOAdaptor *)adaptor
fetchedValueForValue: (id)value
attribute: (EOAttribute *)attribute;
- (NSDictionary *)reconnectionDictionaryForAdaptor: (EOAdaptor *)adaptor;
@end /* NSObject (EOAdaptorDelegate) */
#endif /* __EOAdaptor_h__*/

719
EOAccess/EOAdaptor.m Normal file
View file

@ -0,0 +1,719 @@
/**
EOAdaptor.m <title>EOAdaptor Class</title>
Copyright (C) 1996-2001 Free Software Foundation, Inc.
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
Date: October 1996
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#if HAVE_LIBC_H
# include <libc.h>
#else
#ifndef __WIN32__
# include <unistd.h>
#endif /* !__WIN32__ */
#endif
#import <Foundation/NSArray.h>
#import <Foundation/NSString.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSObjCRuntime.h>
#import <Foundation/NSUtilities.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSProcessInfo.h>
#import <extensions/NSException.h>
#import <extensions/exceptions/GeneralExceptions.h>
#import <EOAccess/EOAdaptor.h>
#import <EOAccess/EOAdaptorPriv.h>
#import <EOAccess/EOModel.h>
#import <EOAccess/EOAttribute.h>
#import <EOAccess/EOSQLExpression.h>
#import <EOAccess/EOAdaptor.h>
#import <EOAccess/EOAdaptorContext.h>
#import <EOAccess/EOAdaptorChannel.h>
#import <EOControl/EODebug.h>
NSString *EOGeneralAdaptorException = @"EOGeneralAdaptorException";
@implementation EOAdaptor
+ (id)adaptorWithModel: (EOModel *)model
{
//OK
/* Check first to see if the adaptor class exists in the running program
by testing the existence of [_model adaptorClassName]. */
EOAdaptor *adaptor = nil;
if(!model)
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: no model specified",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
else
{
NSString *adaptorName = [model adaptorName];
if (!adaptorName)
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: no adaptor name in model named %@",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
[model name]];
else
{
Class adaptorClass = NSClassFromString([NSString stringWithFormat: @"%@%@", adaptorName, @"Adaptor"]);
if(adaptorClass)
adaptor = [[[adaptorClass alloc] initWithName: adaptorName]
autorelease];
else
adaptor = [self adaptorWithName: adaptorName];
[adaptor setModel: model];
[adaptor setConnectionDictionary: [model connectionDictionary]];
}
}
return adaptor;
}
+ (id) adaptorWithName: (NSString *)adaptorName
{
//OK
NSBundle *bundle = [NSBundle mainBundle];
NSString *adaptorBundlePath;
NSMutableArray *paths;
Class adaptorClass;
NSString *adaptorClassName;
NSProcessInfo *pInfo;
NSDictionary *env;
NSMutableString *user, *local, *system;
int i, count;
/* Check error */
if ([adaptorName length] == 0)
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: adaptor name can't be nil",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
// append EOAdaptor
adaptorName = [adaptorName stringByAppendingString: @"EOAdaptor"];
/* Look in application bundle */
adaptorBundlePath = [bundle pathForResource: adaptorName
ofType: @"framework"];
// should be NSString *path=[NSBundle pathForLibraryResource:libraryResource type:@"framework" directory:@"Frameworks"]; ?
/* Look in standard paths */
if (!adaptorBundlePath)
{
/*
The path of where to search for the adaptor files
is based upon environment variables.
GDL_ADAPTORS_PATH
GNUSTEP_USER_ROOT
GNUSTEP_LOCAL_ROOT
GNUSTEP_SYSTEM_ROOT
*/
pInfo = [NSProcessInfo processInfo];
env = [pInfo environment];
paths = [NSMutableArray array];
user = [[[env objectForKey: @"GNUSTEP_USER_ROOT"]
mutableCopy] autorelease];
[user appendString: @"/Libraries/Frameworks"];
if (user)
[paths addObject: user];
local = [[[env objectForKey: @"GNUSTEP_LOCAL_ROOT"]
mutableCopy] autorelease];
[local appendString: @"/Libraries/Frameworks"];
if (local)
[paths addObject: local];
local = [[[env objectForKey: @"GNUSTEP_LOCAL_ROOT"]
mutableCopy] autorelease];
[local appendString: @"/Library/Frameworks"];
if (local)
[paths addObject: local];
system = [[[env objectForKey: @"GNUSTEP_SYSTEM_ROOT"]
mutableCopy] autorelease];
[system appendString: @"/Libraries/Frameworks"];
if (system)
[paths addObject: system];
/* Loop through the paths and check each one */
for(i = 0, count = [paths count]; i < count; i++)
{
bundle = [NSBundle bundleWithPath: [paths objectAtIndex: i]];
adaptorBundlePath = [bundle pathForResource: adaptorName
ofType: @"framework"];
if(adaptorBundlePath && [adaptorBundlePath length])
break;
}
}
/* Make adaptor bundle */
if(adaptorBundlePath)
bundle = [NSBundle bundleWithPath: adaptorBundlePath];
else
bundle = nil;
/* Check bundle */
if (!bundle)
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: the adaptor bundle '%@' does not exist",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
adaptorName];
/* Get the adaptor bundle "infoDictionary", and pricipal class, ie. the
adaptor class. Other info about the adaptor should be put in the
bundle's "Info.plist" file (property list format - see NSBundle class
documentation for details about reserved keys in this dictionary
property list containing one entry whose key is adaptorClassName. It
identifies the actual adaptor class from the bundle. */
adaptorClass = [bundle principalClass]; //NSString* adaptorClassName=[infoDictionary objectForKey:@"EOAdaptorClassName"]; ??
if (adaptorClass == Nil) {
adaptorClassName = [[bundle infoDictionary] objectForKey: @"EOAdaptorClassName"];
NSLog(@"adaptorClassName is %@", adaptorClassName);
adaptorClass = NSClassFromString(adaptorClassName);
}
if(!adaptorClass)
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: the adaptor bundle '%@' doesn't contain a principal class",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
adaptorName];
return [[[adaptorClass alloc] initWithName: adaptorName] autorelease];
}
+ (void)setExpressionClassName: (NSString *)sqlExpressionClassName
adaptorClassName: (NSString *)adaptorClassName
{
// TODO
[self notImplemented: _cmd];
}
+ (EOLoginPanel *)sharedLoginPanelInstance
{
// TODO
[self notImplemented: _cmd];
return nil;
}
+ (NSArray *)availableAdaptorNames
{
NSArray *pathArray = NSStandardLibraryPaths();
NSEnumerator *pathEnum = [pathArray objectEnumerator];
NSString *searchPath;
NSFileManager *defaultManager = [NSFileManager defaultManager];
NSArray *fileNames;
NSEnumerator *filesEnum;
NSString *fileName;
NSMutableArray *adaptorNames = [[NSMutableArray new] autorelease];
EOFLOGObjectFnStartOrCond2(@"AdaptorLevel", @"EOAdaptor");
while ((searchPath = [pathEnum nextObject]))
{
fileNames = [defaultManager
directoryContentsAtPath:
[searchPath stringByAppendingPathComponent:@"Frameworks"]];
filesEnum = [fileNames objectEnumerator];
//NSLog(@"EOAdaptor : availableAdaptorNames, path = %@", searchPath);
while ((fileName = [filesEnum nextObject]))
{
//NSLog(@"EOAdaptor : availableAdaptorNames, fileName = %@", fileName);
if ([fileName hasSuffix:@"EOAdaptor.framework"]) {
[adaptorNames addObject:
[fileName substringToIndex:
([fileName length]
- [@"EOAdaptor.framework" length])]];
}
}
}
EOFLOGObjectFnStopOrCond2(@"AdaptorLevel", @"EOAdaptor");
return adaptorNames;
}
+ (NSArray *)prototypes
{
// TODO
[self notImplemented: _cmd];
return nil;
}
- initWithName:(NSString *)name
{
if ((self = [super init]))
{
ASSIGN(_name, name);
_contexts = [NSMutableArray new];
}
return self;
}
- (void)dealloc
{
DESTROY(_model);
DESTROY(_name);
DESTROY(_connectionDictionary);
DESTROY(_contexts);
[super dealloc];
}
- (void)setConnectionDictionary: (NSDictionary *)dictionary
{
//OK
if ([self hasOpenChannels])
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: cannot set the connection dictionary while the adaptor is connected!",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
ASSIGN(_connectionDictionary, dictionary);
// [model setConnectionDictionary:dictionary]; // TODO ??
}
- (void)assertConnectionDictionaryIsValid
{
return;
}
- (EOAdaptorContext *)createAdaptorContext
{
[self subclassResponsibility: _cmd];
return nil;
}
- (NSArray *)contexts
{
return _contexts;
}
- (BOOL)hasOpenChannels
{
int i;
for (i = [_contexts count] - 1; i >= 0; i--)
{
EOAdaptorContext *ctx = [[_contexts objectAtIndex: i]
nonretainedObjectValue];
if([ctx hasOpenChannels] == YES)
return YES;
}
return NO;
}
- (void)setDelegate:delegate
{
_delegate = delegate;
_delegateRespondsTo.processValue
= [delegate respondsToSelector:
@selector(adaptor:fetchedValueForValue:attribute:)];
}
- (void)setModel: (EOModel *)model
{
ASSIGN(_model, model);
}
- (NSString *)name
{
return _name;
}
- (NSDictionary *)connectionDictionary
{
return _connectionDictionary;
}
- (EOModel *)model
{
return _model;
}
- delegate
{
return _delegate;
}
- (Class)expressionClass
{
Class expressionClass = Nil;
EOFLOGObjectFnStart();
/* retrieve EOAdaptorQuotesExternalNames from ? or from user default */
expressionClass = _expressionClass;
if(!expressionClass)
expressionClass = [self defaultExpressionClass];
EOFLOGObjectFnStop();
return expressionClass;
}
- (Class)defaultExpressionClass
{
[self subclassResponsibility: _cmd];
return Nil; //TODO vedere setExpressionClass
}
- (BOOL)canServiceModel: (EOModel *)model
{
return [_connectionDictionary isEqual: [model connectionDictionary]];
}
- (NSStringEncoding)databaseEncoding
{
NSString *encodingString=nil;
NSDictionary *encodingsDict = [self connectionDictionary];
NSStringEncoding *availableEncodingsArray;
int count = 0;
NSStringEncoding availableEncodingValue;
NSString *availableEncodingString;
EOFLOGObjectFnStartOrCond2(@"AdaptorLevel",@"EOAdaptor");
if (encodingsDict
&& (encodingString = [encodingsDict objectForKey: @"databaseEncoding"]))
{
availableEncodingsArray = [NSString availableStringEncodings];
while (availableEncodingsArray[count] != 0)
{
availableEncodingValue = availableEncodingsArray[count++];
availableEncodingString = (NSString *)GetEncodingName(availableEncodingValue);
if (availableEncodingString)
{
if ([availableEncodingString isEqual: encodingString])
{
EOFLOGObjectFnStopOrCond2(@"AdaptorLevel", @"EOAdaptor");
return availableEncodingValue;
}
}
}
}
EOFLOGObjectFnStopOrCond2(@"AdaptorLevel", @"EOAdaptor");
return [NSString defaultCStringEncoding];
}
- (id)fetchedValueForValue: (id)value
attribute: (EOAttribute *)attribute
{
//Should be OK
SEL valueFactoryMethod;
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"value=%@", value);
NSDebugMLLog(@"gsdb", @"attribute=%@", attribute);
valueFactoryMethod = [attribute valueFactoryMethod];
if (valueFactoryMethod)
{
NSEmitTODO();
[self notImplemented: _cmd]; //TODO
}
else
{
if ([value isKindOfClass: [NSString class]])
[self fetchedValueForStringValue: value
attribute: attribute];
else if ([value isKindOfClass: [NSNumber class]])
value = [self fetchedValueForNumberValue: value
attribute: attribute];
else if ([value isKindOfClass: [NSDate class]])
value = [self fetchedValueForDateValue: value
attribute: attribute];
else if ([value isKindOfClass: [NSData class]])
value = [self fetchedValueForDataValue: value
attribute: attribute];
NSDebugMLLog(@"gsdb",@"value=%@",value);
}
if(_delegateRespondsTo.processValue)
value = [_delegate adaptor: self
fetchedValueForValue: value
attribute: attribute];
NSDebugMLLog(@"gsdb", @"value=%@", value);
EOFLOGObjectFnStop();
return value;
}
- (NSString *)fetchedValueForStringValue: (NSString *)value
attribute: (EOAttribute *)attribute
{
NSString *resultValue = nil;
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"value=%@", value);
NSDebugMLLog(@"gsdb", @"attribute=%@", attribute);
if([value length]>0)
{
//TODO-NOW: correct this code which loop!
/*
const char *cstr=NULL;
int i=0, spc=0;
cstr = [value cString];
while(*cstr)
{
if(*cstr == ' ')
spc++;
else
spc = 0;
i++;
}
cstr = &cstr[-i];
if(!spc)
resultValue=value;
else if(!(&cstr[i-spc]-cstr))
resultValue=nil;
else
resultValue=[NSString stringWithCString:cstr
length:&cstr[i-spc]-cstr];
*/
resultValue = value;
}
EOFLOGObjectFnStop();
return resultValue;
}
- (NSNumber *)fetchedValueForNumberValue: (NSNumber *)value
attribute: (EOAttribute *)attribute
{
return value;
}
- (NSCalendarDate *)fetchedValueForDateValue: (NSCalendarDate *)value
attribute: (EOAttribute *)attribute
{
return value;
}
- (NSData *)fetchedValueForDataValue: (NSData *)value
attribute: (EOAttribute *)attribute
{
return value;
}
/* Reconnection to database */
- (void)handleDroppedConnection
{
NSDictionary *newConnectionDictionary = nil;
int i;
for (i = [_contexts count] - 1; i >= 0; i--)
{
EOAdaptorContext *ctx = [[_contexts objectAtIndex:i]
nonretainedObjectValue];
[ctx handleDroppedConnection];
}
[_contexts removeAllObjects];
if (_delegate
&& [_delegate
respondsToSelector: @selector(reconnectionDictionaryForAdaptor:)])
{
if ((newConnectionDictionary = [_delegate
reconnectionDictionaryForAdaptor: self]))
{
[self setConnectionDictionary: newConnectionDictionary];
}
}
}
- (BOOL)isDroppedConnectionException: (NSException *)exception
{
EOFLOGObjectFnStartOrCond2(@"AdaptorLevel", @"EOAdaptor");
EOFLOGObjectFnStopOrCond2(@"AdaptorLevel", @"EOAdaptor");
return NO;
}
//NOT in EOF
- (void)createDatabaseWithAdministrativeConnectionDictionary: (NSDictionary *)connectionDictionary
{
[self notImplemented: _cmd];
}
//NOT in EOF
- (void)dropDatabaseWithAdministrativeConnectionDictionary: (NSDictionary *)connectionDictionary
{
[self notImplemented: _cmd];
}
@end /* EOAdaptor */
@implementation EOAdaptor (EOAdaptorLoginPanel)
- (BOOL)runLoginPanelAndValidateConnectionDictionary
{
// TODO
NSEmitTODO();
return NO;
}
- (NSDictionary *)runLoginPanel
{
// TODO
[self notImplemented: _cmd];
return nil;
}
@end
@implementation EOAdaptor (EOExternalTypeMapping)
+ (NSString *)internalTypeForExternalType: (NSString *)extType
model: (EOModel *)model
{
[self subclassResponsibility: _cmd];
return nil;
}
+ (NSArray *)externalTypesWithModel: (EOModel *)model
{
[self subclassResponsibility: _cmd];
return nil;
}
+ (void)assignExternalTypeForAttribute: (EOAttribute *)attribute
{
return;
}
+ (void)assignExternalInfoForAttribute: (EOAttribute *)attribute
{
// TODO
NSEmitTODO();
[self assignExternalTypeForAttribute: attribute];
}
+ (void)assignExternalInfoForEntity: (EOEntity *)entity
{
// TODO
[self notImplemented: _cmd];
}
+ (void)assignExternalInfoForEntireModel: (EOModel *)model
{
// TODO
[self notImplemented: _cmd];
}
@end
@implementation EOAdaptor (EOAdaptorPrivate)
- (void) _requestConcreteImplementationForSelector: (SEL)param0
{
[self notImplemented: _cmd]; //TODO
}
- (void) _unregisterAdaptorContext: (EOAdaptorContext*)adaptorContext
{
int i = 0;
for (i = [_contexts count] - 1; i >= 0; i--)
{
if ([[_contexts objectAtIndex: i] nonretainedObjectValue]
== adaptorContext)
{
[_contexts removeObjectAtIndex: i];
break;
}
}
}
- (void) _registerAdaptorContext: (EOAdaptorContext*)adaptorContext
{
[_contexts addObject: [NSValue valueWithNonretainedObject: adaptorContext]];
}
@end

233
EOAccess/EOAdaptorChannel.h Normal file
View file

@ -0,0 +1,233 @@
/*
EOAdaptorChannel.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOAdaptorChannel_h__
#define __EOAdaptorChannel_h__
#import <extensions/NSException.h>
#import <EOControl/EOFetchSpecification.h>
#import <EOAccess/EOAdaptorContext.h>
@class NSArray;
@class NSMutableArray;
@class NSDictionary;
@class NSMutableDictionary;
@class NSString;
@class NSMutableString;
@class NSCalendarDate;
@class EOModel;
@class EOEntity;
@class EOAttribute;
@class EOQualifier;
@class EOStoredProcedure;
@class EOAdaptorOperation;
@class EOSQLExpression;
/* The EOAdaptorChannel class could be overriden for a concrete database
adaptor. You have to override only those methods marked in this header
with `override'.
*/
@interface EOAdaptorChannel : NSObject
{
EOAdaptorContext *_context;
id _delegate; // not retained
BOOL _debug;
/* Flags used to check if the delegate responds to several messages */
struct {
unsigned willPerformOperations:1;
unsigned didPerformOperations:1;
unsigned shouldSelectAttributes:1;
unsigned didSelectAttributes:1;
unsigned willFetchRow:1;
unsigned didFetchRow:1;
unsigned didChangeResultSet:1;
unsigned didFinishFetching:1;
unsigned shouldEvaluateExpression:1;
unsigned didEvaluateExpression:1;
unsigned shouldExecuteStoredProcedure:1;
unsigned didExecuteStoredProcedure:1;
unsigned shouldConstructStoredProcedureReturnValues:1;
unsigned shouldReturnValuesForStoredProcedure:1;
} _delegateRespondsTo;
}
+ (EOAdaptorChannel *)adaptorChannelWithAdaptorContext: (EOAdaptorContext *)adaptorContext;
/* Initializing an adaptor context */
- initWithAdaptorContext: (EOAdaptorContext *)adaptorContext;
/* Getting the adaptor context */
- (EOAdaptorContext *)adaptorContext;
/* Opening and closing a channel */
- (BOOL)isOpen;
- (void)openChannel;
- (void)closeChannel;
/* Modifying rows */
- (void)insertRow: (NSDictionary *)row forEntity: (EOEntity *)entity;
- (void)updateValues: (NSDictionary *)values
inRowDescribedByQualifier: (EOQualifier *)qualifier
entity: (EOEntity *)entity;
- (unsigned)updateValues: (NSDictionary *)values
inRowsDescribedByQualifier: (EOQualifier *)qualifier
entity: (EOEntity *)entity;
- (void)deleteRowDescribedByQualifier: (EOQualifier *)qualifier
entity: (EOEntity *)entity;
- (unsigned)deleteRowsDescribedByQualifier: (EOQualifier *)qualifier
entity: (EOEntity *)entity;
/* Fetching rows */
- (void)selectAttributes: (NSArray *)attributes
fetchSpecification: (EOFetchSpecification *)fetchSpecification
lock: (BOOL)aLockFlag
entity: (EOEntity *)entity;
- (void)lockRowComparingAttributes: (NSArray *)atts
entity: (EOEntity *)entity
qualifier: (EOQualifier *)qualifier
snapshot: (NSDictionary *)snapshot;
- (void)evaluateExpression: (EOSQLExpression *)expression;
- (BOOL)isFetchInProgress;
- (NSArray *)describeResults;
- (NSMutableDictionary *)fetchRowWithZone: (NSZone *)zone;
- (void)setAttributesToFetch: (NSArray *)attributes;
- (NSArray *)attributesToFetch;
- (void)cancelFetch;
- (NSDictionary *)primaryKeyForNewRowWithEntity: (EOEntity *)entity;
- (NSArray *)describeTableNames;
- (NSArray *)describeStoredProcedureNames;
- (EOModel *)describeModelWithTableNames: (NSArray *)tableNames;
- (void)addStoredProceduresNamed: (NSArray *)storedProcedureNames
toModel: (EOModel *)model;
- (void)setDebugEnabled:(BOOL)yn;
- (BOOL)isDebugEnabled;
- (id)delegate;
- (void)setDelegate:(id)delegate;
- (NSMutableDictionary *)dictionaryWithObjects: (id *)objects
forAttributes: (NSArray *)attributes
zone: (NSZone *)zone;
@end
@interface EOAdaptorChannel (EOStoredProcedures)
- (void)executeStoredProcedure: (EOStoredProcedure *)storedProcedure
withValues: (NSDictionary *)values;
- (NSDictionary *)returnValuesForLastStoredProcedureInvocation;
@end
@interface EOAdaptorChannel (EOBatchProcessing)
- (void)performAdaptorOperation: (EOAdaptorOperation *)adaptorOperation;
- (void)performAdaptorOperations: (NSArray *)adaptorOperations;
@end
@interface NSObject (EOAdaptorChannelDelegation)
- (NSArray *)adaptorChannel: channel
willPerformOperations: (NSArray *)operations;
- (NSException *)adaptorChannel: channel
didPerformOperations: (NSArray *)operations
exception: (NSException *)exception;
- (BOOL)adaptorChannel: channel
shouldSelectAttributes: (NSArray *)attributes
fetchSpecification: (EOFetchSpecification *)fetchSpecification
lock: (BOOL)flag
entity: (EOEntity *)entity;
- (void)adaptorChannel: channel
didSelectAttributes: (NSArray *)attributes
fetchSpecification: (EOFetchSpecification *)fetchSpecification
lock:(BOOL) flag
entity: (EOEntity *)entity;
- (void)adaptorChannelWillFetchRow: channel;
- (void)adaptorChannel: channel didFetchRow: (NSMutableDictionary *)row;
- (void)adaptorChannelDidChangeResultSet: channel;
- (void)adaptorChannelDidFinishFetching: channel;
- (BOOL)adaptorChannel: channel
shouldEvaluateExpression: (EOSQLExpression *)expression;
- (void)adaptorChannel: channel
didEvaluateExpression: (EOSQLExpression *)expression;
- (NSDictionary *)adaptorChannel: channel
shouldExecuteStoredProcedure: (EOStoredProcedure *)procedure
withValues: (NSDictionary *)values;
- (void)adaptorChannel: channel
didExecuteStoredProcedure: (EOStoredProcedure *)procedure
withValues: (NSDictionary *)values;
- (NSDictionary *)adaptorChannelShouldConstructStoredProcedureReturnValues: channel;
- (NSDictionary *)adaptorChannel: channel
shouldReturnValuesForStoredProcedure: (NSDictionary *)returnValues;
@end /* NSObject(EOAdaptorChannelDelegation) */
extern NSString *EOAdaptorOperationsKey;
extern NSString *EOFailedAdaptorOperationKey;
extern NSString *EOAdaptorFailureKey;
extern NSString *EOAdaptorOptimisticLockingFailure;
#endif /* __EOAdaptorChannel_h__ */

609
EOAccess/EOAdaptorChannel.m Normal file
View file

@ -0,0 +1,609 @@
/**
EOAdaptorChannel.m <title>EOAdaptorChannel</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/Foundation.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSValue.h>
#import <extensions/NSException.h>
#import <extensions/exceptions/GeneralExceptions.h>
#import <EOAccess/EOAccess.h>
#import <EOAccess/EOEntity.h>
#import <EOAccess/EOAttribute.h>
#import <EOAccess/EOAdaptor.h>
#import <EOAccess/EOAdaptorContext.h>
#import <EOAccess/EOAdaptorChannel.h>
#import <EOAccess/EOSQLExpression.h>
#import <EOAccess/EODatabaseOperation.h>
#import <EOControl/EOMutableKnownKeyDictionary.h>
#import <EOControl/EONSAddOns.h>
NSString *EOAdaptorOperationsKey = @"EOAdaptorOperationsKey";
NSString *EOFailedAdaptorOperationKey = @"EOFailedAdaptorOperationKey";
NSString *EOAdaptorFailureKey = @"EOAdaptorFailureKey";
NSString *EOAdaptorOptimisticLockingFailure = @"EOAdaptorOptimisticLockingFailure";
@implementation EOAdaptorChannel
+ (EOAdaptorChannel *)adaptorChannelWithAdaptorContext: (EOAdaptorContext *)adaptorContext
{
return [[[self alloc] initWithAdaptorContext: adaptorContext] autorelease];
}
- (id) initWithAdaptorContext: (EOAdaptorContext *)adaptorContext
{
if ((self = [super init]))
{
ASSIGN(_context, adaptorContext);
[_context _channelDidInit: self]; //TODO it's _registerAdaptorChannel:
}
return self;
}
- (void)dealloc
{
[_context _channelWillDealloc: self];
DESTROY(_context);
[super dealloc];
}
- (void)openChannel
{
[self subclassResponsibility: _cmd];
}
- (void)closeChannel
{
[self subclassResponsibility: _cmd];
}
- (void)insertRow: (NSDictionary *)row
forEntity: (EOEntity *)entity
{
[self subclassResponsibility: _cmd];
}
- (void)updateValues: (NSDictionary *)row
inRowDescribedByQualifier: (EOQualifier *)qualifier
entity: (EOEntity *)entity
{
int rows;
rows = [self updateValues: row
inRowsDescribedByQualifier: qualifier
entity: entity];
if(rows != 1)
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: updated %d rows",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
rows];
}
- (unsigned)updateValues: (NSDictionary *)values
inRowsDescribedByQualifier: (EOQualifier *)qualifier
entity: (EOEntity *)entity
{
[self subclassResponsibility: _cmd];
return 0;
}
- (void)deleteRowDescribedByQualifier: (EOQualifier *)qualifier
entity: (EOEntity *)entity
{
int rows = 0;
rows = [self deleteRowsDescribedByQualifier: qualifier
entity: entity];
if (rows != 1)
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: deleted %d rows",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
rows];
}
- (unsigned)deleteRowsDescribedByQualifier: (EOQualifier *)qualifier
entity: (EOEntity *)entity
{
[self subclassResponsibility: _cmd];
return 0;
}
- (void)selectAttributes: (NSArray *)attributes
fetchSpecification: (EOFetchSpecification *)fetchSpecification
lock: (BOOL)flag
entity: (EOEntity *)entity
{
[self subclassResponsibility: _cmd];
}
- (void)lockRowComparingAttributes: (NSArray *)attrs
entity: (EOEntity *)entity
qualifier: (EOQualifier *)qualifier
snapshot: (NSDictionary *)snapshot
{
EOFetchSpecification *fetch = nil;
NSDictionary *row = nil;
NSEnumerator *attrsEnum = nil;
EOAttribute *attr = nil;
NSMutableArray *attributes = nil;
BOOL isEqual = YES;
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"attrs=%@", attrs);
NSDebugMLLog(@"gsdb", @"entity=%@", entity);
NSDebugMLLog(@"gsdb", @"qualifier=%@" ,qualifier);
NSDebugMLLog(@"gsdb", @"snapshot=%@", snapshot);
if (attrs)
attributes = [[attrs mutableCopy] autorelease];
if(attributes == nil)
attributes = [NSMutableArray array];
[attributes removeObjectsInArray: [entity primaryKeyAttributes]];
[attributes addObjectsFromArray: [entity primaryKeyAttributes]];
fetch = [EOFetchSpecification fetchSpecificationWithEntityName: [entity name]
qualifier: qualifier
sortOrderings: nil];
[self selectAttributes: attributes
fetchSpecification: fetch
lock: YES
entity: entity];
row = [self fetchRowWithZone: NULL];
NSDebugMLLog(@"gsdb", @"row=%@", row);
if(row == nil || [self fetchRowWithZone: NULL] != nil)
{
[NSException raise: EOGeneralAdaptorException
format: @"%@ -- %@ 0x%x: cannot lock row for entity '%@' with qualifier: %@",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
[entity name],
qualifier];
}
attrsEnum = [attributes objectEnumerator];
while((attr = [attrsEnum nextObject]))
{
NSString *name;
name = [attr name];
if([[row objectForKey: name]
isEqual: [snapshot objectForKey:name]] == NO)
{
isEqual = NO;
break;
}
}
if(isEqual == NO)
{
[NSException raise: EOGeneralAdaptorException
format: @"%@ -- %@ 0x%x: cannot lock row for entity '%@' with qualifier: %@",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
[entity name],
qualifier];
}
EOFLOGObjectFnStop();
}
- (void)evaluateExpression: (EOSQLExpression *)expression
{
[self subclassResponsibility: _cmd];
}
- (BOOL)isFetchInProgress
{
[self subclassResponsibility: _cmd];
return NO;
}
- (NSArray *)describeResults
{
[self subclassResponsibility: _cmd];
return nil;
}
- (NSMutableDictionary *)fetchRowWithZone: (NSZone *)zone
{
[self subclassResponsibility: _cmd];
return nil;
}
- (void)setAttributesToFetch: (NSArray *)attributes
{
[self subclassResponsibility: _cmd];
}
- (NSArray *)attributesToFetch
{
[self subclassResponsibility: _cmd];
return nil;
}
- (void)cancelFetch
{
[self subclassResponsibility: _cmd];
}
- (NSDictionary *)primaryKeyForNewRowWithEntity: (EOEntity *)entity
{
EOFLOGObjectFnStart();
EOFLOGObjectFnStop();
return nil;//no or subclass respo ?
}
- (NSArray *)describeTableNames
{
return nil;
}
- (NSArray *)describeStoredProcedureNames
{
[self subclassResponsibility: _cmd];
return nil;
}
- (EOModel *)describeModelWithTableNames: (NSArray *)tableNames
{
return nil;
}
- (void)addStoredProceduresNamed: (NSArray *)storedProcedureNames
toModel: (EOModel *)model
{
[self subclassResponsibility: _cmd];
}
- (void)setDebugEnabled: (BOOL)flag
{
_debug = flag;
}
- (BOOL)isDebugEnabled
{
return _debug;
}
- delegate
{
return _delegate;
}
- (void)setDelegate:delegate
{
_delegate = delegate;
_delegateRespondsTo.willPerformOperations =
[_delegate respondsToSelector:
@selector(adaptorChannel:willPerformOperations:)];
_delegateRespondsTo.didPerformOperations =
[_delegate respondsToSelector:
@selector(adaptorChannel:didPerformOperations:exception:)];
_delegateRespondsTo.shouldSelectAttributes =
[_delegate respondsToSelector:
@selector(adaptorChannel:shouldSelectAttributes:fetchSpecification:lock:)];
_delegateRespondsTo.didSelectAttributes =
[_delegate respondsToSelector:
@selector(adaptorChannel:didSelectAttributes:fetchSpecification:lock:)];
_delegateRespondsTo.willFetchRow =
[_delegate respondsToSelector:
@selector(adaptorChannelWillFetchRow:)];
_delegateRespondsTo.didFetchRow =
[_delegate respondsToSelector:
@selector(adaptorChannel:didFetchRow:)];
_delegateRespondsTo.didChangeResultSet =
[_delegate respondsToSelector:
@selector(adaptorChannelDidChangeResultSet:)];
_delegateRespondsTo.didFinishFetching =
[_delegate respondsToSelector:
@selector(adaptorChannelDidFinishFetching:)];
_delegateRespondsTo.shouldEvaluateExpression =
[_delegate respondsToSelector:
@selector(adaptorChannel:shouldEvaluateExpression:)];
_delegateRespondsTo.didEvaluateExpression =
[_delegate respondsToSelector:
@selector(adaptorChannel:didEvaluateExpression:)];
_delegateRespondsTo.shouldExecuteStoredProcedure =
[_delegate respondsToSelector:
@selector(adaptorChannel:shouldExecuteStoredProcedure:withValues:)];
_delegateRespondsTo.didExecuteStoredProcedure =
[_delegate respondsToSelector:
@selector(adaptorChannelDidExecuteStoredProcedure:withValues:)];
_delegateRespondsTo.shouldConstructStoredProcedureReturnValues =
[_delegate respondsToSelector:
@selector(adaptorChannelShouldConstructStoredProcedureReturnValues:)];
_delegateRespondsTo.shouldReturnValuesForStoredProcedure =
[_delegate respondsToSelector:
@selector(adaptorChannel:shouldReturnValuesForStoredProcedure:)];
}
- (NSMutableDictionary *)dictionaryWithObjects: (id *)objects
forAttributes: (NSArray *)attributes
zone: (NSZone *)zone
{
//OK (can be improved by calling EOMutableKnownKeyDictionary iini with objects but the order may be different
EOMutableKnownKeyDictionary *dict=nil;
EOAttribute *anAttribute=[attributes firstObject];
NSAssert(anAttribute, @"No attribute");
if (anAttribute)
{
EOEntity *entity = [anAttribute entity];
NSAssert1(entity,@"No entity for attribute %@",anAttribute);
if (entity)
{
NSArray *attributesToFetch = [entity _attributesToFetch];
EOMKKDInitializer *initializer = [entity _adaptorDictionaryInitializer];
int i = 0;
int count = [attributes count];
NSDebugMLLog(@"gsdb",@"\ndictionaryWithObjects:forAttributes:zone: attributes=%@ objects=%p\n",attributes,objects);
NSAssert(initializer,@"No initializer");
NSDebugMLLog(@"gsdb",@"initializer=%@",initializer);
dict = [[[EOMutableKnownKeyDictionary allocWithZone: zone]
initWithInitializer:initializer] autorelease];
NSDebugMLLog(@"gsdb", @"dict=%@", dict);
for(i = 0; i < count; i++)
{
EOAttribute *attribute = (EOAttribute *)[attributes objectAtIndex: i];
NSDebugMLLog(@"gsdb", @"Attribute=%@ value=%@", attribute, objects[i]);
[dict setObject: objects[i]
forKey: [attribute name]];
}
}
}
return dict;
}
- (EOAdaptorContext *)adaptorContext
{
return _context;
}
- (BOOL)isOpen
{
[self subclassResponsibility: _cmd];
return NO;
}
@end /* EOAdaptorChannel */
@implementation EOAdaptorChannel (EOStoredProcedures)
- (void)executeStoredProcedure: (EOStoredProcedure *)storedProcedure
withValues: (NSDictionary *)values
{
[self subclassResponsibility: _cmd];
}
- (NSDictionary *)returnValuesForLastStoredProcedureInvocation
{
[self subclassResponsibility: _cmd];
return nil;
}
@end
@implementation EOAdaptorChannel (EOBatchProcessing)
- (void)performAdaptorOperation: (EOAdaptorOperation *)adaptorOperation
{
EOAdaptorContext *adaptorContext = nil;
EOEntity *entity = nil;
EOAdaptorOperator operator;
NSDictionary *changedValues=nil;
EOFLOGObjectFnStart();
adaptorContext = [self adaptorContext];
//adaptorcontext transactionNestingLevel
//2fois
//...
NSDebugMLLog(@"gsdb", @"adaptorOperation=%@", adaptorOperation);
entity = [adaptorOperation entity];
operator = [adaptorOperation adaptorOperator];
changedValues = [adaptorOperation changedValues];
NSDebugMLLog(@"gsdb", @"ad op: %d %@", operator, [entity name]);
NSDebugMLLog(@"gsdb", @"ad op: %@ %@", [adaptorOperation changedValues], [adaptorOperation qualifier]);
NS_DURING
switch(operator)
{
case EOAdaptorLockOperator:
NSDebugMLLog(@"gsdb", @"EOAdaptorLockOperator");
[self lockRowComparingAttributes: [adaptorOperation attributes]
entity: entity
qualifier: [adaptorOperation qualifier]
snapshot: changedValues];
break;
case EOAdaptorInsertOperator:
NSDebugMLLog(@"gsdb", @"EOAdaptorInsertOperator");
/*
//self adaptorContext
//adaptorcontext transactionNestingLevel
NSArray* attributes=[entity attributes];
forech: externaltype
name
PostgreSQLExpression initWithEntity:
//called from ??: expr setUseAliases:NO
prepareInsertExpressionWithRow:changedValues
[expr staement];
*/
[self insertRow: [adaptorOperation changedValues]
forEntity: entity];
break;
case EOAdaptorUpdateOperator:
NSDebugMLLog(@"gsdb", @"EOAdaptorUpdateOperator");
//OK
[self updateValues: [adaptorOperation changedValues]
inRowDescribedByQualifier: [adaptorOperation qualifier]
entity: entity];
break;
case EOAdaptorDeleteOperator:
NSDebugMLLog(@"gsdb", @"EOAdaptorDeleteOperator");
[self deleteRowDescribedByQualifier: [adaptorOperation qualifier]
entity: entity];
break;
case EOAdaptorStoredProcedureOperator:
NSDebugMLLog(@"gsdb", @"EOAdaptorStoredProcedureOperator");
[self executeStoredProcedure: [adaptorOperation storedProcedure]
withValues: [adaptorOperation changedValues]];
break;
case EOAdaptorUndefinedOperator:
NSDebugMLLog(@"gsdb", @"EOAdaptorUndefinedOperator");
default:
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: Operator %d is not defined",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
(int)operator];
break;
}
NS_HANDLER
{
NSDebugMLog(@"EXCEPTION %@", localException);
[adaptorOperation setException: localException];
[localException raise];
}
NS_ENDHANDLER;
//end
EOFLOGObjectFnStop();
}
- (void)performAdaptorOperations: (NSArray *)adaptorOperations
{
int i = 0;
int count = 0;
EOFLOGObjectFnStart();
count=[adaptorOperations count];
for(i = 0; i < count; i++)
{
EOAdaptorOperation *operation = [adaptorOperations objectAtIndex:i];
NS_DURING
[self performAdaptorOperation: operation];
NS_HANDLER
{
NSException *exp = nil;
NSMutableDictionary *userInfo = nil;
EOAdaptorOperator operator = 0;
NSDebugMLog(@"EXCEPTION %@", localException);
operator = [operation adaptorOperator];
userInfo = [NSMutableDictionary dictionaryWithCapacity: 3];
[userInfo setObject: adaptorOperations
forKey: EOAdaptorOperationsKey];
[userInfo setObject: operation
forKey: EOFailedAdaptorOperationKey];
if(operator == EOAdaptorLockOperator
|| operator == EOAdaptorUpdateOperator)
[userInfo setObject: EOAdaptorOptimisticLockingFailure
forKey: EOAdaptorFailureKey];
exp = [NSException exceptionWithName: EOGeneralAdaptorException
reason: [NSString stringWithFormat:@"%@ -- %@ 0x%x: failed with exception name:%@ reason:\"%@\"",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
[localException name],
[localException reason]]
userInfo: userInfo];
[exp raise];
}
NS_ENDHANDLER;
}
EOFLOGObjectFnStop();
}
@end

135
EOAccess/EOAdaptorContext.h Normal file
View file

@ -0,0 +1,135 @@
/*
EOAdaptorContext.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOAdaptorContext_h__
#define __EOAdaptorContext_h__
#import <Foundation/NSObject.h>
@class NSMutableArray;
@class EOAdaptor;
@class EOAdaptorChannel;
typedef enum {
EODelegateRejects,
EODelegateApproves,
EODelegateOverrides
} EODelegateResponse;
/* The EOAdaptorContext class could be overriden for a concrete database
adaptor. You have to override only those methods marked in this header
with `override'.
*/
@interface EOAdaptorContext : NSObject
{
EOAdaptor *_adaptor;
NSMutableArray *_channels; // values with channels
id _delegate; // not retained
unsigned short _transactionNestingLevel;
BOOL _debug;
/* Flags used to check if the delegate responds to several messages */
struct {
unsigned shouldConnect:1;
unsigned shouldBegin:1;
unsigned didBegin:1;
unsigned shouldCommit:1;
unsigned didCommit:1;
unsigned shouldRollback:1;
unsigned didRollback:1;
} _delegateRespondsTo;
}
+ (EOAdaptorContext *)adaptorContextWithAdaptor: (EOAdaptor *)adaptor;
- initWithAdaptor: (EOAdaptor *)adaptor;
- (EOAdaptor*)adaptor;
- (EOAdaptorChannel *)createAdaptorChannel; // override
- (BOOL)hasOpenChannels;
- (BOOL)hasBusyChannels;
- delegate;
- (void)setDelegate:aDelegate;
- (void)handleDroppedConnection;
@end
@interface EOAdaptorContext (EOTransactions)
- (void)beginTransaction;
- (void)commitTransaction;
- (void)rollbackTransaction;
- (void)transactionDidBegin;
- (void)transactionDidCommit;
- (void)transactionDidRollback;
- (BOOL)hasOpenTransaction;
- (BOOL)canNestTransactions; // override
- (unsigned)transactionNestingLevel;
+ (void)setDebugEnabledDefault: (BOOL)yn;
+ (BOOL)debugEnabledDefault;
- (void)setDebugEnabled: (BOOL)debugEnabled;
- (BOOL)isDebugEnabled;
@end /* EOAdaptorContext (EOTransactions) */
@interface EOAdaptorContext(Private)
- (void)_channelDidInit: aChannel;
- (void)_channelWillDealloc: aChannel;
@end
@interface NSObject (EOAdaptorContextDelegation)
- (BOOL)adaptorContextShouldConnect: context;
- (BOOL)adaptorContextShouldBegin: context;
- (void)adaptorContextDidBegin: context;
- (BOOL)adaptorContextShouldCommit: context;
- (void)adaptorContextDidCommit: context;
- (BOOL)adaptorContextShouldRollback: context;
- (void)adaptorContextDidRollback: context;
@end /* NSObject(EOAdaptorContextDelegate) */
extern NSString *EOAdaptorContextBeginTransactionNotification;
extern NSString *EOAdaptorContextCommitTransactionNotification;
extern NSString *EOAdaptorContextRollbackTransactionNotification;
#endif /* __EOAdaptorContext_h__*/

277
EOAccess/EOAdaptorContext.m Normal file
View file

@ -0,0 +1,277 @@
/**
EOAdaptorContext.m <title>EOAdaptorContext Class</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSArray.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSUtilities.h>
#import <Foundation/NSNotification.h>
#import <Foundation/NSUserDefaults.h>
#import <EOAccess/EOAccess.h>
#import <EOAccess/EOAdaptor.h>
#import <EOAccess/EOAdaptorContext.h>
#import <EOAccess/EOAdaptorChannel.h>
NSString *EOAdaptorContextBeginTransactionNotification = @"EOAdaptorContextBeginTransactionNotofication";
NSString *EOAdaptorContextCommitTransactionNotification = @"EOAdaptorContextCommitTransactionNotofication";
NSString *EOAdaptorContextRollbackTransactionNotification = @"EOAdaptorContextRollbackTransactionNotofication";
@implementation EOAdaptorContext
+ (EOAdaptorContext *)adaptorContextWithAdaptor: (EOAdaptor *)adaptor
{
return [[[self alloc] initWithAdaptor: adaptor] autorelease];
}
- (id) initWithAdaptor: (EOAdaptor *)adaptor
{
if ((self = [super init]))
{
[adaptor _registerAdaptorContext: self];
ASSIGN(_adaptor, adaptor);
_channels = [NSMutableArray new];
_transactionNestingLevel = 0;
[self setDebugEnabled: [[self class] debugEnabledDefault]];
}
return self;
}
- (void)dealloc
{
[_adaptor _unregisterAdaptorContext: self];
DESTROY(_adaptor);
DESTROY(_channels);
[super dealloc];
}
- (EOAdaptorChannel *)createAdaptorChannel
{
[self subclassResponsibility: _cmd];
return nil;
}
- (BOOL)hasOpenChannels
{
int i, count = [_channels count];
for (i = 0; i < count; i++)
if ([[[_channels objectAtIndex: i] nonretainedObjectValue] isOpen])
return YES;
return NO;
}
- (BOOL)hasBusyChannels
{
int i, count = [_channels count];
for (i = 0; i < count; i++)
if ([[[_channels objectAtIndex: i] nonretainedObjectValue]
isFetchInProgress])
return YES;
return NO;
}
- (void)setDelegate:delegate
{
_delegate = delegate;
_delegateRespondsTo.shouldConnect =
[delegate respondsToSelector:@selector(adaptorContextShouldConnect:)];
_delegateRespondsTo.shouldBegin =
[delegate respondsToSelector:@selector(adaptorContextShouldBegin:)];
_delegateRespondsTo.didBegin =
[delegate respondsToSelector:@selector(adaptorContextDidBegin:)];
_delegateRespondsTo.shouldCommit =
[delegate respondsToSelector:@selector(adaptorContextShouldCommit:)];
_delegateRespondsTo.didCommit =
[delegate respondsToSelector:@selector(adaptorContextDidCommit:)];
_delegateRespondsTo.shouldRollback =
[delegate respondsToSelector:@selector(adaptorContextShouldRollback:)];
_delegateRespondsTo.didRollback =
[delegate respondsToSelector:@selector(adaptorContextDidRollback:)];
}
- (EOAdaptor *)adaptor
{
return _adaptor;
}
- delegate
{
return _delegate;
}
- (void)handleDroppedConnection
{
[self subclassResponsibility: _cmd];
}
@end
@implementation EOAdaptorContext (EOTransactions)
- (void)beginTransaction
{
[self subclassResponsibility: _cmd];
}
- (void)commitTransaction
{
[self subclassResponsibility: _cmd];
}
- (void)rollbackTransaction
{
[self subclassResponsibility: _cmd];
}
- (void)transactionDidBegin
{
// Increment the transaction scope
_transactionNestingLevel++;
[[NSNotificationCenter defaultCenter]
postNotificationName: EOAdaptorContextBeginTransactionNotification
object: self];
//the notification call dbcontext _beginTransaction
}
- (void)transactionDidCommit
{
EOFLOGObjectFnStart();
// Decrement the transaction scope
_transactionNestingLevel--;//OK
//OK
[[NSNotificationCenter defaultCenter]
postNotificationName: EOAdaptorContextCommitTransactionNotification
object: self];
EOFLOGObjectFnStop();
}
- (void)transactionDidRollback
{
// Decrement the transaction scope
_transactionNestingLevel--;
[[NSNotificationCenter defaultCenter]
postNotificationName: EOAdaptorContextRollbackTransactionNotification
object: self];
}
- (BOOL)hasOpenTransaction
{
if (_transactionNestingLevel > 0)
return YES;
return NO;
}
- (BOOL)canNestTransactions
{
[self subclassResponsibility: _cmd];
return NO;
}
- (unsigned)transactionNestingLevel
{
return _transactionNestingLevel;
}
+ (void)setDebugEnabledDefault: (BOOL)flag
{
NSString *yn = (flag ? @"YES" : @"NO");
[[NSUserDefaults standardUserDefaults] setObject: yn
forKey: @"EOAdaptorDebugEnabled"];
}
+ (BOOL)debugEnabledDefault
{
//OK
return [[NSUserDefaults standardUserDefaults]
boolForKey: @"EOAdaptorDebugEnabled"];
}
- (void)setDebugEnabled:(BOOL)debugEnabled
{
_debug = debugEnabled;
}
- (BOOL)isDebugEnabled
{
return _debug;
}
@end /* EOAdaptorContext (EOTransactions) */
@implementation EOAdaptorContext (EOAdaptorContextPrivate)
//_registerAdaptorChannel:
- (void)_channelDidInit: channel
{
[_channels addObject: [NSValue valueWithNonretainedObject: channel]];
[channel setDebugEnabled: [self isDebugEnabled]];
//call self delegate
//call channel setDelegate: returned ?
}
- (void)_channelWillDealloc:channel
{
int i;
for (i = [_channels count] - 1; i >= 0; i--)
{
if ([[_channels objectAtIndex: i] nonretainedObjectValue] == channel)
{
[_channels removeObjectAtIndex: i];
break;
}
}
}
@end

View file

@ -0,0 +1,215 @@
/**
EOAdaptorOperation.m <title>EOAdaptorOperation Class</title>
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSObject.h>
#import <extensions/NSException.h>
#import <EOAccess/EOAccess.h>
#import <EOAccess/EODatabaseOperation.h>
#import <EOAccess/EOAttribute.h>
#import <EOAccess/EOEntity.h>
#import <EOControl/EOSortOrdering.h>
@implementation EOAdaptorOperation
+ (EOAdaptorOperation *)adaptorOperationWithEntity: (EOEntity *)entity
{
return [[[self alloc] initWithEntity: entity] autorelease];
}
- (id) initWithEntity: (EOEntity *)entity
{
if ((self = [self init]))
{
ASSIGN(_entity, entity);
}
return self;
}
- (void)dealloc
{
DESTROY(_entity);
DESTROY(_qualifier);
DESTROY(_changedValues);
DESTROY(_attributes);
DESTROY(_storedProcedure);
DESTROY(_exception);
[super dealloc];
}
- (EOAdaptorOperator)adaptorOperator
{
return _adaptorOperator;
}
- (void)setAdaptorOperator: (EOAdaptorOperator)adaptorOperator
{
NSDebugMLLog(@"gsdb", @"adaptorOperator=%d", adaptorOperator);
_adaptorOperator = adaptorOperator;
NSDebugMLLog(@"gsdb", @"_adaptorOperator=%d", _adaptorOperator);
}
- (EOEntity *)entity
{
return _entity;
}
- (EOQualifier *)qualifier
{
return _qualifier;
}
- (void)setQualifier: (EOQualifier *)qualifier
{
ASSIGN(_qualifier, qualifier);
}
- (NSDictionary *)changedValues
{
return _changedValues;
}
- (void)setChangedValues: (NSDictionary *)changedValues
{
ASSIGN(_changedValues, changedValues);
}
- (NSArray *)attributes
{
return _attributes;
}
- (void)setAttributes: (NSArray *)attributes
{
ASSIGN(_attributes, attributes);
}
- (EOStoredProcedure *)storedProcedure
{
return _storedProcedure;
}
- (void)setStoredProcedure: (EOStoredProcedure *)storedProcedure
{
ASSIGN(_storedProcedure, storedProcedure);
}
- (NSException *)exception
{
return _exception;
}
- (void)setException: (NSException *)exception
{
ASSIGN(_exception, exception);
}
- (NSComparisonResult)compareAdaptorOperation: (EOAdaptorOperation *)adaptorOp
{
NSComparisonResult res;
EOAdaptorOperator otherOp = [adaptorOp adaptorOperator];
res = [[_entity name] compare: [[adaptorOp entity] name]];
if(res == NSOrderedSame)
{
if(_adaptorOperator == otherOp)
res = NSOrderedSame;
else if(_adaptorOperator < otherOp)
res = NSOrderedAscending;
else
res = NSOrderedDescending;
}
return res;
}
- (NSString *)description
{
//TODO revoir
NSString *operatorString = nil;
NSString *desc = nil;
EOFLOGObjectFnStart();
switch(_adaptorOperator)
{
case EOAdaptorUndefinedOperator:
operatorString = @"EOAdaptorUndefinedOperator";
break;
case EOAdaptorLockOperator:
operatorString = @"EOAdaptorLockOperator";
break;
case EOAdaptorInsertOperator:
operatorString = @"EOAdaptorInsertOperator";
break;
case EOAdaptorUpdateOperator:
operatorString = @"EOAdaptorUpdateOperator";
break;
case EOAdaptorDeleteOperator:
operatorString = @"EOAdaptorDeleteOperator";
break;
case EOAdaptorStoredProcedureOperator:
operatorString = @"EOAdaptorStoredProcedureOperator";
break;
default:
operatorString = @"Unknwon";
break;
}
desc = [NSString stringWithFormat: @"<%s %p : operator: %@ entity: %@ qualifier:%@\nchangedValues: %@\nattributes:%@\nstoredProcedure: %@\nexception: %@>",
object_get_class_name(self),
(void*)self,
operatorString,
[_entity name],
_qualifier,
_changedValues,
_attributes,
_storedProcedure,
_exception];
EOFLOGObjectFnStop();
return desc;
}
@end

40
EOAccess/EOAdaptorPriv.h Normal file
View file

@ -0,0 +1,40 @@
/*
EOAdaptorPriv.h
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: Nov 2002
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOAdaptorPriv_h__
#define __EOAdaptorPriv_h__
@interface EOAdaptor(EOAdaptorPrivate)
- (void) _requestConcreteImplementationForSelector: (SEL)param0;
- (void) _unregisterAdaptorContext: (EOAdaptorContext*)adaptorContext;
- (void) _registerAdaptorContext: (EOAdaptorContext*)adaptorContext;
@end
#endif /* __EOAdaptorPriv_h__ */

282
EOAccess/EOAttribute.h Normal file
View file

@ -0,0 +1,282 @@
/*
EOAttribute.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: Feb 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOAttribute_h__
#define __EOAttribute_h__
#import <Foundation/NSString.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSDate.h>
#import <extensions/GCObject.h>
#import <extensions/GCArray.h>
#import <extensions/NSException.h>
#import <EOAccess/EOPropertyListEncoding.h>
@class EOEntity;
@class EOExpressionArray;
@class EOStoredProcedure;
typedef enum {
EOFactoryMethodArgumentIsNSData = 0,
EOFactoryMethodArgumentIsNSString,
EOFactoryMethodArgumentIsBytes
} EOFactoryMethodArgumentType;
typedef enum {
EOAdaptorNumberType = 0,
EOAdaptorCharactersType,
EOAdaptorBytesType,
EOAdaptorDateType
} EOAdaptorValueType;
typedef enum {
EOVoid = 0,
EOInParameter,
EOOutParameter,
EOInOutParameter
} EOParameterDirection;
@interface EOAttribute : GCObject <EOPropertyListEncoding>
{
NSString *_name;
NSString *_prototypeName;
NSString *_columnName;
NSString *_externalType;
NSString *_valueType;
NSString *_valueClassName;
NSString *_readFormat;
NSString *_writeFormat;
NSTimeZone *_serverTimeZone;
unsigned int _width;
unsigned short _precision;
short _scale;
Class _valueClass;
EOFactoryMethodArgumentType _argumentType;
NSString *_valueFactoryMethodName;
NSString *_adaptorValueConversionMethodName;
SEL _valueFactoryMethod;
SEL _adaptorValueConversionMethod;
struct {
unsigned int allowsNull:1;
unsigned int isReadOnly:1;
unsigned int isParentAnEOEntity:1;
unsigned int protoOverride:17;
unsigned int unused : 12;
unsigned int extraRefCount;
} _flags;
NSDictionary *_sourceToDestinationKeyMap;
EOParameterDirection _parameterDirection;
NSDictionary *_userInfo;
NSDictionary *_internalInfo;
NSString *_docComment;
/* Garbage collectable objects */
// EOEntity *_entity;
// GCMutableArray *_definitionArray; // These variables are meaningful only
id _parent;
EOAttribute *_prototype;
EOExpressionArray *_definitionArray;
EOAttribute *_realAttribute; // if the attribute is flattened //Not in EOF !
}
/** returns an autoreleased attribute owned by onwer and built from propertyList **/
+ (id) attributeWithPropertyList: (NSDictionary *)propertyList
owner: (id)owner;
/* Accessing the entity */
- (NSString *)name;
- (EOEntity *)entity;
- (EOStoredProcedure *)storedProcedure;
- (id)parent;
- (NSString *)prototypeName;
- (EOAttribute *)prototype;
- (NSString *)externalType;
- (NSString *)columnName;
- (NSString *)definition;
- (BOOL)isFlattened;
- (BOOL)isDerived;
- (BOOL)isReadOnly;
- (NSString *)valueClassName;
- (NSString *)valueType;
- (unsigned)width;
- (unsigned)precision;
- (int)scale;
- (BOOL)allowsNull;
- (NSString *)writeFormat;
- (NSString *)readFormat;
- (EOParameterDirection)parameterDirection;
- (NSDictionary *)userInfo;
- (NSString *)docComment;
- (BOOL)isKeyDefinedByPrototype: (NSString *)key;
@end
@interface EOAttribute (EOAttributeEditing)
- (NSException *)validateName: (NSString *)name;
- (void)setName: (NSString *)name;
- (void)setPrototypeName: (NSString *)prototypeName;
- (void)setReadOnly: (BOOL)yn;
- (void)setColumnName: (NSString *)columnName;
- (void)setDefinition: (NSString *)definition;
- (void)setExternalType: (NSString *)type;
- (void)setValueType: (NSString *)type;
- (void)setValueClassName: (NSString *)name;
- (void)setWidth: (unsigned)length;
- (void)setPrecision: (unsigned)precision;
- (void)setScale: (int)scale;
- (void)setAllowsNull: (BOOL)allowsNull;
- (void)setWriteFormat: (NSString *)string;
- (void)setReadFormat: (NSString *)string;
- (void)setParameterDirection: (EOParameterDirection)parameterDirection;
- (void)setUserInfo: (NSDictionary *)dictionary;
- (void)setInternalInfo: (NSDictionary *)dictionary;
- (void)setDocComment: (NSString *)docComment;
- (id)_normalizeDefinition: (EOExpressionArray*)definition
path: (id)path;
@end
@interface EOAttribute(EOModelBeautifier)
- (void)beautifyName;
@end
@interface EOAttribute (NSCalendarDateSupport)
- (NSTimeZone *)serverTimeZone;
@end
@interface EOAttribute(NSCalendarDateSupportEditing)
- (void)setServerTimeZone: (NSTimeZone *)tz;
@end
@interface EOAttribute (EOAttributeValueCreation)
- (id)newValueForBytes: (const void *)bytes
length: (int)length;
- (id)newValueForBytes: (const void *)bytes
length: (int)length
encoding: (NSStringEncoding)encoding;
- (NSCalendarDate *)newDateForYear: (int)year
month: (unsigned)month
day: (unsigned)day
hour: (unsigned)hour
minute: (unsigned)minute
second: (unsigned)second
millisecond: (unsigned)millisecond
timezone: (NSTimeZone *)timezone
zone: (NSZone *)zone;
- (NSString *)valueFactoryMethodName;
- (SEL)valueFactoryMethod;
- (id)adaptorValueByConvertingAttributeValue: (id)value;
- (NSString *)adaptorValueConversionMethodName;
- (SEL)adaptorValueConversionMethod;
- (EOAdaptorValueType)adaptorValueType;
- (EOFactoryMethodArgumentType)factoryMethodArgumentType;
@end
@interface EOAttribute(EOAttributeValueCreationEditing)
- (void)setValueFactoryMethodName: (NSString *)factoryMethodName;
- (void)setAdaptorValueConversionMethodName: (NSString *)conversionMethodName;
- (void)setFactoryMethodArgumentType: (EOFactoryMethodArgumentType)argumentType;
@end
@interface EOAttribute(EOAttributeValueMapping)
- (NSException *)validateValue: (id *)valueP;
@end
@interface NSObject (EOCustomClassArchiving)
+ objectWithArchiveData: (NSData *)data;
- (NSData *)archiveData;
@end
#endif /* __EOAttribute_h__ */

1285
EOAccess/EOAttribute.m Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,50 @@
/*
EOAttributePriv.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOAttributePriv_h__
#define __EOAttributePriv_h__
@interface EOAttribute (EOAttributePrivate)
- (GCMutableArray *)_definitionArray;
- (void)setParent: (id)parent;
- (EOAttribute *)realAttribute;
@end
@interface EOAttribute (EOAttributePrivate2)
- (BOOL) _hasAnyOverrides;
- (void) _resetPrototype;
- (void) _updateFromPrototype;
- (void) _setOverrideForKeyEnum: (int)keyEnum;
- (BOOL) _isKeyEnumOverriden: (int)param0;
- (BOOL) _isKeyEnumDefinedByPrototype: (int)param0;
@end
#endif /* __EOAttributePriv_h__ */

113
EOAccess/EODatabase.h Normal file
View file

@ -0,0 +1,113 @@
/*
EODatabase.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: Jun 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EODatabase_h__
#define __EODatabase_h__
#import <EOControl/EOControl.h>
@class EOAdaptor;
@class EOModel;
@class EOEntity;
@class EODatabaseContext;
@class EOGlobalID;
@class EOEditingContext;
extern NSString *EOGeneralDatabaseException;
@interface EODatabase : NSObject
{
NSMutableArray *_registeredContexts;
NSMutableDictionary *_snapshots;
NSMutableArray *_models;
NSMutableDictionary *_entityCache;
EOAdaptor *_adaptor;
NSMutableDictionary *_toManySnapshots;
}
+ (EODatabase *)databaseWithModel: (EOModel *)model;
- initWithAdaptor: (EOAdaptor *)adaptor;
- initWithModel: (EOModel *)model;
- (NSArray *)registeredContexts;
- (void)registerContext: (EODatabaseContext *)context;
- (void)unregisterContext: (EODatabaseContext *)context;
- (EOAdaptor *)adaptor;
- (void)addModel: (EOModel *)model;
- (void)removeModel: (EOModel *)model;
- (BOOL)addModelIfCompatible: (EOModel *)model;
- (NSArray *)models;
- (EOEntity *)entityNamed: (NSString *)entityName;
- (EOEntity *)entityForObject: (id)object;
- (NSArray *)resultCacheForEntityNamed: (NSString *)name;
- (void)setResultCache: (NSArray *)cache forEntityNamed: (NSString *)name;
- (void)invalidateResultCacheForEntityNamed: (NSString *)name;
- (void)invalidateResultCache;
- (void)handleDroppedConnection;
@end
@interface EODatabase (EOUniquing)
- (void)recordSnapshot: (NSDictionary *)snapshot forGlobalID: (EOGlobalID *)gid;
- (NSDictionary *)snapshotForGlobalID:(EOGlobalID *)gid;
- (void)recordSnapshot:(NSArray *)gids
forSourceGlobalID:(EOGlobalID *)gid
relationshipName:(NSString *)name;
- (NSArray *)snapshotForSourceGlobalID: (EOGlobalID *)gid
relationshipName: (NSString *)name;
- (void)forgetSnapshotForGlobalID: (EOGlobalID *)gid;
- (void)forgetSnapshotsForGlobalIDs: (NSArray *)array;
- (void)forgetAllSnapshots;
- (void)recordSnapshots: (NSDictionary *)snapshots;
- (void)recordToManySnapshots: (NSDictionary *)snapshots;
- (NSDictionary *)snapshots;
@end
#endif /* __EODatabase_h__ */

617
EOAccess/EODatabase.m Normal file
View file

@ -0,0 +1,617 @@
/**
EODatabase.m <title>EODatabase Class</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: June 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/Foundation.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSString.h>
#import <Foundation/NSException.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSUtilities.h>
#import <extensions/NSException.h>
#import <extensions/exceptions/GeneralExceptions.h>
#import <EOAccess/EOAccess.h>
#import <EOAccess/EOAccessFault.h>
#import <EOAccess/EOAdaptor.h>
#import <EOAccess/EOModel.h>
#import <EOAccess/EOEntity.h>
#import <EOAccess/EODatabase.h>
#import <EOAccess/EODatabaseContext.h>
#import <EOControl/EOObjectStore.h>
/* TODO
Controllare il resultCache, ad ogni forget/invalidate deve essere
updatato.
*/
NSString *EOGeneralDatabaseException = @"EOGeneralDatabaseException";
@implementation EODatabase
/*
* Database Global Methods
*/
static NSMutableArray *databaseInstances;
+ (void)initialize
{
// THREAD
databaseInstances = [NSMutableArray new];
}
+ (void)makeAllDatabasesPerform: (SEL)aSelector withObject: anObject
{
int i;
// THREAD
for (i = [databaseInstances count] - 1; i >= 0; i--)
[[[databaseInstances objectAtIndex: i] nonretainedObjectValue]
performSelector: aSelector withObject: anObject];
}
/*
* Initializing new instances
*/
//OK
- initWithAdaptor: (EOAdaptor *)adaptor
{
EOFLOGObjectFnStart();
if (!adaptor)
{
[self autorelease];
return nil;
}
if ((self = [super init]))
{
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(_globalIDChanged:)
name: @"EOGlobalIDChangedNotification"
object: nil];
// [databaseInstances addObject:[NSValue valueWithNonretainedObject:self]];
ASSIGN(_adaptor,adaptor);
_registeredContexts = [NSMutableArray new];
_snapshots = [NSMutableDictionary new];
_models = [NSMutableArray new];
_entityCache = [NSMutableDictionary new];
_toManySnapshots = [NSMutableDictionary new];
}
EOFLOGObjectFnStop();
return self;
}
+ (EODatabase *)databaseWithModel: (EOModel *)model
{
return [[[self alloc] initWithModel: model] autorelease];
}
- (id)initWithModel: (EOModel *)model
{
EOAdaptor *adaptor = [EOAdaptor adaptorWithModel:model]; //Handle exception to deallocate self ?
if ((self = [self initWithAdaptor: adaptor]))
{
[self addModel: model];
}
return self;
}
- (void)dealloc
{
[_adaptor release];
[_registeredContexts release];
[_snapshots release];
[_models release];
[_entityCache release];
[_toManySnapshots release];
[super dealloc];
}
- (NSArray *)registeredContexts
{
NSMutableArray *array = [NSMutableArray array];
int i, n;
for (i = 0, n = [_registeredContexts count]; i < n; i++)
[array addObject: [[_registeredContexts objectAtIndex: i]
nonretainedObjectValue]];
return array;
}
- (unsigned int) _indexOfRegisteredContext: (EODatabaseContext *)context
{
int i;
for( i = [_registeredContexts count]-1; i >= 0; i--)
if ([[_registeredContexts objectAtIndex: i]
nonretainedObjectValue] == context)
{
return i;
}
return -1;
}
- (void)registerContext: (EODatabaseContext *)context
{
unsigned int index=0;
//OK
NSAssert(([context database] == self),@"Database context is not me");
index = [self _indexOfRegisteredContext:context];
NSAssert(index == (unsigned int) -1 , @"DatabaseContext already registred");
[_registeredContexts addObject:
[NSValue valueWithNonretainedObject: context]];
}
- (void)unregisterContext: (EODatabaseContext *)context
{
//OK
unsigned int index = [self _indexOfRegisteredContext:context];
NSAssert(index != (unsigned int) -1, @"DatabaseContext wasn't registred");
[_registeredContexts removeObjectAtIndex:index];
}
- (EOAdaptor *)adaptor
{
return _adaptor;
}
- (void)addModel: (EOModel *)model
{
[_models addObject: model];
}
- (void)removeModel: (EOModel *)model
{
[_models removeObject: model];
}
- (BOOL)addModelIfCompatible: (EOModel *)model;
{
BOOL modelOk = NO;
NSAssert(model, @"No model");//WO simply return NO (doesn't handle this case).
if ([_models containsObject:model] == YES)
modelOk = YES;
else
{
EOAdaptor *adaptor = [self adaptor];
if ([[model adaptorName] isEqualToString: [adaptor name]] == YES
|| [_adaptor canServiceModel: model] == YES)
{
[_models addObject: model];
modelOk = YES;
}
}
return modelOk;
}
- (NSArray *)models
{
return _models;
}
- (EOEntity *)entityNamed: (NSString *)entityName
{
//OK
EOEntity *entity=nil;
int i = 0;
int count = 0;
NSAssert(entityName, @"No entity name");
count = [_models count];
for(i = 0; !entity && i < count; i++)
{
EOModel *model = [_models objectAtIndex: i];
entity = [model entityNamed: entityName];
}
return entity;
}
- (EOEntity *)entityForObject: (id)object
{
//OK
EOEntity *entity = nil;
NSString *entityName = nil;
EOFLOGObjectFnStart();
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"object=%p (of class %@)",
object, [object class]);
NSAssert(object, @"No object");
if ([EOFault isFault: object])
{
EOFaultHandler *faultHandler = [EOFault handlerForFault: object];
EOKeyGlobalID *gid;
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"faultHandler=%p (of class %@)",
faultHandler, [faultHandler class]);
gid = [(EOAccessFaultHandler *)faultHandler globalID];
NSAssert3(gid, @"No gid for fault handler %p for object %p of class %@",
faultHandler, object, [object class]);
entityName = [gid entityName];
}
else
entityName = [object entityName];
NSAssert2(entityName, @"No object entity name for object %@ of class %@",
object, [object class]);
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"entityName=%@", entityName);
entity = [self entityNamed: entityName];
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"entity=%p", entity);
EOFLOGObjectFnStop();
return entity;
}
- (NSArray *)resultCacheForEntityNamed: (NSString *)name
{
return [_entityCache objectForKey: name];
}
- (void)setResultCache: (NSArray *)cache
forEntityNamed: (NSString *)name
{
EOFLOGObjectFnStart();
[_entityCache setObject: cache
forKey: name];
EOFLOGObjectFnStop();
}
- (void)invalidateResultCacheForEntityNamed: (NSString *)name
{
[_entityCache removeObjectForKey: name];//??
}
- (void)invalidateResultCache
{
[_entityCache removeAllObjects];
}
- (void)handleDroppedConnection
{
NSArray *dbContextArray;
NSEnumerator *contextEnum;
EODatabaseContext *dbContext;
EOFLOGObjectFnStartOrCond2(@"DatabaseLevel", @"EODatabase");
[_adaptor handleDroppedConnection];
dbContextArray = [self registeredContexts];
contextEnum = [dbContextArray objectEnumerator];
while ((dbContext = [contextEnum nextObject]))
[dbContext handleDroppedConnection];
EOFLOGObjectFnStopOrCond2(@"DatabaseLevel", @"EODatabase");
}
@end
@implementation EODatabase (EOUniquing)
- (void)recordSnapshot: (NSDictionary *)snapshot
forGlobalID: (EOGlobalID *)gid
{
EOFLOGObjectFnStart();
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"snapshot %p %@", snapshot, snapshot);
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"gid=%@", gid);
NSAssert(gid, @"No gid");
NSAssert(snapshot, @"No snapshot");
NSAssert(_snapshots, @"No _snapshots");
[_snapshots setObject: snapshot
forKey: gid];
NSAssert([_snapshots objectForKey: gid], @"SNAPSHOT not save !!");
EOFLOGObjectFnStop();
}
//"Receive EOGlobalIDChangedNotification notification"
- (void)_globalIDChanged: (NSNotification *)notification
{
NSDictionary *snapshot = nil;
NSDictionary *userInfo = nil;
NSEnumerator *enumerator = nil;
EOGlobalID *tempGID = nil;
EOGlobalID *gid = nil;
EOFLOGObjectFnStart();
userInfo = [notification userInfo];
enumerator = [userInfo keyEnumerator];
while ((tempGID = [enumerator nextObject]))
{
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"tempGID=%@", tempGID);
gid = [userInfo objectForKey: tempGID];
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"gid=%@", gid);
//OK ?
snapshot = [_snapshots objectForKey: tempGID];
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"_snapshots snapshot=%@", snapshot);
if (snapshot)
{
[_snapshots removeObjectForKey: tempGID];
[_snapshots setObject: snapshot
forKey: gid];
}
//OK ?
snapshot = [_toManySnapshots objectForKey: tempGID];
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"_toManySnapshots snapshot=%@",
snapshot);
if (snapshot)
{
[_toManySnapshots removeObjectForKey: tempGID];
[_toManySnapshots setObject: snapshot
forKey: gid];
}
}
EOFLOGObjectFnStop();
}
- (NSDictionary *)snapshotForGlobalID: (EOGlobalID *)gid
{
//seems OK
NSDictionary *snapshot = nil;
EOFLOGObjectFnStart();
NSAssert(gid, @"No gid");
snapshot = [_snapshots objectForKey: gid];
EOFLOGObjectFnStop();
return snapshot;
}
- (void)recordSnapshot: (NSArray*)gids
forSourceGlobalID: (EOGlobalID *)gid
relationshipName: (NSString *)name
{
//OK
NSMutableDictionary *toMany = nil;
EOFLOGObjectFnStart();
NSAssert(gid,@"No snapshot");
NSAssert(gid,@"No Source Global ID");
NSAssert(name,@"No relationship name");
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"self=%p snapshot gids=%@", self, gids);
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"SourceGlobalID gid=%@", gid);
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"relationshipName=%@", name);
toMany = [_toManySnapshots objectForKey: gid];
if (!toMany)
{
toMany = [NSMutableDictionary dictionaryWithCapacity: 10];
[_toManySnapshots setObject: toMany
forKey: gid];
}
[toMany setObject: gids
forKey: name];
EOFLOGObjectFnStop();
}
- (NSArray *)snapshotForSourceGlobalID: (EOGlobalID *)gid
relationshipName: (NSString *)name
{
NSAssert(gid, @"No Source Global ID");
NSAssert(name, @"No relationship name");
return [[_toManySnapshots objectForKey: gid] objectForKey: name];
}
- (void)forgetSnapshotForGlobalID: (EOGlobalID *)gid
{
//Seems OK
EOFLOGObjectFnStart();
NSAssert(gid,@"No Global ID");
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"gid=%@", gid);
[_snapshots removeObjectForKey: gid];
[_toManySnapshots removeObjectForKey: gid];
[[NSNotificationCenter defaultCenter]
postNotificationName: EOObjectsChangedInStoreNotification
object: self
userInfo: [NSDictionary dictionaryWithObject:
[NSArray arrayWithObject: gid]
forKey: EOInvalidatedKey]];
EOFLOGObjectFnStop();
};
- (void)forgetSnapshotsForGlobalIDs: (NSArray*)ids
{
NSEnumerator *gidEnum = nil;
id gid = nil;
EOFLOGObjectFnStart();
NSAssert(ids, @"No Global IDs");
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"ids=%@", ids);
gidEnum = [ids objectEnumerator];
while ((gid = [gidEnum nextObject]))
{
[_snapshots removeObjectForKey: gid];
[_toManySnapshots removeObjectForKey: gid];
}
[[NSNotificationCenter defaultCenter]
postNotificationName: EOObjectsChangedInStoreNotification
object: self
userInfo: [NSDictionary dictionaryWithObject: ids
forKey: EOInvalidatedKey]];
EOFLOGObjectFnStop();
}
- (void)forgetAllSnapshots
{
NSMutableSet *gidSet = [NSMutableSet new];
NSMutableArray *gidArray = [NSMutableArray array];
EOFLOGObjectFnStartOrCond2(@"DatabaseLevel", @"EODatabase");
[gidSet addObjectsFromArray: [_snapshots allKeys]];
[gidSet addObjectsFromArray: [_toManySnapshots allKeys]];
[gidArray addObjectsFromArray: [gidSet allObjects]];
[gidSet release];
[_snapshots removeAllObjects];
[_toManySnapshots removeAllObjects];
[[NSNotificationCenter defaultCenter]
postNotificationName: EOObjectsChangedInStoreNotification
object:self
userInfo: [NSDictionary dictionaryWithObject: gidArray
forKey: EOInvalidatedKey]];
EOFLOGObjectFnStopOrCond2(@"DatabaseLevel", @"EODatabase");
}
- (void)recordSnapshots: (NSDictionary *)snapshots
{
//OK
//VERIFY: be sure to replace all anapshot entries if any !
EOFLOGObjectFnStart();
[_snapshots addEntriesFromDictionary: snapshots];
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"self=%p _snapshots=%@",
self, _snapshots);
EOFLOGObjectFnStop();
}
- (void)recordToManySnapshots: (NSDictionary *)snapshots
{
//Seems OK
NSEnumerator *keyEnum = nil;
id key = nil;
EOFLOGObjectFnStart();
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"snapshots=%@", snapshots);
NSAssert(snapshots, @"No snapshots");
keyEnum = [snapshots keyEnumerator];
while ((key = [keyEnum nextObject]))
{
NSMutableDictionary *toMany = nil;
toMany = [_toManySnapshots objectForKey: key]; // look if already exists
if (!toMany)
{
toMany = [NSMutableDictionary dictionaryWithCapacity: 10];
[_toManySnapshots setObject: toMany
forKey: key];
}
[toMany addEntriesFromDictionary: [snapshots objectForKey: key]];
}
EOFLOGObjectLevelArgs(@"EODatabaseContext", @"snapshots=%@", snapshots);
EOFLOGObjectFnStop();
}
- (NSDictionary *)snapshots
{
return _snapshots;
}
@end /* EODatabase (EOUniquing) */

View file

@ -0,0 +1,92 @@
/*
EODatabaseChannel.h
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EODatabaseChannel_h__
#define __EODatabaseChannel_h__
#import <EOAccess/EOAdaptorChannel.h>
#import <EOControl/EOControl.h>
@class EOAdaptorChannel;
@class EORelationship;
@class EODatabaseContext;
@interface EODatabaseChannel : NSObject
{
EODatabaseContext *_databaseContext;
id _delegate;
EOAdaptorChannel *_adaptorChannel;
EOEntity *_currentEntity;
EOEditingContext *_currentEditingContext;
NSMutableArray *_fetchProperties;
NSMutableArray *_fetchSpecifications;
BOOL _isLocking;
BOOL _isRefreshingObjects;
struct {
unsigned int shouldSelectObjects:1;
unsigned int didSelectObjects:1;
unsigned int shouldUsePessimisticLock:1;
unsigned int shouldUpdateSnapshot:1;
unsigned int _reserved:28;
} _delegateRespondsTo;
}
+ (EODatabaseChannel*)databaseChannelWithDatabaseContext: (EODatabaseContext *)databaseContext;
- initWithDatabaseContext: (EODatabaseContext *)databaseContext;
- (void)setCurrentEntity: (EOEntity *)entity;
- (void) setEntity: (EOEntity *)entity;
- (void)setCurrentEditingContext: (EOEditingContext *)context;
- (void)selectObjectsWithFetchSpecification: (EOFetchSpecification *)fetchSpecification
editingContext: (EOEditingContext *)context;
- (id)fetchObject;
- (BOOL)isFetchInProgress;
- (void)cancelFetch;
- (EODatabaseContext *)databaseContext;
- (EOAdaptorChannel *)adaptorChannel;
- (BOOL)isRefreshingObjects;
- (void)setIsRefreshingObjects: (BOOL)yn;
- (BOOL)isLocking;
- (void)setIsLocking: (BOOL)isLocking;
- (void)setDelegate: (id)delegate;
- (id) delegate;
@end
#endif /* __EODatabaseChannel_h__ */

View file

@ -0,0 +1,792 @@
/**
EODatabaseChannel.m <title>EODatabaseChannel</title>
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: June 2000
Author: Manuel Guesdon <mguesdon@orange-concept.com>
Date: October 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/Foundation.h>
#import <EOAccess/EOAccess.h>
#import <EOAccess/EODatabaseChannel.h>
#import <EOAccess/EODatabaseChannelPriv.h>
#import <EOAccess/EODatabaseContext.h>
#import <EOAccess/EODatabaseContextPriv.h>
#import <EOAccess/EODatabase.h>
#import <EOAccess/EOAdaptor.h>
#import <EOAccess/EOAdaptorChannel.h>
#import <EOAccess/EOEntity.h>
#import <EOAccess/EOAttribute.h>
#import <EOAccess/EORelationship.h>
#import <EOAccess/EOModel.h>
#import <EOAccess/EOAccessFault.h>
#import <EOControl/EOEditingContext.h>
#import <EOControl/EOKeyValueCoding.h>
#import <EOControl/EOFetchSpecification.h>
#import <EOControl/EOClassDescription.h>
#import <EOControl/EOGlobalID.h>
#import <EOControl/EOObjectStore.h>
@implementation EODatabaseChannel
+ (void)load
{
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(_registerDatabaseChannel:)
name: EODatabaseChannelNeededNotification
object: nil];
}
+ (void)_registerDatabaseChannel: (NSNotification *)notification
{
// TODO who release it ?
[[EODatabaseChannel alloc] initWithDatabaseContext: [notification object]];
}
+ (EODatabaseChannel*)databaseChannelWithDatabaseContext: (EODatabaseContext *)databaseContext
{
return [[[self alloc] initWithDatabaseContext: databaseContext] autorelease];
}
- (id) initWithDatabaseContext:(EODatabaseContext *)databaseContext
{
if ((self = [super init]))
{
ASSIGN(_databaseContext, databaseContext);
ASSIGN(_adaptorChannel, [[_databaseContext adaptorContext]
createAdaptorChannel]);
//TODO NO<<<<
[_adaptorChannel openChannel];
_fetchProperties = [NSMutableArray new];
_fetchSpecifications = [NSMutableArray new];
//NO>>>>>>>
[_databaseContext registerChannel: self];//should be in caller
}
return self;
}
- (void)dealloc
{
[_databaseContext unregisterChannel: self];
DESTROY(_databaseContext);
[_adaptorChannel closeChannel];
DESTROY(_adaptorChannel);
DESTROY(_currentEntity);
DESTROY(_currentEditingContext);
DESTROY(_fetchProperties);
DESTROY(_fetchSpecifications);
[super dealloc];
}
- (void)setCurrentEntity: (EOEntity *)entity
{
//OK
ASSIGN(_currentEntity, entity);
[self setEntity: entity];
}
- (void) setEntity: (EOEntity *)entity
{
//Near OK
NSArray *relationships = [entity relationships];
int i = 0;
int count = [relationships count];
NSDebugMLLog(@"gsdb", @"relationships=%@", relationships);
for (i = 0; i < count; i++)
{
EORelationship *relationship = [relationships objectAtIndex:i];
EOEntity *destinationEntity = [relationship destinationEntity];
EOModel *destinationEntityModel = [destinationEntity model];
EOEntity *entity = [relationship entity];
EOModel *entityModel = [entity model];
NSDebugMLLog(@"gsdb", @"relationship=%@", relationship);
NSDebugMLLog(@"gsdb", @"destinationEntity=%@", [destinationEntity name]);
NSAssert2(destinationEntity, @"No destinationEntity in relationship: %@ of entity %@",
relationship, [entity name]); //TODO: flattened relationship
NSDebugMLLog(@"gsdb", @"entity=%@", [entity name]);
NSDebugMLLog(@"gsdb", @"destinationEntityModel=%p", destinationEntityModel);
NSDebugMLLog(@"gsdb", @"entityModel=%p", entityModel);
//If different: try to add destinationEntityModel
if (destinationEntityModel != entityModel)
{
EOEditingContext *editingContext = [self currentEditingContext];
//EODatabaseContext *databaseContext = [self databaseContext];
EOObjectStore *rootObjectStore = [editingContext rootObjectStore];
NSArray *cooperatingObjectStores =
[(EOObjectStoreCoordinator *)rootObjectStore
cooperatingObjectStores];
int cosCount = [cooperatingObjectStores count];
int i;
for (i = 0; i < cosCount; i++)
{
id objectStore = [cooperatingObjectStores objectAtIndex: i];
EODatabase *objectStoreDatabase = [objectStore database];
BOOL modelOK = [objectStoreDatabase
addModelIfCompatible: destinationEntityModel];
if (!modelOK)
{
/*EODatabase *dbDatabase = [[[EODatabase alloc]
initWithModel: destinationEntityModel] autorelease];*/
[self notImplemented: _cmd]; //TODO: finish it
}
}
}
}
}
- (void)setCurrentEditingContext: (EOEditingContext*)context
{
//OK
EOCooperatingObjectStore *cooperatingObjectStore = [self databaseContext];
EOObjectStore *objectStore = [context rootObjectStore];
[(EOObjectStoreCoordinator*)objectStore
addCooperatingObjectStore: cooperatingObjectStore];
ASSIGN(_currentEditingContext, context);
}
- (void)selectObjectsWithFetchSpecification: (EOFetchSpecification *)fetch
editingContext: (EOEditingContext *)context
{
//should be OK
NSString *entityName = nil;
EODatabase *database = nil;
EOEntity *entity = nil;
EOQualifier *qualifier = nil;
EOQualifier *schemaBasedQualifier = nil;
EOFLOGObjectFnStart();
entityName = [fetch entityName];
database = [_databaseContext database];
NSDebugMLLog(@"gsdb", @"database=%@", database);
entity = [database entityNamed: entityName];
NSDebugMLLog(@"gsdb", @"entity name=%@", [entity name]);
qualifier=[fetch qualifier];
NSDebugMLLog(@"gsdb", @"qualifier=%@", qualifier);
schemaBasedQualifier =
[(id<EOQualifierSQLGeneration>)qualifier
schemaBasedQualifierWithRootEntity: entity];
NSDebugMLLog(@"gsdb", @"schemaBasedQualifier=%@", schemaBasedQualifier);
NSDebugMLLog(@"gsdb", @"qualifier=%@", qualifier);
if (schemaBasedQualifier && schemaBasedQualifier != qualifier)
{
EOFetchSpecification *newFetch = nil;
NSDebugMLLog(@"gsdb", @"fetch=%@", fetch);
//howto avoid copy of uncopiable qualifiers (i.e. those who contains uncopiable key or value)
NSDebugMLLog(@"gsdb", @"fetch=%@", fetch);
newFetch = [[fetch copy] autorelease];
NSDebugMLLog(@"gsdb", @"newFetch=%@", newFetch);
[newFetch setQualifier: schemaBasedQualifier];
NSDebugMLLog(@"gsdb", @"newFetch=%@", newFetch);
fetch = newFetch;
}
NSDebugMLLog(@"gsdb", @"%@ -- %@ 0x%x: isFetchInProgress=%s",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
([self isFetchInProgress] ? "YES" : "NO"));
[self _selectWithFetchSpecification:fetch
editingContext:context];
EOFLOGObjectFnStop();
}
- (id)fetchObject
{
//seems OK
EODatabase *database=nil;
id object = nil;
EOFLOGObjectFnStart();
database = [_databaseContext database];
if (![self isFetchInProgress])
{
NSLog(@"No Fetch in progress");
NSDebugMLog(@"No Fetch in progress");
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: no fetch in progress",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
}
else
{
NSArray *propertiesToFetch=nil;
NSDictionary *row =nil;
NSAssert(_currentEditingContext, @"No current editing context");
NSAssert(_adaptorChannel,@"No adaptor channel");
propertiesToFetch = [self _propertiesToFetch];
NSDebugMLLog(@"gsdb", @"Will fetchRow");
row = [_adaptorChannel fetchRowWithZone: NULL];
NSDebugMLLog(@"gsdb", @"row=%@", row);
//NSDebugMLog(@"TEST attributesToFetch=%@", [_currentEntity attributesToFetch]);
if (!row)
{
//TODO
//VERIFY
/*
if no more obj:
if transactionNestingLevel
adaptorContext transactionDidCommit
*/
}
else
{
BOOL isObjectNew = YES; //TODO used to avoid double fetch. We should see how to do when isRefreshingObjects == YES
EOGlobalID *gid;
NSDictionary *snapshot = nil;
NSAssert(_currentEntity, @"Not current Entity");
gid = [_currentEntity globalIDForRow: row
isFinal: YES];//OK
NSDebugMLLog(@"gsdb",@"gid=%@",gid);
//NSDebugMLog(@"TEST attributesToFetch=%@",[_currentEntity attributesToFetch]);
object = [_currentEditingContext objectForGlobalID: gid]; //OK //nil
NSDebugMLLog(@"gsdb",@"object=%@",object);
if (object)
isObjectNew = NO;
NSAssert(_databaseContext,@"No database context");
snapshot = [_databaseContext snapshotForGlobalID: gid]; //OK
NSDebugMLLog(@"gsdb", @"snapshot=%@", snapshot);
//NSDebugMLog(@"TEST attributesToFetch=%@", [_currentEntity attributesToFetch]);
if (snapshot)
{
NSDebugMLLog(@"gsdb", @"_delegateRespondsTo.shouldUpdateSnapshot=%d",
(int)_delegateRespondsTo.shouldUpdateSnapshot);
NSDebugMLLog(@"gsdb", @"[self isLocking]=%d",
(int)[self isLocking]);
NSDebugMLLog(@"gsdb", @"[self isRefreshingObjects]=%d",
(int)[self isRefreshingObjects]);
//mirko:
if((_delegateRespondsTo.shouldUpdateSnapshot == NO
&& ([self isLocking] == YES
|| [self isRefreshingObjects] == YES))
|| (_delegateRespondsTo.shouldUpdateSnapshot == YES
&& (row = (id)[_delegate databaseContext: _databaseContext
shouldUpdateCurrentSnapshot: snapshot
newSnapshot: row
globalID: gid
databaseChannel: self])))
{ // TODO delegate not correct !
NSDebugMLLog(@"gsdb", @"Updating Snapshot=%@", snapshot);
NSDebugMLLog(@"gsdb", @"row=%@", row);
[_databaseContext recordSnapshot: row
forGlobalID: gid];
isObjectNew = YES; //TODO
}
}
else
{
//NSDebugMLog(@"TEST attributesToFetch=%@", [_currentEntity attributesToFetch]);
NSDebugMLLog(@"gsdb", @"database class=%@", [database class]);
NSAssert(database, @"No database-context database");
[database recordSnapshot: row
forGlobalID: gid];
}
NSDebugMLLog(@"gsdb", @"[self isRefreshingObjects]=%d",
(int)[self isRefreshingObjects]);
//From mirko
if ([self isRefreshingObjects] == YES)
{
[[NSNotificationCenter defaultCenter]
postNotificationName: EOObjectsChangedInStoreNotification
object: _databaseContext
userInfo: [NSDictionary dictionaryWithObject:
[NSArray arrayWithObject:gid]
forKey: EOUpdatedKey]]; //OK ?
}
if (!object)
{
EOClassDescription *entityClassDescripton = [_currentEntity classDescriptionForInstances];
object = [entityClassDescripton createInstanceWithEditingContext: _currentEditingContext
globalID: gid
zone: NULL];
//NSDebugMLog(@"TEST attributesToFetch=%@", [_currentEntity attributesToFetch]);
NSDebugMLLog(@"gsdb", @"object=%@", object);
NSAssert1(object, @"No Object. entityClassDescripton=%@", entityClassDescripton);
[_currentEditingContext recordObject: object
globalID: gid];
}
else if (object && [EOFault isFault: object])
{
EOAccessFaultHandler *handler = [EOFault handlerForFault: object];
EOKeyGlobalID *handlerGID = (EOKeyGlobalID *)[handler globalID];
isObjectNew = YES; //TODO
[handlerGID isFinal]; //YES //TODO
[EOFault clearFault: object];
/*mirko:
[_databaseContext _removeBatchForGlobalID:gid
fault:obj];
[EOFault clearFault:obj];
*/
}
if (isObjectNew) //TODO
{
[EOObserverCenter suppressObserverNotification];
NS_DURING
{
NSDebugMLLog(@"gsdb", @"Initialize %p", object);
[_currentEditingContext initializeObject: object
withGlobalID: gid
editingContext: _currentEditingContext];
}
NS_HANDLER
{
[EOObserverCenter enableObserverNotification];
[localException raise];
}
NS_ENDHANDLER;
[EOObserverCenter enableObserverNotification];
[object awakeFromFetchInEditingContext: _currentEditingContext];
}
}
}
EOFLOGObjectFnStop();
return object;
};
- (BOOL)isFetchInProgress
{
//NSDebugMLog(@"TEST attributesToFetch=%@", [_currentEntity attributesToFetch]);
return [_adaptorChannel isFetchInProgress];
}
- (void)cancelFetch
{
EOFLOGObjectFnStart();
[self _cancelInternalFetch];
//TODO VERIFY - NO ??!!
[_adaptorChannel cancelFetch];
[_fetchProperties removeAllObjects];
[_fetchSpecifications removeAllObjects];
EOFLOGObjectFnStop();
}
- (EODatabaseContext *)databaseContext
{
return _databaseContext;
}
- (EOAdaptorChannel *)adaptorChannel
{
return _adaptorChannel;
}
- (BOOL)isRefreshingObjects
{
return _isRefreshingObjects;
}
- (void)setIsRefreshingObjects: (BOOL)yn
{
_isRefreshingObjects = yn;
}
- (BOOL)isLocking
{
return _isLocking;
}
- (void)setIsLocking: (BOOL)isLocking
{
_isLocking = isLocking;
}
- (void)setDelegate: delegate
{
_delegate = delegate;
_delegateRespondsTo.shouldSelectObjects =
[delegate respondsToSelector:@selector(databaseContext:shouldSelectObjectsWithFetchSpecification:databaseChannel:)];
_delegateRespondsTo.didSelectObjects =
[delegate respondsToSelector:@selector(databaseContext:didSelectObjectsWithFetchSpecification:databaseChannel:)];
_delegateRespondsTo.shouldUsePessimisticLock =
[delegate respondsToSelector:@selector(databaseContext:shouldUsePessimisticLockWithFetchSpecification: databaseChannel:)];
_delegateRespondsTo.shouldUpdateSnapshot =
[delegate respondsToSelector:@selector(databaseContext:shouldUpdateCurrentSnapshot:newSnapshot:globalID:databaseChannel:)];
}
- delegate
{
return _delegate;
}
@end
@implementation EODatabaseChannel (EODatabaseChannelPrivate)
- (NSArray*) _propertiesToFetch
{
//OK
NSArray *attributesToFetch=nil;
EOFLOGObjectFnStart();
attributesToFetch = [_currentEntity _attributesToFetch];
NSAssert(_currentEntity, @"No current Entity");
EOFLOGObjectFnStop();
return attributesToFetch;
}
-(void)_setCurrentEntityAndRelationshipWithFetchSpecification: (EOFetchSpecification *)fetch
{
//OK
NSString *entityName = [fetch entityName];
EODatabase *database = [_databaseContext database];
EOEntity *entity = [database entityNamed: entityName];
NSAssert1(entity, @"No Entity named %@", entityName);
[self setCurrentEntity: entity];
}
- (void) _buildNodeList:(id) param0
withParent:(id) param1
{
//TODO
[self notImplemented: _cmd];
}
- (id) currentEditingContext
{
return _currentEditingContext;
}
- (void) _cancelInternalFetch
{
//OK
EOFLOGObjectFnStart();
if ([_adaptorChannel isFetchInProgress])
{
[_adaptorChannel cancelFetch];
}
EOFLOGObjectFnStop();
}
- (void) _closeChannel
{
//TODO
[self notImplemented: _cmd];
}
- (void) _openChannel
{
//TODO
[self notImplemented: _cmd];
}
- (void)_selectWithFetchSpecification: (EOFetchSpecification *)fetch
editingContext: (EOEditingContext *)context
{
NSArray *propertiesToFetch = nil;
EOUpdateStrategy updateStrategy = EOUpdateWithOptimisticLocking;
BOOL fetchLocksObjects = NO;
BOOL refreshesRefetchedObjects = NO;
NSString *entityName = nil;
EODatabase *database = nil;
EOEntity *entity = nil;
NSArray *primaryKeyAttributes = nil;
NSDictionary *hints = nil;
EOModel *model = nil;
EOModelGroup *modelGroup = nil;
EOQualifier *qualifier = nil;
EOStoredProcedure *storedProcedure = nil;
id customQueryExpressionHint = nil;//TODO
EOSQLExpression *customQueryExpression = nil;//TODO
NSString *storedProcedureName = nil;
BOOL isDeep = NO;
NSArray *subEntities = nil;
NSDictionary *_hints = nil;
EOFLOGObjectFnStart();
_hints = [fetch _hints];
customQueryExpressionHint = [_hints objectForKey: @"EOCustomQueryExpressionHintKey"];//TODO use it
if (customQueryExpressionHint)
{
EOAdaptorContext *adaptorContext = nil;
EOAdaptor *adaptor = nil;
Class expressionClass = Nil;
NSDebugMLLog(@"gsdb", @"customQueryExpressionHint=%@", customQueryExpressionHint);
adaptorContext = [_databaseContext adaptorContext];
NSDebugMLLog(@"gsdb", @"adaptorContext=%p", adaptorContext);
adaptor = [adaptorContext adaptor];
NSDebugMLLog(@"gsdb", @"adaptor=%p", adaptor);
NSDebugMLLog(@"gsdb", @"adaptor=%@", adaptor);
NSDebugMLLog(@"gsdb", @"adaptor class=%@", [adaptor class]);
//TODO VERIFY
expressionClass = [adaptor expressionClass];
NSDebugMLLog(@"gsdb", @"expressionClass=%@", expressionClass);
customQueryExpression = [expressionClass expressionForString:
customQueryExpressionHint];
NSDebugMLLog(@"gsdb", @"customQueryExpression=%@", customQueryExpression);
}
[self setCurrentEditingContext: context]; //OK even if customQueryExpressionHintKey
[self _setCurrentEntityAndRelationshipWithFetchSpecification: fetch];
isDeep = [fetch isDeep]; //ret 1
if (!customQueryExpressionHint)
{
subEntities = [entity subEntities];
NSDebugMLLog(@"gsdb", @"subEntities=%@", subEntities);
//Strange
{
NSMutableArray *array = nil;
array = [NSMutableArray arrayWithCapacity: 8];
if ([subEntities count] > 0 && isDeep)
{
//??
NSEnumerator *subEntitiesEnum = [subEntities objectEnumerator];
id subEntity = nil;
while ((subEntity = [subEntitiesEnum nextObject]))
{
EOFetchSpecification *fetchSubEntity;
fetchSubEntity = [[fetch copy] autorelease];
[fetchSubEntity setEntityName: [entity name]];
[array addObjectsFromArray:
[context objectsWithFetchSpecification:
fetchSubEntity]];
}
}
}
}
propertiesToFetch = [self _propertiesToFetch];
updateStrategy = [_databaseContext updateStrategy];//Ret 0
fetchLocksObjects = [fetch locksObjects];
refreshesRefetchedObjects = [fetch refreshesRefetchedObjects];
entityName = [fetch entityName];
database = [_databaseContext database];
entity = [database entityNamed:entityName];
primaryKeyAttributes = [entity primaryKeyAttributes];
hints = [fetch hints]; // ret {}
storedProcedureName = [hints objectForKey: @"EOStoredProcedureNameHintKey"];//TODO use it
model = [entity model];
modelGroup = [model modelGroup]; //ret nil
//TODO if model gr
qualifier = [fetch qualifier]; //<EOAndQualifier> //Can be nil
if (customQueryExpression)
{
[_adaptorChannel evaluateExpression: customQueryExpression];
NSAssert([propertiesToFetch count] > 0, @"No properties to fetch");
[_adaptorChannel setAttributesToFetch: propertiesToFetch];
}
else
{
storedProcedure = [entity storedProcedureForOperation:
@"EOFetchWithPrimaryKeyProcedure"];
if (storedProcedure)
{
NSEmitTODO(); //TODO
[self notImplemented: _cmd];
}
NSAssert([propertiesToFetch count] > 0, @"No properties to fetch");
NSDebugMLLog(@"gsdb", @"%@ -- %@ 0x%x: isFetchInProgress=%s",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
([self isFetchInProgress] ? "YES" : "NO"));
[_adaptorChannel selectAttributes: propertiesToFetch
fetchSpecification: fetch
lock: fetchLocksObjects
entity: entity];
}
NSDebugMLLog(@"gsdb", @"%@ -- %@ 0x%x: isFetchInProgress=%s",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
([self isFetchInProgress] ? "YES" : "NO"));
//TODO: verify
/*
if([_databaseContext updateStrategy] == EOUpdateWithPessimisticLocking
&& ![[_databaseContext adaptorContext] transactionNestingLevel])
[NSException raise:NSInvalidArgumentException
format:@"%@ -- %@ 0x%x: no transaction in progress",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
if(_delegateRespondsTo.shouldSelectObjects)
{
if(![_delegate databaseContext:_databaseContext
shouldSelectObjectsWithFetchSpecification:fetch
databaseChannel:self])
[NSException raise:EOGeneralDatabaseException
format:@"%@ -- %@ 0x%x: delegate refuses to select objects",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
};
[_fetchSpecifications addObject:fetch];
[self setCurrentEntity:[[_databaseContext database]
entityNamed:[fetch entityName]]];//done
[self setCurrentEditingContext:context];//done
[self setIsLocking:([_databaseContext updateStrategy] ==
EOUpdateWithPessimisticLocking ?
YES :
[fetch locksObjects])];
[self setIsRefreshingObjects:[fetch refreshesRefetchedObjects]];
attributesToFetch = [_currentEntity attributesToFetch];//done
NSDebugMLLog(@"gsdb",@"[_adaptorChannel class]: %@",[_adaptorChannel class]);
[_adaptorChannel selectAttributes:attributesToFetch
fetchSpecification:fetch
lock:_isLocking
entity:_currentEntity];//done
[_fetchProperties addObjectsFromArray:attributesToFetch];
if(_delegateRespondsTo.didSelectObjects)
[_delegate databaseContext:_databaseContext
didSelectObjectsWithFetchSpecification:fetch
databaseChannel:self];
*/
EOFLOGObjectFnStop();
}
@end /* EODatabaseChannel */

View file

@ -0,0 +1,48 @@
/*
EODatabaseChannelPriv.h
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: Mars 2002
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EODatabaseChannelPriv_h__
#define __EODatabaseChannelPriv_h__
@class NSArray;
@class EOFetchSpecification;
@class EOEditingContext;
@interface EODatabaseChannel (EODatabaseChannelPrivate)
- (NSArray*) _propertiesToFetch;
- (void)_setCurrentEntityAndRelationshipWithFetchSpecification: (EOFetchSpecification *)fetch;
-(void)_selectWithFetchSpecification: (EOFetchSpecification *)fetch
editingContext: (EOEditingContext *)context;
- (void) _buildNodeList: (id)param0
withParent: (id)param1;
- (id) currentEditingContext;
- (void) _cancelInternalFetch;
- (void) _closeChannel;
- (void) _openChannel;
@end
#endif /* __EODatabaseChannelPriv_h__ */

View file

@ -0,0 +1,432 @@
/*
EODatabaseContext.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EODatabaseContext_h__
#define __EODatabaseContext_h__
#import <EOControl/EOControl.h>
@class EOAdaptorContext;
@class EOAdaptorChannel;
@class EOAdaptorOperation;
@class EOEntity;
@class EOModel;
@class EORelationship;
@class EOAttribute;
@class EODatabase;
@class EODatabaseChannel;
@class EODatabaseOperation;
typedef enum {
EOUpdateWithOptimisticLocking,
EOUpdateWithPessimisticLocking,
EOUpdateWithNoLocking
} EOUpdateStrategy;
struct _EOTransactionScope;
@interface EODatabaseContext : EOCooperatingObjectStore
{
EODatabase *_database;
EOAdaptorContext *_adaptorContext;
EOUpdateStrategy _updateStrategy;
/*TOADD
NSMutableArray *_uniqueStack;
NSMutableArray *_deleteStack;
NSMutableArray *_modifiedObjects;
*/
NSMutableArray *_registeredChannels;
NSMapTable *_dbOperationsByGlobalID;
EOObjectStoreCoordinator *_coordinator; // not retained
EOEditingContext *_editingContext; // not retained
id *_lockedObjects;//void*
/*TO ADD unsigned int _currentGeneration;
unsigned int _concurentFetches;
*/
unsigned int _numLocked;//TO REMOVE
NSMutableDictionary *_batchFaultBuffer;
NSMutableDictionary *_batchToManyFaultBuffer;
// NSMutableDictionary *_snapshots;
// NSMutableDictionary *_toManySnapshots;
EOEntity* _lastEntity;
/*TOADD
EOGlobalID *_currentGlobalID;
NSDictionary *_currentSnapshot;
objc_object *_currentBatch;
*/
NSMutableArray *_uniqueStack;// snaps
NSMutableArray *_uniqueArrayStack;//to many snaps
NSMutableArray *_deleteStack;
NSHashTable *_nonPrimaryKeyGenerators;
struct {
unsigned int preparingForSave:1;
unsigned int beganTransaction:1;
unsigned int ignoreEntityCaching:1;
unsigned int _reserved:29;
} _flags;
id _delegate; // not retained
struct {
unsigned int willRunLoginPanelToOpenDatabaseChannel:1;
unsigned int newPrimaryKey:1;
unsigned int willPerformAdaptorOperations:1;
unsigned int shouldInvalidateObject:1;
unsigned int willOrderAdaptorOperations:1;
unsigned int shouldLockObject:1;
unsigned int shouldRaiseForLockFailure:1;
unsigned int shouldFetchObjects:1;
unsigned int didFetchObjects:1;
unsigned int shouldFetchObjectFault:1;
unsigned int shouldFetchArrayFault:1;
unsigned int _reserved:21;
} _delegateRespondsTo;
NSRecursiveLock *_lock; //TODO: not lock object !
}
+ (EODatabaseContext *)databaseContextWithDatabase: (EODatabase *)database;
- initWithDatabase: (EODatabase *)database;
+ (EODatabaseContext *)registeredDatabaseContextForModel: (EOModel *)model
editingContext: (EOEditingContext *)editingContext;
+ (Class)contextClassToRegister;
+ (void)setContextClassToRegister: (Class)contextClass;
- (BOOL)hasBusyChannels;
- (NSArray *)registeredChannels;
- (void)registerChannel: (EODatabaseChannel *)channel;
- (void)unregisterChannel: (EODatabaseChannel *)channel;
- (EODatabaseChannel *)_availableChannelFromRegisteredChannels;
- (EODatabaseChannel *)availableChannel;
- (EODatabase *)database;
- (EOObjectStoreCoordinator *)coordinator;
- (EOAdaptorContext *)adaptorContext;
- (void)setUpdateStrategy: (EOUpdateStrategy)strategy;
- (EOUpdateStrategy)updateStrategy;
- (id)delegate;
- (void)setDelegate: (id)delegate;
- (void)handleDroppedConnection;
@end /* EODatabaseContext */
@interface EODatabaseContext(EOObjectStoreSupport)
- (id)faultForRawRow: (NSDictionary *)row
entityNamed: (NSString *)entityName
editingContext: (EOEditingContext *)editingContext;
- (id)faultForGlobalID: (EOGlobalID *)globalID
editingContext: (EOEditingContext *)context;
- (NSArray *)arrayFaultWithSourceGlobalID: (EOGlobalID *)globalID
relationshipName: (NSString *)name
editingContext: (EOEditingContext *)context;
- (void)initializeObject: (id)object
withGlobalID: (EOGlobalID *)globalID
editingContext: (EOEditingContext *)context;
- (NSArray *)objectsForSourceGlobalID: (EOGlobalID *)globalID
relationshipName: (NSString *)name
editingContext: (EOEditingContext *)context;
- (void)_registerSnapshot: (NSArray*)snapshot
forSourceGlobalID: (EOGlobalID*)globalID
relationshipName: (NSString*)name
editingContext: (EOEditingContext*)context;
- (void)refaultObject: object
withGlobalID: (EOGlobalID *)globalID
editingContext: (EOEditingContext *)context;
- (void)saveChangesInEditingContext: (EOEditingContext *)context;
- (NSArray *)objectsWithFetchSpecification: (EOFetchSpecification *)fetchSpecification
editingContext:(EOEditingContext *)context;
- (BOOL)isObjectLockedWithGlobalID: (EOGlobalID *)gid
editingContext: (EOEditingContext *)context;
- (void)lockObjectWithGlobalID: (EOGlobalID *)gid
editingContext: (EOEditingContext *)context;
- (void)invalidateAllObjects;
- (void)invalidateObjectsWithGlobalIDs: (NSArray *)globalIDs;
@end
@interface EODatabaseContext(EOCooperatingObjectStoreSupport)
- (BOOL)ownsGlobalID:(EOGlobalID *)globalID;
- (BOOL)ownsObject: (id)object;
- (BOOL)ownsEntityNamed: (NSString *)entityName;
- (BOOL)handlesFetchSpecification: (EOFetchSpecification *)fetchSpecification;
- (void)prepareForSaveWithCoordinator: (EOObjectStoreCoordinator *)coordinator
editingContext: (EOEditingContext *)context;
/** The method overrides the inherited implementation to create a list of EODatabaseOperations for EOEditingContext objects changes (only objects owned by the receiver).
It forwards any relationship changes found which are not owned by the receiver to the EOObjectStoreCoordinator.
It's invoked during EOObjectStoreCoordinator saving changes (saveChangesInEditingContext:) method.
It's invoked after prepareForSaveWithCoordinator:editingContext: and before ownsGlobalID:.
**/
- (void)recordChangesInEditingContext;
- (void)recordUpdateForObject: object
changes: (NSDictionary *)changes;
- (void)performChanges;
- (void)commitChanges;
- (void)rollbackChanges;
- (NSDictionary *)valuesForKeys: (NSArray *)keys object: object;
-(void)relayPrimaryKey: (NSDictionary*)pk
object: (id)object
entity: (EOEntity*)entity;
-(void)nullifyAttributesInRelationship: (EORelationship*)relationship
sourceObject: (id)sourceObject
destinationObjects: (NSArray*)destinationObjects;
-(void)nullifyAttributesInRelationship: (EORelationship*)relationship
sourceObject: (id)sourceObject
destinationObject: (id)destinationObject;
-(void)relayAttributesInRelationship: (EORelationship*)relationship
sourceObject: (id)sourceObject
destinationObjects: (NSArray*)destinationObjects;
-(NSDictionary*)relayAttributesInRelationship: (EORelationship*)relationship
sourceObject: (id)sourceObject
destinationObject: (id)destinationObject;
- (id) databaseOperationForObject: (id)param0;
- (id) databaseOperationForGlobalID: (id)param0;
- (void) recordDatabaseOperation: (id)param0;
- (void) recordDeleteForObject: (id)param0;
- (void) recordInsertForObject: (id)param0;
- (void) createAdaptorOperationsForDatabaseOperation: (EODatabaseOperation*)dbOpe
attributes: (NSArray*)attributes;
- (void) createAdaptorOperationsForDatabaseOperation: (EODatabaseOperation*)dbOpe;
- (NSArray*) orderAdaptorOperations;
- (id) entitiesOnWhichThisEntityDepends: (EOEntity *)entity;
-(NSArray*)entityNameOrderingArrayForEntities: (NSArray *)entities;
- (BOOL) isValidQualifierTypeForAttribute: (EOAttribute*)attribute;
- (id) lockingNonQualifiableAttributes: (NSArray*)attributes;
- (NSArray*) lockingAttributesForAttributes: (NSArray*)attributes
entity: (EOEntity*)enity;
- (NSArray*) primaryKeyAttributesForAttributes: (NSArray*)attributes
entity: (EOEntity*)entity;
- (EOQualifier*) qualifierForLockingAttributes: (NSArray*)attributes
primaryKeyAttributes: (NSArray*)primaryKeyAttributes
entity: (EOEntity*)entity
snapshot: (NSDictionary*)snapshot;
- (void) insertEntity: (EOEntity*)entity
intoOrderingArray: (NSMutableArray*)orderingArray
withDependencies: (NSDictionary*)dependencies
processingSet: (NSMutableSet*)processingSet;
- (void) processSnapshotForDatabaseOperation: (EODatabaseOperation*)dbOpe;
- (NSDictionary*) valuesToWriteForAttributes: (NSArray*)attributes
entity: (EOEntity*)entity
changedValues: (NSDictionary*)changedValues;
@end
@interface EODatabaseContext(EOBatchFaulting)
- (void)batchFetchRelationship: (EORelationship *)relationship
forSourceObjects: (NSArray *)objects
editingContext: (EOEditingContext *)editingContext;
@end
@interface EODatabaseContext (EODatabaseSnapshotting)
- (void)recordSnapshot: (NSDictionary *)snapshot
forGlobalID: (EOGlobalID *)gid;
/** Returns snapshot for globalID. (nil if there's no snapshot for the globalID or if the corresponding
tsimestamp is less than ti).
Searches first locally (in the transaction scope) and after in the EODatabase. **/
- (NSDictionary *)snapshotForGlobalID: (EOGlobalID *)gid
after: (NSTimeInterval)ti;
/** Returns snapshot for globalID by calling snapshotForGlobalID:after: with EODistantPastTimeInterval
as time interval.
Searches first locally (in the transaction scope) and after in the EODatabase. **/
- (NSDictionary *)snapshotForGlobalID: (EOGlobalID *)gid;
- (void)recordSnapshot: (NSArray *)gids
forSourceGlobalID: (EOGlobalID *)gid
relationshipName: (NSString *)name;
- (NSArray *)snapshotForSourceGlobalID: (EOGlobalID *)gid
relationshipName: (NSString *)name;
/** Returns the snapshot for the globalID (nil if there's none).
Only searches locally (in the transaction scope), not in the EODatabase. **/
- (NSDictionary *)localSnapshotForGlobalID: (EOGlobalID *)gid;
- (NSArray *)localSnapshotForSourceGlobalID: (EOGlobalID *)gid
relationshipName:(NSString *)name;
- (void)forgetSnapshotForGlobalID: (EOGlobalID *)gid;
- (void)forgetSnapshotsForGlobalIDs: (NSArray *)gids;
- (void)recordSnapshots: (NSDictionary *)snapshots;
- (void)recordToManySnapshots: (NSDictionary *)snapshots;
- (void)registerLockedObjectWithGlobalID: (EOGlobalID *)globalID;
- (BOOL)isObjectLockedWithGlobalID: (EOGlobalID *)globalID;
- (void)forgetAllLocks;
- (void)forgetLocksForObjectsWithGlobalIDs: (NSArray *)gids;
- (void) _rollbackTransaction;
- (void) _commitTransaction;
- (void) _beginTransaction;
- (EODatabaseChannel*) _obtainOpenChannel;
- (BOOL) _openChannelWithLoginPanel:(id)param0;
- (void) _forceDisconnect;
- (void)initializeObject:(id)object
row:(NSDictionary*)row
entity:(EOEntity*)entity
editingContext:(EOEditingContext*)context;
@end
@interface EODatabaseContext(EOMultiThreaded) <NSLocking>
- (void)lock;
- (void)unlock;
@end
// Notifications:
extern NSString *EODatabaseChannelNeededNotification;
@interface NSObject (EODatabaseContextDelegation)
- (BOOL)databaseContext: (EODatabaseContext *)context
willRunLoginPanelToOpenDatabaseChannel: (EODatabaseChannel *)channel;
- (NSDictionary *)databaseContext: (EODatabaseContext *)context
newPrimaryKeyForObject: (id)object
entity: (EOEntity *)entity;
- (BOOL)databaseContext: (EODatabaseContext *)context
failedToFetchObject: (id)object
globalID: (EOGlobalID *)gid;
- (NSArray *)databaseContext: (EODatabaseContext *)context
willOrderAdaptorOperationsFromDatabaseOperations: (NSArray *)databaseOps;
- (NSArray *)databaseContext: (EODatabaseContext *)context
willPerformAdaptorOperations: (NSArray *)adaptorOps
adaptorChannel: (EOAdaptorChannel *)adaptorChannel;
- (BOOL)databaseContext: (EODatabaseContext *)context
shouldInvalidateObjectWithGlobalID: (EOGlobalID *)globalId
snapshot: (NSDictionary *)snapshot;
- (NSArray *)databaseContext: (EODatabaseContext *)context
shouldFetchObjectsWithFetchSpecification: (EOFetchSpecification *)fetchSpecification
editingContext: (EOEditingContext *)editingContext;
- (void)databaseContext: (EODatabaseContext *)context
didFetchObjects: (NSArray *)objects
fetchSpecification: (EOFetchSpecification *)fetchSpecification
editingContext: (EOEditingContext *)editingContext;
- (BOOL)databaseContext: (EODatabaseContext *)context
shouldSelectObjectsWithFetchSpecification: (EOFetchSpecification *)fetchSpecification
databaseChannel: (EODatabaseChannel *)channel;
- (BOOL)databaseContext: (EODatabaseContext *)context
shouldUsePessimisticLockWithFetchSpecification: (EOFetchSpecification *)fetchSpecification
databaseChannel: (EODatabaseChannel *)channel;
- (void)databaseContext: (EODatabaseContext *)context
didSelectObjectsWithFetchSpecification: (EOFetchSpecification *)fetchSpecification
databaseChannel: (EODatabaseChannel *)channel;
- (NSDictionary *)databaseContext: (EODatabaseContext *)context
shouldUpdateCurrentSnapshot: (NSDictionary *)currentSnapshot
newSnapshot: (NSDictionary *)newSnapshot
globalID: (EOGlobalID *)globalID
databaseChannel: (EODatabaseChannel *)channel;
- (BOOL)databaseContext: (EODatabaseContext *)databaseContext
shouldLockObjectWithGlobalID: (EOGlobalID *)globalID
snapshot: (NSDictionary *)snapshot;
- (BOOL)databaseContext: (EODatabaseContext *)databaseContext
shouldRaiseExceptionForLockFailure: (NSException *)exception;
- (BOOL)databaseContext: (EODatabaseContext *)databaseContext
shouldFetchObjectFault: (id)fault;
- (BOOL)databaseContext: (EODatabaseContext *)databaseContext
shouldFetchArrayFault: (id)fault;
@end
extern NSString *EOCustomQueryExpressionHintKey;
extern NSString *EODatabaseContextKey;
extern NSString *EODatabaseOperationsKey;
extern NSString *EOFailedDatabaseOperationKey;
#endif /* __EODatabaseContext_h__ */

6670
EOAccess/EODatabaseContext.m Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,70 @@
/*
EODatabaseContextPriv.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EODatabaseContextPriv_h__
#define __EODatabaseContextPriv_h__
@class EOAccessFaultHandler;
@class EOAccessArrayFaultHandler;
@interface EODatabaseContext (EODatabaseContextPrivate)
- (void) _fireArrayFault: (id)object;
- (void) _fireFault: (id)object;
- (void) _addBatchForGlobalID: (EOKeyGlobalID *)globalID
fault: (EOFault *)fault;
- (void) _removeBatchForGlobalID: (EOKeyGlobalID *)globalID
fault: (EOFault *)fault;
- (void) _addToManyBatchForSourceGlobalID: (EOKeyGlobalID *)globalID
relationshipName: (NSString *)relationshipName
fault: (EOFault *)fault;
/*- (void)_batchToOne: (id)fault
withHandler: (EOAccessFaultHandler *)handler;
- (void)_batchToMany: (id)fault
withHandler: (EOAccessArrayFaultHandler *)handler;*/
@end
@interface EODatabaseContext (EODatabaseContextPrivate2)
- (void) _verifyNoChangesToReadonlyEntity: (EODatabaseOperation*)dbOpe;
- (EOGlobalID*) _globalIDForObject: (id)object;
- (id) _primaryKeyForObject: (id)object;
- (id) _currentCommittedSnapshotForObject: (id)object;
- (id) _addDatabaseContextStateToException: (id)param0;
- (id) _databaseContextState;
- (void) _cleanUpAfterSave;
- (void) _assertValidStateWithSelector: (SEL)sel;
- (BOOL) _shouldGeneratePrimaryKeyForEntityName: (NSString*)entityName;
- (void) _buildPrimaryKeyGeneratorListForEditingContext: (EOEditingContext*)context;
@end
#endif /* __EODatabaseContextPriv_h__ */

View file

@ -0,0 +1,67 @@
/*
EODatabaseDataSource.m
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import <EOControl/EOControl.h>
@class EOEntity;
@class EODatabaseContext;
@interface EODatabaseDataSource : EODataSource <NSCoding>
{
EOEditingContext *_editingContext;
EOFetchSpecification *_fetchSpecification;
EOQualifier *_auxiliaryQualifier;
NSDictionary *_bindings;
struct {
unsigned int fetchEnabled:1;
unsigned int _reserved:31;
} _flags;
}
- initWithEditingContext: (EOEditingContext *)anEditingContext
entityName: (NSString *)anEntityName;
- initWithEditingContext: (EOEditingContext *)editingContext
entityName: (NSString *)entityName
fetchSpecificationName: (NSString *)fetchName;
- (EOEntity *)entity;
- (EODatabaseContext *)databaseContext;
- (void)setFetchSpecification: (EOFetchSpecification *)fetchSpecification;
- (EOFetchSpecification *)fetchSpecification;
- (void)setAuxiliaryQualifier: (EOQualifier *)newQualifier;
- (EOQualifier *)auxiliaryQualifier;
- (EOFetchSpecification *)fetchSpecificationForFetch;
- (void)setFetchEnabled: (BOOL)yn;
- (BOOL)isFetchEnabled;
@end

View file

@ -0,0 +1,418 @@
/**
EODatabaseDataSource.m <title>EODatabaseDataSource Class</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
Author: Manuel Guesdon <mguesdon@orange-concept.com>
Date: December 2001
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
#import <Foundation/NSException.h>
#import <EOAccess/EOAccess.h>
#import <EOAccess/EODatabaseDataSource.h>
#import <EOAccess/EOEntity.h>
#import <EOAccess/EOModel.h>
#import <EOAccess/EOModelGroup.h>
#import <EOAccess/EODatabase.h>
#import <EOAccess/EODatabaseContext.h>
@implementation EODatabaseDataSource
- initWithEditingContext: (EOEditingContext *)editingContext
entityName: (NSString *)entityName
{
return [self initWithEditingContext: editingContext
entityName: entityName
fetchSpecificationName: nil];
}
- initWithEditingContext: (EOEditingContext *)editingContext
entityName: (NSString *)entityName
fetchSpecificationName: (NSString *)fetchName
{
NSArray *stores;
EODatabaseContext *store = nil;
NSEnumerator *storeEnum;
EOModel *model;
EOEntity *entity = nil;
id rootStore;
if ((self = [super init]))
{
ASSIGN(_editingContext, editingContext);
rootStore = [_editingContext rootObjectStore];
if ([rootStore isKindOfClass: [EOObjectStoreCoordinator class]] == YES)
{
stores = [rootStore cooperatingObjectStores];
storeEnum = [stores objectEnumerator];
while ((store = [storeEnum nextObject]))
{
if ([store isKindOfClass: [EODatabaseContext class]] == YES)
{
if ((entity = [[store database] entityNamed: entityName]))
break;
}
}
if (store == nil)
{
entity = [[EOModelGroup defaultGroup] entityNamed: entityName];
model = [entity model];
store = [EODatabaseContext databaseContextWithDatabase:
[EODatabase databaseWithModel:
model]];
[rootStore addCooperatingObjectStore: store];
}
}
else if ([rootStore isKindOfClass: [EODatabaseContext class]] == YES)
{
if ((entity = [[store database] entityNamed: entityName]) == nil)
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: editingContext (%@) cannot handler entity named '%@'",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
editingContext,
entityName];
}
else
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: editingContext (%@) cannot handler entity named '%@'",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
editingContext,
entityName];
ASSIGN(_fetchSpecification, [entity fetchSpecificationNamed:fetchName]);
}
return self;
}
- (void)dealloc
{
DESTROY(_bindings);
DESTROY(_auxiliaryQualifier);
DESTROY(_fetchSpecification);
DESTROY(_editingContext);
[super dealloc];
}
- (NSString *)description
{
return [NSString stringWithFormat:
@"<%s %p : entity name=%@ editingContext=%p fetchSpecification=%@>",
object_get_class_name(self),
(void *)self,
[[self entity]name],
_editingContext,
_fetchSpecification];
}
- (EOEntity *)entity
{
return [[[self databaseContext] database]
entityNamed: [_fetchSpecification entityName]];
}
- (EODatabaseContext *)databaseContext
{
NSArray *stores = nil;
EODatabaseContext *store = nil;
NSEnumerator *storeEnum = nil;
NSString *entityName = nil;
id rootStore = nil;
entityName = [_fetchSpecification entityName];
rootStore = [_editingContext rootObjectStore];
if ([rootStore isKindOfClass: [EOObjectStoreCoordinator class]] == YES)
{
stores = [rootStore cooperatingObjectStores];
storeEnum = [stores objectEnumerator];
while ((store = [storeEnum nextObject]))
{
if ([store isKindOfClass: [EODatabaseContext class]] == YES)
{
if ([[store database] entityNamed: entityName])
break;
}
}
}
else if ([rootStore isKindOfClass: [EODatabaseContext class]] == YES)
{
if ([[store database] entityNamed: entityName])
store = rootStore;
}
return store;
}
- (void)setFetchSpecification: (EOFetchSpecification *)fetchSpecification
{
ASSIGN(_fetchSpecification, fetchSpecification);
}
- (EOFetchSpecification *)fetchSpecification
{
return _fetchSpecification;
}
- (void)setAuxiliaryQualifier: (EOQualifier *)qualifier
{
ASSIGN(_auxiliaryQualifier, qualifier);//OK
}
- (EOQualifier *)auxiliaryQualifier
{
return _auxiliaryQualifier;
}
- (EOFetchSpecification *)fetchSpecificationForFetch
{
EOFetchSpecification *fetch = nil;
EOQualifier *qualifier = nil;
EOFLOGObjectLevelArgs(@"EODataSource", @"_auxiliaryQualifier=%@",
_auxiliaryQualifier);
EOFLOGObjectLevelArgs(@"EODataSource", @"_bindings=%@", _bindings);
EOFLOGObjectLevelArgs(@"EODataSource", @"_fetchSpecification=%@",
_fetchSpecification);
qualifier = [_auxiliaryQualifier
qualifierWithBindings: _bindings
requiresAllVariables: [_fetchSpecification
requiresAllQualifierBindingVariables]]; //ret same ?
EOFLOGObjectLevelArgs(@"EODataSource", @"qualifier=%@", qualifier);
//call _fetchSpecification qualifier //ret nil //TODO
fetch = [[_fetchSpecification copy] autorelease];
EOFLOGObjectLevelArgs(@"EODataSource", @"fetch=%@", fetch);
[fetch setQualifier:qualifier];
/*
fetch = [_fetchSpecification copy];
[fetch setQualifier:[[[EOAndQualifier alloc]
initWithQualifiers:[fetch qualifier],
_auxiliaryQualifier, nil] autorelease]];
*/
EOFLOGObjectLevelArgs(@"EODataSource", @"fetch=%@", fetch);
return fetch;
}
- (void)setFetchEnabled: (BOOL)flag
{
_flags.fetchEnabled = flag;
}
- (BOOL)isFetchEnabled
{
return _flags.fetchEnabled;
}
- (EODataSource *)dataSourceQualifiedByKey: (NSString *)detailKey
{
return [EODetailDataSource detailDataSourceWithMasterDataSource: self
detailKey: detailKey];
}
- (void)insertObject: object
{
[_editingContext insertObject: object];
}
- (void)deleteObject: object
{
[_editingContext deleteObject: object];
}
- (NSArray *)fetchObjects
{
NSArray *objects = nil;
EOFLOGObjectLevelArgs(@"EODataSource", @"_editingContext=%@",
_editingContext);
NSAssert(_editingContext, @"No Editing Context");
//call [self isFetchEnabled];
NS_DURING//For trace purpose
{
objects = [_editingContext objectsWithFetchSpecification:
[self fetchSpecificationForFetch]];//OK
}
NS_HANDLER
{
NSLog(@"%@ (%@)", localException, [localException reason]);
NSDebugMLog(@"%@ (%@)", localException, [localException reason]);
[localException raise];
}
NS_ENDHANDLER;
EOFLOGObjectLevelArgs(@"EODataSource", @"objects=%p", objects);
EOFLOGObjectLevelArgs(@"EODataSource", @"objects count=%d", [objects count]);
EOFLOGObjectLevelArgs(@"EODataSource", @"objects=%@", objects);
return objects;
}
- (EOClassDescription *)classDescriptionForObjects
{
return [[self entity] classDescriptionForInstances];
}
- (NSArray *)qualifierBindingKeys
{
return [_bindings allKeys]; // TODO resolve all bindings question
}
- (void)setQualifierBindings: (NSDictionary *)bindings
{
ASSIGN(_bindings, bindings);
}
- (NSDictionary *)qualifierBindings
{
return _bindings;
}
- (id)initWithCoder: (NSCoder *)coder
{
self = [super init];
ASSIGN(_editingContext, [coder decodeObject]);
ASSIGN(_fetchSpecification, [coder decodeObject]);
ASSIGN(_auxiliaryQualifier, [coder decodeObject]);
ASSIGN(_bindings, [coder decodeObject]);
// TODO flags
return self;
}
- (void)encodeWithCoder: (NSCoder *)coder
{
[coder encodeObject:_editingContext];
[coder encodeObject:_fetchSpecification];
[coder encodeObject:_auxiliaryQualifier];
[coder encodeObject:_bindings];
// TODO flags
}
- (id) initWithKeyValueUnarchiver: (EOKeyValueUnarchiver *)unarchiver
{
NSString *entityName = nil;
EOFetchSpecification *fetchSpecification = nil;
EOQualifier *auxiliaryQualifier = nil;
EOEditingContext *editingContext = nil;
NSString *fetchSpecificationName = nil;
EOFLOGObjectFnStart();
entityName = [unarchiver decodeObjectForKey: @"entityName"];
EOFLOGObjectLevelArgs(@"EODataSource",@"entityName=%@",entityName);
fetchSpecification = [unarchiver decodeObjectForKey: @"fetchSpecification"];
EOFLOGObjectLevelArgs(@"EODataSource", @"fetchSpecification=%@",
fetchSpecification);
auxiliaryQualifier = [unarchiver decodeObjectForKey: @"auxiliaryQualifier"];
EOFLOGObjectLevelArgs(@"EODataSource", @"auxiliaryQualifier=%@",
auxiliaryQualifier);
editingContext = [unarchiver decodeObjectReferenceForKey: @"editingContext"];
EOFLOGObjectLevelArgs(@"EODataSource", @"editingContext=%@", editingContext);
fetchSpecificationName = [unarchiver decodeObjectForKey:
@"fetchSpecificationName"];
EOFLOGObjectLevelArgs(@"EODataSource", @"fetchSpecificationName=%@",
fetchSpecificationName);
if (!entityName)
{
entityName = [fetchSpecification entityName];
EOFLOGObjectLevelArgs(@"EODataSource", @"entityName=%@", entityName);
}
if ((self = [self _partialInitWithEditingContext: editingContext
entityName: entityName
fetchSpecificationName: fetchSpecificationName]))
{
[self setFetchSpecification: fetchSpecification];
}
return self;
}
- (void) encodeWithKeyValueArchiver: (EOKeyValueUnarchiver *)archiver
{
[self notImplemented: _cmd];
}
- (id)_partialInitWithEditingContext: (EOEditingContext*)editingContext
entityName: (NSString*)entityName
fetchSpecificationName: (NSString*)fetchSpecificationName
{
if ((self = [self initWithEditingContext: editingContext
entityName: entityName
fetchSpecificationName: nil]))
{
//turbocat ASSIGN(_editingContext,editingContext);
ASSIGN(_fetchSpecification, [EOFetchSpecification new]);
[_fetchSpecification setEntityName: entityName];
}
return self;
}
- (EOEditingContext*)editingContext
{
return _editingContext;
}
@end

View file

@ -0,0 +1,180 @@
/*
EODatabaseOperation.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EODatabaseOperation_h__
#define __EODatabaseOperation_h__
#import <EOControl/EOControl.h>
@class EOStoredProcedure;
@class EOEntity;
typedef enum {
EOAdaptorUndefinedOperator = 0,
EOAdaptorLockOperator,
EOAdaptorInsertOperator,
EOAdaptorUpdateOperator,
EOAdaptorDeleteOperator,
EOAdaptorStoredProcedureOperator
} EOAdaptorOperator;
/**
EOAdaptorOperation represent an adaptor 'elementaty' operation.
Instance objects are created by EODatabaseOperation
**/
@interface EOAdaptorOperation : NSObject
{
EOAdaptorOperator _adaptorOperator; /** Database Adaptor **/
EOEntity *_entity; /** Main concerned entity **/
EOQualifier *_qualifier; /** qualifier **/
NSDictionary *_changedValues; /** dictionary of changed fields/values **/
NSArray *_attributes;
EOStoredProcedure *_storedProcedure; /** Stored Procedure **/
NSException *_exception;
}
+ (EOAdaptorOperation *)adaptorOperationWithEntity: (EOEntity *)entity;
/** Init the instance with the main concerned entity **/
- (id) initWithEntity: (EOEntity *)entity;
/** returns adaptor operator **/
- (EOAdaptorOperator)adaptorOperator;
/** set adaptor operator **/
- (void)setAdaptorOperator: (EOAdaptorOperator)adaptorOperator;
/** returns entity **/
- (EOEntity *)entity;
/** returns qualifier **/
- (EOQualifier *)qualifier;
/** set Qualifier **/
- (void)setQualifier: (EOQualifier *)qualifier;
/** returns dictionary of changed values **/
- (NSDictionary *)changedValues;
/** set dictionary of changed values **/
- (void)setChangedValues: (NSDictionary *)changedValues;
- (NSArray *)attributes;
- (void)setAttributes: (NSArray *)attributes;
- (EOStoredProcedure *)storedProcedure;
- (void)setStoredProcedure: (EOStoredProcedure *)storedProcedure;
- (NSException *)exception;
- (void)setException: (NSException *)exception;
/** compare 2 adaptor operations **/
- (NSComparisonResult)compareAdaptorOperation: (EOAdaptorOperation *)adaptorOp;
@end
typedef enum {
EODatabaseNothingOperator = 0,
EODatabaseInsertOperator,
EODatabaseUpdateOperator,
EODatabaseDeleteOperator
} EODatabaseOperator;
/**
EODatabaseOperation represent a database high level operation on an object (record)
It creates EOAdaptorOperations.
You generally don't need to create such objects by yourself. They are created by EOEditingContext
**/
@interface EODatabaseOperation : NSObject
{
EODatabaseOperator _databaseOperator; //** Database Operator **/
NSMutableDictionary *_newRow; //** New Row (new state of the object) **/
EOGlobalID *_globalID; /** global ID of the object **/
EOEntity *_entity; /** entity **/
NSMutableArray *_adaptorOps; /** EOAdaptorOperations generated to perfor this DatabaseOperation **/
id _object; /** object (record) **/
NSDictionary *_dbSnapshot; /** The last known database values for the object (i.e. values from last fetch or last commited operation) **/
NSMutableDictionary *_toManySnapshots; /** **/
}
+ (EODatabaseOperation*)databaseOperationWithGlobalID: (EOGlobalID *)globalID
object: (id)object
entity: (EOEntity *)entity;
- (id)initWithGlobalID: (EOGlobalID *)globalID
object: (id)object
entity: (EOEntity *)entity;
/** Returns the database snapshot for the object.
The snapshot contains the last known database values for the object.
If the object has just been inserted (i.e. not yet in database), the returned dictionary is empty
**/
- (NSDictionary *)dbSnapshot;
/** sets the snapshot for the object (should be empty if the object has just been inserted into an EOEditingContext **/
- (void)setDBSnapshot: (NSDictionary *)dbSnapshot;
/** Returns a dictionary with (new) values (properties+primary keys...) of the object.
The newRow dictionary is created when creating the database operation (in EODatabaseChannel -databaseOperationForObject: for exemple). Values come from object state in database and overrides by changes made on the object
**/
- (NSMutableDictionary *)newRow;
- (void)setNewRow:(NSMutableDictionary *)newRow;
- (EOGlobalID *)globalID;
- (id)object;
- (EOEntity *)entity;
- (EODatabaseOperator)databaseOperator;
- (void)setDatabaseOperator: (EODatabaseOperator)dbOp;
- (NSDictionary *)rowDiffs;
- (NSDictionary *)rowDiffsForAttributes: (NSArray *)attributes;
- (NSDictionary *)primaryKeyDiffs;
/** returns array of EOAdaptorOperations to perform **/
- (NSArray *)adaptorOperations;
/** adds an Adaptor Operation
Raises an exception if adaptorOperation is nil
**/
- (void)addAdaptorOperation: (EOAdaptorOperation *)adaptorOperation;
/** removes an Adaptor Operation **/
- (void)removeAdaptorOperation: (EOAdaptorOperation *)adaptorOperation;
- (void)recordToManySnapshot: (NSArray *)gids relationshipName:(NSString *)name;
- (NSDictionary *)toManySnapshots;
@end
#endif /* __EODatabaseOperation_h__ */

View file

@ -0,0 +1,351 @@
/**
EOAdaptorOperation.m <title>EOAdaptorOperation Class</title>
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSObject.h>
#import <extensions/NSException.h>
#import <EOAccess/EOAccess.h>
#import <EOAccess/EODatabaseOperation.h>
#import <EOAccess/EOAttribute.h>
#import <EOAccess/EOEntity.h>
@implementation EODatabaseOperation
+ (EODatabaseOperation *)databaseOperationWithGlobalID: (EOGlobalID *)globalID
object: (id)object
entity: (EOEntity *)entity
{
return [[[self alloc] initWithGlobalID: globalID
object: object
entity: entity] autorelease];
}
- (id) initWithGlobalID: (EOGlobalID *)globalID
object: (id)object
entity: (EOEntity *)entity
{
if ((self = [super init]))
{
ASSIGN(_object, object);
ASSIGN(_globalID, globalID);
ASSIGN(_entity, entity);
//_newRow = [NSMutableDictionary new];//still nil
//_toManySnapshots = [NSMutableDictionary new];//TODO no: still nil
}
return self;
}
- (void)dealloc
{
DESTROY(_newRow);
DESTROY(_globalID);
DESTROY(_entity);
DESTROY(_adaptorOps);
DESTROY(_object);
DESTROY(_dbSnapshot);
DESTROY(_toManySnapshots);
[super dealloc];
}
- (NSDictionary *)dbSnapshot
{
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"dbOpe %@ snapshot %p=%@", self, _dbSnapshot, _dbSnapshot);
EOFLOGObjectFnStop();
return _dbSnapshot;
}
- (void)setDBSnapshot: (NSDictionary *)dbSnapshot
{
EOFLOGObjectFnStart();
ASSIGN(_dbSnapshot, dbSnapshot);
NSDebugMLLog(@"gsdb", @"dbOpe %@ snapshot %p=%@", self, _dbSnapshot, _dbSnapshot);
if (dbSnapshot)
[_newRow addEntriesFromDictionary: dbSnapshot];
NSDebugMLLog(@"gsdb", @"dbOpe %@", self);
EOFLOGObjectFnStop();
}
- (NSMutableDictionary *)newRow
{
return _newRow;
}
- (void)setNewRow: (NSMutableDictionary *)newRow
{
ASSIGN(_newRow, newRow);
}
- (EOGlobalID *)globalID
{
return _globalID;
}
- (id)object
{
return _object;
}
- (EOEntity *)entity
{
return _entity;
}
- (EODatabaseOperator)databaseOperator
{
return _databaseOperator;
}
- (void)setDatabaseOperator: (EODatabaseOperator)dbOpe
{
BOOL setOpe = YES;
//Don't set Update if it's alreay insert
if (dbOpe == EODatabaseUpdateOperator)
{
if (_databaseOperator==EODatabaseInsertOperator
|| _databaseOperator==EODatabaseDeleteOperator)
setOpe=NO;
}
if (setOpe)
_databaseOperator = dbOpe;
}
- (NSDictionary *)rowDiffs
{
//OK
NSMutableDictionary *row = nil;
NSEnumerator *newRowEnum = nil;
NSString *key = nil;
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"self %p=%@", self, self);
newRowEnum= [_newRow keyEnumerator];
while ((key = [newRowEnum nextObject]))
{
if (![_entity anyRelationshipNamed: key]) //Don't care about relationships
{
id value = [_newRow objectForKey: key];
if ([value isEqual: [_dbSnapshot objectForKey: key]] == NO)
{
if (!row)
row = (NSMutableDictionary*)[NSMutableDictionary dictionary];
[row setObject: value
forKey: key];
}
}
}
NSDebugMLLog(@"gsdb", @"diff row %p=%@", row, row);
EOFLOGObjectFnStop();
return row;
}
- (NSDictionary*)rowDiffsForAttributes: (NSArray*)attributes
{
//OK
NSMutableDictionary *row = nil;
EOAttribute *attr = nil;
NSEnumerator *attrsEnum = nil;
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"self %p=%@", self, self);
attrsEnum = [attributes objectEnumerator];
while ((attr = [attrsEnum nextObject]))
{
NSString *name = [attr name];
NSString *snapname = [_entity snapshotKeyForAttributeName: name];
id value = [_newRow objectForKey: name];
if (value && [value isEqual: [_dbSnapshot objectForKey: snapname]] == NO)
{
if (!row)
row = (NSMutableDictionary*)[NSMutableDictionary dictionary];
[row setObject: value
forKey: name];
}
}
NSDebugMLLog(@"gsdb", @"diff row %p=%@", row, row);
EOFLOGObjectFnStop();
return row;
}
- (NSDictionary *)primaryKeyDiffs
{
//OK
NSDictionary *row = nil;
if (_databaseOperator == EODatabaseUpdateOperator)
{
NSArray *pkAttributes = [_entity primaryKeyAttributes];
row = [self rowDiffsForAttributes: pkAttributes];
}
return row;
}
- (NSArray *)adaptorOperations
{
return _adaptorOps;
}
- (void)addAdaptorOperation: (EOAdaptorOperation *)adaptorOperation
{
//OK
if (!_adaptorOps)
_adaptorOps = [NSMutableArray new];
if (!adaptorOperation)
{
//TODO raise exception
}
else
[_adaptorOps addObject: adaptorOperation];
}
- (void)removeAdaptorOperation: (EOAdaptorOperation *)adaptorOperation
{
[_adaptorOps removeObject: adaptorOperation];
}
- (void)recordToManySnapshot: (NSArray *)gids
relationshipName: (NSString *)name
{
//OK ??
if (_toManySnapshots)
[_toManySnapshots setObject: gids
forKey: name];//TODO VERIFY
else
{
_toManySnapshots = [NSMutableDictionary dictionaryWithObject: gids
forKey: name];
RETAIN(_toManySnapshots);
}
}
- (NSDictionary *)toManySnapshots
{
return _toManySnapshots;
}
- (NSString *)description
{
//TODO revoir
NSString *operatorString = nil;
NSString *desc = nil;
EOFLOGObjectFnStart();
switch (_databaseOperator)
{
case EODatabaseNothingOperator:
operatorString = @"EODatabaseNothingOperator";
break;
case EODatabaseInsertOperator:
operatorString = @"EODatabaseInsertOperator";
break;
case EODatabaseUpdateOperator:
operatorString = @"EODatabaseUpdateOperator";
break;
case EODatabaseDeleteOperator:
operatorString = @"EODatabaseDeleteOperator";
break;
default:
operatorString = @"Unknwon";
break;
}
desc = [NSString stringWithFormat: @"<%s %p : operator: %@ entity: %@ globalID:%@\nnewRow %p: %@\nobject %p: %@\ndbSnapshot %p: %@>",
object_get_class_name(self),
(void*)self,
operatorString,
[_entity name],
_globalID,
_newRow,
_newRow,
_object,
_object,
_dbSnapshot,
_dbSnapshot];
EOFLOGObjectFnStop();
return desc;
}
@end
//Mirko
@implementation EODatabaseOperation (private)
- (void)_setGlobalID: (EOGlobalID *)globalID
{
ASSIGN(_globalID, globalID);
}
@end

View file

@ -0,0 +1,37 @@
/*
EODatabaseOperationPriv.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EODatabaseOperationPriv_h__
#define __EODatabaseOperationPriv_h__
@interface EODatabaseOperation (private)
- (void)_setGlobalID: (EOGlobalID *)globalID;
@end
#endif /* __EODatabaseOperationPriv_h__ */

373
EOAccess/EOEntity.h Normal file
View file

@ -0,0 +1,373 @@
/*
EOEntity.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOEntity_h__
#define __EOEntity_h__
#import <Foundation/NSString.h>
#import <extensions/GCObject.h>
#import <extensions/GCArray.h>
#import <extensions/GCDictionary.h>
#import <extensions/NSException.h>
#import <EOAccess/EOPropertyListEncoding.h>
#import <EOControl/EOClassDescription.h>
@class EOModel;
@class EOAttribute;
@class EOQualifier;
@class EORelationship;
@class EOEntity;
@class EOStoredProcedure;
@class EOKeyGlobalID;
@class EOFetchSpecification;
@class EOGlobalID;
@class EOMutableKnownKeyDictionary;
@class EOMKKDInitializer;
@class EOMKKDSubsetMapping;
@interface EOEntity : GCObject <EOPropertyListEncoding>
{
NSString *_name;
NSString *_className;
NSString *_externalName;
NSString *_externalQuery;
NSDictionary *_userInfo;
NSString* _docComment;
NSDictionary * _internalInfo;
EOQualifier *_restrictingQualifier;
NSMutableDictionary *_fetchSpecificationDictionary;
NSArray *_fetchSpecificationNames;
NSMutableDictionary *_storedProcedures;
NSArray *_classPropertyNames;
NSArray *_primaryKeyAttributeNames;
NSArray *_classPropertyAttributeNames;
NSArray *_classPropertyToOneRelationshipNames;
NSArray *_classPropertyToManyRelationshipNames;
EOClassDescription *_classDescription;
NSMutableArray *_hiddenRelationships;
unsigned int _batchCount;
EOMKKDInitializer* _adaptorDictionaryInitializer;
EOMKKDInitializer* _snapshotDictionaryInitializer;
EOMKKDInitializer* _primaryKeyDictionaryInitializer;
EOMKKDInitializer* _propertyDictionaryInitializer;
EOMKKDSubsetMapping* _snapshotToAdaptorRowSubsetMapping;
Class _classForInstances;
/* Garbage collectable objects */
EOModel *_model;
GCMutableArray *_attributes;
GCMutableDictionary *_attributesByName;
GCMutableArray *_relationships;
GCMutableDictionary *_relationshipsByName; // name/EORelationship
GCMutableArray *_primaryKeyAttributes;
GCMutableArray *_classProperties; // EOAttribute/EORelationship
GCMutableArray *_attributesUsedForLocking;
GCMutableArray *_attributesToFetch;
GCMutableArray *_attributesToSave;
GCMutableArray *_propertiesToFault;
GCArray* _dbSnapshotKeys;
GCMutableArray *_subEntities;
EOEntity *_parent;
struct {
unsigned int attributesIsLazy:1;
unsigned int relationshipsIsLazy:1;
unsigned int classPropertiesIsLazy:1;
unsigned int primaryKeyAttributesIsLazy:1;
unsigned int attributesUsedForLockingIsLazy:1;
unsigned int isReadOnly:1;
unsigned int isAbstractEntity:1;
unsigned int updating:1;
unsigned int cachesObjects:1;
unsigned int createsMutableObjects:1;
unsigned int extraRefCount:22;
} _flags;
}
/** returns an autoreleased entity **/
+ (EOEntity *)entity;
/** returns an autoreleased entity owned by onwer and built from propertyList **/
+ (EOEntity *)entityWithPropertyList: (NSDictionary *)propertyList
owner: (id)owner;
- (NSString *)description;
/* Accessing the name */
- (NSString*)name;
/* Accessing the model */
- (EOModel*)model;
/* Accessing external information */
- (NSString*)externalName;
/* Accessing the external query */
- (NSString*)externalQuery;
/* Getting the qualifier */
- (EOQualifier *)restrictingQualifier;
- (BOOL)isQualifierForPrimaryKey: (EOQualifier *)qualifier;
- (EOQualifier *)qualifierForPrimaryKey: (NSDictionary *)row;
/* Accessing read-only status */
- (BOOL)isReadOnly;
- (BOOL)cachesObjects;
/* Accessing the enterprise object class */
- (NSString*)className;
/* Accessing attributes */
- (EOAttribute *)attributeNamed: (NSString *)attributeName;
- (EOAttribute *)anyAttributeNamed: (NSString *)relationshipName;
- (NSArray *)attributes;
/* Accessing relationships */
- (EORelationship *)relationshipNamed: (NSString *)relationshipName;
- (EORelationship *)anyRelationshipNamed: (NSString *)relationshipName;
- (NSArray *)relationships;
/* Accessing class properties */
- (NSArray *)classProperties;
- (NSArray *)classPropertyNames;
- (NSArray *)fetchSpecificationNames;
- (EOFetchSpecification *)fetchSpecificationNamed: (NSString *)fetchSpecName;
/* Accessing primary key attributes */
- (NSArray *)primaryKeyAttributes;
- (NSArray *)primaryKeyAttributeNames;
/* Accessing locking attributes */
- (NSArray *)attributesUsedForLocking;
- (NSArray *)attributesToFetch;
/* Getting primary keys and snapshot for row */
- (NSDictionary *)primaryKeyForRow: (NSDictionary *)row;
- (BOOL)isValidAttributeUsedForLocking: (EOAttribute *)anAttribute;
- (BOOL)isValidPrimaryKeyAttribute: (EOAttribute *)anAttribute;
- (BOOL)isPrimaryKeyValidInObject: (id)object;
- (BOOL)isValidClassProperty: aProp;
/** Accessing the user dictionary **/
- (NSDictionary *)userInfo;
/** Accessing the documentation **/
- (NSString *)docComment;
- (NSArray *)subEntities;
- (EOEntity *)parentEntity;
- (BOOL)isAbstractEntity;
- (unsigned int)maxNumberOfInstancesToBatchFetch;
- (BOOL)isPrototypeEntity;
@end
@interface EOEntity (EOKeyGlobalID)
- (EOGlobalID *)globalIDForRow: (NSDictionary *)row;
- (id) globalIDForRow: (NSDictionary*)row
isFinal: (BOOL)isFinal;
- (NSDictionary *)primaryKeyForGlobalID: (EOKeyGlobalID *)gid;
- (Class)classForObjectWithGlobalID: (EOKeyGlobalID*)globalID;
@end
@interface EOEntity (EOEntityEditing)
- (BOOL)setClassProperties: (NSArray*)properties;
- (BOOL)setPrimaryKeyAttributes: (NSArray*)keys;
- (BOOL)setAttributesUsedForLocking: (NSArray*)attributes;
- (NSException *)validateName: (NSString *) name;
- (void)setName: (NSString*)name;
- (void)setExternalName: (NSString*)name;
- (void)setExternalQuery: (NSString*)query;
- (void)setRestrictingQualifier: (EOQualifier *)qualifier;
- (void)setReadOnly: (BOOL)flag;
- (void)setCachesObjects: (BOOL)yn;
- (void)addAttribute: (EOAttribute *)attribute;
- (void)removeAttribute: (EOAttribute *)attribute;
- (void)addRelationship: (EORelationship *)relationship;
- (void)removeRelationship: (EORelationship *)relationship;
- (void)addFetchSpecification: (EOFetchSpecification *)fetchSpec
named: (NSString *)name;
- (void)removeFetchSpecificationNamed: (NSString *)name;
- (void)setClassName: (NSString*)name;
- (void)setUserInfo: (NSDictionary*)dictionary;
- (void) _setInternalInfo: (NSDictionary*)dictionary;
- (void) setDocComment:(NSString *)docComment;
- (void)addSubEntity: (EOEntity *)child;
- (void)removeSubEntity: (EOEntity *)child;
- (void)setIsAbstractEntity: (BOOL)f;
- (void)setMaxNumberOfInstancesToBatchFetch: (unsigned int)size;
@end
@interface EOEntity (EOModelReferentialIntegrity)
- (BOOL)referencesProperty:property;
- (NSArray *)externalModelsReferenced;
@end
@interface EOEntity (EOModelBeautifier)
- (void)beautifyName;
@end
extern NSString *EOFetchAllProcedureOperation;
extern NSString *EOFetchWithPrimaryKeyProcedureOperation;
extern NSString *EOInsertProcedureOperation;
extern NSString *EODeleteProcedureOperation;
extern NSString *EONextPrimaryKeyProcedureOperation;
@interface EOEntity (MethodSet11)
- (NSException *)validateObjectForDelete: (id)object;
- (id) classPropertyAttributeNames;
- (id) classPropertyToManyRelationshipNames;
- (id) classPropertyToOneRelationshipNames;
- (id) qualifierForDBSnapshot: (id)param0;
- (EOAttribute*) attributeForPath: (NSString*)path;
- (EORelationship*) relationshipForPath: (NSString*)path;
- (void) _addAttributesToFetchForRelationshipPath: (NSString*)path
atts: (NSMutableDictionary*)atts;
- (id) dbSnapshotKeys;
- (NSArray*) flattenedAttributes;
@end
@interface EOEntity (EOStoredProcedures)
- (EOStoredProcedure *)storedProcedureForOperation: (NSString *)operation;
- (void)setStoredProcedure: (EOStoredProcedure *)storedProcedure
forOperation: (NSString *)operation;
@end
@interface EOEntity (EOPrimaryKeyGeneration)
- (NSString *)primaryKeyRootName;
@end
@interface EOEntity (EOEntityClassDescription)
- (EOClassDescription *)classDescriptionForInstances;
@end
@interface EOEntity (EOEntityHidden)
- (NSDictionary*)attributesByName;
- (NSDictionary*)relationshipsByName;
- (NSArray*) _allFetchSpecifications;
- (NSDictionary*) _fetchSpecificationDictionary;
- (void) _loadEntity;
- (id) parentRelationship;
- (int) _numberOfRelationships;
- (BOOL) _hasReadOnlyAttributes;
- (NSArray*) writableDBSnapshotKeys;
- (NSArray*) rootAttributesUsedForLocking;
- (BOOL) isSubEntityOf:(id)param0;
- (id) initObject: (id)param0
editingContext: (id)param1
globalID: (id)param2;
- (id) allocBiggestObjectWithZone:(NSZone*)zone;
- (Class) _biggestClass;
- (NSArray*) relationshipsPlist;
- (id) rootParent;
- (void) _setParent: (id)param0;
- (NSArray*) _hiddenRelationships;
- (NSArray*) _propertyNames;
- (id) _flattenAttribute: (id)param0
relationshipPath: (id)param1
currentAttributes: (id)param2;
- (NSString*) snapshotKeyForAttributeName: (NSString*)attributeName;
- (id) _flattenedAttNameToSnapshotKeyMapping;
- (EOMKKDSubsetMapping*) _snapshotToAdaptorRowSubsetMapping;
- (EOMutableKnownKeyDictionary*) _dictionaryForPrimaryKey;
- (EOMutableKnownKeyDictionary*) _dictionaryForProperties;
- (NSArray*) _relationshipsToFaultForRow: (NSDictionary*)row;
- (NSArray*) _classPropertyAttributes;
- (NSArray*) _attributesToSave;
- (NSArray*) _attributesToFetch;
- (EOMKKDInitializer*) _adaptorDictionaryInitializer;
- (EOMKKDInitializer*) _snapshotDictionaryInitializer;
- (EOMKKDInitializer*) _primaryKeyDictionaryInitializer;
- (EOMKKDInitializer*) _propertyDictionaryInitializer;
- (void) _setModel: (EOModel*)model;
- (void) _setIsEdited;
- (NSArray*) _classPropertyAttributes;
@end
@interface EOEntityClassDescription:EOClassDescription
{
EOEntity *_entity;
unsigned int extraRefCount;
}
/** returns an autoreleased entity class description for entity entity **/
+ (EOEntityClassDescription*)entityClassDescriptionWithEntity: (EOEntity *)entity;
/** initialize with entity **/
- initWithEntity: (EOEntity *)entity;
/** returns entity **/
- (EOEntity *)entity;
@end
@interface NSString (EODatabaseNameConversion)
+ (NSString *)nameForExternalName: (NSString *)externalName
separatorString: (NSString *)separatorString
initialCaps: (BOOL)initialCaps;
+ (NSString *)externalNameForInternalName: (NSString *)internalName
separatorString: (NSString *)separatorString
useAllCaps: (BOOL)allCaps;
@end
#endif /* __EOEntity_h__ */

4367
EOAccess/EOEntity.m Normal file

File diff suppressed because it is too large Load diff

68
EOAccess/EOEntityPriv.h Normal file
View file

@ -0,0 +1,68 @@
/*
EOEntityPriv.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOEntityPriv_h__
#define __EOEntityPriv_h__
@interface EOEntity (EOEntityPrivate)
- (void)setCreateMutableObjects: (BOOL)flag;
- (BOOL)createsMutableObjects;
- (void)setModel: (EOModel *)model;
- (void)setParentEntity: (EOEntity *)parent;
@end
@interface EOEntity (EOEntityRelationshipPrivate)
- (EORelationship*) _inverseRelationshipPathForPath: (NSString*)path;
- (id) _keyMapForRelationshipPath: (NSString*)path;
- (id) _keyMapForIdenticalKeyRelationshipPath: (id)param0;
- (id) _mapAttribute: (id)param0
toDestinationAttributeInLastComponentOfRelationshipPath: (NSString*)path;
- (BOOL) _relationshipPathIsToMany: (id)param0;
- (BOOL) _relationshipPathHasIdenticalKeys: (id)param0;
@end
@class EOExpressionArray;
@interface EOEntity (EOEntitySQLExpression)
- (id) valueForSQLExpression: (id)param0;
+ (id) valueForSQLExpression: (id)param0;
@end
@interface EOEntity (EOEntityPrivateXX)
- (EOExpressionArray *) _parseDescription: (NSString *)description
isFormat: (BOOL)isFormat
arguments: (char*)param2;
- (EOExpressionArray*) _parseRelationshipPath: (NSString*)path;
- (id) _parsePropertyName: (id)param0;
//- (id) _newStringWithBuffer: (unsigned short*)param0
// length: (unsigned int*)param1;
@end
#endif

View file

@ -0,0 +1,107 @@
/*
EOExpressionArray.h
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
Date: September 1996
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOExpressionArray_h__
#define __EOExpressionArray_h__
#import <Foundation/NSString.h>
#import <extensions/GCArray.h>
@class EOAttribute;
@class EOEntity;
@class EOExpressionArray;
@protocol EOExpressionContext <NSObject>
- (NSString *)expressionValueForAttribute: (EOAttribute *)anAttribute;
- (NSString *)expressionValueForAttributePath: (NSArray *)path;
@end
@interface EOExpressionArray : GCMutableArray
{
NSString *_prefix;
NSString *_infix;
NSString *_suffix;
// NSString *_definition; it's rebuilt
EOAttribute *_realAttribute;
struct
{
unsigned int isFlattened:1; //TODO Why ?
} _flags;
}
+ (EOExpressionArray*)expressionArray;
+ (EOExpressionArray*)expressionArrayWithPrefix: (NSString *)prefix
infix: (NSString *)infix
suffix: (NSString *)suffix;
/* Initializing instances */
- initWithPrefix: (NSString *)prefix
infix: (NSString *)infix
suffix: (NSString *)suffix;
- (NSString *)prefix;
- (NSString *)infix;
- (NSString *)suffix;
- (NSString *)definition;
- (BOOL)isFlattened;
- (EOAttribute *)realAttribute;
/* Accessing the components */
- (void)setPrefix: (NSString*)prefix;
- (void)setInfix: (NSString*)infix;
- (void)setSuffix: (NSString*)suffix;
/* Checking contents */
- (BOOL)referencesObject: (id)anObject;
- (NSString *)expressionValueForContext: (id<EOExpressionContext>)ctx;
+ (EOExpressionArray *)parseExpression: (NSString *)expression
entity: (EOEntity *)entity
replacePropertyReferences: (BOOL)flag;
- (NSString*)valueForSQLExpression: (EOSQLExpression *)sqlExpression;
@end /* EOExpressionArray */
@interface NSObject (EOExpression)
- (NSString*)expressionValueForContext: (id<EOExpressionContext>)context;
@end
@interface NSString (EOAttributeTypeCheck)
- (BOOL)isNameOfARelationshipPath;
@end
#endif /* __EOExpressionArray_h__ */

View file

@ -0,0 +1,400 @@
/**
EOExpressionArray.m <title>EOExpressionArray</title>
Copyright (C) 1996-2002 Free Software Foundation, Inc.
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
Date: September 1996
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <ctype.h>
#import <Foundation/NSString.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSDate.h>
#import <extensions/objc-runtime.h>
#import <extensions/NSException.h>
#import <extensions/GarbageCollector.h>
#import <extensions/exceptions/GeneralExceptions.h>
#import <EOAccess/EOAccess.h>
#import <EOAccess/EOEntity.h>
#import <EOAccess/EOExpressionArray.h>
#import <EOAccess/EORelationship.h>
@implementation EOExpressionArray
+ (void)initialize
{
static BOOL initialized = NO;
if (!initialized)
{
initialized = YES;
class_add_behavior(self, [GCArray class]);
}
}
+ (EOExpressionArray*)expressionArray
{
return [[self new] autorelease];
}
- (id) init
{
EOFLOGObjectFnStart();
self = [super init];
EOFLOGObjectFnStop();
return self;
}
+ (EOExpressionArray*)expressionArrayWithPrefix: (NSString *)prefix
infix: (NSString *)infix
suffix: (NSString *)suffix
{
return [[[self alloc]initWithPrefix: prefix
infix: infix
suffix: suffix] autorelease];
}
- (id)initWithPrefix: (NSString *)prefix
infix: (NSString *)infix
suffix: (NSString *)suffix
{
EOFLOGObjectFnStart();
if ((self = [self init]))
{
ASSIGN(_prefix, prefix);
ASSIGN(_infix, infix);
ASSIGN(_suffix, suffix);
}
EOFLOGObjectFnStop();
return self;
}
- (void)dealloc
{
DESTROY(_realAttribute); //TODO mettere nei metodi GC
// DESTROY(_definition);
[_prefix release];
[_infix release];
[_suffix release];
[super dealloc];
}
- (BOOL)referencesObject: (id)anObject
{
return [self indexOfObject: anObject] != NSNotFound;
}
- (NSString *)expressionValueForContext: (id<EOExpressionContext>)ctx
{
if (ctx && [self count]
&& [[self objectAtIndex: 0] isKindOfClass: [EORelationship class]])
return [ctx expressionValueForAttributePath: self];
else
{
int i, count = [self count];
id result = [[NSMutableString new] autorelease];
SEL sel = @selector(appendString:);
IMP imp = [result methodForSelector: sel];
if (_prefix)
[result appendString:_prefix];
if (count)
{
(*imp)(result, sel, [[self objectAtIndex: 0]
expressionValueForContext: ctx]);
for (i = 1 ; i < count; i++)
{
if (_infix)
(*imp)(result, sel, _infix);
(*imp)(result, sel, [[self objectAtIndex: i]
expressionValueForContext: ctx]);
}
}
if(_suffix)
[result appendString: _suffix];
return result;
}
}
- (void)setPrefix: (NSString *)prefix
{
ASSIGN(_prefix, prefix);
}
- (void)setInfix: (NSString *)infix
{
ASSIGN(_infix, infix);
}
- (void)setSuffix: (NSString *)suffix
{
ASSIGN(_suffix, suffix);
}
- (NSString *)prefix
{
return _prefix;
}
- (NSString *)infix
{
return _infix;
}
- (NSString *)suffix
{
return _suffix;
}
- (NSString *)definition
{
// return _definition;
return [self valueForSQLExpression: nil];
}
- (BOOL)isFlattened
{
// return _flags.isFlattened;
return ([self count] > 1);
}
- (EOAttribute *)realAttribute
{
return _realAttribute;
}
/*
+ (EOExpressionArray *)parseExpression:(NSString *)expression
entity:(EOEntity *)entity
replacePropertyReferences:(BOOL)replacePropertyReferences
{
EOExpressionArray *array = nil;
const char *s = NULL;
const char *start=NULL;
id objectToken=nil;
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb",@"expression=%@",expression);
NSDebugMLLog(@"gsdb",@"entity=%@",entity);
array = [[EOExpressionArray new] autorelease];
s = [expression cString];
// ASSIGN(array->_definition, expression);
array->_flags.isFlattened = NO;
if([expression isNameOfARelationshipPath])
{
NSArray *defArray;
NSString *realAttributeName;
int count, i;
array->_flags.isFlattened = YES;
defArray = [expression componentsSeparatedByString:@"."];
count = [defArray count];
for(i = 0; i < count - 1; i++)
{
id relationshipName = [defArray objectAtIndex:i];
id relationship=nil;
relationship = [entity relationshipNamed:relationshipName];
if(!relationship)
[NSException raise:NSInvalidArgumentException
format:@"%@ -- %@ 0x%x: '%@' for entity '%@' is an invalid property",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
relationshipName,
entity];
// if([relationship isToMany])
// [NSException raise:NSInvalidArgumentException format:@"%@ -- %@ 0x%x: '%@' for entity '%@' must be a to one relationship",
//NSStringFromSelector(_cmd),
//NSStringFromClass([self class]),
//self,
//relationshipName,
//entity];
[array addObject:relationship];
entity = [relationship destinationEntity];
}
realAttributeName = [defArray lastObject];
ASSIGN(array->_realAttribute, [entity attributeNamed:realAttributeName]);
if(!array->_realAttribute)
ASSIGN(array->_realAttribute, [entity relationshipNamed:realAttributeName]);
if(!array->_realAttribute)
[NSException raise:NSInvalidArgumentException
format:@"%@ -- %@ 0x%x: '%@' for entity '%@' is an invalid property",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
realAttributeName,
entity];
[array addObject:array->_realAttribute];
}
else
{
//IN eoentity persedescr
}
NSDebugMLLog(@"gsdb",@"_prefix=%@",array->_prefix);
NSDebugMLLog(@"gsdb",@"_infix=%@",array->_infix);
NSDebugMLLog(@"gsdb",@"_suffix=%@",array->_suffix);
// NSDebugMLLog(@"gsdb",@"_definition=%@",array->_definition);
NSDebugMLLog(@"gsdb",@"_realAttribute=%@",array->_realAttribute);
EOFLOGObjectFnStop();
return array;
}
*/
- (BOOL)_isPropertyPath
{
/*
int i=0;
int count=0;
count=[self count];
objectAtIndex:i
if it's a string return NO
*/
//TODO
return NO;
}
- (NSString *)valueForSQLExpression: (EOSQLExpression*)sqlExpression
{
//TODO verify
NSMutableString *value = [NSMutableString string];
int i, count;
NS_DURING //Just for debugging
{
count = [self count];
for(i = 0; i < count; i++)
{
id obj = [self objectAtIndex: i];
NSString *relValue;
relValue = [obj valueForSQLExpression: sqlExpression];
if (i > 0)
[value appendString: @"."];
[value appendString: relValue];
}
}
NS_HANDLER
{
NSLog(@"exception in EOExpressionArray valueForSQLExpression: self=%p class=%@ i=%d", self, [self class], i);
NSLog(@"exception in EOExpressionArray valueForSQLExpression: self=%@ class=%@ i=%d", self, [self class], i);
NSLog(@"exception=%@", localException);
[localException raise];
}
NS_ENDHANDLER;
return value;
}
@end /* EOExpressionArray */
@implementation NSObject (EOExpression)
- (NSString*)expressionValueForContext: (id<EOExpressionContext>)ctx
{
if ([self respondsToSelector: @selector(stringValue)])
return [(id)self stringValue];
else
return [self description];
}
@end
@implementation NSString (EOExpression)
/* Avoid returning the description in case of NSString because if the string
contains whitespaces it will be quoted. Particular adaptors have to override
-formatValue:forAttribute: and they have to quote with the specific
database character the returned string. */
- (NSString*)expressionValueForContext: (id<EOExpressionContext>)ctx
{
return self;
}
@end
@implementation NSString (EOAttributeTypeCheck)
- (BOOL)isNameOfARelationshipPath
{
const char *s = [self cString];
BOOL result = NO;
if (isalnum(*s) || *s == '@' || *s == '_' || *s == '#')
{
for (++s; *s; s++)
{
if (!isalnum(*s) && *s != '@' && *s != '_' && *s != '#' && *s != '$'
&& *s != '.')
return NO;
if (*s == '.')
result = YES;
}
}
return result;
}
@end

70
EOAccess/EOJoin.h Normal file
View file

@ -0,0 +1,70 @@
/*
EOJoin.h
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
Date: August 1996
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOJoin_h__
#define __EOJoin_h__
#import <extensions/GCObject.h>
#import <extensions/GCArray.h>
@class EOEntity;
@class EOAttribute;
@interface EOJoin : GCObject
{
/* Garbage collectable objects */
EOAttribute *_sourceAttribute;
EOAttribute *_destinationAttribute;
}
+ (EOJoin *)joinWithSourceAttribute: (EOAttribute *)source
destinationAttribute: (EOAttribute *)destination;
- initWithSourceAttribute: (EOAttribute *)source
destinationAttribute: (EOAttribute *)destination;
- (NSString *)description;
- (EOAttribute *)sourceAttribute;
- (EOAttribute *)destinationAttribute;
- (BOOL)isReciprocalToJoin: (EOJoin *)otherJoin;
@end
@interface EOJoin (EOJoinPrivate)
//+ (EOJoin*)joinFromPropertyList:(id)propertyList;
//- (void)replaceStringsWithObjectsInRelationship:(EORelationship*)entity;
//- (id)propertyList;
@end /* EOJoin (EOJoinPrivate) */
#endif /* __EOJoin_h__ */

202
EOAccess/EOJoin.m Normal file
View file

@ -0,0 +1,202 @@
/**
EOJoin.m <title>EOJoin Class</title>
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/Foundation.h>
#import <Foundation/NSString.h>
#import <Foundation/NSUtilities.h>
#import <EOAccess/EOAccess.h>
#import <EOAccess/EOModel.h>
#import <EOAccess/EOEntity.h>
#import <EOAccess/EOAttribute.h>
#import <EOAccess/EORelationship.h>
#import <EOAccess/EOJoin.h>
@implementation EOJoin
+ (EOJoin *) joinWithSourceAttribute: (EOAttribute *)source
destinationAttribute: (EOAttribute *)destination
{
return [[[self alloc] initWithSourceAttribute: source
destinationAttribute: destination] autorelease];
}
- (id) initWithSourceAttribute: (EOAttribute *)source
destinationAttribute: (EOAttribute *)destination
{
if ((self = [super init]))
{
if (!source || !destination)
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: source and destination attributes can't be nil",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
ASSIGN(_sourceAttribute, source);
ASSIGN(_destinationAttribute, destination);
}
return self;
}
- (void)gcDecrementRefCountOfContainedObjects
{
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"sourceAttribute gcDecrementRefCount");
[_sourceAttribute gcDecrementRefCount];
NSDebugMLLog(@"gsdb", @"destinationAttribute gcDecrementRefCount");
[_destinationAttribute gcDecrementRefCount];
EOFLOGObjectFnStop();
}
- (BOOL)gcIncrementRefCountOfContainedObjects
{
if (![super gcIncrementRefCountOfContainedObjects])
return NO;
[_sourceAttribute gcIncrementRefCount];
[_destinationAttribute gcIncrementRefCount];
[_sourceAttribute gcIncrementRefCountOfContainedObjects];
[_destinationAttribute gcIncrementRefCountOfContainedObjects];
return YES;
}
- (unsigned)hash
{
return [_sourceAttribute hash];
}
- (NSString *)description
{
NSString *dscr = nil;
/*NSString *joinOperatorDescr = nil;
NSString *joinSemanticDescr = nil;
switch(joinOperator)
{
case EOJoinEqualTo:
joinOperatorDescr=@"EOJoinEqualTo";
break;
case EOJoinNotEqualTo:
joinOperatorDescr=@"EOJoinNotEqualTo";
break;
case EOJoinGreaterThan:
joinOperatorDescr=@"EOJoinGreaterThan";
break;
case EOJoinGreaterThanOrEqualTo:
joinOperatorDescr=@"EOJoinGreaterThanOrEqualTo";
break;
case EOJoinLessThan:
joinOperatorDescr=@"EOJoinLessThan";
break;
case EOJoinLessThanOrEqualTo:
joinOperatorDescr=@"EOJoinLessThanOrEqualTo";
break;
};
switch(joinSemantic)
{
case EOInnerJoin:
joinSemanticDescr=@"EOInnerJoin";
break;
case EOFullOuterJoin:
joinSemanticDescr=@"EOFullOuterJoin";
break;
case EOLeftOuterJoin:
joinSemanticDescr=@"EOLeftOuterJoin";
break;
case EORightOuterJoin:
joinSemanticDescr=@"EORightOuterJoin";
break;
};
*/
dscr = [NSString stringWithFormat: @"<%s %p -",
object_get_class_name(self),
(void*)self];
dscr = [dscr stringByAppendingFormat: @" sourceAttribute=%@",
[_sourceAttribute name]];
dscr = [dscr stringByAppendingFormat: @" destinationAttribute=%@",
[_destinationAttribute name]];
/* dscr=[dscr stringByAppendingFormat:@" relationship name=%@",
[relationship name]];
dscr=[dscr stringByAppendingFormat:@" joinOperator=%@ joinSemantic=%@>",
joinOperatorDescr,
joinSemanticDescr];*/
return dscr;
}
- (EOAttribute *)destinationAttribute
{
return _destinationAttribute;
}
- (EOAttribute *)sourceAttribute
{
return _sourceAttribute;
}
- (BOOL)isReciprocalToJoin: (EOJoin *)otherJoin
{
//OK
NSDebugMLLog(@"gsdb", @"_sourceAttribute name=%@",
[_sourceAttribute name]);
NSDebugMLLog(@"gsdb", @"[[otherJoin destinationAttribute] name]=%@",
[[otherJoin destinationAttribute] name]);
NSDebugMLLog(@"gsdb", @"_destinationAttribute name=%@",
[_destinationAttribute name]);
NSDebugMLLog(@"gsdb", @"[[otherJoin sourceAttribute] name]=%@",
[[otherJoin sourceAttribute] name]);
if ([[_sourceAttribute name]
isEqual: [[otherJoin destinationAttribute] name]]
&& [[_destinationAttribute name]
isEqual: [[otherJoin sourceAttribute] name]])
return YES;
else
return NO;
}
@end

191
EOAccess/EOModel.h Normal file
View file

@ -0,0 +1,191 @@
/*
EOModel.h
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOModel_h__
#define __EOModel_h__
#import <Foundation/NSString.h>
#import <extensions/GCObject.h>
#import <extensions/GCArray.h>
#import <extensions/GCDictionary.h>
#import <EOAccess/EOPropertyListEncoding.h>
@class EOEntity;
@class EOModelGroup;
@class EOStoredProcedure;
@interface EOModel : GCObject
{
NSString *_name;
NSString *_path;
NSString *_adaptorName;
NSString *_adaptorClassName;
float _version;
NSDictionary *_connectionDictionary;
NSDictionary *_userInfo;
NSDictionary * _internalInfo;
NSString *_docComment;
void *_entitiesByClass;
/* Garbage collectable objects */
EOModelGroup *_group;
GCArray *_entities;
GCMutableDictionary *_entitiesByName;
GCMutableArray *_storedProcedures;
GCMutableDictionary *_subEntitiesCache;
//GCMutableDictionary *_prototypesByName;
struct
{
BOOL createsMutableObjects:1;
BOOL errors:1;
} _flags;
}
+ (EOModel *)model;
/** Getting the filename **/
- (NSString*)path;
/** Getting the name **/
- (NSString *)name;
- (NSString *)adaptorName;
- (NSString *)adaptorClassName;
- (float)version;
+ (float)version;
/** Using entities **/
- (EOEntity *)entityNamed: (NSString*)name;
- (NSArray *)entities;
- (NSArray *)entityNames;
- (NSArray *)storedProcedureNames;
- (EOStoredProcedure *)storedProcedureNamed: (NSString *)name;
- (NSArray *)storedProcedures;
/** Getting an object's entity **/
- (EOEntity *)entityForObject: object;
/** Accessing the connection dictionary **/
- (NSDictionary *)connectionDictionary;
/** Accessing the user dictionary **/
- (NSDictionary *)userInfo;
/** Accessing documentation comments **/
- (NSString*)docComment;
- (EOModelGroup *)modelGroup;
@end
@interface EOModel (EOModelFileAccess)
+ (EOModel *)modelWithContentsOfFile: (NSString *)path;
- initWithContentsOfFile: (NSString *)path;
- (void)writeToFile: (NSString *)path;
@end
@interface EOModel (EOModelPropertyList) <EOPropertyListEncoding>
- (id) initWithTableOfContentsPropertyList: (NSDictionary *)tableOfContents
path: (NSString *)path;
- (void)encodeTableOfContentsInfoPropertyList: (NSMutableDictionary *)propertyList;
- (void)encodeIntoPropertyList: (NSMutableDictionary *)propertyList;
- (void)awakeWithPropertyList: (NSDictionary *)propertyList;
- (id)initWithPropertyList: (NSDictionary *)propertyList
owner: (id)owner;
@end
@interface EOModel (EOModelHidden)
- (void)_resetPrototypeCache;
- (BOOL)isPrototypesEntity: (id)param0;
- (void)_classDescriptionNeeded: (id)param0;
- (id)_instantiatedEntities;
- (void)_setPath: (NSString *)path;
- (id)_entityForClass: (Class)param0;
- (id)_childrenForEntityNamed: (id)param0;
- (void)_registerChild: (id)param0
forParent: (id)param1;
- (void)_setInheritanceLinks: (id)param0;
- (void)_removeEntity: (id)param0;
- (id)_addEntityWithPropertyList: (NSDictionary *)propertyList;
- (void)_addFakeEntityWithPropertyList: (NSDictionary *)propertyList;
- (id)_addEntity: (EOEntity *)entity;
- (void)_setEntity: (id)entity
forEntityName: (NSString *)entityName
className: (NSString *)className;
@end
@interface EOModel (EOModelEditing)
/* Accessing the adaptor bundle */
- (void)setName: (NSString *)name;
- (void)setAdaptorName: (NSString *)adaptorName;
- (void)setConnectionDictionary: (NSDictionary *)connectionDictionary;
- (void)setUserInfo: (NSDictionary *)dictionary;
- (void)addEntity: (EOEntity *)entity;
- (void)removeEntity: (EOEntity *)entity;
- (void)removeEntityAndReferences: (EOEntity *)entity;
- (void)addStoredProcedure: (EOStoredProcedure *)storedProcedure;
- (void)removeStoredProcedure: (EOStoredProcedure *)storedProcedure;
- (void)setModelGroup: (EOModelGroup *)group;
- (void)loadAllModelObjects;
/* Checking references */
- (NSArray *)referencesToProperty: property;
- (NSArray *)externalModelsReferenced;
@end
@interface EOModel (EOModelBeautifier)
- (void)beautifyNames;
@end
extern NSString *EOEntityLoadedNotification;
@interface EOModel (EOModelPrivate)
- (void)setCreateMutableObjects: (BOOL)flag;
- (BOOL)createsMutableObjects;
- (EOEntity *)_verifyBuiltEntityObject: (id)entity
named: (NSString *)name;
@end /* EOModel (EOModelPrivate) */
#endif /* __EOModel_h__ */

1608
EOAccess/EOModel.m Normal file

File diff suppressed because it is too large Load diff

137
EOAccess/EOModelGroup.h Normal file
View file

@ -0,0 +1,137 @@
/*
EOModelGroup.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOModelGroup_h__
#define __EOModelGroup_h__
#import <extensions/GCObject.h>
#import <EOControl/EOControl.h>
@class EOModel;
@class EOEntity;
@class EORelationship;
@class EOGlobalID;
@class EOAttribute;
@class EOStoredProcedure;
@interface EOModelGroup : GCObject
{
NSMutableDictionary *_modelsByName;
id _delegate;
struct {
unsigned int entityNamed:1;
unsigned int relationshipForRow:1;
unsigned int subEntityForEntity:1;
unsigned int failedToLookupClassNamed:1;
unsigned int classForObjectWithGlobalID:1;
unsigned int _RESERVED:27;
} _delegateRespondsTo;
}
+ (EOModelGroup *)defaultGroup;
+ (void)setDefaultGroup: (EOModelGroup *)group;
+ (EOModelGroup *)globalModelGroup;
+ (void)setDelegate: (id)delegate;
+ (id)delegate;
- (NSArray *)models;
- (NSArray *)modelNames;
- (EOModel *)modelNamed: (NSString *)name;
- (EOModel *)modelWithPath: (NSString *)path;
- (void)addModel: (EOModel *)model;
- (EOModel*)addModelWithFile: (NSString *)path;
- (void)removeModel: (EOModel *)model;
- (EOEntity *)entityNamed: (NSString *)entityName;
- (NSArray *)availablePrototypesForAdaptorName: (NSString *)adaptorName;
- (EOAttribute *)prototypeAttributeForAttribute: (EOAttribute *)attribute;
- (EOEntity *)entityForObject: (id)object;
- (void)loadAllModelObjects;
- (id)delegate;
- (void)setDelegate: (id)delegate;
- (EOFetchSpecification *)fetchSpecificationNamed: (NSString *)fetchSpecName
entityNamed: (NSString *)entityName;
- (EOStoredProcedure *)storedProcedureNamed: (NSString *)aName;
@end
// Notifications:
extern NSString *EOModelAddedNotification;
extern NSString *EOModelInvalidatedNotification;
@interface NSObject (EOModelGroupClassDelegation)
- (EOModelGroup *)defaultModelGroup;
@end
@interface NSObject (EOModelGroupDelegation)
- (EOModel *)modelGroup: (EOModelGroup *)group entityNamed: (NSString *)name;
- (EORelationship *)entity: (EOEntity *)entity
relationshipForRow: (NSDictionary *)row
relationship: (EORelationship *)relationship;
- (EOEntity *)subEntityForEntity: (EOEntity *)entity
primaryKey: (NSDictionary *)primaryKey
isFinal: (BOOL *)flag;
- (Class)entity: (EOEntity *)entity
failedToLookupClassNamed: (NSString *)className;
- (Class)entity: (EOEntity *)entity
classForObjectWithGlobalID: (EOGlobalID *)globalID;
- (EOEntity *)relationship: (EORelationship *)relationship
failedToLookupDestinationNamed: (NSString *)entityName;
@end
@interface EOObjectStoreCoordinator (EOModelGroupSupport)
- (void)setModelGroup: (EOModelGroup *)group;
- (EOModelGroup *)modelGroup;
@end
#endif

403
EOAccess/EOModelGroup.m Normal file
View file

@ -0,0 +1,403 @@
/**
EOModelGroup.m <title>EOModelGroup Class</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: June 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSBundle.h>
#import <Foundation/NSNotification.h>
#import <EOAccess/EOModelGroup.h>
#import <EOAccess/EOModel.h>
#import <EOAccess/EOEntity.h>
#import <EOAccess/EOStoredProcedure.h>
#import <EOControl/EODebug.h>
@implementation EOModelGroup
NSString *EOModelAddedNotification = @"EOModelAddedNotification";
NSString *EOModelInvalidatedNotification = @"EOModelInvalidatedNotification";
static id classDelegate = nil;
static int delegateDefaultModelGroup = 0;
static EOModelGroup *defaultModelGroup = nil;
+ (EOModelGroup *)defaultGroup
{
EOModelGroup *modelGroup = nil;
EOFLOGObjectFnStart();
if (defaultModelGroup)
modelGroup = defaultModelGroup;
else if (delegateDefaultModelGroup)
modelGroup = [classDelegate defaultModelGroup];
else
modelGroup = [EOModelGroup globalModelGroup];
if (!modelGroup)
{
NSLog(@"WARNING: No default Group");
}
EOFLOGObjectFnStop();
return modelGroup;
}
+ (void)setDefaultGroup: (EOModelGroup *)group
{
if (group != defaultModelGroup)
{
if (defaultModelGroup)
DESTROY(defaultModelGroup);
if (delegateDefaultModelGroup)
group = [classDelegate defaultModelGroup];
ASSIGN(defaultModelGroup, group);
}
}
+ (EOModelGroup *)globalModelGroup
{
NSMutableArray *bundles = [NSMutableArray arrayWithCapacity: 2];
NSBundle *bundle = nil;
NSArray *paths = nil;
NSEnumerator *pathsEnum = nil;
NSEnumerator *bundleEnum = nil;
EOModelGroup *group;
NSString *path = nil;
EOFLOGObjectFnStart();
group = [EOModelGroup new];
[bundles addObjectsFromArray: [NSBundle allBundles]];
[bundles addObjectsFromArray: [NSBundle allFrameworks]];
bundleEnum = [bundles objectEnumerator];
while ((bundle = [bundleEnum nextObject]))
{
paths = [bundle pathsForResourcesOfType: @"eomodeld"
inDirectory: nil];
if (!paths)
{
NSLog(@"WARNING: paths for resource of type eomodeld in bundle %@",bundle);
}
pathsEnum = [paths objectEnumerator];
while ((path = [pathsEnum nextObject]))
{
NSLog(@"%@", path);
[group addModelWithFile: [path stringByDeletingPathExtension]];
}
}
EOFLOGObjectFnStop();
return [group autorelease]; // TODO release problem with EOModel
}
/** returns a model group composed of all models in the resource directory
of the mainBundle, and all bundles and frameworks loaded into the app.
**/
+ (void)setDelegate: (id)delegate
{
classDelegate = delegate;
delegateDefaultModelGroup = [delegate respondsToSelector:
@selector(defaultModelGroup)];
}
+ (id)delegate
{
return classDelegate;
}
- init
{
self = [super init];
_modelsByName = [NSMutableDictionary new];
return self;
}
- (void)dealloc
{
DESTROY(_modelsByName);
[super dealloc];
}
- (void)gcDecrementRefCountOfContainedObjects
{
EOFLOGObjectFnStart();
EOFLOGObjectFnStop();
}
- (BOOL)gcIncrementRefCountOfContainedObjects
{
if (![super gcIncrementRefCountOfContainedObjects])
return NO;
return YES;
}
- (NSArray *)models
{
return [_modelsByName allValues];
}
- (NSArray *)modelNames
{
return [_modelsByName allKeys];
}
- (EOModel *)modelNamed: (NSString *)name
{
return [_modelsByName objectForKey: name];
}
- (EOModel *)modelWithPath: (NSString *)path
{
NSEnumerator *modelEnum;
EOModel *model;
modelEnum = [_modelsByName objectEnumerator];
while ((model = [modelEnum nextObject]))
if ([[path stringByStandardizingPath]
isEqual: [[model path] stringByStandardizingPath]] == YES)
return model;
return nil;
}
- (void)addModel: (EOModel *)model
{
//OK
//call model entityNames
NSString *modelName;
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"model=%p", model);
modelName = [model name];
[model setModelGroup: self];
NSDebugMLLog(@"gsdb", @"model=%p name=%@", model, modelName);
if (!modelName)
{
[NSException raise: NSInvalidArgumentException
format: [NSString stringWithFormat:
@"The model name is emtpy"]];
}
NSAssert1(modelName, @"No name for model %@", model);
if ([_modelsByName objectForKey: modelName])
{
[NSException raise: NSInvalidArgumentException
format: [NSString stringWithFormat: @"The modelname '%@' already exists in modelGroup",
modelName]];
}
[_modelsByName setObject: model
forKey: modelName];
NSDebugMLLog(@"gsdb", @"Notification for model:%p", model);
[[NSNotificationCenter defaultCenter]
postNotificationName: EOModelAddedNotification
object: model];
EOFLOGObjectFnStop();
}
- (EOModel *)addModelWithFile: (NSString *)path
{
EOModel *model;
EOFLOGObjectFnStart();
model = [EOModel modelWithContentsOfFile: path];
NSDebugMLLog(@"gsdb", @"model=%p", model);
if (model)
[self addModel: model];
EOFLOGObjectFnStop();
return model;
}
- (void)removeModel: (EOModel *)model
{
[_modelsByName removeObjectForKey: [model name]];
[model setModelGroup: nil];
[[NSNotificationCenter defaultCenter]
postNotificationName: EOModelInvalidatedNotification
object: model];
}
- (EOEntity *)entityNamed: (NSString *)entityName
{
NSEnumerator *modelEnum;
EOModel *model;
EOEntity *entity;
modelEnum = [_modelsByName objectEnumerator];
while ((model = [modelEnum nextObject]))
if ((entity = [model entityNamed: entityName]))
return entity;
return nil;
}
- (EOEntity *)entityForObject: (id)object
{
NSEnumerator *modelEnum;
EOModel *model;
EOEntity *entity;
modelEnum = [_modelsByName objectEnumerator];
while ((model = [modelEnum nextObject]))
if ((entity = [model entityForObject: object]))
return entity;
return nil;
}
- (NSArray *)availablePrototypesForAdaptorName: (NSString *)adaptorName
{
[self notImplemented: _cmd];
return nil;
}
- (EOAttribute *)prototypeAttributeForAttribute: (EOAttribute *)attribute
{
[self notImplemented: _cmd];
return nil;
}
- (void)loadAllModelObjects
{
NSEnumerator *modelEnum;
EOModel *model;
modelEnum = [_modelsByName objectEnumerator];
while ((model = [modelEnum nextObject]))
[model loadAllModelObjects];
}
- (id)delegate
{
return _delegate;
}
- (void)setDelegate: (id)delegate
{
EOFLOGObjectFnStartOrCond2(@"ModelingClasses", @"EOModelGroup");
ASSIGN(_delegate, delegate);
_delegateRespondsTo.entityNamed =
[_delegate respondsToSelector: @selector(modelGroup:entityNamed:)];
_delegateRespondsTo.failedToLookupClassNamed =
[_delegate respondsToSelector: @selector(entity:failedToLookupClassNamed:)];
_delegateRespondsTo.classForObjectWithGlobalID =
[_delegate respondsToSelector: @selector(entity:classForObjectWithGlobalID:)];
_delegateRespondsTo.subEntityForEntity =
[_delegate respondsToSelector: @selector(subEntityForEntity:primaryKey:isFinal:)];
_delegateRespondsTo.relationshipForRow =
[_delegate respondsToSelector: @selector(entity:relationshipForRow:relationship:)];
EOFLOGObjectFnStopOrCond2(@"ModelingClasses", @"EOModelGroup");
}
- (EOFetchSpecification *)fetchSpecificationNamed: (NSString *)fetchSpecName
entityNamed: (NSString *)entityName
{
EOFetchSpecification *newFetchSpecification = nil;
EOEntity *anEntity;
EOFLOGObjectFnStartOrCond2(@"ModelingClasses", @"EOModelGroup");
if (fetchSpecName
&& entityName && (anEntity = [self entityNamed: entityName]))
{
newFetchSpecification = [anEntity fetchSpecificationNamed: fetchSpecName];
}
EOFLOGObjectFnStopOrCond2(@"ModelingClasses", @"EOModelGroup");
return newFetchSpecification;
}
- (EOStoredProcedure *)storedProcedureNamed: (NSString *)aName
{
EOStoredProcedure *newStoredProcedure = nil;
NSEnumerator *modelEnum;
EOModel *model;
EOFLOGObjectFnStartOrCond2(@"ModelingClasses", @"EOModelGroup");
modelEnum = [_modelsByName objectEnumerator];
while ((model = [modelEnum nextObject]))
{
if ((newStoredProcedure = [model storedProcedureNamed: aName]))
{
EOFLOGObjectFnStopOrCond2(@"ModelingClasses", @"EOModelGroup");
return newStoredProcedure;
}
}
EOFLOGObjectFnStopOrCond2(@"ModelingClasses", @"EOModelGroup");
return nil;
}
@end

View file

@ -0,0 +1,43 @@
/*
EOPropertyListEncoding.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOPropertyListEncoding_h__
#define __EOPropertyListEncoding_h__
#import <Foundation/NSDictionary.h>
@protocol EOPropertyListEncoding
- initWithPropertyList: (NSDictionary *)propertyList owner: (id)owner;
- (void)awakeWithPropertyList: (NSDictionary *)propertyList;
- (void)encodeIntoPropertyList: (NSMutableDictionary *)propertyList;
@end
#endif /* __EOPropertyListEncoding_h__ */

231
EOAccess/EORelationship.h Normal file
View file

@ -0,0 +1,231 @@
/*
EORelationship.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EORelationship_h__
#define __EORelationship_h__
#import <Foundation/NSString.h>
#import <extensions/GCObject.h>
#import <extensions/GCArray.h>
#import <EOControl/EOClassDescription.h>
#import <EOControl/EOQualifier.h>
#import <EOAccess/EOJoin.h>
#import <EOAccess/EOPropertyListEncoding.h>
@class EOEntity;
@class EOAttribute;
@class EOExpressionArray;
@class EOMKKDSubsetMapping;
typedef enum {
EOInnerJoin = 0,
EOFullOuterJoin,
EOLeftOuterJoin,
EORightOuterJoin
} EOJoinSemantic;
@interface EORelationship : GCObject <EOPropertyListEncoding>
{
NSString *_name;
EOQualifier *_qualifier;
NSMutableDictionary *_sourceNames;
NSMutableDictionary *_destinationNames;
NSDictionary *_userInfo;
NSDictionary *_internalInfo;
NSString *_docComment;
NSDictionary *_sourceToDestinationKeyMap;
unsigned int _batchCount;
EOJoinSemantic _joinSemantic;
struct {
unsigned int isToMany:1;
unsigned int useBatchFaulting:1;
unsigned int deleteRule:2;
unsigned int isMandatory:1;
unsigned int ownsDestination:1;
unsigned int propagatesPrimaryKey:1;
unsigned int createsMutableObjects:1;
unsigned int isBidirectional:1;
unsigned int extraRefCount:23;
} _flags;
id _sourceRowToForeignKeyMapping;
/* Garbage collectable objects */
EOExpressionArray *_definitionArray;
EORelationship *_inverseRelationship;
EORelationship *_hiddenInverseRelationship;
EOEntity *_entity;
EOEntity *_destination;
GCMutableArray *_joins;
/* Computed values */
GCArray *_sourceAttributes;
GCArray *_destinationAttributes;
GCMutableArray *_componentRelationships;//Used ????
}
+ (id) relationshipWithPropertyList: (NSDictionary *)propertyList
owner: (id)owner;
- (NSString *)name;
- (EOEntity *)entity;
- (EOEntity *)destinationEntity;
- (NSString *)definition;
- (BOOL)isFlattened;
- (BOOL)isToMany;
- (BOOL)isCompound;
- (BOOL) isParentRelationship;
- (NSArray *)sourceAttributes;
- (NSArray *)destinationAttributes;
- (NSArray *)joins;
- (EOJoinSemantic)joinSemantic;
- (NSString*)joinSemanticString;
- (NSArray *)componentRelationships;
- (NSDictionary *)userInfo;
- (BOOL)referencesProperty: (id)property;
- (EODeleteRule)deleteRule;
- (BOOL)isMandatory;
- (BOOL)propagatesPrimaryKey;
- (BOOL)isBidirectional;
- (EORelationship *)hiddenInverseRelationship;
- (EORelationship *)inverseRelationship;
- (EORelationship *)anyInverseRelationship;
- (unsigned int)numberOfToManyFaultsToBatchFetch;
- (BOOL)ownsDestination;
- (EOQualifier *)qualifierWithSourceRow: (NSDictionary *)sourceRow;
@end
@interface EORelationship(EORelationshipEditing)
- (NSException *)validateName: (NSString *)name;
- (void)setName: (NSString *)name;
- (void)setDefinition: (NSString *)definition;
- (void)setEntity: (EOEntity *)entity;
- (void)setToMany: (BOOL)yn;
- (void)setPropagatesPrimaryKey: (BOOL)yn;
- (void)setIsBidirectional:(BOOL)yn;
- (void)setOwnsDestination: (BOOL)yn;
- (void)addJoin: (EOJoin *)join;
- (void)removeJoin: (EOJoin *)join;
- (void)setJoinSemantic: (EOJoinSemantic)joinSemantic;
- (void)setUserInfo: (NSDictionary *)dictionary;
- (void)setInternalInfo: (NSDictionary *)dictionary;
- (void)beautifyName;
- (void)setNumberOfToManyFaultsToBatchFetch: (unsigned int)size;
- (void)setDeleteRule: (EODeleteRule)deleteRule;
- (void)setIsMandatory: (BOOL)isMandatory;
- (void)setDocComment: (NSString *)docComment;
@end
@interface EORelationship(EORelationshipValueMapping)
- (NSException *)validateValue: (id *)valueP;
@end
@interface EORelationship (EORelationshipPrivate)
/*+ (EORelationship*)relationshipFromPropertyList: (id)propertyList
model: (EOModel*)model;
- (void)replaceStringsWithObjects;
- (void)initFlattenedRelationship;
- (id)propertyList;*/
- (void)setCreateMutableObjects: (BOOL)flag;
- (BOOL)createsMutableObjects;
- (void)setInverseRelationship: (EORelationship*)relationship;
@end /* EORelationship (EORelationshipPrivate) */
@interface EORelationship (EORelationshipXX)
- (NSArray*) _intermediateAttributes;
- (EORelationship*) lastRelationship;
- (EORelationship*) firstRelationship;
- (id) intermediateEntity;
- (BOOL) isMultiHop;
- (void) _setSourceToDestinationKeyMap: (id)param0;
- (id) qualifierForDBSnapshot: (id)param0;
- (id) primaryKeyForTargetRowFromSourceDBSnapshot: (id)param0;
- (NSString*)relationshipPath;
- (BOOL)isToManyToOne;
- (NSDictionary*)_sourceToDestinationKeyMap;
- (BOOL)foreignKeyInDestination;
@end
@interface EORelationship (EORelationshipPrivate2)
- (BOOL) isPropagatesPrimaryKeyPossible;
- (id) qualifierOmittingAuxiliaryQualifierWithSourceRow: (id)param0;
- (id) auxiliaryQualifier;
- (void) setAuxiliaryQualifier: (id)param0;
- (id) _foreignKeyForSourceRow: (NSDictionary*)row;
- (EOMKKDSubsetMapping*) _sourceRowToForeignKeyMapping;
- (NSArray*) _sourceAttributeNames;
- (EOJoin*) joinForAttribute: (EOAttribute*)attribute;
- (void) _flushCache;
- (EOExpressionArray*) _definitionArray;
- (NSString*) _stringFromDeleteRule: (EODeleteRule)deleteRule;
- (EODeleteRule) _deleteRuleFromString: (NSString*)deleteRuleString;
- (NSDictionary*) _rightSideKeyMap;
- (NSDictionary*) _leftSideKeyMap;
- (EORelationship*)_substitutionRelationshipForRow: (NSDictionary*)row;
- (void) _joinsChanged;
@end
#endif /* __EORelationship_h__ */

2370
EOAccess/EORelationship.m Normal file

File diff suppressed because it is too large Load diff

229
EOAccess/EOSQLExpression.h Normal file
View file

@ -0,0 +1,229 @@
/*
EOSQLExpression.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOSQLExpression_h__
#define __EOSQLExpression_h__
#import <Foundation/NSDictionary.h>
#import <Foundation/NSArray.h>
#import <EOControl/EOFetchSpecification.h>
#import <EOControl/EOSortOrdering.h>
#import <EOAccess/EORelationship.h>
@class EOAttribute;
@class EOEntity;
@class EOQualifier;
extern NSString *EOBindVariableNameKey;
extern NSString *EOBindVariableAttributeKey;
extern NSString *EOBindVariableValueKey;
extern NSString *EOBindVariablePlaceHolderKey;
extern NSString *EOBindVariableColumnKey;
@interface EOSQLExpression : NSObject
{
NSMutableDictionary *_aliasesByRelationshipPath;
EOEntity *_entity;
NSMutableString *_listString;
NSMutableString *_valueListString;
NSString *_whereClauseString;
NSMutableString *_joinClauseString;
NSMutableString *_orderByString;
NSMutableArray *_bindings;
NSMutableArray *_contextStack;
NSString *_statement;
BOOL _useAliases;
@private
int _alias;
}
+ (EOSQLExpression *)expressionForString: (NSString *)string;
+ (EOSQLExpression *)insertStatementForRow: (NSDictionary *)row
entity: (EOEntity *)entity;
+ (EOSQLExpression *)updateStatementForRow: (NSDictionary *)row
qualifier: (EOQualifier *)qualifier
entity: (EOEntity *)entity;
+ (EOSQLExpression *)deleteStatementWithQualifier: (EOQualifier *)qualifier
entity: entity;
+ (EOSQLExpression *)selectStatementForAttributes: (NSArray *)attributes
lock: (BOOL)yn
fetchSpecification: (EOFetchSpecification *)fetchSpecification
entity: (EOEntity *)entity;
- initWithEntity: (EOEntity *)entity;
- (NSMutableDictionary *)aliasesByRelationshipPath;
- (EOEntity *)entity;
- (NSMutableString *)listString;
- (NSMutableString *)valueList;
- (NSMutableString *)joinClauseString;
- (NSMutableString *)orderByString;
- (NSString *)whereClauseString;
- (NSString *)statement;
- (void)setStatement:(NSString *)statement;
- (NSString *)lockClause;
- (NSString *)tableListWithRootEntity: (EOEntity *)entity;
- (void)prepareInsertExpressionWithRow: (NSDictionary *)row;
- (void)prepareUpdateExpressionWithRow: (NSDictionary *)row
qualifier: (EOQualifier *)qualifier;
- (void)prepareDeleteExpressionForQualifier: (EOQualifier *)qualifier;
- (void)prepareSelectExpressionWithAttributes: (NSArray *)attributes
lock: (BOOL)yn
fetchSpecification: (EOFetchSpecification *)fetchSpecification;
- (NSString *)assembleJoinClauseWithLeftName: (NSString *)leftName
rightName: (NSString *)rightName
joinSemantic: (EOJoinSemantic)semantic;
- (void)addJoinClauseWithLeftName: (NSString *)leftName
rightName: (NSString *)rightName
joinSemantic: (EOJoinSemantic)semantic;
- (void)joinExpression;
- (NSString *)assembleInsertStatementWithRow: (NSDictionary *)row
tableList: (NSString *)tableList
columnList: (NSString *)columnList
valueList: (NSString *)valueList;
- (NSString *)assembleUpdateStatementWithRow: (NSDictionary *)row
qualifier: (EOQualifier *)qualifier
tableList: (NSString *)tableList
updateList: (NSString *)updateList
whereClause: (NSString *)whereClause;
- (NSString *)assembleDeleteStatementWithQualifier: (EOQualifier *)qualifier
tableList: (NSString *)tableList
whereClause: (NSString *)whereClause;
- (NSString *)assembleSelectStatementWithAttributes: (NSArray *)attributes
lock: (BOOL)lock
qualifier: (EOQualifier *)qualifier
fetchOrder: (NSArray *)fetchOrder
selectString: (NSString *)selectString
columnList: (NSString *)columnList
tableList: (NSString *)tableList
whereClause: (NSString *)whereClause
joinClause: (NSString *)joinClause
orderByClause: (NSString *)orderByClause
lockClause: (NSString *)lockClause;
- (void)addSelectListAttribute: (EOAttribute *)attribute;
- (void)addInsertListAttribute: (EOAttribute *)attribute
value: (NSString *)value;
- (void)addUpdateListAttribute: (EOAttribute *)attribute
value: (NSString *)value;
+ (NSString *)formatStringValue: (NSString *)string;
+ (NSString *)formatValue: (id)value forAttribute: (EOAttribute *)attribute;
+ (NSString *)formatSQLString: (NSString *)sqlString
format: (NSString *)format;
- (NSString *)sqlStringForConjoinedQualifiers: (NSArray *)qualifiers;
- (NSString *)sqlStringForDisjoinedQualifiers: (NSArray *)qualifiers;
- (NSString *)sqlStringForNegatedQualifier: (EOQualifier *)qualifier;
- (NSString *)sqlStringForKeyValueQualifier: (EOKeyValueQualifier *)qualifier;
- (NSString *)sqlStringForKeyComparisonQualifier: (EOKeyComparisonQualifier *)qualifier;
- (NSString *)sqlStringForValue: (NSString *)valueString
caseInsensitiveLikeKey: (NSString *)keyString;
- (void)addOrderByAttributeOrdering: (EOSortOrdering *)sortOrdering;
+ (BOOL)useQuotedExternalNames;
+ (void)setUseQuotedExternalNames: (BOOL)yn;
- (NSString *)externalNameQuoteCharacter;
- (void)setUseAliases: (BOOL)useAliases;
- (BOOL)useAliases;
- (NSString *)sqlStringForSchemaObjectName: (NSString *)name;
- (NSString *)sqlStringForAttributeNamed: (NSString *)name;
- (NSString *)sqlStringForSelector: (SEL)selector value: (id)value;
- (NSString *)sqlStringForValue: (id)value attributeNamed: (NSString *)string;
- (NSString *)sqlStringForAttribute: (EOAttribute *)anAttribute;
- (NSString *)sqlStringForAttributePath: (NSArray *)path;
- (void)appendItem: (NSString *)itemString
toListString: (NSMutableString *)listString;
+ (NSString *)sqlPatternFromShellPattern: (NSString *)pattern;
+ (NSString *)sqlPatternFromShellPattern: (NSString *)pattern
withEscapeCharacter: (unichar)escapeCharacter;
- (NSMutableDictionary *)bindVariableDictionaryForAttribute: (EOAttribute *)attribute
value: value;
- (BOOL)shouldUseBindVariableForAttribute: (EOAttribute *)att;
- (BOOL)mustUseBindVariableForAttribute: (EOAttribute *)att;
+ (BOOL)useBindVariables;
+ (void)setUseBindVariables: (BOOL)yn;
- (NSArray *)bindVariableDictionaries;
- (void)addBindVariableDictionary: (NSMutableDictionary *)binding;
@end
@interface NSString (EOSQLFormatting)
- (NSString *)sqlString;
@end
@interface NSNumber (EOSQLFormatting)
- (NSString *)sqlString;
@end
#endif /* __EOSQLExpression_h__ */

2878
EOAccess/EOSQLExpression.m Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,48 @@
/*
EOSQLExpression.h
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: Mars 2002
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOSQLExpressionPriv_h__
#define __EOSQLExpressionPriv_h__
@class EOEntity;
@interface EOSQLExpression (EOSQLExpressionPrivate)
- (EOEntity *)_rootEntityForExpression;
- (id) _aliasForRelationshipPath: (id)param0;
- (id) _flattenRelPath: (id)param0
entity: (id)param1;
- (NSString*) _sqlStringForJoinSemantic: (EOJoinSemantic)joinSemantic
matchSemantic: (int)param1;
- (id) _aliasForRelatedAttribute: (id)param0
relationshipPath: (id)param1;
- (id) _entityForRelationshipPath: (id)param0
origin: (id)param1;
@end
#endif /* __EOSQLExpressionPriv_h__ */

91
EOAccess/EOSQLQualifier.h Normal file
View file

@ -0,0 +1,91 @@
/*
EOSQLQualifier.h
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
Author: Manuel Guesdon <mguesdon@orange-concept.com>
Date: February 2002
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOSQLQualifier_h__
#define __EOSQLQualifier_h__
#import <Foundation/Foundation.h>
#import <EOControl/EOControl.h>
@class EOSQLExpression;
@class EOExpressionArray;
@class EOEntity;
@class EOModel;
/** Protocol for all qualifiers used used to generate SQL queries **/
@protocol EOQualifierSQLGeneration
- (NSString *)sqlStringForSQLExpression: (EOSQLExpression *)sqlExpression;
/** Returns an equivalent EOQualifier with object references replaced by foreign key references. **/
- (EOQualifier *)schemaBasedQualifierWithRootEntity: (EOEntity *)entity;
@end
@interface EOAndQualifier (EOQualifierSQLGeneration) <EOQualifierSQLGeneration>
@end
@interface EOOrQualifier (EOQualifierSQLGeneration) <EOQualifierSQLGeneration>
@end
@interface EOKeyComparisonQualifier (EOQualifierSQLGeneration) <EOQualifierSQLGeneration>
@end
@interface EOKeyValueQualifier (EOQualifierSQLGeneration) <EOQualifierSQLGeneration>
@end
@interface EONotQualifier (EOQualifierSQLGeneration) <EOQualifierSQLGeneration>
@end
//
// Finally, declare the EOSQLQualifier class.
//
@interface EOSQLQualifier : EOQualifier <EOQualifierSQLGeneration>
{
EOEntity *_entity;
EOExpressionArray *_contents;
struct
{
unsigned int usesDistinct:1;
unsigned int _RESERVED:31;
} _flags;
}
+ (EOQualifier *)qualifierWithQualifierFormat: (NSString *)format, ...;
- (id)initWithEntity: (EOEntity *)entity
qualifierFormat: (NSString *)qualifierFormat, ...;
// This is the designated initializer for EOSQLQualifier.
@end
@interface NSString (NSStringSQLExpression)
- (NSString *) valueForSQLExpression: (EOSQLExpression *)sqlExpression;
@end
#endif

369
EOAccess/EOSQLQualifier.m Normal file
View file

@ -0,0 +1,369 @@
/**
EOSQLQualifier.m <title>EOSQLQualifier Class</title>
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Manuel Guesdon <mguesdon@orange-concept.coù>
Date: February 2002
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#include <stdio.h>
#include <string.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSUtilities.h>
#import <extensions/NSException.h>
#import <extensions/DefaultScannerHandler.h>
#import <extensions/PrintfFormatScanner.h>
#import <extensions/exceptions/GeneralExceptions.h>
#import <EOAccess/EOAccess.h>
#import <EOControl/EOControl.h>
#import <EOControl/EOQualifier.h>
#import <EOControl/EODebug.h>
@implementation EOSQLQualifier
+ (EOQualifier *)qualifierWithQualifierFormat: (NSString *)format, ...
{
NSEmitTODO(); //TODO
[self notImplemented: _cmd]; //TODO
return nil;
}
- (id)initWithEntity: (EOEntity *)entity
qualifierFormat: (NSString *)qualifierFormat, ...
{
NSEmitTODO(); //TODO
[self notImplemented: _cmd]; //TODO
return nil;
}
- (EOQualifier *)schemaBasedQualifierWithRootEntity:(EOEntity *)entity
{
[self notImplemented: _cmd];
return nil;
}
- (NSString *)sqlStringForSQLExpression:(EOSQLExpression *)sqlExpression
{
[self notImplemented: _cmd];
return nil;
}
@end
@implementation EOAndQualifier (EOQualifierSQLGeneration)
- (NSString *)sqlStringForSQLExpression: (EOSQLExpression *)sqlExpression
{
//OK?
return [sqlExpression sqlStringForConjoinedQualifiers: _qualifiers];
/*
//TODO finish to add sqlExpression
NSEnumerator *qualifiersEnum=nil;
EOQualifier *qualifier=nil;
NSMutableString *sqlString = nil;
qualifiersEnum = [_qualifiers objectEnumerator];
while ((qualifier = [qualifiersEnum nextObject]))
{
if (!sqlString)
{
sqlString = [NSMutableString stringWithString:
[(<EOQualifierSQLGeneration>)qualifier sqlStringForSQLExpression:sqlExpression]];
}
else
{
[sqlString appendFormat:@" %@ %@",
@"AND",
[(<EOQualifierSQLGeneration>)qualifier sqlStringForSQLExpression:sqlExpression]];
}
}
return sqlString;
*/
}
- (EOQualifier *)schemaBasedQualifierWithRootEntity: (EOEntity *)entity
{
int qualifierCount = [_qualifiers count];
if (qualifierCount > 0)
{
NSMutableArray *qualifiers = [NSMutableArray array];
int i;
for (i = 0; i < qualifierCount; i++)
{
EOQualifier *qualifier = [_qualifiers objectAtIndex: i];
EOQualifier *schemaBasedQualifierTmp =
[(<EOQualifierSQLGeneration>)qualifier
schemaBasedQualifierWithRootEntity:
entity];
[qualifiers addObject: schemaBasedQualifierTmp];
}
}
//TODO
/*
call schemaBasedQualifierWithRootEntity:entity for each qualifier
if none return something different self, return self
[self notImplemented:_cmd];//TODO
*/
return self;
}
@end
@implementation EOOrQualifier (EOQualifierSQLGeneration)
- (NSString *)sqlStringForSQLExpression: (EOSQLExpression *)sqlExpression
{
NSEnumerator *qualifiersEnum;
EOQualifier *qualifier;
NSMutableString *sqlString = nil;
qualifiersEnum = [_qualifiers objectEnumerator];
while ((qualifier = [qualifiersEnum nextObject]))
{
if (!sqlString)
{
sqlString = [NSMutableString stringWithString:
[(<EOQualifierSQLGeneration>)qualifier sqlStringForSQLExpression: sqlExpression]];
}
else
{
[sqlString appendFormat: @" %@ %@",
@"OR",
[(<EOQualifierSQLGeneration>)qualifier sqlStringForSQLExpression: sqlExpression]];
}
}
return sqlString;
}
- (EOQualifier *)schemaBasedQualifierWithRootEntity: (EOEntity *)entity
{
/*
call schemaBasedQualifierWithRootEntity:entity for each qualifier
if none return something different self, return self
[self notImplemented:_cmd];//TODO
*/
return self;
}
@end
@implementation EOKeyComparisonQualifier (EOQualifierSQLGeneration)
- (NSString *)sqlStringForSQLExpression: (EOSQLExpression *)sqlExpression
{
return [sqlExpression sqlStringForKeyComparisonQualifier: self];
}
- (EOQualifier *)schemaBasedQualifierWithRootEntity: (EOEntity *)entity
{
//TODO
[self notImplemented: _cmd];
return nil;
}
@end
@implementation EOKeyValueQualifier (EOQualifierSQLGeneration)
- (NSString *)sqlStringForSQLExpression: (EOSQLExpression *)sqlExpression
{
return [sqlExpression sqlStringForKeyValueQualifier: self];
}
- (EOQualifier *)schemaBasedQualifierWithRootEntity: (EOEntity *)entity
{
EOQualifier *qualifier = nil;
NSMutableArray *qualifiers = nil;
id key;
EORelationship *relationship;
EOFLOGObjectFnStart();
key = [self key];
EOFLOGObjectLevelArgs(@"EOQualifier", @"key=%@", key);
relationship = [entity relationshipForPath: key];
EOFLOGObjectLevelArgs(@"EOQualifier", @"relationship=%@", relationship);
if (relationship)
{
EORelationship *destinationRelationship;
NSDictionary *keyValues = nil;
id value = nil;
EOEditingContext* editingContext = nil;
EOObjectStore *rootObjectStore = nil;
NSMutableArray *destinationAttributeNames = [NSMutableArray array];
NSArray *joins;
int i, count;
SEL sel = NULL;
if ([relationship isFlattened])
destinationRelationship = [relationship lastRelationship];
else
destinationRelationship = relationship;
joins = [destinationRelationship joins];
count = [joins count];
for (i = 0; i < count; i++)
{
EOJoin *join = [joins objectAtIndex: i];
EOAttribute *destinationAttribute = [join destinationAttribute];
NSString *destinationAttributeName = [destinationAttribute name];
[destinationAttributeNames addObject: destinationAttributeName];
}
value = [self value];
EOFLOGObjectLevelArgs(@"EOQualifier", @"value=%@", value);
editingContext = [value editingContext];
rootObjectStore = [editingContext rootObjectStore];
EOFLOGObjectLevelArgs(@"EOQualifier", @"rootObjectStore=%@",
rootObjectStore);
EOFLOGObjectLevelArgs(@"EOQualifier", @"destinationAttributeNames=%@",
destinationAttributeNames);
keyValues = [(EOObjectStoreCoordinator*)rootObjectStore
valuesForKeys:
destinationAttributeNames
object: value];
EOFLOGObjectLevelArgs(@"EOQualifier", @"keyValues=%@", keyValues);
sel = [self selector];
/*
when flattened: ???
entity relationshipForPath:key
and get joins on it ?
*/
for (i = 0; i < count; i++)
{
EOQualifier *tmpQualifier = nil;
NSString *attributeName = nil;
NSString *destinationAttributeName;
EOJoin *join = [joins objectAtIndex: i];
EOFLOGObjectLevelArgs(@"EOQualifier",@"join=%@",join);
destinationAttributeName = [destinationAttributeNames
objectAtIndex: i];
if (destinationRelationship != relationship)
{
// flattened: take destattr
attributeName = [NSString stringWithFormat: @"%@.%@",
key, destinationAttributeName];
//==> rel.attr
}
else
{
EOAttribute *sourceAttribute = [join sourceAttribute];
attributeName = [sourceAttribute name];
}
tmpQualifier = [EOKeyValueQualifier
qualifierWithKey: attributeName
operatorSelector: sel
value: [keyValues objectForKey:
destinationAttributeName]];
if (qualifier)//Already a qualifier
{
//Create an array of qualifiers
qualifiers = [NSMutableArray arrayWithObjects: qualifier,
tmpQualifier, nil];
qualifier = nil;
}
else if (qualifiers) //Already qualifiers
//Add this one
[qualifiers addObject: tmpQualifier];
else
//No previous qualifier
qualifier = tmpQualifier;
}
if (qualifiers)
{
//TODOVERIFY
qualifier = [EOAndQualifier qualifierWithQualifierArray: qualifiers];
}
}
else
qualifier = self;
EOFLOGObjectFnStop();
return qualifier;
}
@end
@implementation EONotQualifier (EOQualifierSQLGeneration)
- (NSString *)sqlStringForSQLExpression: (EOSQLExpression *)sqlExpression
{
return [sqlExpression sqlStringForNegatedQualifier: self];
}
- (EOQualifier *)schemaBasedQualifierWithRootEntity: (EOEntity *)entity
{
//TODO
[self notImplemented: _cmd];
return nil;
}
@end
@implementation NSString (NSStringSQLExpression)
- (NSString *) valueForSQLExpression: (EOSQLExpression *)sqlExpression
{
return self;
}
@end

View file

@ -0,0 +1,79 @@
/*
EOStoredProcedure.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOStoredProcedure_h__
#define __EOStoredProcedure_h__
#import <Foundation/Foundation.h>
#import <extensions/GCObject.h>
#import <EOAccess/EOPropertyListEncoding.h>
@class EOModel;
@class EOAttribute;
@class GCArray;
@interface EOStoredProcedure : GCObject <EOPropertyListEncoding>
{
NSString *_name;
NSString *_externalName;
NSDictionary *_userInfo;
NSDictionary *_internalInfo;
/* Garbage collectable objects */
EOModel *_model;
GCArray *_arguments;
}
+ (EOStoredProcedure *)storedProcedureWithPropertyList: (NSDictionary *)propertyList
owner: (id)owner;
- (EOStoredProcedure *)initWithName:(NSString *)name;
- (NSString *)name;
- (NSString *)externalName;
- (EOModel *)model;
- (NSArray *)arguments;
- (NSDictionary *)userInfo;
- (void)setName:(NSString *)name;
- (void)setExternalName:(NSString *)name;
- (void)setArguments:(NSArray *)arguments;
- (void)setUserInfo:(NSDictionary *)dictionary;
@end
@interface EOStoredProcedure(EOModelBeautifier)
- (void)beautifyName;
@end
#endif

View file

@ -0,0 +1,226 @@
/**
EOStoredProcedure.m <title>EOStoredProcedure Class</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <extensions/GCArray.h>
#import <EOAccess/EOStoredProcedure.h>
#import <EOAccess/EOAttribute.h>
#import <EOAccess/EOModel.h>
#import <EOControl/EODebug.h>
@implementation EOStoredProcedure
- (EOStoredProcedure *)initWithName:(NSString *)name
{
self = [super init];
[self setName:name];
_userInfo = [NSDictionary new];
_internalInfo = [NSDictionary new];
return self;
}
- (void)gcDecrementRefCountOfContainedObjects
{
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"model gcDecrementRefCount");
[(id)_model gcDecrementRefCount];
[(id)_arguments gcDecrementRefCount];
EOFLOGObjectFnStop();
}
- (BOOL)gcIncrementRefCountOfContainedObjects
{
if (![super gcIncrementRefCountOfContainedObjects])
return NO;
[(id)_model gcIncrementRefCount];
[(id)_arguments gcIncrementRefCount];
[(id)_model gcIncrementRefCountOfContainedObjects];
[(id)_arguments gcIncrementRefCountOfContainedObjects];
return YES;
}
+ (EOStoredProcedure *)storedProcedureWithPropertyList: (NSDictionary *)propertyList
owner: (id)owner
{
return [[[self alloc] initWithPropertyList: propertyList
owner: owner] autorelease];
}
- initWithPropertyList: (NSDictionary *)propertyList owner: (id)owner
{
NSArray *array;
NSEnumerator *enumerator;
id attributePList;
_model = [owner retain];
[self setName: [propertyList objectForKey: @"name"]];
[self setExternalName: [propertyList objectForKey: @"externalName"]];
[self setUserInfo: [propertyList objectForKey: @"userInfo"]];
if (!_userInfo)
[self setUserInfo:[propertyList objectForKey:@"userInfo"]];
array = [propertyList objectForKey:@"attributes"];
if ([array count])
{
_arguments = [[GCMutableArray alloc] initWithCapacity: [array count]];
enumerator = [array objectEnumerator];
while ((attributePList = [enumerator nextObject]))
{
EOAttribute *attribute = [EOAttribute
attributeWithPropertyList: attributePList
owner: self];
[(GCMutableArray *)_arguments addObject: attribute];
}
}
return self;
}
- (void)awakeWithPropertyList: (NSDictionary *)propertyList
{
NSEnumerator *argsEnum;
EOAttribute *attribute;
argsEnum = [_arguments objectEnumerator];
while ((attribute = [argsEnum nextObject]))
[attribute awakeWithPropertyList: propertyList];
}
- (void)encodeIntoPropertyList: (NSMutableDictionary *)propertyList
{
return;
}
- (NSString *)name
{
return _name;
}
- (NSString *)externalName
{
return _externalName;
}
- (EOModel *)model
{
return _model;
}
- (NSArray *)arguments
{
return _arguments;
}
- (NSDictionary *)userInfo
{
return _userInfo;
}
- (void)setName: (NSString *)name
{
ASSIGN(_name, name);
}
- (void)setExternalName: (NSString *)name
{
ASSIGN(_externalName, name);
}
- (void)setArguments: (NSArray *)arguments
{
if ([arguments isKindOfClass: [GCArray class]]
|| [arguments isKindOfClass: [GCMutableArray class]])
ASSIGN(_arguments, arguments);
else
_arguments = [[GCArray alloc] initWithArray: arguments];
}
- (void)setUserInfo: (NSDictionary *)dictionary
{
ASSIGN(_userInfo, dictionary);
}
@end
@implementation EOStoredProcedure (EOModelBeautifier)
- (void)beautifyName
{
NSArray *listItems;
NSString *newString = [NSMutableString string];
int anz, i;
EOFLOGObjectFnStartOrCond2(@"ModelingClasses", @"EOStoredProcedure");
if ((_name) && ([_name length] > 0))
{
listItems = [_name componentsSeparatedByString: @"_"];
newString = [newString stringByAppendingString: [[listItems objectAtIndex: 0]
lowercaseString]];
anz = [listItems count];
for (i = 1; i < anz; i++)
{
newString = [newString stringByAppendingString:
[[listItems objectAtIndex: i] capitalizedString]];
}
NS_DURING
[self setName: newString];
NS_HANDLER
NSLog(@"%@ in Class: EOStoredProcedure , Method: beautifyName >> error : %@",
[localException name], [localException reason]);
NS_ENDHANDLER;
}
EOFLOGObjectFnStopOrCond2(@"ModelingClasses", @"EOStoredProcedure");
}
@end

105
EOAccess/EOUtilities.h Normal file
View file

@ -0,0 +1,105 @@
/*
EOUtilities.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Manuel Guesdon <mguesdon@orange-concept.com>
Date: Sep 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOUtilities_h__
#define __EOUtilities_h__
#import <EOControl/EOControl.h>
@class EODatabaseContext;
@class EOModelGroup;
@class EOEntity;
extern NSString *EOMoreThanOneException;
@interface EOEditingContext(EOUtilities)
- (NSArray*)objectsForEntityNamed: (NSString*)name;
- (NSArray*)objectsOfClass: (Class)classObject;
- (NSArray*)objectsWithFetchSpecificationNamed: (NSString*)fetchSpecName
entityNamed: (NSString*)entityName
bindings: (NSDictionary*)bindings;
- (NSArray*)objectsForEntityNamed: (NSString*)name
qualifierFormat: (NSString*)format, ...;
- (NSArray*)objectsMatchingValue: (id)value
forKey: (NSString*)key
entityNamed: (NSString*)name;
- (NSArray*)objectsMatchingValues: (NSDictionary*)values
entityNamed: (NSString*)name;
- (id)objectWithFetchSpecificationNamed: (NSString*)fetchSpecName
entityNamed: (NSString*)entityName
bindings: (NSDictionary*)bindings;
- (id)objectForEntityNamed: (NSString*)name
qualifierFormat: (NSString*)format, ...;
- (id)objectMatchingValue: (id)value
forKey: (NSString*)key
entityNamed: (NSString*)name;
- (id)objectMatchingValues: (NSDictionary*)values
entityNamed: (NSString*)name;
- (id)objectWithPrimaryKeyValue: (id)value
entityNamed: (NSString*)name;
- (id)objectWithPrimaryKey: (NSDictionary*)pkDict
entityNamed: (NSString*)name;
- (NSArray *)objectsOfClass: (Class)class;
- (NSArray*)rawRowsForEntityNamed: (NSString*)name
qualifierFormat: (NSString*)format, ...;
- (NSArray*)rawRowsMatchingValue: (id)value
forKey: (NSString*)key
entityNamed: (NSString*)name;
- (NSArray*)rawRowsMatchingValues: (NSDictionary*)values
entityNamed: (NSString*)name;
- (NSArray*)rawRowsWithSQL: (NSString*)sqlString
modelNamed: (NSString*)name;
- (NSArray*)rawRowsWithStoredProcedureNamed: (NSString*)name
arguments: (NSDictionary*)args;
- (NSDictionary*)executeStoredProcedureNamed: (NSString*)name
arguments: (NSDictionary*)args;
- (id)objectFromRawRow: (NSDictionary*)row
entityNamed: (NSString*)name;
- (EODatabaseContext*)databaseContextForModelNamed: (NSString*)name;
- (void)connectWithModelNamed: (NSString*)name
connectionDictionaryOverrides: (NSDictionary*)overrides;
- (NSDictionary*)primaryKeyForObject: (id)object;
- (NSDictionary*)destinationKeyForSourceObject: (id)object
relationshipNamed: (NSString*)name;
- (id)localInstanceOfObject: (id)object;
- (NSArray*)localInstancesOfObjects: (NSArray*)objects;
- (EOModelGroup*)modelGroup;
- (EOEntity*)entityNamed: (NSString*)name;
- (EOEntity*)entityForClass: (Class)classObject;
- (EOEntity*)entityForObject: (id)obj;
@end
#endif

1039
EOAccess/EOUtilities.m Normal file

File diff suppressed because it is too large Load diff

123
EOAccess/GNUmakefile Normal file
View file

@ -0,0 +1,123 @@
#
# EOAccess makefile for GNUstep Database Library.
#
# Copyright (C) 2000-2002 Free Software Foundation, Inc.
#
# Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
#
# This file is part of the GNUstep Database Library.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Install into the system root by default
GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
include $(GNUSTEP_MAKEFILES)/common.make
include ../Version
# The library to be compiled
LIBRARY_NAME=libgnustep-db2
LIBRARIES_DEPEND_UPON=-lgnustep-base -lFoundationExt -lgnustep-db2control
# The C source files to be compiled
libgnustep-db2_C_FILES =
# The Objective-C source files to be compiled
libgnustep-db2_OBJC_FILES = \
EOModelGroup.m \
EOModel.m \
EOEntity.m \
EOAttribute.m \
EORelationship.m \
EOJoin.m \
EOStoredProcedure.m \
EOExpressionArray.m \
EOAdaptor.m \
EOAdaptorContext.m \
EOAdaptorChannel.m \
EOAdaptorOperation.m \
EODatabaseOperation.m \
EOSQLExpression.m \
EOSQLQualifier.m \
EODatabase.m \
EODatabaseChannel.m \
EODatabaseContext.m \
EOAccessFault.m \
EODatabaseDataSource.m \
EOUtilities.m
libgnustep-db2_HEADER_FILES_DIR = .
libgnustep-db2_HEADER_FILES_INSTALL_DIR = /EOAccess
libgnustep-db2_HEADER_FILES = \
EOModelGroup.h \
EOModel.h \
EOEntity.h \
EOAttribute.h \
EORelationship.h \
EOJoin.h \
EOStoredProcedure.h \
EOAdaptor.h \
EOAdaptorContext.h \
EOAdaptorChannel.h \
EODatabaseOperation.h \
EOSQLExpression.h \
EOSQLQualifier.h \
EODatabase.h \
EODatabaseChannel.h \
EODatabaseContext.h \
EOAccessFault.h \
EOPropertyListEncoding.h \
EODatabaseDataSource.h \
EOSchemaGeneration.h \
EOUtilities.h \
EOAccess.h
gdl2_AUTOGSDOC_HEADERS = $(libgnustep-db2_HEADER_FILES)
gdl2_AUTOGSDOC_SOURCE = $(libgnustep-db2_OBJC_FILES)
DOCUMENT_NAME = gdl2
gdl2_HEADER_FILES_DIR = $(HEADER_DIR)
gdl2_AGSDOC_FILES = gdl2.gsdoc $(gdl2_AUTOGSDOC_HEADERS)
#$(gdl2_AUTOGSDOC_SOURCE)
gdl2_AGSDOC_FLAGS = \
-Declared EOAccess \
-Standards YES \
-Project gdl2 \
-WordMap '{\
FOUNDATION_EXPORT=extern;FOUNDATION_STATIC_INLINE="";\
GS_GEOM_SCOPE=extern;GS_GEOM_ATTR="";\
GS_EXPORT=extern;GS_DECLARE="";\
GS_RANGE_SCOPE=extern;GS_RANGE_ATTR="";\
GS_ZONE_SCOPE=extern;GS_ZONE_ATTR="";\
}' -Up gdl2
-include Makefile.preamble
-include GNUmakefile.local
include $(GNUSTEP_MAKEFILES)/library.make
# Only build the doc if doc=yes was passed on the command line
ifeq ($(doc),yes)
include $(GNUSTEP_MAKEFILES)/documentation.make
endif
-include Makefile.postamble

View file

@ -0,0 +1,69 @@
#
# Makefile.postamble
#
# Copyright (C) 1997 Free Software Foundation, Inc.
#
# Written by: Scott Christley <scottc@net-community.com>
#
# This file is part of the GNUstep Database Library.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# Makefile.postamble
#
# Project specific makefile rules
#
# Uncomment the targets you want.
# The double colons (::) are important, do not make them single colons
# otherwise the normal makefile rules will not be performed.
#
# Things to do before compiling
before-all::
# Things to do after compiling
# after-all::
# Things to do before installing
# before-install::
# Things to do after installing
# after-install::
# Things to do before uninstalling
# before-uninstall::
# Things to do after uninstalling
# after-uninstall::
# Things to do before cleaning
# before-clean::
# Things to do after cleaning
# after-clean::
# Things to do before distcleaning
# before-distclean::
# Things to do after distcleaning
# after-distclean::
# Things to do before checking
# before-check::
# Things to do after checking
# after-check:

View file

@ -0,0 +1,72 @@
#
# Makefile.preamble
#
# Copyright (C) 1997 Free Software Foundation, Inc.
#
# Written by: Scott Christley <scottc@net-community.com>
#
# This file is part of the GNUstep Database Library.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# Makefile.preamble
#
# Project specific makefile variables, and additional
#
# Do not put any Makefile rules in this file, instead they should
# be put into Makefile.postamble.
#
#
# Flags dealing with compiling and linking
#
# Additional flags to pass to the preprocessor
ADDITIONAL_CPPFLAGS = $(FND_DEFINE) $(RUNTIME_DEFINE) -g
# Additional flags to pass to the Objective-C compiler
ADDITIONAL_OBJCFLAGS =
# Additional flags to pass to the C compiler
ADDITIONAL_CFLAGS =
# Additional include directories the compiler should search
ADDITIONAL_INCLUDE_DIRS = -I..
# Additional LDFLAGS to pass to the linker
ADDITIONAL_LDFLAGS =
# Additional library directories the linker should search
ADDITIONAL_LIB_DIRS =
#
# Flags dealing with installing and uninstalling
#
# Additional directories to be created during installation
ADDITIONAL_INSTALL_DIRS =
# What are the libraries this library depends upon. This is needed for some
# systems where building a shared library requires to pass to the linker
# all the libraries the target library depends upon.
LIBRARIES_DEPEND_UPON = -l$(FOUNDATION_LIBRARY_NAME)
ifeq ($(FOUNDATION_HAS_KVC), yes)
ADDITIONAL_OBJCFLAGS := $(ADDITIONAL_OBJCFLAGS) -DFOUNDATION_HAS_KVC=1
endif

23
EOAccess/gdl2.gsdoc Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0"?>
<!DOCTYPE gsdoc PUBLIC "-//GNUstep//DTD gsdoc 0.6.7//EN" "http://www.gnustep.org/gsdoc-0_6_7.xml">
<gsdoc base="index">
<head>
<title>GDL2</title>
<author name="Mirko Viviani">
<email address="mirko.viviani@rccr.cremona.it"/>
<url url="http://www.gnustep.org/developers/whoiswho.html"/></author>
<author name="Manuel Guesdon">
<email address="mguesdon@orange-concept.com"/>
<url url="http://www.gnustep.org/developers/whoiswho.html"/></author>
</head>
<body>
<chapter>
<heading>GDL2</heading>
<p>...
</p>
</chapter>
<back>
<index scope="project" type="title" />
</back>
</body>
</gsdoc>

40
EOAdaptors/GNUmakefile.in Normal file
View file

@ -0,0 +1,40 @@
#
# EOAdaptors makefile for GNUstep Database Library.
#
# Copyright (C) 2002 Free Software Foundation, Inc.
#
# Written by: Mirko Viviani <mirko.viviani@rccr.cremona.it>
#
# This file is part of the GNUstep Database Library.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
include $(GNUSTEP_MAKEFILES)/common.make
include ../Version
#
# The list of subproject directories
#
SUBPROJECTS = @EOADAPTORS@
-include Makefile.preamble
include $(GNUSTEP_MAKEFILES)/aggregate.make
-include Makefile.postamble

View file

@ -0,0 +1,91 @@
#
# PostgreSQL makefile for GNUstep Database Library.
#
# Copyright (C) 2000-2002 Free Software Foundation, Inc.
#
# Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
#
# This file is part of the GNUstep Database Library.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
include $(GNUSTEP_MAKEFILES)/common.make
include ../../Version
POSTGRES95_DATABASE=@POSTGRES_DATABASE@
# The framework to be compiled
FRAMEWORK_NAME=Postgres95EOAdaptor
# Install into the local root by default
Postgres95EOAdaptor_INSTALLATION_DIR = $(GNUSTEP_LOCAL_ROOT)
# The framework principal class
Postgres95EOAdaptor_PRINCIPAL_CLASS = Postgres95Adaptor
# The framework Objective-C source files to be compiled
Postgres95EOAdaptor_OBJC_FILES = \
Postgres95Adaptor.m \
Postgres95Context.m \
Postgres95Channel.m \
Postgres95SQLExpression.m \
Postgres95Values.m
Postgres95EOAdaptor_HEADER_FILES = \
Postgres95Adaptor.h \
Postgres95Context.h \
Postgres95Channel.h \
Postgres95SQLExpression.h \
Postgres95Values.h
Postgres95EOAdaptor_AUTOGSDOC_HEADERS = $(Postgres95EOAdaptor_HEADER_FILES)
Postgres95EOAdaptor_AUTOGSDOC_SOURCE = $(Postgres95EOAdaptor_OBJC_FILES)
DOCUMENT_NAME = Postgres95EOAdaptor
Postgres95EOAdaptor_AGSDOC_FILES = Postgres95EOAdaptor.gsdoc $(Postgres95EOAdaptor_AUTOGSDOC_HEADERS)
#$(Postgres95EOAdaptor_AUTOGSDOC_SOURCE)
Postgres95EOAdaptor_AGSDOC_FLAGS = \
-Declared Foundation \
-Standards YES \
-SystemProjects System \
-Project Postgres95EOAdaptor \
-WordMap '{\
FOUNDATION_EXPORT=extern;FOUNDATION_STATIC_INLINE="";\
GS_GEOM_SCOPE=extern;GS_GEOM_ATTR="";\
GS_EXPORT=extern;GS_DECLARE="";\
GS_RANGE_SCOPE=extern;GS_RANGE_ATTR="";\
GS_ZONE_SCOPE=extern;GS_ZONE_ATTR="";\
}' -Up Postgres95EOAdaptor
-include Makefile.preamble
-include GNUmakefile.local
ifeq ($(POSTGRES95_DATABASE),yes)
include $(GNUSTEP_MAKEFILES)/framework.make
else
include $(GNUSTEP_MAKEFILES)/rules.make
endif
# Only build the doc if doc=yes was passed on the command line
ifeq ($(doc),yes)
include $(GNUSTEP_MAKEFILES)/documentation.make
endif
-include Makefile.postamble

View file

@ -0,0 +1,4 @@
{
NSPrincipalClass = Postgres95Adaptor;
NSExecutable = Postgres95;
}

View file

@ -0,0 +1,61 @@
#
# Makefile.preamble
#
# Copyright (C) 2000-2002 Free Software Foundation, Inc.
#
# Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
#
# This file is part of the GNUstep Database Library.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# Makefile.preamble
#
# Project specific makefile variables, and additional
#
# Do not put any Makefile rules in this file, instead they should
# be put into Makefile.postamble.
#
#
# Flags dealing with compiling and linking
#
# Additional flags to pass to the preprocessor
ADDITIONAL_CPPFLAGS =
# Additional flags to pass to the Objective-C compiler
ADDITIONAL_OBJCFLAGS =
# Additional flags to pass to the C compiler
ADDITIONAL_CFLAGS =
# Additional include directories the compiler should search
ADDITIONAL_INCLUDE_DIRS = -I../.. -I/usr/local/pgsql/include
# Additional LDFLAGS to pass to the linker
ADDITIONAL_LDFLAGS = -lpq
# Additional library directories the linker should search
ADDITIONAL_LIB_DIRS = -L/usr/local/pgsql/lib
#
# Flags dealing with installing and uninstalling
#
# Additional directories to be created during installation
ADDITIONAL_INSTALL_DIRS =

View file

@ -0,0 +1,61 @@
#
# Makefile.preamble
#
# Copyright (C) 2000-2002 Free Software Foundation, Inc.
#
# Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
#
# This file is part of the GNUstep Database Library.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# Makefile.preamble
#
# Project specific makefile variables, and additional
#
# Do not put any Makefile rules in this file, instead they should
# be put into Makefile.postamble.
#
#
# Flags dealing with compiling and linking
#
# Additional flags to pass to the preprocessor
ADDITIONAL_CPPFLAGS =
# Additional flags to pass to the Objective-C compiler
ADDITIONAL_OBJCFLAGS =
# Additional flags to pass to the C compiler
ADDITIONAL_CFLAGS =
# Additional include directories the compiler should search
ADDITIONAL_INCLUDE_DIRS = -I../.. @POSTGRES_INCLUDES@
# Additional LDFLAGS to pass to the linker
ADDITIONAL_LDFLAGS = @POSTGRES_LIBS@
# Additional library directories the linker should search
ADDITIONAL_LIB_DIRS = @POSTGRES_LIB_DIRS@
#
# Flags dealing with installing and uninstalling
#
# Additional directories to be created during installation
ADDITIONAL_INSTALL_DIRS =

View file

@ -0,0 +1,104 @@
/*
Postgres95Adaptor.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it
Date: February 2000
based on the Postgres95 adaptor written by
Mircea Oancea <mircea@jupiter.elcom.pub.ro>
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __Postgres95Adaptor_h__
#define __Postgres95Adaptor_h__
#import <EOAccess/EOAdaptor.h>
/* Include Postgres 95 Headers */
#undef Assert
#include <stdio.h>
#include <libpq-fe.h>
#include <libpq/libpq-fs.h>
#undef Assert
@class NSMutableArray;
@class NSMutableSet;
/* The following keys are meaningful in the connectionDictionary in a model:
databaseServer or hostName - the name of the server
(default getenv(PGHOST) or localhost)
databaseName - the name of the database to use
(default getenv(PGDATABASE))
options - additional options sent to the POSTGRES95 backend
(default getenv(PGOPTIONS))
port - port to communicate with POSTGRES95 backend
(default getenv(PGPORT))
debugTTY - filename (file/device) used for debugging output
(default getenv(PGTTY))
primaryKeySequenceNameFormat - Format for pk sequence name;
like @"%@_SEQ" or @"EOSEQ_%@", "%@" is replaced by external table name
(default: @"%@_SEQ")
NOTE: user name is not given explicitly - the library uses the
real user id of the user running the program and that user id
is interpreted by the server (AFAIK)
*/
@interface Postgres95Adaptor : EOAdaptor
{
NSMutableArray *_pgConnPool;
int _pgConnPoolLimit;
NSString* _primaryKeySequenceNameFormat;
struct {
BOOL cachePGconn:1;
} _flags;
}
/* Reporting errors */
- (void)privateReportError: (PGconn *)pgConn;
/* Configure the adaptor to share the PGconn or not. The default is not to
share PGconn. */
- (void)setCachePGconn: (BOOL)flag;
- (BOOL)cachePGconn;
- (void)setPGconnPoolLimit: (int)newLimit;
- (int)pgConnPoolLimit;
/* Inherited methods */
// Private methods
/* Obtaining and releasing a PGconn from pool */
- (PGconn *)createPGconn;
- (PGconn *)newPGconn;
- (void)releasePGconn: (PGconn *)pgConn force: (BOOL)flag;
// format is something like @"%@_SEQ" or @"EOSEQ_%@", "%@" is replaced by external table name
- (void)setPrimaryKeySequenceNameFormat: (NSString*)format;
- (NSString*)primaryKeySequenceNameFormat;
extern NSString *Postgres95Exception;
@end
#endif /* __Postgres95Adaptor_h__ */

View file

@ -0,0 +1,489 @@
/**
Postgres95Adaptor.m <title>Postgres95Adaptor</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
based on the Postgres95 adaptor written by
Mircea Oancea <mircea@jupiter.elcom.pub.ro>
Author: Manuel Guesdon <mguesdon@orange-concept.com>
Date: October 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSString.h>
#import <Foundation/NSUtilities.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSAutoreleasePool.h>
#import <extensions/NSException.h>
#import <EOAccess/EOAccess.h>
#import <EOAccess/EOAttribute.h>
#import <EOAccess/EOExpressionArray.h>
#import <EOAccess/EOEntity.h>
#import <EOAccess/EOModel.h>
#import <Postgres95EOAdaptor/Postgres95Adaptor.h>
#import <Postgres95EOAdaptor/Postgres95Context.h>
#import <Postgres95EOAdaptor/Postgres95Channel.h>
#import <Postgres95EOAdaptor/Postgres95SQLExpression.h>
#import <Postgres95EOAdaptor/Postgres95Values.h>
NSString *Postgres95Exception = @"Postgres95Exception";
static int pgConnTotalAllocated = 0;
static int pgConnCurrentAllocated = 0;
@implementation Postgres95Adaptor
- init
{
return [self initWithName: @"Postgres95"];
}
- initWithName: (NSString *)name
{
if ((self = [super initWithName: name]))
{
_pgConnPool = [NSMutableArray new];
}
return self;
}
- (void)dealloc
{
NSEnumerator *enumerator;
PGconn *pgConn;
enumerator = [_pgConnPool objectEnumerator];
while ((pgConn = [[enumerator nextObject] pointerValue]))
[self releasePGconn: pgConn force: YES];
[_pgConnPool release];
[super dealloc];
}
- (void)privateReportError: (PGconn*)pgConn
{
char *message = "NULL pgConn in privateReportError:";
EOFLOGObjectFnStart();
if (pgConn)
message = PQerrorMessage(pgConn);
NSLog(@"%s", message);
EOFLOGObjectFnStop();
}
- (void)setCachePGconn: (BOOL)flag
{
_flags.cachePGconn = flag;
}
- (BOOL)cachePGconn
{
return _flags.cachePGconn;
}
- (void)setPGconnPoolLimit: (int)value
{
_pgConnPoolLimit = value;
}
- (int)pgConnPoolLimit
{
return _pgConnPoolLimit;
}
/*+ (NSDictionary *)defaultConnectionDictionary
{
static NSDictionary *dict = nil;
if (!dict)
dict = [[NSDictionary dictionaryWithObjectsAndKeys:NSHomeDirectory(), FlatFilePathKey, [self defaultRowSeparator], FlatFileRowSeparatorKey, [self defaultColumnSeparator], FlatFileColumnSeparatorKey, @"Y", FlatFileUseHeadersKey, nil] retain];
return dict;
}*/
static NSString *externalTypeNames[] = {
@"bool",
@"char", @"char2", @"char4", @"char8", @"char16", @"filename",
@"date", @"reltime", @"time", @"tinterval", @"abstime",
@"float4", @"float8",
@"int4", @"int2",
@"oid", @"oid8", @"oidint2", @"oidint4", @"oidchar16",
@"varchar", @"bpchar",
@"cid", @"tid", @"xid",
nil
};
static NSString *internalTypeNames[] = {
@"NSNumber",
@"NSNumber", @"NSNumber", @"NSNumber", @"NSNumber", @"NSNumber", @"NSNumber",
@"NSCalendarDate", @"NSCalendarDate", @"NSCalendarDate", @"NSCalendarDate", @"NSCalendarDate",
@"NSNumber", @"NSNumber",
@"NSNumber", @"NSNumber",
@"NSNumber", @"NSNumber", @"NSNumber", @"NSNumber", @"NSNumber",
@"NSString", @"NSString",
@"NSDecimalNumber", @"NSDecimalNumber", @"NSDecimalNumber",
nil
};
+ (NSDictionary *)externalToInternalTypeMap
{
static NSDictionary *externalToInternalTypeMap = nil;
if (!externalToInternalTypeMap)
{
int i;
for (i = 0; externalTypeNames[i]; i++);
externalToInternalTypeMap = [[NSDictionary dictionaryWithObjects: internalTypeNames forKeys: externalTypeNames count: i] retain];
}
return externalToInternalTypeMap;
}
+ (NSString *)internalTypeForExternalType: (NSString *)extType
model: (EOModel *)model
{
return [[self externalToInternalTypeMap] objectForKey: extType];
}
+ (NSArray *)externalTypesWithModel:(EOModel *)model
{
return [[self externalToInternalTypeMap] allKeys];
}
+ (void)assignExternalInfoForAttribute: (EOAttribute *)attribute
{
// TODO
EOAdaptorValueType value = [attribute adaptorValueType];
[attribute setExternalType: externalTypeNames[value]];
}
+ (void)assignExternalInfoForEntity: (EOEntity *)entity
{
NSEnumerator *attributeEnumerator = [[entity attributes] objectEnumerator];
EOAttribute *attribute;
while ((attribute = [attributeEnumerator nextObject]))
[self assignExternalInfoForAttribute: attribute];
}
/* Inherited methods */
- (EOAdaptorContext *)createAdaptorContext
{
//OK
return [Postgres95Context adaptorContextWithAdaptor: self];
}
- (Class)defaultExpressionClass
{
Class expressionClass;
EOFLOGObjectFnStart();
expressionClass = [Postgres95SQLExpression class];
EOFLOGObjectFnStop();
return expressionClass;
}
- (BOOL)isValidQualifierType: (NSString *)typeName
model: (EOModel *)model
{
int i;
for (i = 0; externalTypeNames[i]; i++)
{
//TODO REMOVE
NSDebugMLog(@"externalTypeNames[i]=%@", externalTypeNames[i]);
if ([externalTypeNames[i] isEqualToString: typeName])
return YES;
}
//TODO REMOVE
NSDebugMLog(@"typeName=%@", typeName);
return NO;
}
- (void)assertConnectionDictionaryIsValid
{
NSException *exception = nil;
EOAdaptorContext *adaptorContext;
EOAdaptorChannel *adaptorChannel;
if (![self hasOpenChannels])
{
adaptorContext = [self createAdaptorContext];
adaptorChannel = [adaptorContext createAdaptorChannel];
NS_DURING
[adaptorChannel openChannel];
NS_HANDLER
exception = localException;
NS_ENDHANDLER;
[adaptorChannel closeChannel];
if (exception)
[exception raise];
}
}
/*
-(NSString *)formatValue:(id)value
forAttribute:(EOAttribute*)attribute
{
return [value stringValueForPostgres95Type:[attribute externalType]
attribute:attribute];
}
*/
- (NSString *)fetchedValueForString: (NSString *)value
attribute: (EOAttribute *)attribute
{
return value;
}
//TODO: don't need to be overriden ??
- (NSNumber *)fetchedValueForNumberValue: (NSNumber *)value
attribute: (EOAttribute *)attribute
{
return value; // TODO scale and precision
}
- (NSCalendarDate *)fetchedValueForDateValue: (NSCalendarDate *)value
attribute: (EOAttribute *)attribute
{
return value;
}
- (NSData *)fetchedValueForDataValue: (NSData *)value
attribute: (EOAttribute *)attribute
{
return value;
}
- (void)createDatabaseWithAdministrativeConnectionDictionary: (NSDictionary *)connectionDictionary
{
}
- (void)dropDatabaseWithAdministrativeConnectionDictionary: (NSDictionary *)connectionDictionary
{
}
/* Private methods for Postgres Adaptor */
- (PGconn *)createPGconn
{
char *pg_host = NULL;
char *pg_database = NULL;
char *pg_port = NULL;
char *pg_options = NULL;
char *pg_tty = NULL;
char *pg_user = NULL;
char *pg_pwd = NULL;
PGconn *pgConn = NULL;
PGresult *pgResult = NULL;
NSString *str = nil;
EOFLOGObjectFnStart();
//OK
str = [_connectionDictionary objectForKey: @"databaseServer"];
if (!str)
str = [_connectionDictionary objectForKey: @"hostName"];
pg_host = (char*)[str cString];
pg_database = (char*)[[_connectionDictionary objectForKey: @"databaseName"]
cString];
pg_port = (char*)[[_connectionDictionary objectForKey: @"port"] cString];
if (!pg_port)
pg_port = (char*)[[_connectionDictionary objectForKey: @"hostPort"]
cString];
pg_options = (char*)[[_connectionDictionary objectForKey: @"options"]
cString];
pg_tty = (char*)[[_connectionDictionary objectForKey: @"debugTTY"] cString];
pg_user = (char*)[[_connectionDictionary objectForKey: @"userName"]
cString];
pg_pwd = (char*)[[_connectionDictionary objectForKey: @"password"]
cString];
NSLog(@"%s %s %s %s %s", pg_host, pg_port, pg_database, pg_user, pg_pwd);
NSDebugMLog(@"%s %s %s %s %s", pg_host, pg_port, pg_database, pg_user, pg_pwd);
// Try to connect to the Postgres95 server
if (pg_user)
pgConn = PQsetdbLogin(pg_host, pg_port, pg_options, pg_tty,
pg_database,pg_user,pg_pwd);
else
pgConn = PQsetdb(pg_host, pg_port, pg_options, pg_tty, pg_database);
NSDebugMLog(@"%s %s %s %s %s", pg_host, pg_port, pg_database, pg_user,
pg_pwd);
// Check connection
if (PQstatus(pgConn) == CONNECTION_BAD)
{
//TODO: report error in an exception ?
[self privateReportError: pgConn];
PQfinish(pgConn);
pgConn = NULL;
}
if (pgConn)
{
pgResult = PQexec(pgConn, "SET DATESTYLE TO 'SQL'");
PQclear(pgResult);
pgResult = NULL;
if (pgConn)
{
pgConnTotalAllocated++;
pgConnCurrentAllocated++;
}
}
EOFLOGObjectFnStop();
return pgConn;
}
- (PGconn *)newPGconn
{
PGconn *pgConn = NULL;
if(_flags.cachePGconn && [_pgConnPool count])
{
NSDebugMLog(@"newPGconn cached %p (pgConn=%p) total=%d current=%d",
self,
pgConn,
pgConnTotalAllocated,
pgConnCurrentAllocated);
pgConn = [[_pgConnPool lastObject] pointerValue];
[_pgConnPool removeLastObject];
}
else
{
pgConn = [self createPGconn];
NSDebugMLog(@"newPGconn not cached %p (pgConn=%p) total=%d current=%d",
self,
pgConn,
pgConnTotalAllocated,
pgConnCurrentAllocated);
}
return pgConn;
}
- (void)releasePGconn: (PGconn *)pgConn
force: (BOOL)flag
{
if (!flag
&& _flags.cachePGconn
&& (PQstatus(pgConn) == CONNECTION_OK)
&& [_pgConnPool count] < _pgConnPoolLimit)
{
NSDebugMLog(@"releasePGconn -> in pool %p (pgConn=%p) total=%d current=%d",
self,
pgConn,
pgConnTotalAllocated,
pgConnCurrentAllocated);
[_pgConnPool addObject: [NSValue value: pgConn
withObjCType: @encode(PGconn*)]];
}
else
{
NSDebugMLog(@"releasePGconn really %p (pgConn=%p) total=%d current=%d",
self,
pgConn,
pgConnTotalAllocated,
pgConnCurrentAllocated);
pgConnCurrentAllocated--;
PQfinish(pgConn);
}
}
// format is something like @"%@_SEQ" or @"EOSEQ_%@", "%@" is replaced by external table name
- (void)setPrimaryKeySequenceNameFormat: (NSString*)format
{
ASSIGN(_primaryKeySequenceNameFormat, format);
}
- (NSString*)primaryKeySequenceNameFormat
{
if (!_primaryKeySequenceNameFormat)
_primaryKeySequenceNameFormat = [_connectionDictionary objectForKey: @"primaryKeySequenceNameFormat"];
if (!_primaryKeySequenceNameFormat)
_primaryKeySequenceNameFormat = @"%@_SEQ";
return _primaryKeySequenceNameFormat;
}
@end /* Postgres95Adaptor */
/*
//TODO
databaseEncoding
{
self connectionDictionary
call dict obj for key databaseEncoding
return 2 par defaut
};
*/

View file

@ -0,0 +1,89 @@
/*
Postgres95Channel.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
based on the Postgres95 adaptor written by
Mircea Oancea <mircea@jupiter.elcom.pub.ro>
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __Postgres95Channel_h__
#define __Postgres95Channel_h__
#import <EOAccess/EOAdaptorChannel.h>
#import <Postgres95EOAdaptor/Postgres95Context.h>
@class NSMutableDictionary;
@class NSMutableArray;
@class EOAttribute;
@interface Postgres95Channel : EOAdaptorChannel
{
Postgres95Context *_adaptorContext;
PGconn *_pgConn;
PGresult *_pgResult;
NSArray *_attributes;
NSArray *_origAttributes;
EOSQLExpression *_sqlExpression;
int _currentResultRow;
NSMutableDictionary *_oidToTypeName;
BOOL _isFetchInProgress;
BOOL _fetchBlobsOid;
NSArray *_pkAttributeArray;
struct {
unsigned int postgres95InsertedRowOid:1;
unsigned int postgres95Notification:1;
} _postgres95DelegateRespondsTo;
}
- (PGconn*)pgConn;
- (PGresult*)pgResult;
- (BOOL)advanceRow;
- (void)cleanupFetch;
- (void)_cancelResults;
- (void)_describeResults;
/* Private methods */
- (char*)_readBinaryDataRow: (Oid)oid length: (int*)length zone: (NSZone*)zone;
- (Oid)_insertBinaryData: (NSData*)binaryData forAttribute: (EOAttribute*)attr;
- (Oid)_updateBinaryDataRow: (Oid)oid data: (NSData*)binaryData;
- (void)_describeDatabaseTypes;
- (BOOL)_evaluateExpression: (EOSQLExpression *)expression
withAttributes: attrs;
@end
@interface NSObject (Postgres95ChannelDelegate)
- (void)postgres95Channel: (Postgres95Channel*)channel
insertedRowWithOid: (Oid)oid;
- (void)postgres95Channel: (Postgres95Channel*)channel
receivedNotification: (NSString*)notification;
@end
#endif /* __Postgres95Channel_h__ */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,71 @@
/*
Postgres95Context.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
based on the Postgres95 adaptor written by
Mircea Oancea <mircea@jupiter.elcom.pub.ro>
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __Postgres95Context_h__
#define __Postgres95Context_h__
#import <EOAccess/EOAdaptorContext.h>
#import <Postgres95EOAdaptor/Postgres95Adaptor.h>
@interface Postgres95Context : EOAdaptorContext
{
NSString* _primaryKeySequenceNameFormat;
struct
{
unsigned int didAutoBegin:1;
unsigned int didBegin:1;
unsigned int forceTransaction:1;
} _flags;
}
- initWithAdaptor: (EOAdaptor *)adaptor;
- (void)beginTransaction;
- (void)commitTransaction;
- (void)rollbackTransaction;
- (BOOL)canNestTransactions;
- (EOAdaptorChannel *)createAdaptorChannel;
- (BOOL)autoBeginTransaction: (BOOL)force;
- (BOOL)autoCommitTransaction;
// format is something like @"%@_SEQ" or @"EOSEQ_%@", "%@" is replaced by external table name
- (void)setPrimaryKeySequenceNameFormat: (NSString*)format;
- (NSString*)primaryKeySequenceNameFormat;
- (BOOL)autoBeginTransaction: (BOOL)force;
- (BOOL)autoCommitTransaction;
@end
#endif /* __Postgres95Context_h__ */

View file

@ -0,0 +1,318 @@
/**
Postgres95Context.m <title>Postgres95Context</title>
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
based on the Postgres95 adaptor written by
Mircea Oancea <mircea@jupiter.elcom.pub.ro>
Author: Manuel Guesdon <mguesdon@orange-concept.com>
Date: October 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSString.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSException.h>
#import <EOAccess/EOAccess.h>
#import <Postgres95EOAdaptor/Postgres95Adaptor.h>
#import <Postgres95EOAdaptor/Postgres95Context.h>
#import <Postgres95EOAdaptor/Postgres95Channel.h>
#import <Postgres95EOAdaptor/Postgres95SQLExpression.h>
@implementation Postgres95Context
- (id)initWithAdaptor: (EOAdaptor *)adaptor
{
if ((self = [super initWithAdaptor: adaptor]))
{
if (adaptor)
[self setPrimaryKeySequenceNameFormat:
[(Postgres95Adaptor*)adaptor primaryKeySequenceNameFormat]];
}
return self;
}
- (void)beginTransaction
{
Postgres95Channel *channel = nil;
EOFLOGObjectFnStart();
if ([self transactionNestingLevel])
[NSException raise: NSInternalInconsistencyException
format: @"%@ -- %@ 0x%x: attempted to begin a transaction within a transaction",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
if (_delegateRespondsTo.shouldBegin)
{
if (![_delegate adaptorContextShouldBegin: self])
[NSException raise: Postgres95Exception
format: @"%@ -- %@ 0x%x: delegate refuses",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
}
channel = [[_channels objectAtIndex: 0] nonretainedObjectValue];
if ([channel isOpen] == NO)
[NSException raise: Postgres95Exception
format: @"cannot execute SQL expression. Channel is not opened."];
_flags.didBegin = YES;
[channel _evaluateExpression: [EOSQLExpression
expressionForString: @"BEGIN TRANSACTION"]
withAttributes: nil];
[self transactionDidBegin];
if (_delegateRespondsTo.didBegin)
[_delegate adaptorContextDidBegin: self];
NSDebugMLLog(@"gsdb", @"_flags.didBegin=%s",
(_flags.didBegin ? "YES" : "NO"));
NSDebugMLLog(@"gsdb", @"_flags.didAutoBegin=%s",
(_flags.didAutoBegin ? "YES" : "NO"));
EOFLOGObjectFnStop();
}
- (void)commitTransaction
{
//channel conn
//self transactionNestingLevel
//self transactionDidCommit
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"_flags.didBegin=%s",
(_flags.didBegin ? "YES" : "NO"));
NSDebugMLLog(@"gsdb", @"_flags.didAutoBegin=%s",
(_flags.didAutoBegin ? "YES" : "NO"));
if ([self transactionNestingLevel] == 0)
[NSException raise: NSInternalInconsistencyException
format: @"%@ -- %@ 0x%x:illegal attempt to commit a transaction when there are none in progress",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
if (_delegateRespondsTo.shouldCommit)
{
if (![_delegate adaptorContextShouldCommit: self])
[NSException raise: Postgres95Exception
format: @"%@ -- %@ 0x%x: delegate refuses",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
}
//???
[[[_channels objectAtIndex: 0] nonretainedObjectValue]
_evaluateExpression: [EOSQLExpression
expressionForString: @"END TRANSACTION"]
withAttributes: nil];
_flags.didBegin = NO;
[self transactionDidCommit];
if (_delegateRespondsTo.didCommit)
[_delegate adaptorContextDidCommit: self];
NSDebugMLLog(@"gsdb", @"_flags.didBegin=%s",
(_flags.didBegin ? "YES" : "NO"));
NSDebugMLLog(@"gsdb", @"_flags.didAutoBegin=%s",
(_flags.didAutoBegin ? "YES" : "NO"));
EOFLOGObjectFnStop();
}
- (void)rollbackTransaction
{
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"_flags.didBegin=%s",
(_flags.didBegin ? "YES" : "NO"));
NSDebugMLLog(@"gsdb", @"_flags.didAutoBegin=%s",
(_flags.didAutoBegin ? "YES" : "NO"));
if (![self transactionNestingLevel])
{
[NSException raise: NSInternalInconsistencyException
format: @"%@ -- %@ 0x%x:illegal attempt to commit a transaction when there are none in progress",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
}
if (_delegateRespondsTo.shouldRollback)
{
if (![_delegate adaptorContextShouldRollback: self])
[NSException raise: Postgres95Exception
format: @"%@ -- %@ 0x%x: delegate refuses",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self];
}
[[[_channels objectAtIndex: 0] nonretainedObjectValue]
_evaluateExpression: [EOSQLExpression
expressionForString: @"ABORT TRANSACTION"]
withAttributes: nil];
_flags.didBegin = NO;
[self transactionDidRollback];
if (_delegateRespondsTo.didRollback)
[_delegate adaptorContextDidRollback: self];
NSDebugMLLog(@"gsdb", @"_flags.didBegin=%s",
(_flags.didBegin ? "YES" : "NO"));
NSDebugMLLog(@"gsdb", @"_flags.didAutoBegin=%s",
(_flags.didAutoBegin ? "YES" : "NO"));
EOFLOGObjectFnStop();
}
- (BOOL)canNestTransactions
{
return NO;
}
- (EOAdaptorChannel *)createAdaptorChannel
{
//OK
EOAdaptorChannel *adaptorChannel;
adaptorChannel = [Postgres95Channel adaptorChannelWithAdaptorContext: self];
return adaptorChannel;
}
- (BOOL)autoBeginTransaction: (BOOL)force
{
//seems OK
BOOL ok = NO;
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"force=%d _flags.didBegin=%s [self transactionNestingLevel]=%d",
force,
(_flags.didBegin ? "YES" : "NO"),
[self transactionNestingLevel]);
if (!_flags.didBegin && [self transactionNestingLevel] == 0)
{
if (force == YES)
[self beginTransaction];
_flags.didAutoBegin = YES;
_flags.forceTransaction = force;
ok = YES;
}
NSDebugMLLog(@"gsdb", @"_flags.didBegin=%s",
(_flags.didBegin ? "YES" : "NO"));
NSDebugMLLog(@"gsdb", @"_flags.didAutoBegin=%s",
(_flags.didAutoBegin ? "YES" : "NO"));
EOFLOGObjectFnStop();
return ok;
}
- (BOOL)autoCommitTransaction
{
//seems ok
BOOL ok = NO;
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"_flags.didBegin=%s",
(_flags.didBegin ? "YES" : "NO"));
NSDebugMLLog(@"gsdb", @"_flags.didAutoBegin=%s",
(_flags.didAutoBegin ? "YES" : "NO"));
if (_flags.didAutoBegin)
{
NSDebugMLLog(@"gsdb", @"_flags.forceTransaction=%s",
(_flags.forceTransaction ? "YES" : "NO"));
if (_flags.forceTransaction == YES)
{
[self commitTransaction];
}
_flags.didAutoBegin = NO;
_flags.forceTransaction = NO;
ok = YES;
}
NSDebugMLLog(@"gsdb", @"_flags.didBegin=%s",
(_flags.didBegin ? "YES" : "NO"));
NSDebugMLLog(@"gsdb", @"_flags.didAutoBegin=%s",
(_flags.didAutoBegin ? "YES" : "NO"));
EOFLOGObjectFnStop();
return ok;
}
/** format is something like @"%@_SEQ" or @"EOSEQ_%@", "%@" is replaced by external table name **/
- (void)setPrimaryKeySequenceNameFormat: (NSString*)format
{
ASSIGN(_primaryKeySequenceNameFormat, format);
}
- (NSString*)primaryKeySequenceNameFormat
{
return _primaryKeySequenceNameFormat;
}
@end /* Postgres95Context */
/*
//TODO
autoCommitTransaction
{
self commitTransaction
};
*/

View file

@ -0,0 +1,23 @@
<?xml version="1.0"?>
<!DOCTYPE gsdoc PUBLIC "-//GNUstep//DTD gsdoc 0.6.7//EN" "http://www.gnustep.org/gsdoc-0_6_7.xml">
<gsdoc base="index">
<head>
<title>GDL2 Postgres95 Adaptor</title>
<author name="Mirko Viviani">
<email address="mirko.viviani@rccr.cremona.it"/>
<url url="http://www.gnustep.org/developers/whoiswho.html"/></author>
<author name="Manuel Guesdon">
<email address="mguesdon@orange-concept.com"/>
<url url="http://www.gnustep.org/developers/whoiswho.html"/></author>
</head>
<body>
<chapter>
<heading>GDL2 Postgres95 Adaptor</heading>
<p>...
</p>
</chapter>
<back>
<index scope="project" type="title" />
</back>
</body>
</gsdoc>

View file

@ -0,0 +1,57 @@
/*
Postgres95SQLExpression.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __Postgres95SQLExpression_h__
#define __Postgres95SQLExpression_h__
#import <EOAccess/EOSQLExpression.h>
@class NSString;
@interface Postgres95SQLExpression : EOSQLExpression
+ (NSString *)formatValue: (id)value
forAttribute: (EOAttribute *)attribute;
- (NSString *)externalNameQuoteCharacter;
- (NSString *)lockClause;
- (NSString *)assembleSelectStatementWithAttributes: (NSArray *)attributes
lock: (BOOL)lock
qualifier: (EOQualifier *)qualifier
fetchOrder: (NSArray *)fetchOrder
selectString: (NSString *)selectString
columnList: (NSString *)columnList
tableList: (NSString *)tableList
whereClause: (NSString *)whereClause
joinClause: (NSString *)joinClause
orderByClause: (NSString *)orderByClause
lockClause: (NSString *)lockClause;
@end
#endif /* __Postgres95SQLExpression_h__ */

View file

@ -0,0 +1,299 @@
/**
Postgres95SQLExpression.m <title>Postgres95SQLExpression</title>
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
This product includes software developed by Turbocat's Development.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/Foundation.h>
#import <Foundation/NSUtilities.h>
#import <extensions/NSException.h>
#import <EOAccess/EOAccess.h>
#import <Postgres95EOAdaptor/Postgres95SQLExpression.h>
#import <Postgres95EOAdaptor/Postgres95Values.h>
@implementation Postgres95SQLExpression
+ (NSString *)formatValue: (id)value
forAttribute: (EOAttribute *)attribute
{
NSString *formatted = nil;
NSString *externalType;
NSMutableString *string;
const char *tempString;
int i, dif;
EOFLOGObjectFnStart();
EOFLOGObjectLevelArgs(@"EOSQLExpression", @"value=%@ class=%@", value,
[value class]);
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"[EONull null] %p=%@ [EONull null] class=%@",
[EONull null],
[EONull null],
[[EONull null] class]);
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"[value isEqual:[EONull null]]=%s",
([value isEqual: [EONull null]] ? "YES" : "NO"));
externalType = [attribute externalType];
if (!value)
{
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"NULL case - value=%@ class=%@",
value, [value class]);
formatted = @"NULL";
}
else if ([value isEqual: [EONull null]])
{
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"EONULL case - value=%@ class=%@",
value, [value class]);
formatted = [value sqlString];
}
else if ([externalType hasPrefix: @"int"])
{
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"int case - value=%@ class=%@",
value, [value class]);
formatted = [NSString stringWithFormat: @"%@", value];
// value was for example 0 length string
if ([formatted length] == 0)
formatted = @"NULL";
}
else if ([externalType hasPrefix: @"float"])
{
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"float case - value=%@ class=%@",
value, [value class]);
formatted = [NSString stringWithFormat: @"%@", value];
// value was for example 0 length string
if ([formatted length] == 0)
formatted=@"NULL";
}
else if ([externalType hasPrefix: @"bool"])
{
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"BOOL case - value=%@ class=%@",
value, [value class]);
if ([value isKindOfClass: [NSNumber class]] == YES)
{
BOOL boolValue = [value boolValue];
if (boolValue == NO)
formatted = @"'f'";
else
formatted = @"'t'";
}
else
{
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"BOOL case/NSString - value=%@ class=%@",
value, [value class]);
formatted = [NSString stringWithFormat: @"'%@'", value];
// value was for example 0 length string
if ([formatted length] == 0)
formatted = @"NULL";
}
}
else if ([externalType isEqualToString: @"oid"])
{
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"OID case - value=%@ class=%@",
value, [value class]);
formatted = [NSString stringWithFormat: @"%@", value];
// value was for example 0 length string
if ([formatted length] == 0)
formatted=@"NULL";
}
else if ([externalType isEqualToString: @"money"])
{
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"Money case - value=%@ class=%@",
value, [value class]);
formatted = [NSString stringWithFormat: @"'$%@'", value];
// value was for example 0 length string
if ([formatted length] == 3) // only '$'
formatted = @"NULL";
}
else if (([externalType isEqualToString: @"abstime"])
|| ([externalType isEqualToString: @"datetime"])
|| ([externalType isEqualToString: @"timestamp"]))
{
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"Time case - value=%@ class=%@",
value, [value class]);
if ([[value description] length] == 0)
{
NSWarnLog(@"empty description for %p %@ of class %@",
value, value, [value class]);
}
// Value can also be a string...
if ([value isKindOfClass:[NSDate class]])
{
formatted = [NSString stringWithFormat: @"'%@'",
[value
descriptionWithCalendarFormat:
[NSCalendarDate postgres95Format]//@"%d/%m/%Y %H:%M:%S"
timeZone: nil
locale: nil]];
}
else
formatted = [NSString stringWithFormat: @"'%@'",value];
}
else
{
int length = 0;
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"other case - value=%@ class=%@",
value, [value class]);
string = [NSMutableString stringWithFormat: @"%@", value];
EOFLOGObjectLevelArgs(@"EOSQLExpression", @"string %p='%@'",
string, string);
length=[string cStringLength];
tempString = [string cString];
for (i = 0, dif = 0; i < length; i++)
{
switch (tempString[i])
{
case '\\':
case '\'':
[string insertString: @"\\" atIndex: dif + i];
dif++;
break;
case '_':
[string insertString: @"\\" atIndex: dif + i];
dif++;
break;
default:
break;
}
}
formatted = [NSString stringWithFormat: @"'%@'", string];
EOFLOGObjectLevelArgs(@"EOSQLExpression", @"formatted %p=%@",
formatted, formatted);
}
EOFLOGObjectLevelArgs(@"EOSQLExpression", @"formatted=%@", formatted);
EOFLOGObjectFnStop();
return formatted;
}
- (NSString *)externalNameQuoteCharacter
{
if ([EOSQLExpression useQuotedExternalNames])
return @"'";
else
return @"";
}
- (NSString *)lockClause
{
return @"FOR UPDATE";
}
- (NSString *)assembleSelectStatementWithAttributes: (NSArray *)attributes
lock: (BOOL)lock
qualifier: (EOQualifier *)qualifier
fetchOrder: (NSArray *)fetchOrder
selectString: (NSString *)selectString
columnList: (NSString *)columnList
tableList: (NSString *)tableList
whereClause: (NSString *)whereClause
joinClause: (NSString *)joinClause
orderByClause: (NSString *)orderByClause
lockClause: (NSString *)lockClause
{
//OK
NSMutableString *sqlString = nil;
EOFLOGObjectFnStart();
EOFLOGObjectLevelArgs(@"EOSQLExpression", @"selectString=%@", selectString);
EOFLOGObjectLevelArgs(@"EOSQLExpression", @"columnList=%@", columnList);
EOFLOGObjectLevelArgs(@"EOSQLExpression", @"tableList=%@", tableList);
sqlString = [NSMutableString stringWithFormat: @"%@ %@ FROM %@",
selectString,
columnList,
tableList];
if (whereClause && joinClause)
[sqlString appendFormat: @" WHERE %@ AND %@",
whereClause,
joinClause];
else if (whereClause || joinClause)
[sqlString appendFormat: @" WHERE %@",
(whereClause ? whereClause : joinClause)];
if (orderByClause)
[sqlString appendFormat: @" ORDER BY %@", orderByClause];
if (lockClause)
[sqlString appendFormat: @" %@", lockClause];
EOFLOGObjectFnStop();
return sqlString;
}
@end

View file

@ -0,0 +1,79 @@
/*
Postgres95Values.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __Postgres95Values_h__
#define __Postgres95Values_h__
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSData.h>
#import <Foundation/NSDate.h>
#import <EOControl/EONull.h>
@class EOAttribute;
@class Postgres95Channel;
extern NSString *Postgres95CalendarFormat;
@interface Postgres95Values
{
}
+ (id)newValueForBytes: (const void *)bytes
length: (int)length
attribute: (EOAttribute *)attribute;
+ (id)newValueForNumberType: (const void *)bytes
length: (int)length
attribute: (EOAttribute *)attribute;
+ (id)newValueForCharactersType: (const void *)bytes
length: (int)length
attribute: (EOAttribute *)attribute;
+ (id)newValueForBytesType: (const void *)bytes
length: (int)length
attribute: (EOAttribute *)attribute;
+ (id)newValueForDateType: (const void *)bytes
length: (int)length
attribute: (EOAttribute *)attribute;
@end
@interface NSCalendarDate (Postgres95ValueCreation)
+ (void)setPostgres95Format: (NSString *)_format;
+ (NSString *)postgres95Format;
@end
#endif /* __Postgres95Values_h__ */

View file

@ -0,0 +1,330 @@
/**
Postgres95Values.m
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSData.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>
#import <extensions/NSException.h>
#import <EOAccess/EOAccess.h>
#import <EOAccess/EOAttribute.h>
#import <Postgres95EOAdaptor/Postgres95Adaptor.h>
#import <Postgres95EOAdaptor/Postgres95Channel.h>
#import <Postgres95EOAdaptor/Postgres95Values.h>
void __postgres95_values_linking_function (void)
{
}
//NSString *Postgres95CalendarFormat = @"%m-%d-%Y %H:%M:%S %Z";
NSString *Postgres95CalendarFormat = nil;
@implementation Postgres95Values
+ (id)newValueForBytes: (const void *)bytes
length: (int)length
attribute: (EOAttribute *)attribute
{
switch ([attribute adaptorValueType])
{
case EOAdaptorNumberType:
return [self newValueForNumberType: bytes
length: length
attribute: attribute];
case EOAdaptorCharactersType:
return [self newValueForCharactersType: bytes
length: length
attribute: attribute];
case EOAdaptorBytesType:
return [self newValueForBytesType: bytes
length: length
attribute: attribute];
case EOAdaptorDateType:
return [self newValueForDateType: bytes
length: length
attribute: attribute];
}
return nil;
}
/**
For efficiency reasons, the returned value is NOT autoreleased !
**/
+ (id)newValueForNumberType: (const void *)bytes
length: (int)length
attribute: (EOAttribute *)attribute
{
NSString *str = [NSString stringWithCString:(char *)bytes
length:length];
id value = nil;
if ([[attribute externalType] isEqualToString: @"bool"])
{
if (((char *)bytes)[0] == 't' && ((char *)bytes)[1] == 0)
return [[NSNumber alloc] initWithBool:YES];
if (((char *)bytes)[0] == 'f' && ((char *)bytes)[1] == 0)
return [[NSNumber alloc] initWithBool:NO];
}
if ([[attribute valueClassName] isEqualToString: @"NSDecimalNumber"])
value = [[NSDecimalNumber decimalNumberWithString: str] retain];
else if ([[attribute valueType] isEqualToString: @"i"])
value = [[NSNumber alloc] initWithInt: [str intValue]];
else
value = [[NSNumber alloc] initWithDouble: [str doubleValue]];
return value;
}
/**
For efficiency reasons, the returned value is NOT autoreleased !
**/
+ (id)newValueForCharactersType: (const void *)bytes
length: (int)length
attribute: (EOAttribute *)attribute
{
return [attribute newValueForBytes: bytes
length: length
encoding: [NSString defaultCStringEncoding]];
}
/**
For efficiency reasons, the returned value is NOT autoreleased !
**/
+ (id)newValueForBytesType: (const void *)bytes
length: (int)length
attribute: (EOAttribute *)attribute
{
return [attribute newValueForBytes: bytes
length: length];
}
/**
For efficiency reasons, the returned value is NOT autoreleased !
**/
+ (id)newValueForDateType: (const void *)bytes
length: (int)length
attribute: (EOAttribute *)attribute
{
id d;
NSString *str = [NSString stringWithCString: bytes length: length];
NSString *format = [NSCalendarDate postgres95Format];
d = [[[NSCalendarDate alloc] initWithString: str
calendarFormat: format]
// TODO server TZ ?
retain];
// NSDebugMLLog(@"gsdb",@"str=%@ d=%@ format=%@",str,d,format);
NSDebugMLog(@"str=%@ d=%@ format=%@", str, d, format);
return d;
}
@end
/*
@implementation NSString (Postgres95ValueCreation)
For efficiency reasons, the returned value is NOT autoreleased !
- stringValueForPostgres95Type:(NSString*)type
attribute:(EOAttribute*)attribute
{
if ([type isEqual:@"bytea"])
return [[NSData alloc]initWithBytes:[self cString]
length:[self cStringLength]]
stringValueForPostgres95Type:type
attribute:attribute];
else
return [[[[EOQuotedExpression alloc]
initWithExpression:self
quote:@"'"
escape:@"\\'"]
autorelease]
expressionValueForContext:nil];
return nil;
}
@end // NSString (Postgres95ValueCreation)
@implementation NSNumber (Postgres95ValueCreation)
- stringValueForPostgres95Type:(NSString*)type
attribute:(EOAttribute*)attribute;
{
if ([[attribute externalType] isEqualToString:@"bool"])
return [self boolValue] ? @"'t'" : @"'f'";
return [self description];
}
@end // NSNumber (Postgres95ValueCreation)
@implementation NSData (Postgres95ValueCreation)
- stringValueForPostgres95Type:(NSString*)type
attribute:(EOAttribute*)attribute
{
if ([[attribute externalType] isEqualToString:@"bytea"]) {
const char* bytes = [self bytes];
int length = [self length];
int final_length;
char *description, *temp;
int i;
if (!length)
return @"''";
final_length = 4 + 2 * length + 1;
description = Malloc (final_length);
temp = description + 3;
description[0] = 0;
strcat (description, "'0x");
for (i = 0; i < length; i++, temp += 2)
sprintf (temp, "%02X", (unsigned char)bytes[i]);
temp[0] = '\'';
temp[1] = 0;
return [[[NSString alloc]
initWithCStringNoCopy:description
length:final_length-1
freeWhenDone:YES]
autorelease];
}
return [[NSString stringWithCString:[self bytes] length:[self length]]
stringValueForPostgres95Type:type attribute:attribute];
}
@end // NSData (Postgres95ValueCreation)
*/
@implementation NSCalendarDate (Postgres95ValueCreation)
/*
- stringValueForPostgres95Type:(NSString*)type
attribute:(EOAttribute*)attribute
{
NSString* externalType = [attribute externalType];
if (!CALENDAR_FORMAT)
[NSCalendarDate setPostgres95Format:[NSString stringWithCString:"%b %d %Y %I:%M%p %Z"]];
if ([externalType isEqualToString:@"abstime"]) {
id tz = [attribute serverTimeZone];
id date;
if (tz) {
date = [[self copy] autorelease];
[date setTimeZone:tz];
}
else
date = self;
return [NSString stringWithFormat:@"'%@'",
[date descriptionWithCalendarFormat:CALENDAR_FORMAT]];
}
THROW([[DataTypeMappingNotSupportedException alloc]
initWithFormat:@"Postgres95 cannot map NSCalendarDate in "
@"attribute %@ to external type %@",
[attribute name], externalType]);
return nil;
}
*/
+ (NSString*)postgres95Format
{
if (!Postgres95CalendarFormat)
//Mirko: @"%d/%m/%Y %H:%M:%S.00 %Z"
[NSCalendarDate setPostgres95Format: [NSString stringWithCString: "%m-%d-%Y %H:%M:%S %Z"]]; //"%b %d %Y %I:%M%p %Z"]];
return Postgres95CalendarFormat;
}
+ (void)setPostgres95Format: (NSString*)_format
{
ASSIGN(Postgres95CalendarFormat, _format);
}
@end // NSCalendarDate (Postgres95ValueCreation)
/*
@implementation EONull (Postgres95ValueCreation)
- stringValueForPostgres95Type:(NSString*)type
attribute:(EOAttribute*)attribute
{
return @"NULL";
}
@end
@implementation NSObject (Postgres95ValueCreation)
- stringValueForPostgres95Type:(NSString*)type
attribute:(EOAttribute*)attribute
{
if ([self respondsToSelector:@selector(stringForType:)])
return [[self stringForType:[attribute valueType]]
stringValueForPostgres95Type:type attribute:attribute];
else if ([self respondsToSelector:@selector(dataForType:)])
return [[self dataForType:[attribute valueType]]
stringValueForPostgres95Type:type attribute:attribute];
else
THROW([[DataTypeMappingNotSupportedException alloc]
initWithFormat:@"Postgres95 cannot map value class %@ "
@"because its instances does not responds to either "
@" `stringForType:' or `dataForType:'. ",
NSStringFromClass([self class])]);
return nil;
}
@end // NSObject (Postgres95ValueCreation)
*/

194
EOControl/EOAndQualifier.m Normal file
View file

@ -0,0 +1,194 @@
/**
EOAndQualifier.m <title>EOAndQualifier Class</title>
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
Author: Manuel Guesdon <mguesdon@orange-concept.com>
Date: January 2002
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSDictionary.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSUtilities.h>
#import <EOControl/EOControl.h>
#import <EOControl/EOQualifier.h>
#import <EOControl/EODebug.h>
#import <EOAccess/EOSQLExpression.h>
@implementation EOAndQualifier
+ (EOQualifier *)qualifierWithQualifierArray: (NSArray *)array
{
return [[[self alloc] initWithQualifierArray: array] autorelease];
}
+ (EOQualifier *)qualifierWithQualifiers: (EOQualifier *)qualifiers, ...
{
NSMutableArray *qualArray = [NSMutableArray array];
EOQualifier *tmpId;
va_list ap;
va_start(ap, qualifiers);
for (tmpId = qualifiers; tmpId != nil;)
{
[qualArray addObject: tmpId];
tmpId = va_arg(ap, id);
}
va_end(ap);
return [[[self alloc] initWithQualifierArray: qualArray] autorelease];
}
- (id) initWithQualifiers: (EOQualifier *)qualifiers, ...
{
NSMutableArray *qualArray = [NSMutableArray array];
EOQualifier *tmpId;
va_list ap;
va_start(ap, qualifiers);
for (tmpId = qualifiers; tmpId != nil;)
{
[qualArray addObject: tmpId];
tmpId = va_arg(ap, id);
}
va_end(ap);
return [self initWithQualifierArray: qualArray];
}
- (id) initWithQualifierArray: (NSArray *)array
{
if ((self = [self init]))
{
ASSIGN(_qualifiers, array);
}
return self;
}
- (void)dealloc
{
DESTROY(_qualifiers);
[super dealloc];
}
- (NSArray *)qualifiers
{
return _qualifiers;
}
- (id)copyWithZone: (NSZone *)zone
{
EOAndQualifier *qual = [[EOAndQualifier allocWithZone: zone] init];
qual->_qualifiers = [_qualifiers copyWithZone: zone];
return qual;
}
- (BOOL)evaluateWithObject: (id)object
{
NSEnumerator *qualifiersEnum;
EOQualifier *qualifier;
qualifiersEnum = [_qualifiers objectEnumerator];
while ((qualifier = [qualifiersEnum nextObject]))
{
if ([qualifier evaluateWithObject: object] == NO)
return NO;
}
return YES;
}
- (id) qualifierMigratedFromEntity: (id)param0
relationshipPath: (id)param1
{
return [self notImplemented: _cmd]; //TODO
}
- (void) _addBindingsToDictionary: (id)param0
{
[self notImplemented: _cmd]; //TODO
}
- (EOQualifier *) qualifierWithBindings: (NSDictionary *)bindings
requiresAllVariables: (BOOL)requiresAllVariables
{
EOFLOGObjectLevelArgs(@"EOQualifier", @"bindings=%@", bindings);
if ([bindings count] > 0)
{
NSEmitTODO();
return [self notImplemented: _cmd]; //TODO
}
else
return self;
}
- (id) initWithKeyValueUnarchiver: (id)param0
{
return [self notImplemented: _cmd]; //TODO
}
- (void) encodeWithKeyValueArchiver: (id)param0
{
[self notImplemented: _cmd]; //TODO
}
- (id) validateKeysWithRootClassDescription: (id)param0
{
return [self notImplemented: _cmd]; //TODO
}
- (id) description
{
NSString *dscr;
dscr = [NSString stringWithFormat: @"<%s %p - qualifiers: %@>",
object_get_class_name(self),
(void*)self,
_qualifiers];
return dscr;
}
@end

86
EOControl/EOCheapArray.h Normal file
View file

@ -0,0 +1,86 @@
/*
EOCheapArray.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Manuel Guesdon <mguesdon@orange-concept.com>
Date: Sep 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOCheapArray_h__
#define __EOCheapArray_h__
@interface EOCheapCopyArray : NSArray
{
unsigned int _count;
id *_contents_array;
unsigned int _refcount;
}
- (id) initWithArray: (id)array;
- (id) initWithObjects: (id*)objects
count: (unsigned int)count;
- (void) dealloc;
- (void) release;
- (unsigned int) retainCount;
- (id) retain;
- (id) objectAtIndex: (unsigned int)index;
//- (id) copyWithZone: (NSZone*)zone;
- (unsigned int) count;
//- (BOOL) containsObject: (id)obejct;
@end
@interface EOCheapCopyMutableArray : NSMutableArray
{
unsigned int _count;
id *_contents_array;
unsigned int _capacity;
unsigned int _grow_factor;
id _immutableCopy;
}
- (id) initWithCapacity: (unsigned int)capacity;
- (id) initWithObjects: (id*)objects
count: (unsigned int)count;
- (id) initWithArray: (NSArray*)array;
- (void) dealloc;
- (id) shallowCopy;
- (void) _setCopy: (id)param0;
- (void) _mutate;
- (unsigned int) count;
- (id) objectAtIndex: (unsigned int)index;
- (void) addObject: (id)object;
- (void) insertObject: (id)object
atIndex: (unsigned int)index;
- (void) removeLastObject;
- (void) removeObjectAtIndex: (unsigned int)index;
- (void) replaceObjectAtIndex: (unsigned int)index
withObject: (id)object;
//- (BOOL) containsObject: (id)object;
//- (unsigned int) indexOfObjectIdenticalTo: (id)object;
//- (void) removeAllObjects;
- (void) exchangeObjectAtIndex: (unsigned int)index1
withObjectAtIndex: (unsigned int)index2;
@end
#endif //__EOCheapArray_h__

446
EOControl/EOCheapArray.m Normal file
View file

@ -0,0 +1,446 @@
/**
EOCheapArray.m <title>EOCheapCopyArray Classes</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Manuel Guesdon <mguesdon@orange-concept.com>
Date: Sep 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/Foundation.h>
#import <EOControl/EOCheapArray.h>
#import <EOControl/EODebug.h>
@implementation EOCheapCopyArray : NSArray
- (id) initWithArray: (id)array
{
if ((self = [super initWithArray: array]))
{
}
return self;
}
- (id) initWithObjects: (id*)objects
count: (unsigned int)count
{
if (count > 0)
{
unsigned i;
_contents_array = NSZoneMalloc([self zone], sizeof(id) * count);
if (_contents_array == 0)
{
RELEASE(self);
return nil;
}
for (i = 0; i < count; i++)
{
if ((_contents_array[i] = RETAIN(objects[i])) == nil)
{
_count = i;
RELEASE(self);
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil"];
}
}
_count = count;
}
return self;
}
- (void) dealloc
{
NSDebugMLLog(@"gsdb", @"Deallocate EOCheapCopyArray %p", self);
if (_contents_array)
{
#if !GS_WITH_GC
unsigned i;
for (i = 0; i < _count; i++)
{
[_contents_array[i] release];
}
#endif
NSZoneFree([self zone], _contents_array);
}
NSDeallocateObject(self);
}
- (void) release
{
NSDebugMLLog(@"gsdb", @"Release EOCheapCopyArray %p", self);
//TODO-NOW
}
- (unsigned int) retainCount
{
NSDebugMLLog(@"gsdb", @"retainCount EOCheapCopyArray %p", self);
//TODO-NOW
return 1;
}
- (id) retain
{
//TODO-NOW
NSDebugMLLog(@"gsdb", @"retain EOCheapCopyArray %p", self);
return self;
}
- (id) objectAtIndex: (unsigned int)index
{
if (index >= _count)
{
[NSException raise: NSRangeException
format: @"Index out of bounds"];
}
return _contents_array[index];
}
//- (id) copyWithZone: (NSZone*)zone;
- (unsigned int) count
{
return _count;
}
//- (BOOL) containsObject: (id)obejct;
@end
@implementation EOCheapCopyMutableArray
- (id) initWithCapacity: (unsigned int)capacity
{
if (capacity == 0)
{
capacity = 1;
}
_contents_array = NSZoneMalloc([self zone], sizeof(id) * capacity);
_capacity = capacity;
_grow_factor = capacity > 1 ? capacity/2 : 1;
return self;
}
- (id) initWithObjects: (id*)objects
count: (unsigned int)count
{
self = [self initWithCapacity: count];
if (self != nil && count > 0)
{
unsigned i;
for (i = 0; i < count; i++)
{
if ((_contents_array[i] = RETAIN(objects[i])) == nil)
{
_count = i;
RELEASE(self);
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil"];
}
}
_count = count;
}
return self;
}
- (id) initWithArray:(NSArray*)array
{
_grow_factor = 5;
if ((self = [super initWithArray: array]))
{
}
return self;
}
- (void) dealloc
{
NSDebugMLLog(@"gsdb", @"Deallocate EOCheapCopyArray %p", self);
if (_contents_array)
{
#if !GS_WITH_GC
unsigned i;
for (i = 0; i < _count; i++)
{
[_contents_array[i] release];
}
#endif
NSZoneFree([self zone], _contents_array);
}
DESTROY(_immutableCopy);
NSDeallocateObject(self);
}
- (id) shallowCopy
{
//OK
if (!_immutableCopy)
{
_immutableCopy= [[EOCheapCopyArray alloc]
initWithObjects: _contents_array
count: _count];
}
return _immutableCopy;
}
- (void) _setCopy: (id)param0
{
//TODO
}
- (void) _mutate
{
DESTROY(_immutableCopy);
}
- (unsigned int) count
{
return _count;
}
- (id) objectAtIndex: (unsigned int)index
{
if (index >= _count)
{
[NSException raise: NSRangeException
format: @"Index out of bounds"];
}
return _contents_array[index];
}
- (void)addObject: (id)object
{
//7d0
//im=530
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"self %p=%@", self, self);
NSDebugMLLog(@"gsdb", @"object %p of class %@=%@",
object,
[object class],
object);
if (!object)
{
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil"];
}
NSDebugMLLog(@"gsdb", @"self %p=%@", self, self);
[self _mutate];
NSDebugMLLog(@"gsdb",@"self %p=%@", self, self);
if (_count >= _capacity)
{
unsigned int grow = (_grow_factor>5 ? _grow_factor : 5);
size_t size = (_capacity + grow) * sizeof(id);
id *ptr;
ptr = NSZoneRealloc([self zone], _contents_array, size);
if (ptr == 0)
{
[NSException raise: NSMallocException
format: @"Unable to grow"];
}
_contents_array = ptr;
_capacity += _grow_factor;
_grow_factor = _capacity / 2;
}
_contents_array[_count] = RETAIN(object);
_count++; // Do this AFTER we have retained the object.
NSDebugMLLog(@"gsdb", @"self %p=%@", self, self);
EOFLOGObjectFnStop();
}
- (void) insertObject: (id)object
atIndex: (unsigned int)index
{
unsigned i;
if (!object)
{
[NSException raise: NSInvalidArgumentException
format: @"Tried to insert nil"];
}
if (index > _count)
{
[NSException raise: NSRangeException
format:
@"in insertObject:atIndex:, index %d is out of range",
index];
}
[self _mutate];
if (_count == _capacity)
{
id *ptr;
size_t size = (_capacity + _grow_factor) * sizeof(id);
ptr = NSZoneRealloc([self zone], _contents_array, size);
if (ptr == 0)
{
[NSException raise: NSMallocException
format: @"Unable to grow"];
}
_contents_array = ptr;
_capacity += _grow_factor;
_grow_factor = _capacity / 2;
}
for (i = _count; i > index; i--)
{
_contents_array[i] = _contents_array[i - 1];
}
/*
* Make sure the array is 'sane' so that it can be deallocated
* safely by an autorelease pool if the '[anObject retain]' causes
* an exception.
*/
_contents_array[index] = nil;
_count++;
_contents_array[index] = RETAIN(object);
}
- (void) removeLastObject
{
if (_count == 0)
{
[NSException raise: NSRangeException
format: @"Trying to remove from an empty array."];
}
[self _mutate];
_count--;
RELEASE(_contents_array[_count]);
}
- (void) removeObjectAtIndex: (unsigned int)index
{
id obj;
if (index >= _count)
{
[NSException raise: NSRangeException
format: @"in removeObjectAtIndex:, index %d is out of range",
index];
}
obj = _contents_array[index];
[self _mutate];
_count--;
while (index < _count)
{
_contents_array[index] = _contents_array[index+1];
index++;
}
RELEASE(obj); /* Adjust array BEFORE releasing object. */
}
- (void) replaceObjectAtIndex: (unsigned int)index
withObject: (id)object;
{
id obj;
if (index >= _count)
{
[NSException raise: NSRangeException format:
@"in replaceObjectAtIndex:withObject:, index %d is out of range",
index];
}
/*
* Swap objects in order so that there is always a valid object in the
* array in case a retain or release causes an exception.
*/
obj = _contents_array[index];
[self _mutate];
IF_NO_GC(RETAIN(object));
_contents_array[index] = object;
RELEASE(obj);
}
//TODO implement it for speed ?? - (BOOL) containsObject:(id)object
//TODO implement it for speed ?? - (unsigned int) indexOfObjectIdenticalTo:(id)object
//TODO implement it for speed ?? - (void) removeAllObjects;
- (void) exchangeObjectAtIndex: (unsigned int)index1
withObjectAtIndex: (unsigned int)index2
{
id obj = nil;
if (index1 >= _count || index2>=_count)
{
[NSException raise: NSRangeException format:
@"in exchangeObjectAtIndex:withObjectAtIndex:, index %d is out of range",
(index1 >= _count ? index1 : index2)];
}
obj = _contents_array[index1];
[self _mutate];
_contents_array[index1] = _contents_array[index2];
_contents_array[index2] = obj;
}
@end

View file

@ -0,0 +1,226 @@
/*
EOClassDescription.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOClassDescription_h__
#define __EOClassDescription_h__
#import <Foundation/NSObject.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSException.h>
@class NSDictionary;
@class NSFormatter;
@class EOEditingContext;
@class EOGlobalID;
@class EORelationship;
typedef enum
{
EODeleteRuleNullify = 0,
EODeleteRuleCascade,
EODeleteRuleDeny,
EODeleteRuleNoAction
} EODeleteRule;
@interface EOClassDescription : NSObject
+ (void)registerClassDescription: (EOClassDescription *)description
forClass: (Class)aClass;
+ (void)invalidateClassDescriptionCache;
+ (EOClassDescription *)classDescriptionForClass: (Class)aClass;
+ (EOClassDescription *)classDescriptionForEntityName: (NSString *)entityName;
+ (void)setClassDelegate: (id)delegate;
+ (id)classDelegate;
// Must be implemented by subclasses.
- (NSString *)entityName;
- (id)createInstanceWithEditingContext: (EOEditingContext *)editingContext
globalID: (EOGlobalID *)globalID
zone: (NSZone *)zone;
- (void)awakeObject: (id)object
fromInsertionInEditingContext: (EOEditingContext *)editingContext;
- (void)awakeObject: (id)object
fromFetchInEditingContext: (EOEditingContext *)editingContext;
- (void)propagateDeleteForObject: (id)object
editingContext: (EOEditingContext *)editingContext;
- (NSArray *)attributeKeys;
- (NSArray *)toOneRelationshipKeys;
- (NSArray *)toManyRelationshipKeys;
- (EORelationship *)relationshipNamed: (NSString *)relationshipName;
- (EORelationship *)anyRelationshipNamed: (NSString *)relationshipNamed;
- (NSString *)inverseForRelationshipKey: (NSString *)relationshipKey;
- (EODeleteRule)deleteRuleForRelationshipKey: (NSString *)relationshipKey;
- (BOOL)ownsDestinationObjectsForRelationshipKey: (NSString *)relationshipKey;
- (EOClassDescription *)classDescriptionForDestinationKey: (NSString *)detailKey;
- (NSFormatter *)defaultFormatterForKey: (NSString *)key;
- (NSString *)displayNameForKey: (NSString *)key;
- (NSString *)userPresentableDescriptionForObject: (id)anObject;
- (NSException *)validateValue: (id *)valueP forKey: (NSString *)key;
- (NSException *)validateObjectForSave: (id)object;
- (NSException *)validateObjectForDelete: (id)object;
@end
@interface NSObject (EOInitialization)
- initWithEditingContext: (EOEditingContext *)ec
classDescription: (EOClassDescription *)classDesc
globalID: (EOGlobalID *)globalID;
@end
@interface NSObject (EOClassDescriptionPrimitives)
- (EOClassDescription *)classDescription;
- (NSString *)entityName;
- (NSArray *)attributeKeys;
- (NSArray *)toOneRelationshipKeys;
- (NSArray *)toManyRelationshipKeys;
- (NSString *)inverseForRelationshipKey: (NSString *)relationshipKey;
- (EODeleteRule)deleteRuleForRelationshipKey: (NSString *)relationshipKey;
- (BOOL)ownsDestinationObjectsForRelationshipKey: (NSString *)relationshipKey;
- (EOClassDescription *)classDescriptionForDestinationKey: (NSString *)detailKey;
- (NSString *)userPresentableDescription;
- (NSException *)validateValue: (id *)valueP forKey: (NSString *)key;
- (NSException *)validateForSave;
- (NSException *)validateForDelete;
- (void)awakeFromInsertionInEditingContext: (EOEditingContext *)editingContext;
- (void)awakeFromFetchInEditingContext: (EOEditingContext *)editingContext;
@end
// Notifications:
extern NSString *EOClassDescriptionNeededNotification;
extern NSString *EOClassDescriptionNeededForClassNotification;
extern NSString *EOClassDescriptionNeededForEntityNameNotification;
@interface NSArray(EOShallowCopy)
- (NSArray *)shallowCopy;
@end
@interface NSObject (EOClassDescriptionExtras)
- (NSDictionary *)snapshot;
- (void)updateFromSnapshot: (NSDictionary *)snapshot;
- (BOOL)isToManyKey: (NSString *)key;
- (NSException *)validateForInsert;
- (NSException *)validateForUpdate;
- (NSArray *)allPropertyKeys;
- (void)clearProperties;
- (void)propagateDeleteWithEditingContext: (EOEditingContext *)editingContext;
- (NSString *)eoShallowDescription;
- (NSString *)eoDescription;
@end
@interface NSObject (EOKeyRelationshipManipulation)
- (void)addObject: object toPropertyWithKey: (NSString *)key;
- (void)removeObject: object fromPropertyWithKey: (NSString *)key;
- (void)addObject: object toBothSidesOfRelationshipWithKey: (NSString *)key;
- (void)removeObject: object
fromBothSidesOfRelationshipWithKey: (NSString *)key;
@end
// Validation exceptions (with name EOValidationException)
extern NSString *EOValidationException;
extern NSString *EOAdditionalExceptionsKey;
extern NSString *EOValidatedObjectUserInfoKey;
extern NSString *EOValidatedPropertyUserInfoKey;
@interface NSException (EOValidationError)
+ (NSException *)validationExceptionWithFormat: (NSString *)format, ...;
+ (NSException *)aggregateExceptionWithExceptions: (NSArray *)subexceptions;
- (NSException *)exceptionAddingEntriesToUserInfo: (NSDictionary *)additions;
@end
@interface NSObject (EOClassDescriptionClassDelegate)
- (BOOL)shouldPropagateDeleteForObject: (id)object
inEditingContext: (EOEditingContext *)ec
forRelationshipKey: (NSString *)key;
@end
@interface NSObject (_EOValueMerging)
- (void)mergeValue: (id)value forKey: (id)key;
- (void)mergeChangesFromDictionary: (NSDictionary *)changes;
- (NSDictionary *)changesFromSnapshot: (NSDictionary *)snapshot;
- (void)reapplyChangesFromSnapshot: (NSDictionary *)changes;
@end
@interface NSObject (_EOEditingContext)
-(EOEditingContext*)editingContext;
@end
#endif

File diff suppressed because it is too large Load diff

52
EOControl/EOControl.h Normal file
View file

@ -0,0 +1,52 @@
/*
EOControl.h
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOControl_h__
#define __EOControl_h__
#import <EOControl/EOSortOrdering.h>
#import <EOControl/EOFetchSpecification.h>
#import <EOControl/EOGenericRecord.h>
#import <EOControl/EOClassDescription.h>
#import <EOControl/EOKeyValueCoding.h>
#import <EOControl/EOQualifier.h>
#import <EOControl/EONull.h>
#import <EOControl/EOKeyValueArchiver.h>
#import <EOControl/EOGlobalID.h>
#import <EOControl/EOKeyGlobalID.h>
#import <EOControl/EOObjectStore.h>
#import <EOControl/EOObjectStoreCoordinator.h>
#import <EOControl/EOFault.h>
#import <EOControl/EOEditingContext.h>
#import <EOControl/EODataSource.h>
#import <EOControl/EODetailDataSource.h>
#import <EOControl/EOObserver.h>
#import <EOControl/EODebug.h>
#endif /* __EOControl_h__ */

63
EOControl/EODataSource.h Normal file
View file

@ -0,0 +1,63 @@
/*
EODataSource.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EODataSource_h__
#define __EODataSource_h__
#import <Foundation/NSObject.h>
@class NSArray;
@class NSDictionary;
@class EOEditingContext;
@class EOClassDescription;
@interface EODataSource : NSObject
- (id)createObject;
- (void)insertObject: object;
- (void)deleteObject: object;
- (NSArray *)fetchObjects;
- (EOEditingContext *)editingContext;
- (void)qualifyWithRelationshipKey: (NSString *)key ofObject: sourceObject;
- (EODataSource *)dataSourceQualifiedByKey: (NSString *)key;
- (EOClassDescription *)classDescriptionForObjects;
- (NSArray *)qualifierBindingKeys;
- (void)setQualifierBindings: (NSDictionary *)bindings;
- (NSDictionary *)qualifierBindings;
@end
#endif

119
EOControl/EODataSource.m Normal file
View file

@ -0,0 +1,119 @@
/**
EODataSource.m <title>EODataSource Class</title>
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <EOControl/EOControl.h>
#import <EOControl/EODataSource.h>
#import <EOControl/EOClassDescription.h>
#import <EOControl/EOEditingContext.h>
@implementation EODataSource
- (id)createObject
{
id object;
EOClassDescription *cd;
EOEditingContext *receiverEdCtxt;
EOFLOGObjectFnStart();
cd = [self classDescriptionForObjects];
EOFLOGObjectLevelArgs(@"EODataSource", @"cd=%@", cd);
object = [cd createInstanceWithEditingContext: nil
globalID: nil
zone: NULL];
EOFLOGObjectLevelArgs(@"EODataSource", @"object=%@", object);
if (object && (receiverEdCtxt = [self editingContext]))
[receiverEdCtxt insertObject: object];
EOFLOGObjectFnStop();
return object;
}
- (void)insertObject: object
{
[self subclassResponsibility: _cmd];
}
- (void)deleteObject: object
{
[self subclassResponsibility: _cmd];
}
- (NSArray *)fetchObjects
{
return nil;
}
- (EOEditingContext *)editingContext
{
return nil;
}
- (void)qualifyWithRelationshipKey: (NSString *)key ofObject: sourceObject
{
[self subclassResponsibility: _cmd];
}
- (EODataSource *)dataSourceQualifiedByKey: (NSString *)key
{
[self subclassResponsibility: _cmd];
return nil;
}
- (EOClassDescription *)classDescriptionForObjects
{
return nil;
}
- (NSArray *)qualifierBindingKeys
{
return nil;
}
- (void)setQualifierBindings: (NSDictionary *)bindings
{
}
- (NSDictionary *)qualifierBindings
{
return nil;
}
@end

266
EOControl/EODebug.h Normal file
View file

@ -0,0 +1,266 @@
/* debug.h - debug
Copyright (C) 1999 Free Software Foundation, Inc.
Written by: Manuel Guesdon <mguesdon@sbuilders.com>
Date: Jan 1999
This file is part of the GNUstep Web Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
// $Id$
#ifndef _EODebug_h__
#define _EODebug_h__
// call with --GNU-Debug=EOFFn
#ifdef DEBUG
#include <Foundation/NSDebug.h>
#include <Foundation/NSAutoreleasePool.h>
extern void EOFLogC_(const char* file,int line,const char* string);
extern void EOFLogDumpObject_(const char* file,int line,id object,int deep);
extern void EOFLogAssertGood_(const char* file,int line,NSObject* object);
#define EOFLogC(cString); EOFLogC_(__FILE__,__LINE__,cString);
#define EOFLogDumpObject(object,deep); EOFLogDumpObject_(__FILE__,__LINE__,object,deep);
#define EOFLogAssertGood(object); EOFLogAssertGood_(__FILE__,__LINE__,object);
#else // no DEBUG
#define EOFLogC(cString);
#define EOFLogDumpObject(object,deep);
#define EOFLogAssertGood(object);
#endif // DEBUG
#ifdef DEBUG
// call in Class-Methods
#define EOFLOGClassFnStart() \
do { if (GSDebugSet(@"EOFFn") == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"FNSTART"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGObjectFnStartCond(cond) \
do { if ((GSDebugSet(@"EOFFn") == YES) && GSDebugSet(cond) == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTART"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGClassFnStartOrCond(cond) \
do { if ((GSDebugSet(@"EOFFn") == YES) || (GSDebugSet(cond) == YES)) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"FNSTART"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGClassFnStartOrCond2(cond1,cond2) \
do { if ((GSDebugSet(@"EOFFn") == YES) || (GSDebugSet(cond1) == YES) || (GSDebugSet(cond2) == YES)) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"FNSTART"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGClassFnStop() \
do { if (GSDebugSet(@"EOFFn") == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__,__FILE__, __LINE__,@"FNSTOP"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGObjectFnStopCond(cond) \
do { if ((GSDebugSet(@"EOFFn") == YES) && GSDebugSet(cond) == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTOP"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGClassFnStopOrCond(cond) \
do { if ((GSDebugSet(@"EOFFn") == YES) || (GSDebugSet(cond) == YES)) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__,__FILE__, __LINE__,@"FNSTOP"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGClassFnStopOrCond2(cond1,cond2) \
do { if ((GSDebugSet(@"EOFFn") == YES) || (GSDebugSet(cond1) == YES) || (GSDebugSet(cond2) == YES)) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__,__FILE__, __LINE__,@"FNSTOP"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGClassLevel(level,format) \
do { if (GSDebugSet(level) == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugFunctionMsg( \
__PRETTY_FUNCTION__, __FILE__, __LINE__, format); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGClassLevelArgs(level, format, args...) \
do { if (GSDebugSet(level) == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugFunctionMsg( \
__PRETTY_FUNCTION__, __FILE__, __LINE__, format); \
NSLog(fmt, ## args); [tmpPool release]; }} while (0)
#define EOFLOGClassFnNotImplemented() \
do { if (GSDebugSet(@"EOFdflt") == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"NOT IMPLEMENTED"); \
NSLog(fmt); [tmpPool release]; }} while (0)
// call in Instance-Methods
#define EOFLOGObjectFnStart() \
do { if (GSDebugSet(@"EOFFn") == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTART"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGObjectFnStartOrCond(cond) \
do { if ((GSDebugSet(@"EOFFn") == YES) || (GSDebugSet(cond) == YES)) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTART"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGObjectFnStartOrCond2(cond1,cond2) \
do { if ((GSDebugSet(@"EOFFn") == YES) || (GSDebugSet(cond1) == YES) || (GSDebugSet(cond2) == YES)) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTART"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGObjectFnStop() \
do { if (GSDebugSet(@"EOFFn") == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTOP"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGObjectFnStopOrCond(cond) \
do { if ((GSDebugSet(@"EOFFn") == YES) || (GSDebugSet(cond) == YES)) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTOP"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGObjectFnStopOrCond2(cond1,cond2) \
do { if ((GSDebugSet(@"EOFFn") == YES) || (GSDebugSet(cond1) == YES) || (GSDebugSet(cond2) == YES)) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTOP"); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGObjectFnStopPlain(fmt) \
do { if (GSDebugSet(@"EOFFn") == YES) { \
NSLog(fmt); }} while (0)
#define EOFLOGObjectFnStopOrCondPlain(cond,fmt) \
do { if ((GSDebugSet(@"EOFFn") == YES) || (GSDebugSet(cond) == YES)) { \
NSLog(fmt); }} while (0)
#define EOFLOGObjectFnStopOrCond2Plain(cond1,cond2,fmt) \
do { if ((GSDebugSet(@"EOFFn") == YES) || (GSDebugSet(cond1) == YES) || (GSDebugSet(cond2) == YES)) { \
NSLog(fmt); }} while (0)
#define EOFLOGObjectLevel(level,format) \
do { if (GSDebugSet(level) == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg( \
self, _cmd, __FILE__, __LINE__, format); \
NSLog(fmt); [tmpPool release]; }} while (0)
#define EOFLOGObjectLevelArgs(level, format, args...) \
do { if (GSDebugSet(level) == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg( \
self, _cmd, __FILE__, __LINE__, format); \
NSLog(fmt, ## args); [tmpPool release]; }} while (0)
#define EOFLOGObject(format) \
do { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg( \
self, _cmd, __FILE__, __LINE__, format); \
NSLog(fmt); [tmpPool release]; } while (0)
#define EOFLOGObjectArgs(format, args...) \
do { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg( \
self, _cmd, __FILE__, __LINE__, format); \
NSLog(fmt, ## args); [tmpPool release]; }while (0)
#define EOFLOGObjectFnNotImplemented() \
do { if (GSDebugSet(@"EOFdflt") == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"NOT IMPLEMENTED"); \
NSLog(fmt); [tmpPool release]; }} while (0)
// call everywhere
#define EOFLOGException(format) \
do { if (GSDebugSet(@"exception") == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,format); \
NSString *fmt2 = [NSString stringWithFormat:@"*EXCEPTION*: %@",fmt]; \
NSLog(@"%@",fmt2); [tmpPool release]; }} while (0)
#define EOFLOGExceptionArgs(format, args...) \
do { if (GSDebugSet(@"exception") == YES) { \
NSAutoreleasePool *tmpPool = [NSAutoreleasePool new]; \
NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,format); \
NSString *fmt2 = [NSString stringWithFormat:@"*EXCEPTION*: %@",fmt]; \
NSLog(fmt2, ## args); [tmpPool release]; }} while (0)
#else // no DEBUG
#define EOFLOGClassFnStart() {}
#define EOFLOGClassFnStartCond() {}
#define EOFLOGClassFnStartOrCond(cond) {}
#define EOFLOGClassFnStartOrCond2(cond1,cond2) {}
#define EOFLOGClassFnStop() {}
#define EOFLOGClassFnStopCond() {}
#define EOFLOGClassFnStopOrCond(cond) {}
#define EOFLOGClassFnStopOrCond2(cond1,cond2) {}
#define EOFLOGClassLevel(level,format) {}
#define EOFLOGClassLevelArgs(level,format,args...) {}
#define EOFLOGClassFnNotImplemented() {}
#define EOFLOGObjectFnStart() {}
#define EOFLOGObjectFnStartCond(cond) {}
#define EOFLOGObjectFnStartOrCond(cond) {}
#define EOFLOGObjectFnStartOrCond2(cond1,cond2) {}
#define EOFLOGObjectFnStop() {}
#define EOFLOGObjectFnStopCond(cond) {}
#define EOFLOGObjectFnStopOrCond(cond) {}
#define EOFLOGObjectFnStopOrCond2(cond1,cond2) {}
#define EOFLOGObjectFnStopPlain(fmt) {}
#define EOFLOGObjectFnStopOrCondPlain(cond,fmt) {}
#define EOFLOGObjectFnStopOrCond2Plain(cond1,cond2,fmt) {}
#define EOFLOGObjectLevel(level,format) {}
#define EOFLOGObjectLevelArgs(level,format,args...) {}
#define EOFLOGObject(format) {}
#define EOFLOGObjectArgs(format,args...) {}
#define EOFLOGObjectFnNotImplemented() {}
#define EOFLOGException(format) {}
#define EOFLOGExceptionArgs(format, args...) {}
#endif
#ifndef NSEmitTODO
#define NSEmitTODO(); NSLog(@"DVLP WARNING %s (%d): TODO",(char*)__FILE__,(int)__LINE__);
#endif
#endif // _EODebug_h__

402
EOControl/EODebug.m Normal file
View file

@ -0,0 +1,402 @@
/* EODebug.m - <title>debug</title>
Copyright (C) 1999-2002 Free Software Foundation, Inc.
Written by: Manuel Guesdon <mguesdon@orange-concept.com>
Date: Jan 1999
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
</license>
**/
static char rcsId[] = "$Id$";
#include <Foundation/Foundation.h>
#include <Foundation/NSThread.h>
#include <Foundation/NSAutoreleasePool.h>
#include <unistd.h>
#define USTART NSAutoreleasePool* arp=[NSAutoreleasePool new];
#define USTOP DESTROY(arp);
@interface NSObject (GSISA)
-(Class)isa;
@end
@implementation NSObject (GSISA)
-(Class)isa
{
return self->isa;
}
@end
#ifdef DEBUG
void EOFLogC_(const char *file, int line, const char *string)
{
int len = 0;
if ([NSThread isMultiThreaded])
{
NSThread *t = [NSThread currentThread];
fprintf(stderr,"TID=");
#if 0
if (t && t->_thread_id)
fprintf(stderr,"%p [%ld] (%d) ",(void*)t->_thread_id,(long)t->_thread_id,(int)getpid());
else
#endif
{
void *tid = (void*)objc_thread_id();
fprintf(stderr, "%p [%ld] (%d) ", tid, (long)tid, (int)getpid());
}
}
fprintf(stderr, "File %s: %d. ", file, line);
fprintf(stderr, string);
len = strlen(string);
if (len <= 0 || string[len-1] != '\n')
fprintf(stderr, "\n");
fflush(stderr);
}
#endif
#ifdef DEBUG
NSString *objectDescription(id object)
{
NSString *description = nil;
if ([object respondsToSelector: @selector(description)])
{
NS_DURING
description = [object description];
NS_HANDLER
NS_ENDHANDLER;
}
return description;
}
NSString *IVarInString(const char* _type, void* _value)
{
if (_type && _value)
{
switch (*_type)
{
case _C_ID:
{
id *pvalue = (id*)_value;
return [NSString stringWithFormat:
@"object:%ld Class:%s Description:%@",
(long)(*pvalue),
[*pvalue class],
objectDescription(*pvalue)];
}
break;
case _C_CLASS:
{
Class *pvalue = (Class*)_value;
return [NSString stringWithFormat: @"Class:%s",
class_get_class_name(*pvalue)];
}
break;
case _C_SEL:
{
SEL *pvalue = (SEL*)_value;
return [NSString stringWithFormat: @"SEL:%s",
sel_get_name(*pvalue)];
}
break;
case _C_CHR:
{
char *pvalue = (char*)_value;
return [NSString stringWithFormat: @"CHAR:%c",
*pvalue];
}
break;
case _C_UCHR:
{
unsigned char *pvalue = (unsigned char*)_value;
return [NSString stringWithFormat: @"UCHAR:%d",
(int)*pvalue];
}
break;
case _C_SHT:
{
short *pvalue = (short*)_value;
return [NSString stringWithFormat: @"SHORT:%d",
(int)*pvalue];
}
break;
case _C_USHT:
{
unsigned short *pvalue = (unsigned short*)_value;
return [NSString stringWithFormat: @"USHORT:%d",
(int)*pvalue];
}
break;
case _C_INT:
{
int *pvalue = (int*)_value;
return [NSString stringWithFormat: @"INT:%d",
*pvalue];
}
break;
case _C_UINT:
{
unsigned int *pvalue = (unsigned int*)_value;
return [NSString stringWithFormat: @"UINT:%u",
*pvalue];
}
break;
case _C_LNG:
{
long *pvalue = (long*)_value;
return [NSString stringWithFormat: @"LONG:%ld",
*pvalue];
}
break;
case _C_ULNG:
{
unsigned long *pvalue = (unsigned long*)_value;
return [NSString stringWithFormat: @"ULONG:%lu",
*pvalue];
}
break;
case _C_FLT:
{
float *pvalue = (float*)_value;
return [NSString stringWithFormat: @"FLOAT:%f",
(double)*pvalue];
}
break;
case _C_DBL:
{
double *pvalue = (double*)_value;
return [NSString stringWithFormat: @"DOUBLE:%f",
*pvalue];
}
break;
case _C_VOID:
{
void *pvalue = (void*)_value;
return [NSString stringWithFormat: @"VOID:*%lX",
(unsigned long)pvalue];
}
break;
case _C_CHARPTR:
{
char *pvalue = (void*)_value;
return [NSString stringWithFormat: @"CHAR*:%s",
pvalue];
}
break;
case _C_PTR:
{
return [NSString stringWithFormat: @"PTR"];
}
break;
case _C_STRUCT_B:
{
return [NSString stringWithFormat: @"STRUCT"];
}
break;
default:
return [NSString stringWithFormat: @"Unknown"];
}
}
else
return [NSString stringWithString: @"NULL type or NULL pValue"];
}
NSString *TypeToNSString(const char* _type)
{
if (_type)
{
switch (*_type)
{
case _C_ID:
{ // '@'
const char *t = _type + 1;
if (*t == '"')
{
const char *start = t + 1;
do
{
t++;
}
while ((*t != '"') && (*t != '\0'));
return [[NSString stringWithCString: start
length: (t - start)]
stringByAppendingString: @" *"];
}
else
return @"id";
};
break;
case _C_CLASS: return @"Class";
case _C_SEL: return @"SEL";
case _C_CHR: return @"char";
case _C_UCHR: return @"unsigned char";
case _C_SHT: return @"short";
case _C_USHT: return @"unsigned short";
case _C_INT: return @"int";
case _C_UINT: return @"unsigned int";
case _C_LNG: return @"long";
case _C_ULNG: return @"unsigned long";
// case _C_LNG_LNG: return @"long long";
// case _C_ULNG_LNG: return @"unsigned long long";
case _C_FLT: return @"float";
case _C_DBL: return @"double";
case _C_VOID: return @"void";
case _C_CHARPTR: return @"char *";
case _C_PTR:
return [NSString stringWithFormat: @"%@ *",
TypeToNSString(_type + 1)];
break;
case _C_STRUCT_B:
{
NSString *structName = nil;
const char *t = _type + 1;
if (*t == '?')
structName = @"?";
else
{
const char *beg = t;
while ((*t != '=') && (*t != '\0') && (*t != _C_STRUCT_E))
t++;
structName = [NSString stringWithCString:beg length:(t - beg)];
}
return [NSString stringWithFormat: @"struct %@ {...}", structName];
}
default:
return [NSString stringWithFormat: @"%s", _type];
}
}
else
return [NSString stringWithString: @"NULL type"];
}
void DumpIVar(id object, struct objc_ivar *ivar, int deep)
{
if (ivar && object && deep >= 0)
{
void *pValue = ((void*)object) + ivar->ivar_offset;
NSString *pType = TypeToNSString(ivar->ivar_type);
NSString *pIVar = IVarInString(ivar->ivar_type,pValue);
NSDebugFLog(@"IVar %s type:%@ value:%@\n",
ivar->ivar_name,
pType,
pIVar);
if (deep > 0 && ivar->ivar_type && *ivar->ivar_type == _C_ID && pValue)
{
EOFLogDumpObject_(NULL, 0, *((id*)pValue), deep);
}
}
}
//Dump object
void EOFLogDumpObject_(const char *file, int line, id object, int deep)
{
USTART
if (object && deep > 0)
{
struct objc_ivar_list *ivars = NULL;
Class class = [object class];
if (class)
{
NSDebugFLog(@"--%s %d [%d] Dumping object %p of Class %s Description:%@\n",
(file && isalpha(*file) && line >= 0
&& line<=20000) ? file :"",
line,
deep,
(void*)object,
class->name,
objectDescription(object));
while (class)
{
ivars = class->ivars;
class = class->super_class;
if (ivars)
{
int i;
for (i = 0; i < ivars->ivar_count; i++)
{
DumpIVar(object,&ivars->ivar_list[i],deep-1);
}
}
}
}
}
USTOP
}
void EOFLogAssertGood_(const char *file, int line, NSObject *object)
{
if (object)
{
if ([object isa] == ((Class)0xdeadface))
{
NSLog(@"DEAD FACE: object %p isa=%p in %s at %d\n",
(void*)object,
(void*)[object isa],
file,
line);
NSCParameterAssert([object isa] == (Class)0xdeadface);
}
}
else
{
NSLog(@"NULL: object %p in %s at %d\n",
(void*)object,
file,
line);
NSCParameterAssert(object);
}
}
#endif

View file

@ -0,0 +1,62 @@
/*
EODetailDataSource.m
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import <EOControl/EODataSource.h>
@interface EODetailDataSource : EODataSource <NSCoding>
{
EODataSource *_masterDataSource;
id _masterObject;
NSString *_detailKey;
NSString *_masterClassDescriptionName;
}
+ (EODetailDataSource *)detailDataSourceWithMasterDataSource: (EODataSource *)master
detailKey: (NSString *)detailKey;
- initWithMasterClassDescription: (EOClassDescription *)masterClassDescription
detailKey: (NSString *)detailKey;
- initWithMasterDataSource: (EODataSource *)master
detailKey: (NSString *)detailKey;
- (id) initWithKeyValueUnarchiver: (EOKeyValueUnarchiver *)unarchiver;
- (EODataSource *)masterDataSource;
- (EOClassDescription *)masterClassDescription;
- (void)setMasterClassDescription: (EOClassDescription *)classDescription;
- (EOClassDescription *)classDescriptionForObjects;
- (void)qualifyWithRelationshipKey: (NSString *)key
ofObject: masterObject;
- (NSString *)detailKey;
- (id)masterObject;
- (EOEditingContext *)editingContext;
@end

View file

@ -0,0 +1,271 @@
/**
EODetailDataSource.m <title>EODetailDataSource Class</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: July 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
#import <Foundation/NSException.h>
#import <Foundation/NSCoder.h>
#import <EOControl/EOControl.h>
#import <EOControl/EODetailDataSource.h>
#import <EOControl/EOKeyValueCoding.h>
#import <EOControl/EOClassDescription.h>
@implementation EODetailDataSource
+ (EODetailDataSource *)detailDataSourceWithMasterDataSource: (EODataSource *)master
detailKey: (NSString *)detailKey
{
return [[[self alloc] initWithMasterDataSource: master
detailKey: detailKey] autorelease];
}
- initWithMasterClassDescription: (EOClassDescription *)masterClassDescription
detailKey: (NSString *)detailKey
{
if ((self = [super init]))
{
[self setMasterClassDescription: masterClassDescription];
[self qualifyWithRelationshipKey: detailKey
ofObject: nil];
}
return self;
}
- initWithMasterDataSource: (EODataSource *)master
detailKey: (NSString *)detailKey
{
ASSIGN(_masterDataSource, master);
return [self initWithMasterClassDescription: nil
detailKey: detailKey];
}
- (id)initWithKeyValueUnarchiver: (EOKeyValueUnarchiver *)unarchiver
{
//OK
EOFLOGObjectFnStart();
if ((self = [self init]))
{
NSString* detailKey=nil;
NSString* masterClassDescriptionName=nil;
EOClassDescription* masterClassDescription=nil;
EOFLOGObjectLevelArgs(@"EODataSource",@"EODetailDataSource %p",self);
detailKey = [unarchiver decodeObjectForKey: @"detailKey"];
masterClassDescriptionName = [unarchiver decodeObjectForKey:
@"masterClassDescription"];
masterClassDescription = [EOClassDescription
classDescriptionForEntityName:
masterClassDescriptionName];
[self setMasterClassDescription: masterClassDescription];
[self qualifyWithRelationshipKey: detailKey
ofObject: nil];
EOFLOGObjectLevelArgs(@"EODataSource", @"EODetailDataSource %p : %@",
self, self);
}
EOFLOGObjectFnStop();
return self;
}
- (void)dealloc
{
DESTROY(_masterDataSource);
DESTROY(_masterObject);
DESTROY(_detailKey);
DESTROY(_masterClassDescriptionName);
[super dealloc];
}
- (EODataSource *)masterDataSource
{
return _masterDataSource;
}
- (EOClassDescription *)masterClassDescription
{
return [EOClassDescription classDescriptionForEntityName:
_masterClassDescriptionName];
}
- (void)setMasterClassDescription: (EOClassDescription *)classDescription
{
EOFLOGObjectFnStart();
ASSIGN(_masterClassDescriptionName, [classDescription entityName]);
EOFLOGObjectFnStop();
}
- (EOClassDescription *)classDescriptionForObjects
{
EOClassDescription *cd;
EOClassDescription *masterCD;
NSString *detailKey;
detailKey = [self detailKey];
NSAssert(detailKey, @"No detailKey");
masterCD = [self masterClassDescription];
NSAssert(masterCD, @"No masterClassDescription");
cd = [masterCD classDescriptionForDestinationKey: detailKey];
return cd;
}
- (void)qualifyWithRelationshipKey: (NSString *)key
ofObject: masterObject
{
EOFLOGObjectFnStart();
ASSIGN(_detailKey, key);
ASSIGN(_masterObject, masterObject);
EOFLOGObjectFnStop();
}
- (NSString *)detailKey
{
return _detailKey;
}
- (id)masterObject
{
return _masterObject;
}
- (EOEditingContext *)editingContext
{
return [_masterObject editingContext];
}
- (NSArray *)fetchObjects
{
id value=nil;
EOFLOGObjectFnStart();
if(!_masterObject)
value = [NSArray array];
else if(!_detailKey)
value = [NSArray arrayWithObject: _masterObject];
else
{
value = [_masterObject valueForKey: _detailKey];
if (value)
{
if (![value isKindOfClass: [NSArray class]])
value = [NSArray arrayWithObject: value];
}
else
value = [NSArray array];
}
EOFLOGObjectFnStop();
return value;
}
- (void)insertObject: (id)object
{
EOFLOGObjectFnStart();
if (!_masterObject)
[NSException raise: NSInternalInconsistencyException
format: @"%@ -- %@ 0x%x: no masterObject",
NSStringFromSelector(_cmd), NSStringFromClass([self class]),
self];
if (!_detailKey)
[NSException raise: NSInternalInconsistencyException
format: @"%@ -- %@ 0x%x: no detailKey",
NSStringFromSelector(_cmd), NSStringFromClass([self class]),
self];
[_masterObject addObject: object
toBothSidesOfRelationshipWithKey: _detailKey];
EOFLOGObjectFnStop();
}
- (void)deleteObject: (id)object
{
if (!_masterObject)
[NSException raise: NSInternalInconsistencyException
format: @"%@ -- %@ 0x%x: no masterObject",
NSStringFromSelector(_cmd), NSStringFromClass([self class]),
self];
if (!_detailKey)
[NSException raise: NSInternalInconsistencyException
format: @"%@ -- %@ 0x%x: no detailKey",
NSStringFromSelector(_cmd), NSStringFromClass([self class]),
self];
[_masterObject removeObject: object fromPropertyWithKey: _detailKey];
}
- (id)initWithCoder: (NSCoder *)coder
{
if ((self = [super init]))
{
ASSIGN(_masterDataSource, [coder decodeObject]);
ASSIGN(_masterObject, [coder decodeObject]);
ASSIGN(_detailKey, [coder decodeObject]);
ASSIGN(_masterClassDescriptionName, [coder decodeObject]);
}
return self;
}
- (void)encodeWithCoder: (NSCoder *)coder
{
[coder encodeObject: _masterDataSource];
[coder encodeObject: _masterObject];
[coder encodeObject: _detailKey];
[coder encodeObject: _masterClassDescriptionName];
}
@end

View file

@ -0,0 +1,359 @@
/*
EOEditingContext.h
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Date: June 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOEditingContext_h__
#define __EOEditingContext_h__
#import <Foundation/Foundation.h>
#import <EOControl/EOObjectStore.h>
#import <EOControl/EOObserver.h>
@interface EOEditingContext : EOObjectStore <EOObserving>
{
EOObjectStore *_objectStore;
NSUndoManager *_undoManager;
NSHashTable *_unprocessedChanges;
NSHashTable *_unprocessedDeletes;
NSHashTable *_unprocessedInserts;
NSHashTable *_insertedObjects;
NSHashTable *_deletedObjects;
NSHashTable *_changedObjects;
NSMapTable *_objectsById;
NSMapTable *_objectsByGID;
NSMutableDictionary *_snapshotsByGID;
NSMutableDictionary *_eventSnapshotsByGID;
id _delegate;
NSMutableArray *_editors;
id _messageHandler;
unsigned short _undoTransactionID;
struct {
unsigned registeredForCallback:1;
unsigned propagatesDeletesAtEndOfEvent:1;
unsigned ignoreChangeNotification:1;
unsigned exhaustiveValidation:1;// unsigned stopsValidation:1;
unsigned autoLocking:1;
unsigned processingChanges:1;// unsigned savingChanges:1;
unsigned skipInvalidateOnDealloc:1;
unsigned useCommittedSnapshot:1;
unsigned registeredUndoTransactionID:1;
unsigned retainsAllRegisteredObjects:1;
unsigned lockUsingParent:1;
unsigned unused:5;
} _flags;
struct {
unsigned willRunLoginPanel:1;
unsigned shouldFetchObjects:1;
unsigned shouldInvalidateObject:1;
unsigned shouldMergeChanges:1;
unsigned shouldPresentException:1;
unsigned shouldUndoUserActions:1;
unsigned shouldValidateChanges:1;
unsigned willSaveChanges:1;
} _delegateRespondsTo;
NSRecursiveLock*_lock;
int _lockCount;
id _notificationQueue;
NSAutoreleasePool * _lockPool;
}
+ (void)setInstancesRetainRegisteredObjects: (BOOL)flag;
+ (BOOL)instancesRetainRegisteredObjects;
- initWithParentObjectStore:(EOObjectStore *)parentObjectStore;
- init;
- (NSArray *)objectsWithFetchSpecification: (EOFetchSpecification *)fetchSpecification;
- (void)insertObject: (id)object;
- (void)insertObject: object
withGlobalID: (EOGlobalID *)gid;
- (void)_insertObject: (id)object
withGlobalID: (EOGlobalID *)gid;
- (void)deleteObject: (id)object;
- (void)lockObject: (id)object;
- (BOOL)hasChanges;
- (void)saveChanges;
- (void)revert;
- (id)objectForGlobalID: (EOGlobalID *)globalID;
- (EOGlobalID *)globalIDForObject: object;
- (void)setDelegate: (id)delegate;
- (id)delegate;
- (EOObjectStore *)parentObjectStore;
- (EOObjectStore *)rootObjectStore;
- (void)setUndoManager: (NSUndoManager *)undoManager;
- (NSUndoManager *)undoManager;
- (void) _observeUndoManagerNotifications;
- (void)objectWillChange: (id)object;
- (void)recordObject: (id)object
globalID: (EOGlobalID *)globalID;
- (void)forgetObject: (id)object;
- (void) registerUndoForModifiedObject: (id)object;
- (NSArray *)registeredObjects;
- (NSArray *)updatedObjects;
- (NSArray *)insertedObjects;
- (NSArray *)deletedObjects;
- (void) _processDeletedObjects;
- (void) _processOwnedObjectsUsingChangeTable: (NSHashTable*)changeTable
deleteTable: (NSHashTable*)deleteTable;
- (void) propagatesDeletesUsingTable: (NSHashTable*)deleteTable;
- (void) validateDeletesUsingTable: (NSHashTable*)deleteTable;
- (BOOL) validateTable: (NSHashTable*)table
withSelector: (SEL)sel
exceptionArray: (NSMutableArray**)exceptionArray
continueAfterFailure: (BOOL)continueAfterFailure;
- (void)processRecentChanges;
- (void) _registerClearStateWithUndoManager;
- (BOOL)propagatesDeletesAtEndOfEvent;
- (void)setPropagatesDeletesAtEndOfEvent: (BOOL)propagatesDeletesAtEndOfEvent;
- (BOOL)stopsValidationAfterFirstError;
- (void)setStopsValidationAfterFirstError: (BOOL)yn;
- (BOOL)locksObjectsBeforeFirstModification;
- (void)setLocksObjectsBeforeFirstModification: (BOOL)yn;
/** Returns a dictionary containing a snapshot of object
that reflects its committed values (last values putted in
the database; i.e. values before changes were made on the
object).
It is updated after commiting new values.
**/
- (NSDictionary *)committedSnapshotForObject: (id)object;
/** Returns a dictionary containing a snapshot of object
with its state as it was at the beginning of the current
event loop.
After the end of the current event, upon invocation of
processRecentChanges, the snapshot is updated to hold the
modified state of the object.**/
- (NSDictionary *)currentEventSnapshotForObject: (id)object;
- (NSDictionary *)uncommittedChangesForObject: (id)object;
- (void)refaultObjects;
- (void)setInvalidatesObjectsWhenFreed: (BOOL)yn;
- (BOOL)invalidatesObjectsWhenFreed;
- (void)addEditor: (id)editor;
- (void)removeEditor: (id)editor;
- (NSArray *)editors;
- (void)setMessageHandler: (id)handler;
- (id)messageHandler;
- (id)faultForGlobalID: (EOGlobalID *)globalID
editingContext: (EOEditingContext *)context;
- (id)faultForRawRow: (NSDictionary *)row
entityNamed: (NSString *)entityName
editingContext: (EOEditingContext *)context;
- (id)faultForRawRow: (NSDictionary *)row
entityNamed: (NSString *)entityName;
- (NSArray *)arrayFaultWithSourceGlobalID: (EOGlobalID *)globalID
relationshipName: (NSString *)name
editingContext: (EOEditingContext *)context;
- (void)initializeObject: (id)object
withGlobalID: (EOGlobalID *)globalID
editingContext: (EOEditingContext *)context;
- (NSArray *)objectsForSourceGlobalID: (EOGlobalID *)globalID
relationshipName: (NSString *)name
editingContext: (EOEditingContext *)context;
- (void)refaultObject: object
withGlobalID: (EOGlobalID *)globalID
editingContext: (EOEditingContext *)context;
- (void)saveChangesInEditingContext: (EOEditingContext *)context;
- (NSArray *)objectsWithFetchSpecification: (EOFetchSpecification *)fetchSpecification
editingContext: (EOEditingContext *)context;
- (void)lockObjectWithGlobalID: (EOGlobalID *)gid
editingContext: (EOEditingContext *)context;
- (BOOL)isObjectLockedWithGlobalID: (EOGlobalID *)gid
editingContext: (EOEditingContext *)context;
- (void) clearOriginalSnapshotForObject: (id)object;
@end
// used with NSRunLoop's performSelector:target:argument:order:modes:
enum {
EOEditingContextFlushChangesRunLoopOrdering = 300000
};
extern NSString *EOObjectsChangedInEditingContextNotification;
extern NSString *EOEditingContextDidSaveChangesNotification;
@interface NSObject (EOEditingContext)
- (EOEditingContext *)editingContext;
@end
//
// Delegation methods
//
@interface NSObject (EOEditingContextDelegation)
- (BOOL)editingContext: (EOEditingContext *)editingContext
shouldPresentException: (NSException *)exception;
- (BOOL)editingContextShouldValidateChanges: (EOEditingContext *)editingContext;
- (void)editingContextWillSaveChanges: (EOEditingContext *)editingContext;
- (BOOL)editingContext: (EOEditingContext *)editingContext
shouldInvalidateObject: (id)object
globalID: (EOGlobalID *)gid;
- (BOOL)editingContextShouldUndoUserActionsAfterFailure: (EOEditingContext *)context;
- (NSArray *)editingContext: (EOEditingContext *)editingContext
shouldFetchObjectsDescribedByFetchSpecification: (EOFetchSpecification *)fetchSpecification;
- (BOOL) editingContext: (EOEditingContext *)editingContext
shouldMergeChangedObject: (id)object;
- (void)didMergeChangedObjectsInEditingContext: (EOEditingContext *)editingContext;
@end
//
// EOEditors informal protocol
//
@interface NSObject (EOEditors)
- (BOOL)editorHasChangesForEditingContext: (EOEditingContext *)editingContext;
- (void)editingContextWillSaveChanges: (EOEditingContext *)editingContext;
@end
//
// EOMessageHandler informal protocol
//
@interface NSObject (EOMessageHandlers)
- (void)editingContext: (EOEditingContext *)editingContext
presentErrorMessage: (NSString *)message;
- (BOOL)editingContext: (EOEditingContext *)editingContext
shouldContinueFetchingWithCurrentObjectCount: (unsigned)count
originalLimit: (unsigned)limit
objectStore: (EOObjectStore *)objectStore;
@end
@interface EOEditingContext (EORendezvous)
+ (void)setSubstitutionEditingContext: (EOEditingContext *)ec;
+ (EOEditingContext *)substitutionEditingContext;
+ (void)setDefaultParentObjectStore: (EOObjectStore *)store;
+ (EOObjectStore *)defaultParentObjectStore;
@end
@interface EOEditingContext (EOStateArchiving)
+ (void)setUsesContextRelativeEncoding: (BOOL)yn;
+ (BOOL)usesContextRelativeEncoding;
+ (void)encodeObject: (id)object withCoder: (NSCoder *)coder;
+ (id)initObject: (id)object withCoder: (NSCoder *)coder;
@end
@interface EOEditingContext (EOTargetAction)
- (void)saveChanges: (id)sender;
- (void)refault: (id)sender;
- (void)revert: (id)sender;
- (void)refetch: (id)sender;
- (void)undo: (id)sender;
- (void)redo: (id)sender;
//Private
-(NSString*)objectsDescription;
-(NSString*)unprocessedDescription;
@end
@interface EOEditingContext(EOMultiThreaded) <NSLocking>
+ (void)setEOFMultiThreadedEnabled: (BOOL)flag;
- (void)lock;
- (void)unlock;
- (BOOL) tryLock;
@end
// Informations
@interface EOEditingContext(EOEditingContextInfo)
- (NSDictionary*)unprocessedInfo;
- (NSDictionary*)pendingInfo;
@end
#endif

3105
EOControl/EOEditingContext.m Normal file

File diff suppressed because it is too large Load diff

182
EOControl/EOFault.h Normal file
View file

@ -0,0 +1,182 @@
/*
EOFault.h
Copyright (C) 1996-2000 Free Software Foundation, Inc.
Author: Mircea Oancea <mircea@jupiter.elcom.pub.ro>
Date: 1996
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: June 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOFault_h__
#define __EOFault_h__
#include <Foundation/Foundation.h>
@class EOFaultHandler;
/*
* EOFault class
*/
@interface EOFault
{
Class isa;
EOFaultHandler *_handler;
}
+ (void)initialize;
+ (Class)superclass;
+ (Class)class;
+ (id)self;
+ (id)retain;
+ (void)release;
+ (id)autorelease;
+ (unsigned)retainCount;
+ (BOOL)isKindOfClass: (Class)aClass;
+ (void)doesNotRecognizeSelector: (SEL)sel;
+ (BOOL)respondsToSelector: (SEL)sel;
+ (void)makeObjectIntoFault: (id)object withHandler: (EOFaultHandler *)handler;
+ (BOOL)isFault: (id)object;
+ (void)clearFault: (id)fault;
+ (EOFaultHandler *)handlerForFault: (id)fault;
+ (Class)targetClassForFault: (id)fault;
- (Class)superclass;
- (Class)class;
- (BOOL)isKindOfClass: (Class)aclass;
- (BOOL)isMemberOfClass: (Class)aclass;
- (BOOL)conformsToProtocol: (Protocol *)protocol;
- (BOOL)respondsToSelector: (SEL)sel;
- (NSMethodSignature *)methodSignatureForSelector: (SEL)aSelector;
- (id)retain;
- (void)release;
- (id)autorelease;
- (unsigned)retainCount;
- (NSString *)description;
- (NSString *)descriptionWithIndent: (unsigned)level;
- (NSString *)descriptionWithLocale: (NSDictionary *)locale;
- (NSString *)descriptionWithLocale: (NSDictionary *)locale
indent: (unsigned)level;
- (NSString *)eoDescription;
- (NSString *)eoShallowDescription;
- (void)dealloc;
- (NSZone *)zone;
- (BOOL)isProxy; // Always NO.
- (id)self;
- (void)doesNotRecognizeSelector: (SEL)sel;
- (void)forwardInvocation: (NSInvocation *)invocation;
- gcSetNextObject: (id)anObject;
- gcSetPreviousObject: (id)anObject;
- (id)gcNextObject;
- (id)gcPreviousObject;
- (BOOL)gcAlreadyVisited;
- (void)gcSetVisited: (BOOL)flag;
- (void)gcDecrementRefCountOfContainedObjects;
- (BOOL)gcIncrementRefCountOfContainedObjects;
- (BOOL)isGarbageCollectable;
- (void)gcIncrementRefCount;
- (void)gcDecrementRefCount;
@end /* EOFault */
@interface EOFaultHandler : NSObject
{
Class _targetClass; // the first 8 bytes of
void *_extraData; // the faulted object
unsigned _extraRefCount;
BOOL gcEnabled;
id gcNextObject;
id gcPreviousObject;
struct {
unsigned gcVisited:1;
unsigned refCount:31;
} gcFlags;
@public
int gcCountainedObjectRefCount;
}
- (void)setTargetClass: (Class)target extraData: (void *)data;
- (Class)targetClass;
- (void *)extraData;
- (void)incrementExtraRefCount;
- (BOOL)decrementExtraRefCountWasZero;
- (unsigned)extraRefCount;
- (NSString *)descriptionForObject: object;
- (Class)classForFault: (id)fault;
- (BOOL)isKindOfClass: (Class)aclass forFault: (id)fault;
- (BOOL)isMemberOfClass: (Class)aclass forFault: (id)fault;
- (BOOL)conformsToProtocol: (Protocol *)protocol forFault: (id)fault;
- (BOOL)respondsToSelector: (SEL)sel forFault: (id)fault;
- (NSMethodSignature *)methodSignatureForSelector: (SEL)selector
forFault: (id)fault;
- (void)completeInitializationOfObject: (id)object;
- (BOOL)shouldPerformInvocation: (NSInvocation *)invocation;
- (void)faultWillFire: (id)object;
// Garbage Collector
- gcSetNextObject: (id)anObject;
- gcSetPreviousObject: (id)anObject;
- (id)gcNextObject;
- (id)gcPreviousObject;
- (BOOL)gcAlreadyVisited;
- (void)gcSetVisited: (BOOL)flag;
- (void)gcDecrementRefCountOfContainedObjects;
- (BOOL)gcIncrementRefCountOfContainedObjects;
- (BOOL)isGarbageCollectable;
- (void)gcIncrementRefCount;
- (void)gcDecrementRefCount;
@end
#endif /* __EOFault_h__ */

590
EOControl/EOFault.m Normal file
View file

@ -0,0 +1,590 @@
/**
EOFault.m <title>EOFault Class</title>
Copyright (C) 1996-2002 Free Software Foundation, Inc.
Author: Mircea Oancea <mircea@jupiter.elcom.pub.ro>
Date: 1996
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: June 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#include <objc/Object.h>
#include <objc/Protocol.h>
#import <Foundation/NSObject.h>
#import <Foundation/NSUtilities.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSString.h>
#import <Foundation/NSObjCRuntime.h>
#import <extensions/NSException.h>
#import <extensions/objc-runtime.h>
#import <extensions/exceptions/GeneralExceptions.h>
#import <EOControl/EOControl.h>
#import <EOControl/EOFault.h>
#import <EOAccess/EODatabaseContext.h>
typedef struct {
Class isa;
} *my_objc_object;
#define object_is_instance(object) \
((object != nil) && CLS_ISCLASS(((my_objc_object)object)->isa))
/*
* EOFault class
*/
@implementation EOFault
+ (void)initialize
{
// Must be here as initialize is called for each root class
// without asking if it responds to it !
}
+ (Class)superclass
{
return class_get_super_class(self);
}
+ (Class)class
{
return self;
}
+ self
{
return self;
}
+ (id)retain
{
return self;
}
+ (void)release
{
return;
}
+ (id)autorelease
{
return self;
}
+ (unsigned)retainCount
{
return UINT_MAX;
}
+ (BOOL)isKindOfClass: (Class)aClass
{
if(aClass == [EOFault class])
return YES;
return NO;
}
+ (void)doesNotRecognizeSelector: (SEL)sel
{
return;
[self notImplemented: _cmd];
}
+ (BOOL)respondsToSelector: (SEL)sel
{
return (IMP)class_get_instance_method(self, sel) != (IMP)0;
}
// Fault class methods
+ (void)makeObjectIntoFault: (id)object
withHandler: (EOFaultHandler *)handler
{
if (object)
{
EOFault *fault = object;
unsigned int refs;
NSAssert(handler,@"No Handler");
refs = [object retainCount];
[handler setTargetClass: [object class]
extraData: fault->_handler];
fault->isa = self;
fault->_handler = [handler retain];
while (refs-- > 0)
[fault retain];
}
}
+ (BOOL)isFault: (id)object
{
// NSDebugFLLog(@"gsdb",@"object=%p",object);
if (object == nil)
return NO;
else
return ((EOFault *)object)->isa == self;
}
+ (void)clearFault: (id)fault
{
EOFaultHandler *handler;
EOFault *aFault = (EOFault *)fault;
BOOL gcEnabled = NO;
unsigned gcCountainedObjectRefCount = 0;
int refs = 0;
NSDebugFLLog(@"gsdb", @"START fault=%p", fault);
if ([EOFault isFault:fault] == NO)
{
//REVOIR!!!
/*
[NSException raise:NSInvalidArgumentException
format:@"%@ -- %@ 0x%x: object %@ of class %@ is not a fault object",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
fault,
[fault class]];
*/
}
else
{
handler = aFault->_handler;
[handler faultWillFire: fault];
refs = [handler extraRefCount];
gcEnabled = [handler isGarbageCollectable];
gcCountainedObjectRefCount = aFault->_handler->gcCountainedObjectRefCount;
aFault->isa = [handler targetClass];
aFault->_handler = [handler extraData];
[handler autorelease];
refs -= [fault retainCount];
if (refs > 0)
while (refs-- > 0)
[aFault retain];
else
while (refs++ < 0)
[aFault release];
if(gcEnabled)
{
[aFault gcIncrementRefCount];
[aFault gcSetNextObject: [self gcNextObject]];
[aFault gcSetPreviousObject: [self gcPreviousObject]];
while (gcCountainedObjectRefCount-- > 0)
[aFault gcIncrementRefCountOfContainedObjects];
}
}
NSDebugFLLog(@"gsdb", @"STOP fault=%p", fault);
}
+ (EOFaultHandler *)handlerForFault:(id)fault
{
BOOL isFault = [EOFault isFault: fault];
NSDebugFLLog(@"gsdb", @"object %p is%s a fault", fault, (isFault ? "" : " not"));
if (isFault)
return ((EOFault *)fault)->_handler;
else
return nil;
}
+ (Class)targetClassForFault: (id)fault
{
if ([EOFault isFault:fault])
return [((EOFault *)fault)->_handler targetClass];
else
return nil;
}
// Fault Instance methods
- superclass
{
return [[_handler targetClass] superclass];
}
- (Class)class
{
return [_handler targetClass];
}
- (BOOL)isKindOfClass: (Class)aclass;
{
Class class;
BOOL koc=NO;
class = [_handler targetClass];
for (; !koc && class != Nil; class = class_get_super_class(class))
if (class == aclass)
koc = YES;
return koc;
}
- (BOOL)isMemberOfClass: (Class)aclass
{
return [_handler targetClass] == aclass;
}
- (BOOL)conformsToProtocol: (Protocol *)protocol
{
int i;
struct objc_protocol_list* protos;
Class class, sClass;
class = [_handler targetClass];
for (protos = class->protocols; protos; protos = protos->next)
{
for (i = 0; i < protos->count; i++)
if ([protos->list[i] conformsTo: protocol])
return YES;
}
sClass = [class superclass];
if (sClass)
return [sClass conformsToProtocol: protocol];
else
return NO;
}
- (BOOL)respondsToSelector: (SEL)aSelector
{
Class class;
BOOL respondsToSelector;
NSDebugFLLog(@"gsdb", @"START self=%p", self);
class = [_handler targetClass];
NSDebugFLLog(@"gsdb", @"class=%@ aSelector=%s", class, sel_get_name(aSelector));
respondsToSelector = ((IMP)class_get_instance_method(class, aSelector)
!= (IMP)0);
NSDebugFLLog(@"gsdb", @"STOP self=%p", self);
return respondsToSelector;
}
- (NSMethodSignature *)methodSignatureForSelector: (SEL)aSelector
{
NSMethodSignature *sig;
NSDebugFLLog(@"gsdb", @"START self=%p", self);
NSDebugFLLog(@"gsdb", @"_handler=%p", _handler);
sig = [_handler methodSignatureForSelector: aSelector
forFault: self];
NSDebugFLLog(@"gsdb", @"STOP self=%p", self);
return sig;
}
- retain
{
[_handler incrementExtraRefCount];
return self;
}
- (void)release
{
if ([_handler extraRefCount] <= 0)
[self dealloc];
else
[_handler decrementExtraRefCountWasZero];
}
- autorelease
{
[NSAutoreleasePool addObject: self];
return self;
}
- (unsigned)retainCount
{
return [_handler extraRefCount];
}
- (NSString *)description
{
return [_handler descriptionForObject: self];
}
- (NSString *)descriptionWithIndent: (unsigned)level
{
return [self description];
}
- (NSString *)descriptionWithLocale: (NSDictionary *)locale
{
//OK
return [self description];
}
- (NSString *)descriptionWithLocale: (NSDictionary *)locale
indent: (unsigned)level
{
return [self description];
}
- (NSString *)descriptionWithLocale: (NSDictionary *)locale
indent: (unsigned)level
to: (id<GNUDescriptionDestination>)output;
{
return [self description];
}
- (NSString *)eoDescription
{
return [self description];
}
- (NSString *)eoShallowDescription
{
return [self description];
}
- (EOKeyGlobalID *)globalID
{
if ([_handler respondsToSelector: @selector(globalID)])
return [(id)_handler globalID];
else
{
[_handler completeInitializationOfObject: self];
return [self globalID];
}
}
- (EODatabaseContext *)databaseContext
{
if ([_handler respondsToSelector: @selector(databaseContext)])
return [(id)_handler databaseContext];
else
{
[_handler completeInitializationOfObject: self];
return [self databaseContext];
}
}
- (EOEditingContext *)editingContext
{
if ([_handler respondsToSelector: @selector(editingContext)])
return [_handler editingContext];
else
{
[_handler completeInitializationOfObject: self];
return [self editingContext];
}
}
/*
- (EOKeyGlobalID *)sourceGlobalID;
- (NSString *)relationshipName;
*/
- (void)dealloc
{
[EOFault clearFault: self];
[self dealloc];
}
- (NSZone *)zone
{
return NSZoneFromPointer(self);
}
- (BOOL)isProxy
{
return NO;
}
- (id)self
{
[_handler completeInitializationOfObject: self];
return self;
}
- (void)doesNotRecognizeSelector: (SEL)sel
{
[NSException raise: NSInvalidArgumentException
format: @"%@ -- %@ 0x%x: selector \"%@\" not recognized",
NSStringFromSelector(_cmd),
NSStringFromClass([self class]),
self,
NSStringFromSelector(sel)];
}
- (retval_t)forward: (SEL)sel
: (arglist_t)args
{
retval_t ret;
NSInvocation *inv;
NSDebugFLLog(@"gsdb", @"START self=%p", self);
inv = [[[NSInvocation alloc] initWithArgframe: args
selector: sel]
autorelease];
[self forwardInvocation: inv];
ret = [inv returnFrame: args];
NSDebugFLLog(@"gsdb", @"STOP self=%p", self);
return ret;
}
- (void)forwardInvocation: (NSInvocation *)invocation
{
NSDebugFLLog(@"gsdb", @"START self=%p", self);
if ([_handler shouldPerformInvocation: invocation])
[_handler completeInitializationOfObject: self];
[invocation invoke];
NSDebugFLLog(@"gsdb", @"STOP self=%p", self);
}
- (unsigned int)hash
{
unsigned int hash;
EOFaultHandler *handler;
Class fault;
fault = isa;
handler = _handler;
isa = [handler targetClass];
_handler = [handler extraData];
hash = [self hash];
isa = fault;
_handler = handler;
return hash;
}
// GC
- gcSetNextObject: (id)anObject
{
return [_handler gcSetNextObject: anObject];
}
- gcSetPreviousObject: (id)anObject
{
return [_handler gcSetPreviousObject: anObject];
}
- (id)gcNextObject
{
return [_handler gcNextObject];
}
- (id)gcPreviousObject
{
return [_handler gcPreviousObject];
}
- (BOOL)gcAlreadyVisited
{
return [_handler gcAlreadyVisited];
}
- (void)gcSetVisited: (BOOL)flag
{
[_handler gcSetVisited: flag];
}
- (void)gcDecrementRefCountOfContainedObjects
{
[_handler gcDecrementRefCountOfContainedObjects];
}
- (BOOL)gcIncrementRefCountOfContainedObjects
{
return [_handler gcIncrementRefCountOfContainedObjects];
}
- (BOOL)isGarbageCollectable
{
return [_handler isGarbageCollectable];
}
- (void)gcIncrementRefCount
{
[_handler gcIncrementRefCount];
}
- (void)gcDecrementRefCount
{
NSDebugFLLog(@"gsdb", @"START self=%p", self);
NSDebugFLLog(@"gsdb", @"handler gcDecrementRefCount");
[_handler gcDecrementRefCount];
NSDebugFLLog(@"gsdb", @"STOP self=%p", self);
}
@end

374
EOControl/EOFaultHandler.m Normal file
View file

@ -0,0 +1,374 @@
/**
EOFaultHandler.m <title>EOFaultHandler Class</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: June 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSObject.h>
#import <Foundation/NSUtilities.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSString.h>
#import <Foundation/NSObjCRuntime.h>
#import <extensions/NSException.h>
#import <extensions/exceptions/GeneralExceptions.h>
#import <extensions/GCObject.h>
#import <EOControl/EOControl.h>
#import <EOControl/EOFault.h>
BOOL __isGCEnabled(Class class_)
{
Class gcObjectClass = [GCObject class];
if ([class_ conformsToProtocol: @protocol(GarbageCollecting)])
return YES;
else if ([class_ instancesRespondToSelector: @selector(gcIncrementRefCount)])
return YES;
else
{
Class class;
for (class = class_;
class != Nil;
class = class_get_super_class (class))
{
if (class == gcObjectClass)
return YES;
else if ([class instancesRespondToSelector: @selector(gcIncrementRefCount)])
return YES;
else if ([class instancesRespondToSelector: @selector(gcNextObject)])
return YES;
else if ([class conformsToProtocol: @protocol(GarbageCollecting )])
return YES;
}
}
return NO;
}
@implementation EOFaultHandler
- (id)init
{
if ((self = [super init]))
{
}
return self;
}
- (void)setTargetClass: (Class)target
extraData: (void *)data
{
_targetClass = target;
_extraData = data;
gcEnabled = __isGCEnabled(_targetClass);
if (gcEnabled)
_extraRefCount++;
}
- (Class)targetClass
{
return _targetClass;
}
- (void *)extraData
{
return _extraData;
}
- (void)incrementExtraRefCount
{
_extraRefCount++;
}
- (BOOL)decrementExtraRefCountWasZero
{
if (!(--_extraRefCount))
return YES;
return NO;
}
- (unsigned)extraRefCount
{
return _extraRefCount;
}
- (NSString *)descriptionForObject: object
{
return [NSString stringWithFormat: @"%@ (EOFault 0x%08x)",
NSStringFromClass(_targetClass), object];
}
- (Class)classForFault: (id)fault
{
return [self targetClass];
}
- (BOOL)isKindOfClass: (Class)aclass
forFault: (id)fault
{
Class class;
for (class = _targetClass; class != Nil; class = class_get_super_class(class))
{
if (class == aclass)
return YES;
}
return NO;
}
- (BOOL)isMemberOfClass: (Class)aclass
forFault: (id)fault
{
return _targetClass == aclass;
}
- (BOOL)conformsToProtocol: (Protocol *)protocol
forFault: (id)fault
{
int i;
struct objc_protocol_list *proto_list;
Class class;
for(class = _targetClass; class != Nil; class = class_get_super_class(class))
{
for (proto_list =
((struct objc_class *)_targetClass)->class_pointer->protocols;
proto_list; proto_list = proto_list->next)
{
for (i = 0; i < proto_list->count; i++)
{
if ([proto_list->list[i] conformsTo: protocol])
return YES;
}
}
}
return NO;
}
- (BOOL)respondsToSelector: (SEL)sel
forFault: (id)fault
{
[self notImplemented: _cmd];
return NO;
// return __objc_responds_to((id)&self, sel);
}
- (NSMethodSignature *)methodSignatureForSelector: (SEL)selector
forFault: (id)fault
{ // TODO
NSMethodSignature *sig;
EOFLOGObjectFnStart();
NSDebugMLLog(@"gsdb", @"_targetClass=%p", _targetClass);
NSDebugMLLog(@"gsdb", @"_targetClass=%@", _targetClass);
NSDebugMLLog(@"gsdb", @"selector=%@", NSStringFromSelector(selector));
//TODO VERIFY
NSAssert(_targetClass, @"No target class");
sig = [_targetClass instanceMethodSignatureForSelector: selector];
NSDebugMLLog(@"gsdb",@"sig=%p", (void*)sig);
EOFLOGObjectFnStop();
return sig;
}
- (void)completeInitializationOfObject: (id)object
{
[self subclassResponsibility: _cmd];
}
- (BOOL)shouldPerformInvocation: (NSInvocation *)invocation
{
return YES;
}
- (void)faultWillFire: (id)object
{
return;
}
// GC
+ allocWithZone: (NSZone *)zone_
{
id newObject = [super allocWithZone: zone_];
((EOFaultHandler *)newObject)->gcFlags.refCount = 0;
return newObject;
}
/*
- retain
{
if (gcEnabled)
{
gcFlags.refCount++;
return self;
}
else
{
return [super retain];
};
}
- (unsigned int)retainCount
{
if (gcEnabled)
{
return gcFlags.refCount;
}
else
{
return [super retainCount];
};
}
*/
- gcSetNextObject: (id)anObject
{
if (gcEnabled)
gcNextObject = anObject;
return self;
}
- gcSetPreviousObject: (id)anObject
{
if (gcEnabled)
gcPreviousObject = anObject;
return self;
}
- (id)gcNextObject
{
if (gcEnabled)
return gcNextObject;
return nil;
}
- (id)gcPreviousObject
{
if (gcEnabled)
return gcPreviousObject;
return nil;
}
- (BOOL)gcAlreadyVisited
{
if (gcEnabled)
return gcFlags.gcVisited;
return YES;
}
- (void)gcSetVisited: (BOOL)flag
{
if (gcEnabled)
gcFlags.gcVisited = flag;
}
- (void)gcDecrementRefCountOfContainedObjects
{
EOFLOGObjectFnStart();
if (gcEnabled)
gcCountainedObjectRefCount--;
EOFLOGObjectFnStop();
}
- (BOOL)gcIncrementRefCountOfContainedObjects
{
if (gcEnabled)
{
if (gcFlags.gcVisited)
return NO;
gcCountainedObjectRefCount++;
gcFlags.gcVisited = YES;
return YES;
}
return NO;
}
- (BOOL)isGarbageCollectable
{
return gcEnabled;
}
- (void)gcIncrementRefCount
{
if (gcEnabled);
//gcFlags.refCount++;
// faultReferences++;
}
- (void)gcDecrementRefCount
{
if(gcEnabled);
//gcFlags.refCount--;
// faultReferences--;
}
/*
- (BOOL)afterFault
{
if (gcEnabled)
{
[fault gcIncrementRefCount];
[fault gcSetNextObject:[self gcNextObject]];
[fault gcSetPreviousObject:[self gcPreviousObject]];
while(gcCountainedObjectRefCount-- > 0)
[fault gcIncrementRefCountOfContainedObjects];
};
return NO;
}
*/
@end

View file

@ -0,0 +1,146 @@
/*
EOFetchSpecification.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOFetchSpecification_h__
#define __EOFetchSpecification_h__
#import <Foundation/Foundation.h>
@class EOQualifier;
@class EOKeyValueArchiver;
@class EOKeyValueUnarchiver;
@interface EOFetchSpecification : NSObject <NSCopying, NSCoding>
{
EOQualifier *_qualifier;
NSArray *_sortOrderings;
NSString *_entityName;
NSDictionary *_hints;
unsigned int _fetchLimit;
NSArray *_prefetchingRelationshipKeys;
NSArray *_rawAttributeKeys;
struct {
unsigned usesDistinct:1;
unsigned isDeep:1;
unsigned locksObjects:1;
unsigned refreshesRefetchedObjects:1;
unsigned promptsAfterFetchLimit:1;
unsigned allVariablesRequiredFromBindings:1;
unsigned :26; //padding
}_flags;
}
+ (EOFetchSpecification *)fetchSpecification;
- init;
- initWithEntityName: (NSString *)entityName
qualifier: (EOQualifier *)qualifier
sortOrderings: (NSArray *)sortOrderings
usesDistinct: (BOOL)usesDistinct
isDeep: (BOOL)isDeep
hints: (NSDictionary *)hints;
- (EOFetchSpecification *)fetchSpecificationByApplyingBindings: (id)bindings;
- (EOFetchSpecification *)fetchSpecificationWithQualifierBindings: (NSDictionary *)bindings;
+ (EOFetchSpecification *)fetchSpecificationNamed: (NSString *)name
entityNamed: (NSString *)entityName;
+ (EOFetchSpecification *)fetchSpecificationWithEntityName: (NSString *)name
qualifier: (EOQualifier *)qualifier
sortOrderings: (NSArray *)sortOrderings;
- copyWithZone:(NSZone *)zone;
- (id) initWithKeyValueUnarchiver: (EOKeyValueUnarchiver*)unarchiver;
- (void) encodeWithKeyValueArchiver: (EOKeyValueUnarchiver*)archiver;
- (void)setEntityName: (NSString *)entityName;
- (NSString *)entityName;
- (void)setSortOrderings: (NSArray *)sortOrderings;
- (NSArray *)sortOrderings;
- (void)setQualifier: (EOQualifier *)qualifier;
- (EOQualifier *)qualifier;
- (void)setUsesDistinct: (BOOL)usesDistinct;
- (BOOL)usesDistinct;
- (void)setIsDeep: (BOOL)isDeep;
- (BOOL)isDeep;
- (void)setLocksObjects: (BOOL)setLocksObjects;
- (BOOL)locksObjects;
- (void)setRefreshesRefetchedObjects: (BOOL)refreshesRefetchedObjects;
- (BOOL)refreshesRefetchedObjects;
- (void)setFetchLimit: (unsigned)fetchLimit;
- (unsigned)fetchLimit;
- (void)setPromptsAfterFetchLimit: (BOOL)promptsAfterFetchLimit;
- (BOOL)promptsAfterFetchLimit;
- (void)setAllVariablesRequiredFromBindings: (BOOL)allVariablesRequired;
- (BOOL)allVariablesRequiredFromBindings;
- (void)setPrefetchingRelationshipKeyPaths: (NSArray *)prefetchingRelationshipKeys;
- (NSArray *)prefetchingRelationshipKeyPaths;
- (void)setRawAttributeKeys: (NSArray *)rawAttributeKeys;
- (NSArray *)rawAttributeKeys;
- (void)setFetchesRawRows: (BOOL)fetchRawRows;
- (BOOL)fetchesRawRows;
- (void)setHints: (NSDictionary *)hints;
- (NSDictionary *)hints;
- (NSDictionary *)_hints;
- (NSArray *)rawRowKeyPaths;
- (void)setRawRowKeyPaths: (NSArray *)rawRowKeyPaths;
- (BOOL)requiresAllQualifierBindingVariables;
- (void)setRequiresAllQualifierBindingVariables: (BOOL)flag;
@end
extern NSString *EOPrefetchingRelationshipHintKey;
extern NSString *EOFetchLimitHintKey;
extern NSString *EOPromptsAfterFetchLimitHintKey;
#endif

View file

@ -0,0 +1,497 @@
/**
EOFetchSpecification.m <title>EOFetchSpecification</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <EOControl/EOFetchSpecification.h>
#import <EOControl/EOKeyValueArchiver.h>
#import <EOControl/EOObserver.h>
#import <EOControl/EODebug.h>
#import <EOControl/EONSAddOns.h>
#import <EOAccess/EOModelGroup.h>
@implementation EOFetchSpecification
+ (EOFetchSpecification *)fetchSpecification
{
return [[[self alloc] init] autorelease];
}
- (id) init
{
if ((self = [super init]))
{
_flags.isDeep = YES;
}
return self;
}
// Turbocat
- (void)dealloc
{
#ifdef DEBUG
NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__, @"FNSTOP");
EOFLOGObjectFnStartOrCond(@"EOFetchSpecification");
#endif
DESTROY(_qualifier);
DESTROY(_sortOrderings);
DESTROY(_entityName);
DESTROY(_hints);
DESTROY(_prefetchingRelationshipKeys);
DESTROY(_rawAttributeKeys);
[super dealloc];
#ifdef DEBUG
EOFLOGObjectFnStopOrCondPlain(@"EOFetchSpecification", fmt);
#endif
}
- (id) initWithEntityName: (NSString *)entityName
qualifier: (EOQualifier *)qualifier
sortOrderings: (NSArray *)sortOrderings
usesDistinct: (BOOL)usesDistinct
isDeep: (BOOL)isDeep
hints: (NSDictionary *)hints
{
if ((self = [self init]))
{
ASSIGN(_entityName, entityName);
ASSIGN(_qualifier, qualifier);
ASSIGN(_sortOrderings, sortOrderings);
[self setUsesDistinct: usesDistinct];
[self setIsDeep: isDeep];
[self setHints: hints];
}
return self;
}
- (EOFetchSpecification *)fetchSpecificationByApplyingBindings: (id)bindings
{
[self notImplemented:_cmd];
return nil;
}
- (EOFetchSpecification *)fetchSpecificationWithQualifierBindings: (NSDictionary *)bindings
{
[self notImplemented: _cmd];
return nil;
}
+ (EOFetchSpecification *)fetchSpecificationNamed: (NSString *)name
entityNamed: (NSString *)entityName
{
EOFetchSpecification *newEOFetchSpecification = nil;
EOModelGroup *anModelGroup;
EOFLOGClassFnStartOrCond(@"EOFetchSpecification");
anModelGroup = [EOModelGroup defaultGroup];
if (anModelGroup)
newEOFetchSpecification = [anModelGroup fetchSpecificationNamed: name
entityNamed: entityName];
EOFLOGObjectFnStopOrCond(@"EOFetchSpecification");
return newEOFetchSpecification;
}
+ (EOFetchSpecification *)fetchSpecificationWithEntityName: (NSString *)name
qualifier: (EOQualifier *)qualifier
sortOrderings: (NSArray *)sortOrderings
{
return [[[EOFetchSpecification alloc]
initWithEntityName: name
qualifier: qualifier
sortOrderings: sortOrderings
usesDistinct: NO
isDeep: YES
hints: nil] autorelease];
}
- (id) copyWithZone: (NSZone *)zone
{
EOFetchSpecification *ret = [EOFetchSpecification allocWithZone:zone];
//order: hints, isdeep, usesDistinct,sortOrderings, qualifier,entityName
//and call nitWithEntityName:qualifier:sortOrderings:usesDistinct:isDeep:hints:
//after:
/* [fetch setLocksObjects:[_fetchSpecification locksObjects]];
[fetch setRefreshesRefetchedObjects:[_fetchSpecification refreshesRefetchedObjects]];
[fetch setPrefetchingRelationshipKeyPaths:[_fetchSpecification prefetchingRelationshipKeyPaths
[fetch setRawRowKeyPaths:[_fetchSpecification rawRowKeyPaths
setFetchLimit:fetchLimit
setPromptsAfterFetchLimit: promptsAfterFetchLimit
setRequiresAllQualifierBindingVariables:requiresAllQualifierBindingVariables
*/
//call setXX fn instead to have "willChange" ??
ret->_qualifier = [(<NSCopying>)_qualifier copyWithZone: zone];
ret->_sortOrderings = [_sortOrderings copyWithZone: zone]; //mirko: ASSIGN(ret->_sortOrderings, _sortOrderings);
ret->_entityName = [_entityName copyWithZone: zone];
ret->_hints = [_hints copyWithZone: zone];
ret->_prefetchingRelationshipKeys = [_prefetchingRelationshipKeys copyWithZone: zone];
ret->_rawAttributeKeys = [_rawAttributeKeys copyWithZone: zone];
ret->_fetchLimit = _fetchLimit;
ret->_flags = _flags;
return ret;
}
- (void)encodeWithCoder: (NSCoder *)coder
{
[coder encodeObject: _qualifier];
[coder encodeObject: _sortOrderings];
[coder encodeObject: _entityName];
[coder encodeObject: _hints];
[coder encodeValueOfObjCType: @encode(unsigned int) at: &_fetchLimit];
[coder encodeObject: _prefetchingRelationshipKeys];
[coder encodeObject: _rawAttributeKeys];
[coder encodeValueOfObjCType: @encode(unsigned int) at: &_flags];
}
- (id)initWithCoder: (NSCoder *)coder
{
_qualifier = [[coder decodeObject] retain];
_sortOrderings = [[coder decodeObject] retain];
_entityName = [[coder decodeObject] retain];
_hints = [[coder decodeObject] retain];
[coder decodeValueOfObjCType: @encode(unsigned int) at: &_fetchLimit];
_prefetchingRelationshipKeys = [[coder decodeObject] retain];
_rawAttributeKeys = [[coder decodeObject] retain];
[coder decodeValueOfObjCType: @encode(unsigned int) at: &_flags];
return self;
}
- (id) initWithKeyValueUnarchiver: (EOKeyValueUnarchiver*)unarchiver
{
if ((self = [self init]))
{
ASSIGN(_hints, [unarchiver decodeObjectForKey: @"hints"]);
ASSIGN(_qualifier, [unarchiver decodeObjectForKey: @"qualifier"]);
ASSIGN(_sortOrderings, [unarchiver decodeObjectForKey: @"sortOrderings"]);
ASSIGN(_entityName, [unarchiver decodeObjectForKey: @"entityName"]);
ASSIGN(_prefetchingRelationshipKeys,
[unarchiver decodeObjectForKey: @"prefetchingRelationshipKeyPaths"]);
ASSIGN(_rawAttributeKeys, [unarchiver decodeObjectForKey: @"rawRowKeyPaths"]);
_fetchLimit = [unarchiver decodeIntForKey: @"fetchLimit"];
_flags.usesDistinct = [unarchiver decodeBoolForKey: @"usesDistinct"];
_flags.isDeep = [unarchiver decodeBoolForKey: @"isDeep"];
_flags.locksObjects = [unarchiver decodeBoolForKey: @"locksObjects"];
_flags.refreshesRefetchedObjects =
[unarchiver decodeBoolForKey: @"refreshesRefetchedObjects"];
_flags.promptsAfterFetchLimit =
[unarchiver decodeBoolForKey: @"promptsAfterFetchLimit"];
_flags.allVariablesRequiredFromBindings =
[unarchiver decodeBoolForKey: @"requiresAllQualifierBindingVariables"];
}
return self;
}
- (void) encodeWithKeyValueArchiver: (EOKeyValueUnarchiver*)archiver
{
[self notImplemented: _cmd];
}
- (NSString*)description
{
NSMutableString *desc = [NSMutableString string];
[desc appendString: @"{\n"];
[desc appendString: [NSString stringWithFormat: @"hints = %@;\n",
[_hints description]]];
[desc appendString: [NSString stringWithFormat: @"qualifier = %@;\n",
_qualifier]];
[desc appendString: [NSString stringWithFormat: @"sortOrderings = %@;\n",
[_sortOrderings description]]];
[desc appendString: [NSString stringWithFormat: @"entityName = %@;\n",
_entityName]];
[desc appendString: [NSString stringWithFormat: @"prefetchingRelationshipKeyPaths = %@;\n",
[_prefetchingRelationshipKeys description]]];
[desc appendString: [NSString stringWithFormat: @"rawRowKeyPaths = %@;\n",
[_rawAttributeKeys description]]];
[desc appendString: [NSString stringWithFormat: @"fetchLimit = %d;\n",
_fetchLimit]];
[desc appendString: [NSString stringWithFormat: @"usesDistinct = %s;\n",
_flags.usesDistinct ? "YES" : "NO"]];
[desc appendString: [NSString stringWithFormat: @"isDeep = %s;\n",
_flags.isDeep ? "YES" : "NO"]];
[desc appendString: [NSString stringWithFormat: @"locksObjects = %s;\n",
_flags.locksObjects ? "YES" : "NO"]];
[desc appendString: [NSString stringWithFormat: @"refreshesRefetchedObjects = %s;\n",
_flags.refreshesRefetchedObjects ? "YES" : "NO"]];
[desc appendString: [NSString stringWithFormat: @"promptsAfterFetchLimit = %s;\n",
_flags.promptsAfterFetchLimit ? "YES" : "NO"]];
[desc appendString: [NSString stringWithFormat: @"requiresAllQualifierBindingVariables = %s;\n",
_flags.allVariablesRequiredFromBindings ? "YES" : "NO"]];
[desc appendString: @"}"];
return desc;
}
- (void)setEntityName: (NSString *)entityName
{
[self willChange];
ASSIGN(_entityName, entityName);
}
- (NSString *)entityName
{
return _entityName;
}
- (void)setSortOrderings: (NSArray *)sortOrderings
{
ASSIGN(_sortOrderings, sortOrderings);
}
- (NSArray *)sortOrderings
{
return _sortOrderings;
}
- (void)setQualifier: (EOQualifier *)qualifier
{
[self willChange];
ASSIGN(_qualifier, qualifier);
}
- (EOQualifier *)qualifier
{
return _qualifier;
}
- (void)setUsesDistinct: (BOOL)usesDistinct
{
[self willChange];
_flags.usesDistinct = usesDistinct;
}
- (BOOL)usesDistinct
{
return _flags.usesDistinct;
}
- (void)setIsDeep: (BOOL)isDeep
{
[self willChange];
_flags.isDeep = isDeep;
}
- (BOOL)isDeep
{
return _flags.isDeep;
}
- (void)setLocksObjects: (BOOL)locksObjects
{
[self willChange];
_flags.locksObjects = locksObjects;
}
- (BOOL)locksObjects
{
return _flags.locksObjects;
}
- (void)setRefreshesRefetchedObjects: (BOOL)refreshesRefetchedObjects
{
[self willChange];
_flags.refreshesRefetchedObjects = refreshesRefetchedObjects;
}
- (BOOL)refreshesRefetchedObjects
{
return _flags.refreshesRefetchedObjects;
}
- (void)setFetchLimit: (unsigned)fetchLimit
{
[self willChange];
_fetchLimit = fetchLimit;
}
- (unsigned)fetchLimit
{
return _fetchLimit;
}
- (void)setPromptsAfterFetchLimit: (BOOL)promptsAfterFetchLimit
{
[self willChange];
_flags.promptsAfterFetchLimit = promptsAfterFetchLimit;
}
- (BOOL)promptsAfterFetchLimit
{
return _flags.promptsAfterFetchLimit;
}
- (void)setAllVariablesRequiredFromBindings: (BOOL)allVariablesRequired
{
_flags.allVariablesRequiredFromBindings = allVariablesRequired;
}
- (BOOL)allVariablesRequiredFromBindings
{
return _flags.allVariablesRequiredFromBindings;
}
- (void)setPrefetchingRelationshipKeyPaths: (NSArray *)prefetchingRelationshipKeys
{
[self willChange];
ASSIGN(_prefetchingRelationshipKeys, prefetchingRelationshipKeys);
}
- (NSArray *)prefetchingRelationshipKeyPaths
{
return _prefetchingRelationshipKeys;
}
- (void)setRawAttributeKeys: (NSArray *)rawAttributeKeys
{
ASSIGN(_rawAttributeKeys, rawAttributeKeys);
}
- (NSArray *)rawAttributeKeys
{
return _rawAttributeKeys;
}
- (void)setFetchesRawRows: (BOOL)fetchRawRows
{
if (fetchRawRows)
[self setRawRowKeyPaths: [NSArray array]];
else
[self setRawRowKeyPaths: nil];
}
- (BOOL)fetchesRawRows
{
if ([self rawRowKeyPaths])
return YES;
else
return NO;
}
- (void)setHints: (NSDictionary *)hints
{
//TODO: set fetchLimit,... from hints ???
[self willChange];
//even if nil: initWithDictionary:copyItems:
//thedict objectForKey:EOPrefetchingRelationshipHintKey
//EOFetchLimitHintKey
//EOPromptAfterFetchLimitHintKey
ASSIGN(_hints, hints);
}
- (NSDictionary *)_hints
{
return _hints;
}
- (NSDictionary *)hints
{
NSMutableDictionary *hints = _hints;
BOOL promptsAfterFetchLimit;
NSArray *prefetchingRelationshipKeyPaths;
unsigned fetchLimit;
fetchLimit = [self fetchLimit];
promptsAfterFetchLimit = [self promptsAfterFetchLimit];
prefetchingRelationshipKeyPaths = [self prefetchingRelationshipKeyPaths];
if (fetchLimit != 0 || promptsAfterFetchLimit
|| [prefetchingRelationshipKeyPaths count] > 0)
{
NSMutableDictionary *mutableHints = [NSMutableDictionary
dictionaryWithDictionary: hints];
hints = mutableHints;
if (fetchLimit != 0)
{
[mutableHints setObject: [NSNumber numberWithInt: fetchLimit]
forKey: @"EOFetchLimitHintKey"];
}
if (promptsAfterFetchLimit)
{
[mutableHints setObject: [NSNumber numberWithBool:
promptsAfterFetchLimit]
forKey: @"EOPromptAfterFetchLimitHintKey"];
}
if ([prefetchingRelationshipKeyPaths count] > 0)
{
[mutableHints setObject: prefetchingRelationshipKeyPaths
forKey: @"EOPrefetchingRelationshipHintKey"];
}
}
return hints;
}
- (NSArray *)rawRowKeyPaths
{
return _rawAttributeKeys;
}
- (void)setRawRowKeyPaths: (NSArray *)rawRowKeyPaths
{
[self willChange];
ASSIGN(_rawAttributeKeys, rawRowKeyPaths);
}
- (BOOL)requiresAllQualifierBindingVariables
{
NSDebugMLLog(@"gsdb", @"self=%p", self);
return _flags.allVariablesRequiredFromBindings;
}
- (void)setRequiresAllQualifierBindingVariables: (BOOL)flag
{
[self willChange];
[self notImplemented: _cmd];
}
@end

View file

@ -0,0 +1,61 @@
/*
EOGenericRecord.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: June 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOGenericRecord_h__
#define __EOGenericRecord_h__
#import <Foundation/NSObject.h>
@class NSString;
@class NSMutableDictionary;
@class EOClassDescription;
@class EOEditingContext;
@class EOGlobalID;
@class EOMutableKnownKeyDictionary;
@interface EOGenericRecord : NSObject
{
EOClassDescription *classDescription;
EOMutableKnownKeyDictionary *dictionary;
}
// Initializing new instances
- initWithEditingContext: (EOEditingContext *)context
classDescription: (EOClassDescription *)classDesc
globalID: (EOGlobalID *)globalID;
- (id)valueForKey: (NSString *)key;
- (void)takeValue: (id)value
forKey: (NSString *)key;
+ (void)eoCalculateAllSizeWith: (NSMutableDictionary*)dict;
- (unsigned int)eoCalculateSizeWith: (NSMutableDictionary*)dict;
@end /* EOGenericRecord */
#endif /* __EOGenericRecord_h__ */

1354
EOControl/EOGenericRecord.m Normal file

File diff suppressed because it is too large Load diff

67
EOControl/EOGlobalID.h Normal file
View file

@ -0,0 +1,67 @@
/*
EOGlobalID.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOGlobalID_h__
#define __EOGlobalID_h__
#import <Foundation/Foundation.h>
extern NSString *EOGlobalIDChangedNotification;
@interface EOGlobalID : NSObject <NSCopying>
- (BOOL)isEqual:other;
- (unsigned)hash;
- (BOOL)isTemporary;
@end
enum {
EOUniqueBinaryKeyLength = 12
};
@interface EOTemporaryGlobalID : EOGlobalID <NSCoding>
{
unsigned _refCount;
unsigned char _bytes[EOUniqueBinaryKeyLength+1];
}
+ (EOTemporaryGlobalID *)temporaryGlobalID;
+ (void)assignGloballyUniqueBytes: (unsigned char *)buffer;
// < Sequence [2], ProcessID [2] , Time [4], IP Addr [4] >
- init;
- (BOOL)isTemporary;
- (void)encodeWithCoder: (NSCoder *)aCoder;
- (id)initWithCoder: (NSCoder *)aDecoder;
@end
#endif

176
EOControl/EOGlobalID.m Normal file
View file

@ -0,0 +1,176 @@
/**
EOGlobalID.m <title>EOGlobalID</title>
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <EOControl/EOControl.h>
#import <EOControl/EOGlobalID.h>
#include <time.h>
#include <unistd.h>
NSString *EOGlobalIDChangedNotification = @"EOGlobalIDChangedNotification";
@implementation EOGlobalID
- (BOOL)isEqual: other
{
return NO;
}
- (unsigned)hash
{
return 0;
}
- (BOOL)isTemporary
{
return NO;
}
- (id)copyWithZone: (NSZone *)zone
{
EOGlobalID *gid = [[[self class] alloc] init];
return gid;
}
@end
@implementation EOTemporaryGlobalID
static unsigned short sequence = 65535;
static unsigned long sequenceRev = 0;
+ (EOTemporaryGlobalID *)temporaryGlobalID
{
return [[[self alloc] init] autorelease];
}
// < Sequence [2], ProcessID [2] , Time [4], IP Addr [4] >
+ (void)assignGloballyUniqueBytes: (unsigned char *)buffer
{
EOFLOGObjectFnStart();
// sprintf(buffer, "%02x%02x%04x%04x", sequence++ % 0xff, 0, (unsigned int)time( NULL ) % 0xffffffff, 0); // <-- overwrite memory
// buffer should have space for EOUniqueBinaryKeyLength (12) bytes.
// Assigns a world-wide unique ID made up of:
// < Sequence [2], ProcessID [2] , Time [4], IP Addr [4] >
//printf("sequence : %d (%02x,%02x,%04x,%04x)\n",sequence -1, (sequence - 1) % 0xff, getpid() % 0xff, (unsigned int)time( NULL ) % 0xffff, (sequenceRev+1) % 0xffff);
snprintf(buffer, 12,
"%02x%02x%04x%04x",
sequence-- % 0xff,
getpid() % 0xff,
(unsigned int)time( NULL ) % 0xffff,
sequenceRev++ % 0xffff);
if (sequence == 0)
sequence = 65535;
if (sequenceRev == 4294967295UL)
sequenceRev = 1;
EOFLOGObjectFnStop();
return; // TODO
}
- init
{
EOFLOGObjectFnStart();
if ((self = [super init]))
{
[EOTemporaryGlobalID assignGloballyUniqueBytes:_bytes];
}
EOFLOGObjectFnStop();
return self;
}
- (BOOL)isTemporary
{
return YES;
}
- (unsigned char *)_bytes
{
return _bytes;
}
- (BOOL)isEqual:other
{
if (self == other)
return YES;
if ([other isKindOfClass: [EOTemporaryGlobalID class]] == NO)
return NO;
if (!memcmp(_bytes, [other _bytes], sizeof(_bytes)))
return YES;
return NO;
}
- (void)encodeWithCoder: (NSCoder *)coder
{
[coder encodeValueOfObjCType: @encode(unsigned) at: &_refCount];
[coder encodeValueOfObjCType: @encode(unsigned char[]) at: _bytes];
}
- (id)initWithCoder: (NSCoder *)coder
{
self = [super init];
[coder decodeValueOfObjCType: @encode(unsigned) at: &_refCount];
[coder decodeValueOfObjCType: @encode(unsigned char[]) at: _bytes];
return self;
}
- (id)copyWithZone: (NSZone *)zone
{
EOTemporaryGlobalID *gid = [super copyWithZone:zone];
gid->_refCount = _refCount;
memcpy(gid->_bytes, _bytes, sizeof(_bytes));
return gid;
}
@end

View file

@ -0,0 +1,171 @@
/**
EOKeyComparisonQualifier.m <title>EOKeyComparisonQualifier</title>
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: February 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <Foundation/NSDictionary.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSUtilities.h>
#import <EOControl/EOQualifier.h>
#import <EOControl/EOKeyValueCoding.h>
#import <EOControl/EODebug.h>
#import <EOAccess/EOSQLExpression.h>
@implementation EOKeyComparisonQualifier
+ (EOQualifier *)qualifierWithLeftKey: (NSString *)leftKey
operatorSelector: (SEL)selector
rightKey: (id)rightKey
{
return [[[self alloc] initWithLeftKey: leftKey
operatorSelector: selector
rightKey: rightKey] autorelease];
}
- initWithLeftKey: (NSString *)leftKey
operatorSelector: (SEL)selector
rightKey: (id)rightKey
{
if ((self = [super init]))
{
_selector = selector;
ASSIGN(_leftKey, leftKey);
ASSIGN(_rightKey, rightKey);
}
return self;
}
- (void)dealloc
{
DESTROY(_leftKey);
DESTROY(_rightKey);
[super dealloc];
}
- (SEL)selector
{
return _selector;
}
- (NSString *)leftKey
{
return _leftKey;
}
- (NSString *)rightKey
{
return _rightKey;
}
- (id)copyWithZone: (NSZone *)zone
{
EOKeyComparisonQualifier *qual = [[EOKeyComparisonQualifier
allocWithZone: zone] init];
qual->_selector = _selector;
qual->_leftKey = [_leftKey copyWithZone: zone];
qual->_rightKey = [_rightKey copyWithZone: zone];
return qual;
}
- (BOOL)evaluateWithObject: (id)object
{
id leftKey, rightKey;
leftKey = [object valueForKey: _leftKey];
rightKey = [object valueForKey: _rightKey];
if (sel_eq(_selector, EOQualifierOperatorEqual) == YES)
{
return [leftKey isEqual: rightKey] == NSOrderedSame;
}
else if (sel_eq(_selector, EOQualifierOperatorNotEqual) == YES)
{
return [leftKey isEqual: rightKey] != NSOrderedSame;
}
else if (sel_eq(_selector, EOQualifierOperatorLessThan) == YES)
{
return [leftKey compare: rightKey] == NSOrderedAscending;
}
else if (sel_eq(_selector, EOQualifierOperatorGreaterThan) == YES)
{
return [leftKey compare: rightKey] == NSOrderedDescending;
}
else if (sel_eq(_selector, EOQualifierOperatorLessThanOrEqualTo) == YES)
{
return [leftKey compare: rightKey] != NSOrderedDescending;
}
else if (sel_eq(_selector, EOQualifierOperatorGreaterThanOrEqualTo) == YES)
{
return [leftKey compare: rightKey] != NSOrderedAscending;
}
else if (sel_eq(_selector, EOQualifierOperatorContains) == YES)
{
[self notImplemented: _cmd];
return NO;
}
else if (sel_eq(_selector, EOQualifierOperatorLike) == YES)
{
NSEmitTODO(); //TODO
return [leftKey isEqual: rightKey]
== NSOrderedSame;
}
else if (sel_eq(_selector, EOQualifierOperatorCaseInsensitiveLike) == YES)
{
NSEmitTODO(); //TODO
return [[leftKey uppercaseString] isEqual: [rightKey uppercaseString]]
== NSOrderedSame;
}
return NO;
}
- (NSString *)description
{
return [NSString stringWithFormat:@"<%s %p - %@ %@ %@>",
object_get_class_name(self),
(void*)self,
_leftKey,
[isa stringForOperatorSelector:_selector],
_rightKey];
}
@end

63
EOControl/EOKeyGlobalID.h Normal file
View file

@ -0,0 +1,63 @@
/*
EOKeyGlobalID.h
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: June 2000
This file is part of the GNUstep Database Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __EOKeyGlobalID_h__
#define __EOKeyGlobalID_h__
#import <EOControl/EOGlobalID.h>
@interface EOKeyGlobalID : EOGlobalID <NSCoding>
{
unsigned short _keyCount;
NSString *_entityName;
id *_keyValues;
}
+ (id)globalIDWithEntityName: (NSString *)entityName
keys: (id *)keys
keyCount: (unsigned)count
zone: (NSZone *)zone;
- (NSString *)entityName;
- (id *)keyValues;
- (unsigned)keyCount;
- (NSArray *)keyValuesArray;
- (BOOL)isEqual: other;
- (unsigned)hash;
- (void)encodeWithCoder: (NSCoder *)aCoder;
- (id)initWithCoder: (NSCoder *)aDecoder;
- (BOOL) isFinal;
- (NSString*)description;
- (BOOL)areKeysAllNulls;
@end
#endif

221
EOControl/EOKeyGlobalID.m Normal file
View file

@ -0,0 +1,221 @@
/**
EOKeyGlobalID.m <title>EOKeyGlobalID Class</title>
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
Date: June 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
static char rcsId[] = "$Id$";
#import <EOControl/EOKeyGlobalID.h>
#import <EOControl/EODebug.h>
#import <EOControl/EONull.h>
@implementation EOKeyGlobalID
+ (id)globalIDWithEntityName: (NSString *)entityName
keys: (id *)keys
keyCount: (unsigned)count
zone: (NSZone *)zone
{
EOKeyGlobalID *gid = [[[EOKeyGlobalID allocWithZone: zone] init]
autorelease];
int i;
ASSIGN(gid->_entityName, entityName);
gid->_keyCount = count;
gid->_keyValues = NSZoneMalloc(zone, count * sizeof(id));
for (i = 0; i < count; i++)
{
gid->_keyValues[i] = nil;
ASSIGN(gid->_keyValues[i], keys[i]);
}
if ([gid areKeysAllNulls])
NSWarnLog(@"All key of globalID %p (%@) are nulls",
gid,
gid);
return gid;
}
- (void)dealloc
{
int i;
for (i = 0; i < _keyCount; i++)
DESTROY(_keyValues[i]);
NSZoneFree(NULL, _keyValues);
DESTROY(_entityName);
[super dealloc];
}
- (NSString *)entityName
{
return _entityName;
}
- (id *)keyValues
{
return _keyValues;
}
- (unsigned)keyCount
{
return _keyCount;
}
- (NSArray *)keyValuesArray
{
return [NSArray arrayWithObjects: _keyValues count: _keyCount];
}
- (BOOL)isEqual: other
{
unsigned short oCount;
int i;
id *oValues;
if (self == other)
return YES;
if ([self hash] != [other hash])
return NO;
if ([_entityName isEqualToString: [other entityName]] == NO)
return NO;
oCount = [other keyCount];
oValues = [other keyValues];
for (i = 0; i < oCount; i++)
if ([_keyValues[i] isEqual: oValues[i]] == NO)
return NO;
return YES;
}
- (unsigned int)hash // TODO
{
int i;
unsigned int hash = 0;
for (i = 0; i < _keyCount; i++)
hash += [_keyValues[i] hash];
hash += [_entityName hash];
return hash;
}
- (void)encodeWithCoder: (NSCoder *)coder
{
[coder encodeValueOfObjCType: @encode(unsigned short) at: &_keyCount];
[coder encodeObject: _entityName];
[coder encodeArrayOfObjCType: @encode(id) count: _keyCount at: _keyValues];
}
- (id)initWithCoder: (NSCoder *)coder
{
self = [super init];
[coder decodeValueOfObjCType: @encode(unsigned short) at: &_keyCount];
_entityName = [[coder decodeObject] retain];
_keyValues = NSZoneMalloc([coder objectZone], _keyCount);
[coder decodeArrayOfObjCType: @encode(id) count: _keyCount at: _keyValues];
return self;
}
- (id)copyWithZone: (NSZone *)zone
{
EOKeyGlobalID *gid = [super copyWithZone: zone];
int i;
ASSIGN(gid->_entityName, _entityName);
gid->_keyCount = _keyCount;
gid->_keyValues = NSZoneMalloc(zone, _keyCount * sizeof(id));
for (i = 0; i < _keyCount; i++)
{
gid->_keyValues[i] = nil;
ASSIGN(gid->_keyValues[i], _keyValues[i]);
}
return gid;
}
- (BOOL) isFinal
{
// [self notImplemented:_cmd]; //TODO
return YES;
}
- (NSString*)description
{
NSString *dscr;
int i;
dscr = [NSString stringWithFormat: @"<%s %p - Entity %@ - keysValues:",
object_get_class_name(self),
(void*)self,
_entityName];
for(i = 0; i < _keyCount; i++)
{
dscr = [dscr stringByAppendingFormat: @"\"%@\" (%@) ",
_keyValues[i],
[_keyValues[i] class]];
}
dscr = [dscr stringByAppendingString: @">"];
return dscr;
}
-(BOOL)areKeysAllNulls
{
int i;
BOOL areNulls = YES;
for (i = 0; areNulls && i < _keyCount; i++)
areNulls = isNilOrEONull(_keyValues[i]);
return areNulls;
}
@end

Some files were not shown because too many files have changed in this diff Show more