Thought inc.

The Dynamic O/R Mapping Company
     

CocoBase Technical Support Forums
For access to developer site with software download and doc's, please request CocoBase download and password
will be emailed to you. Response to posts will appear when answered by THOUGHT Support team.
NOTE:You must register separately with forum in order to post your questions, please click on register icon below.
Home   Frequently Asked Questions   Search   Edit your profile   Registration is free!  
Email This Page to Someone!
Show a Printable Version
CocoBase Enterprise O/R Forums > Forum Francais Questions
relation avec des cl?s sur plusieurs champs
< Previous Thread     Next Thread >
Author
Thread    Post New Thread     Post A Reply
entdemo
Member

Registered: Jul 2001
Posts: 64

J'ai d?fini plusieurs cl?s (s?par?es par des virgules) au niveau de la d?finition d'un lien mais seule la premi?re est pris en compte dans la requ?te.
Cela ne me semble pas normal.

J'utilise une seule table pour g?n?rer deux classes ayant une relation entre elles :
j'ai une table Person :
CREATE TABLE PERSON(ID NUMERIC,NAME VARCHAR(50), FIRST_NAME VARCHAR(50), SEX VARCHAR(1), ADDRESS VARCHAR(100), CITY VARCHAR(50), ZP NUMERIC, COUNTRY VARCHAR(20), PRIMARY KEY(ID))
je cr??e deux mappes :
Person avec les champs ID, NAME, FIRST_NAME , ADDRESS, CITY,
ZP, COUNTRY
Address avec les champs ID, ADDRESS, CITY, ZP, COUNTRY

je cr?e un lien Person-Address :1-1 en d?finissant ID comme cl?
et un autre Address-Person :1-M avec ADDRESS, CITY, ZP, COUNTRY comme cl?.

fichier de lien :
# This is a navigation model resource bundle
# generated by THOUGHT INC CocoBase Enterprise OR

# Person(address)xAddress(lperson)

Person_address_AUTONAV = true
Person_address_TARGET_DELETE = true
Person_address_TARGET_INSERT = true
Person_address_TARGET_UPDATE = true
Person_address_KEY = ID
Person_address_TARGET_CLASS = Address
Person_address_TARGET_MAP = Address
Person_address_TARGET_KEY = ID
Person_address_TARGET_TYPE = 1_1
Person_address_TARGET_QUALIFIER = STD_LINK
Person_address_INVERSE_OF = Address_lperson

Address_lperson_AUTONAV = true
Address_lperson_TARGET_DELETE = false
Address_lperson_TARGET_INSERT = false
Address_lperson_TARGET_UPDATE = false
Address_lperson_KEY = ID
Address_lperson_TARGET_CLASS = Person
Address_lperson_TARGET_MAP = Person
Address_lperson_TARGET_KEY = ID
Address_lperson_TARGET_TYPE = 1_1
Address_lperson_TARGET_QUALIFIER = STD_LINK
Address_lperson_INVERSE_OF = Person_address

# Person(laddress)xAddress(person)

Person_laddress_AUTONAV = true
Person_laddress_TARGET_DELETE = false
Person_laddress_TARGET_INSERT = false
Person_laddress_TARGET_UPDATE = false
Person_laddress_KEY = CITY,ADDRESS,ZP,COUNTRY
Person_laddress_TARGET_CLASS = Address
Person_laddress_TARGET_MAP = Address
Person_laddress_TARGET_KEY = ADDRESS,CITY,ZP,COUNTRY
Person_laddress_TARGET_TYPE = M_1
Person_laddress_TARGET_QUALIFIER = STD_LINK
Person_laddress_INVERSE_OF = Address_person

Address_person_AUTONAV = true
Address_person_TARGET_DELETE = true
Address_person_TARGET_INSERT = true
Address_person_TARGET_UPDATE = true
Address_person_KEY = CITY,ADDRESS,ZP,COUNTRY
Address_person_TARGET_CLASS = Person
Address_person_TARGET_MAP = Person
Address_person_TARGET_KEY = ADDRESS,CITY,ZP,COUNTRY
Address_person_TARGET_TYPE = 1_M
Address_person_TARGET_QUALIFIER = STD_LINK
Address_person_INVERSE_OF = Person_laddress

# Defined links

Person_LINKS = address,laddress
Address_LINKS = lperson,person

Je g?n?re deux classes Person et Address en " Pure Java" et j'utilise les classes CocoProxyM et SampleProxyFactoryM.

Je r?cup?re une "Person" ? partir de son id, je lis son adresse (classe Address)et je recherche toutes les personnes ? la m?me adresse(m?me rue dans m?me ville et m?me pays). Or la condition where du select ne prend en compte que le premier champ d?fini comme cl? au niveau du lien (ici "ADDRESS") :
la requ?te est : main select PERSON . ID , PERSON . NAME , PERSON . FIRST_NAME , PERSON . ADDRESS , PERSON . CITY , PERSON . ZP , PERSON . COUNTRY from PERSON where PERSON . ADDRESS = rue de Paris
alors que je voudrais :
main select PERSON . ID , PERSON . NAME , PERSON . FIRST_NAME , PERSON . ADDRESS , PERSON . CITY , PERSON . ZP , PERSON . COUNTRY from PERSON where PERSON . ADDRESS = rue de Paris and PERSON.CITY=LAVAL and PERSON.ZP=53000 and PERSON.COUNTRY=FRANCE.

Merci de m'aider ? r?soudre ce probl?me.


10-17-2001 05:40 AM
Click Here to See the Profile for entdemo    Find more posts by entdemo        Edit/Delete Message    Reply w/Quote    IP: Logged
admin
Administrator

Registered: Apr 2001
Posts: 19

Bonjour,

tout d'abord je ne suis pas s?r, mais il semble que vous avez cr?? un lien 1-1 ET un lien 1-M, n'est-ce pas ?
Si tel est le cas vous pouvez effacer le 1-1 : lorsque vous d?finissez un lien 1-M avec CocoBase vous b?n?ficiez automatiquement du lien 1-1 correspondant dans votre deuxi?me classe.
A moins que vous ne recherchiez un comportement sp?cifique ...
Et en tout ?tat de cause votre syntaxe de cl? complexe est correcte

Concernant votre probl?me de select, pourriez vous me donner la syntaxe pr?cise que vous utilisez ? Dans notre cas il me semble que qqch du genre :

Person unePersonne = new Person();
unePersonne.setId(new Integer(1))
unePersonne = (Person)myBase.select(new thought.CocoBase.CocoProxyM(unePersonne), "Person");
.....
unePersonne=(Person)navigator.loadAllLinks(unePersonne, "Person");
Address a = unePersonne.getAddress();
a=(Address)navigator.loadAllLinks(a, "Address"); // optionnel si le flag Cascade est a true
Vector lesPersonnes = a.getPersons();

devrait fonctionner.

Thought Support

10-18-2001 03:04 AM
Click Here to See the Profile for admin    Find more posts by admin        Edit/Delete Message    Reply w/Quote    IP: Logged
entdemo
Member

Registered: Jul 2001
Posts: 64

En fait j'ai cr?? deux liens car dans le sens Person vers Address, la cl? est ID alors que dans le sens Address vers Person, j'ai besoin d'une cl? complexe (ADDRESS,ZP,CITY,COUNTRY).
Le code que j'ai utilis? est :
...
Person tempPerson = new Person();
tempPerson.setId(new Long(1));
Person person = (Person)myBase.select(new CocoProxyM(tempPerson), "Person");
if (person==null)
{
System.out.println("resultat nul");
}
else
{
Navigator navigator = new Navigator(myBase, "Essai13Links");

navigator.loadLink(person, "Person", "address", false, true);
Address address = person.getAddress();
System.out.println("personne trouvee : ");
System.out.println(person.getFirstName()+" "+person.getName());
System.out.println(address);

navigator.loadLink(address, "Address", "person", false, true);
Vector otherPersons = address.getPerson();
System.out.println("");
System.out.print("other people : ");
for(int i=0; i<otherPersons.size(); i++)
{
Person other = (Person)otherPersons.elementAt(i);
System.out.println(other.getFirstName()+" "+ other.getName());
}
}
...

?a ressemble beaucoup ? ce que vous proposez...

10-18-2001 04:00 AM
Click Here to See the Profile for entdemo    Find more posts by entdemo        Edit/Delete Message    Reply w/Quote    IP: Logged
admin
Administrator

Registered: Apr 2001
Posts: 19

Ok, je vois 3 choses ? v?rifier :

- votre d?finition de cl? lors de la g?n?ration de la classe Address : vous avez bien d?coch? le champ par d?faut lu dans la bd par Cocobase (ID) pour vos 4 champs : Address, city, ...
- la d?finition des liens est case sensitive : essayez de remplacer vos champs de cl?s (ADDRESS, CITY, ...) par address, city, ....
- lors d'un deuxi?me appel au navigateur, si le graph d'objets r?sultant est d?ja en m?moire (ie s'il repr?sente un sous-graph d'un graph charg?), le navigator retournera simplement la racine du graph, et la syntaxe :
navigator.loadAllLinks(a, "Address");
doit ?tre remplac?e par :
a=(Address)navigator.loadAllLinks(a, "Address");

Dites-moi si cela vous fait avancer, si vos probl?mes persistent envoyez simplement vos cas ? l'adresse suivante : support@thoughtinc.com, et je regarderai cela de plus pr?s.

Thought Support

10-19-2001 02:23 AM
Click Here to See the Profile for admin    Find more posts by admin        Edit/Delete Message    Reply w/Quote    IP: Logged
All times are PST (US)    Post New Thread     Post A Reply
Forum Jump:
< Previous Thread     Next Thread >

Forum Rules:
Who Can Read The Forum? Any registered user or guest.
Who Can Post New Topics? Any registered user.
Who Can Post Replies? Any registered user.
Changes: Messages can be edited by their author. Messages can be deleted by their author.
Posts: HTML code is OFF. Smilies are OFF. vB code is OFF. [IMG] code is OFF.

Admin Options:
Open / Close Thread
Move Thread
Delete Thread
Edit Thread

< Contact Us - THOUGHT Inc. >

Copyright © Jelsoft Enterprises Limited 2000.
Copyright 2001 All Rights Reserved, THOUGHT Inc.