简体   繁体   中英

How to add a LIST item with Java API Repository in Oracle ATG?

I create this repository:

<gsa-template>

<item-descriptor name="indirizzo" >
    <table name="INDIRIZZO" type="primary" id-column-name="ID_INDIRIZZO">
        <property name="via" data-type="string" column-name="VIA" />
        <property name="civico" data-type="int" column-name="CIVICO" />
    </table>
</item-descriptor>


<item-descriptor name="utente" >
    <table name="UTENTE" type="primary" id-column-name="ID_UTENTE">
        <property name="nome" data-type="string" column-name="NOME" />
        <property name="cognome" data-type="string" column-name="COGNOME" />
        <property name="indirizzi" data-type="list" component-item-type="indirizzo" />
    </table>
</item-descriptor>

In the Java class I want to add a new user with a multiple address. Then I want to use the Java API repository. I tried this:

MutableRepositoryItem item_utente = getMutableRepository().createItem(
                UTENTE);
        MutableRepositoryItem item_indirizzo = getMutableRepository().createItem(
                INDIRIZZO);

        item_indirizzo.setPropertyValue(VIA, v1);
        item_indirizzo.setPropertyValue(CIVICO, civ1);
        getMutableRepository().addItem(item_indirizzo);
        item_indirizzo.setPropertyValue(VIA, v2);
        item_indirizzo.setPropertyValue(CIVICO, civ2);
        getMutableRepository().addItem(item_indirizzo);

        item_utente.setPropertyValue(NOME, n);
        item_utente.setPropertyValue(COGNOME, c);
        item_utente.setPropertyValue(INDIRIZZI, item_indirizzo);

        getMutableRepository().addItem(item_utente);

but it does not work, I SUPPOSE because I did not create an actual java list. I want to insert in my DB an user with respective 2 or more addresses. Some different idea or do I fix my code?

If your datatype is list, you can add items using an xml just like you do for primitive data types with comma separated values as below:

<add-item item-descriptor="utente" id="test1">
    <set-property name="nome" value="testNome"/>
    <set-property name="cognome" value="testCognome"/>
    <set-property name="indirizzi" value="test2,test3,test4"/>
</add-tem>

Take look at below page for more details.

http://docs.oracle.com/cd/E24152_01/Platform.10-1/ATGRepositoryGuide/html/s1302setproperty01.html

create the List of Repository item .

List<RepositoryItem> item_indirizzo_List=new ArrayList<RepositoryItem>();

add item to the list. And then add like below

item_utente.setPropertyValue(INDIRIZZI, item_indirizzo_List);

May be this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM