on 03-16-2006 2:00 PM
hello,
i need to insert in my syncBo more than 1 Row structure.
this example working if i want insert 1 row related to 1 toprow structure:
<i> public void insertNewSyncBo() {
SyncBo newCustomerOrder = this.syncBoDataFacade.createEmptySyncBo(this.customerOrderD);
Row customerOrderHead = newCustomerOrder.getTopRow();
customerOrderHead.setFieldValue(this.customerNumberD, "987");
customerOrderHead.setFieldValue(this.orderValueD, new FixedDecimal("1234,25"));
customerOrderHead.setFieldValue(this.salesRegion, "Walldorf");
<b>// add 1 Row</b>
Row customerOrderItem = newCustomerOrder.createEmptyRow(customerOrderItemD);
customerOrderItem.setFieldValue(this.productNumberD, new Integer(1241294));
customerOrderItem.setQuantity(this.productNumberD, new Integer(3));
<b>//if i need insert another Row in this bo?</b>
//insert Bo locally
this.syncBoDataFacade.insertSyncBo(newCustomerOrder);
}</i>
> <i> public void insertNewSyncBo() {
> SyncBo newCustomerOrder =
> der =
> this.syncBoDataFacade.createEmptySyncBo(this.customerO
> rderD);
>
> Row customerOrderHead =
> ead = newCustomerOrder.getTopRow();
>
>
>
>
> customerOrderHead.setFieldValue(this.customerNumberD,
> "987");
>
> customerOrderHead.setFieldValue(this.orderValueD,
> ueD, new FixedDecimal("1234,25"));
>
> customerOrderHead.setFieldValue(this.salesRegion,
> ion, "Walldorf");
>
> <b>// add 1 Row</b>
> Row customerOrderItem =
> tem =
> newCustomerOrder.createEmptyRow(customerOrderItemD);
>
>
>
>
> customerOrderItem.setFieldValue(this.productNumberD,
> , new Integer(1241294));
>
>
> customerOrderItem.setQuantity(this.productNumberD,
> rD, new Integer(3));
>
> <b>//if i need insert another Row in this bo?</b>
at this point i need to add in my syncbo another Row object .
i need to use these methods:
createInitialCopy()
createUnlinkedCopy()
?
>
> //insert Bo locally
>
>
>
>
> this.syncBoDataFacade.insertSyncBo(newCustomerOrder);
>
> }</i>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Elina ,
u can use,,,
in this way...
SyncBo unlinkedCopy = existingSyncBo.createUnlinkedCopy();
Row newRow = unlinkedCopy.createEmptyRow(rowDesc);
//Set some values to the new row
//Insert the row into the syncbo
unlinkedCopy.insertRow(newRow);
//Commit the txn
refer this link also..
Regards
Kishor Gopinathan
if i want insert 2 child Row in the same syncbo?
SyncBo unlinkedCopy = existingSyncBo.createUnlinkedCopy();
Row newRow1 = unlinkedCopy.createEmptyRow(rowDesc);
Row newRow2 = unlinkedCopy.createEmptyRow(rowDesc);
//Set some values to the new row
//Insert the row into the syncbo
unlinkedCopy.insertRow(newRow1);
unlinkedCopy.insertRow(newRow2);
//Commit the txn
HI Elina
u can try in this way also...
SyncBo unlinkedCopy = existingSyncBo.createUnlinkedCopy();
Row newRow1 = unlinkedCopy.createEmptyRow(rowDesc);
<b> Row newRow2 = newRow1.createInitialCopy();</b>
ur code will work perfectly..
refer this also...
Regards
Kishor Gopinathan
hello eliana,
looking in your code, at the point where you are asking what
to use, createUnlinkedCopy or createInitialCopy; note
that you can only use
SyncBo.createInitialCopy or Row.createInitialCopy
coz your SyncBo as well as Row instances at that point are
still NOT inserted in the repository. you can only use
createUnlinkedCopy from objects that are already inserted
in the local repository.
use insertSyncBo or insertRow method when inserting the
initial copies, and replaceSyncBo or replaceRow when replacing
the existing object that is already in the local repository with that of your unlinked copies.
regards
jo
Hi Jo,
can explain me?
i have this code but when i read the values of fields of the Row the result is NULL.
my code:
+ /* MODIFIED VERSION OF ADDROW IN DB.
WE TRY TO ADD ONE SYNC BO WITH ONE TOP STRUCTURE AND A CERTAIN NUMBER OF
CHILD STRUCUTRE INSTANCES, BUT THE CHILD FIELDS ARE INSERTED NULL
*/
public String addRowInDB(String syBName, Vector HeaderFieldNames, Vector ChildFieldNames, Vector HeaderValues, Vector ChildValues, String Structure)
throws SmartSyncException, PersistenceException
{
String ToReturn = "";
String syncBoName = syBName;
SyncBoDescriptor sbd = descriptorFacade.getSyncBoDescriptor(syBName);
System.out.println("descriptor: " + syBName);
SmartSyncTransactionManager transactionManager;
String[] IdeaMalsana = new String[] {"010", "020", "030", "040", "050", "060"};
transactionManager = dataFacade.getSmartSyncTransactionManager();
// here we insert the header values and all is ok with that
try
{
// Create new syncbo
SyncBo newsyncBo = dataFacade.createEmptySyncBo(sbd);
// A transaction manager is valid for one action starting with beginTransaction and ending with commit/rollback
// In this example we commit (save) every row we add - no rollback.
for (int i = 0; i < HeaderFieldNames.size(); i++) {
System.out.println("header: "+ HeaderFieldNames.elementAt(i).toString() + ": " + HeaderValues.elementAt(i));
if (HeaderValues.elementAt(i) != null) {
System.out.println(
setHeaderFieldValue(
newsyncBo,
HeaderFieldNames.elementAt(i).toString(),
HeaderValues.elementAt(i).toString()));
}
else
ToReturn = "Tipo dati non supportato nel campo.";
}
int ElementCounter = 0;
// HERE WE TRY TO INSERT CHILD STRUCTURES, CYCLING ON A VACTOR
// THAT GOES THROUGH ALL CHILD FIELD NAMES
RowDescriptor rd = null;
for(int count=0;count<ChildValues.size();count++)
{
try
{
rd = sbd.getRowDescriptor("010");
Row r010Row = newsyncBo.createEmptyRow(rd).createInitialCopy();
FieldDescriptor r010MovDesc = rd.getFieldDescriptor(ChildFieldNames.elementAt(ElementCounter).toString());
System.out.println("CAMPO CORRENTE: " + r010MovDesc.getFieldName());
System.out.println("----
-
: " + count);
BasisFieldType bft = r010MovDesc.getFieldType();
System.out.println(ChildFieldNames.elementAt(ElementCounter).toString() + ": " + ChildValues.elementAt(count));
if(bft == BasisFieldType.C)
{
System.out.print("tipo dati carattere ");
System.out.println("adding: " + ChildValues.elementAt(count));
r010Row.modifyFieldValue(r010MovDesc, (String) ChildValues.elementAt(count));
//Campo.setValue((String) ChildValues.elementAt(c));
}
else if(bft == BasisFieldType.P)
{
System.out.print("tipo dati P - bigdecimal ");
BigDecimal bd = new BigDecimal((String) ChildValues.elementAt(count));
System.out.println("adding: " + ChildValues.elementAt(count));
r010Row.modifyFieldValue(r010MovDesc, bd);
//Campo.setValue(bd);
}
else if(bft == BasisFieldType.N)
{
System.out.print("tipo dati N - biginteger ");
BigInteger bi = new BigInteger((String) ChildValues.elementAt(count));
System.out.println("adding: " + ChildValues.elementAt(count));
r010Row.modifyFieldValue(r010MovDesc, bi);
//Campo.setValue(bi);
}
else
{
ToReturn = "Tipo dati non riconosciuto.";
return ToReturn;
}
ElementCounter ++;
if(ElementCounter >= ChildFieldNames.size())
{
System.out.println("insertrow");
transactionManager.beginTransaction();
newsyncBo.insertRow(r010Row);
FieldDescriptor fd1 = rd.getFieldDescriptor("KTEXT1");
System.out.println("prima di aggiungere: " + r010Row.getFieldValue(fd1));
//System.out.println(newsyncBo.getRows());
ElementCounter = 0;
}
}
catch(NumberFormatException nf)
{
//transactionManager.rollback();
nf.printStackTrace();
ToReturn = "Formato dati non valido in uno o più campi.";
return ToReturn;
}
catch(NullPointerException npe)
{
//transactionManager.rollback();
npe.printStackTrace();
ToReturn = "Impossibile inserire uno o più campi.";
return ToReturn;
}
catch(Exception e)
{
//transactionManager.rollback();
e.printStackTrace();
ToReturn = "Impossibile processare la richiesta: " + e.getMessage();
return ToReturn;
}
}
//transactionManager.beginTransaction();
transactionManager.beginTransaction();
RowCollection rc = newsyncBo.getRows(rd);
System.out.println("Ho questi items: " + rc.iterator().elementCount());
dataFacade.insertSyncBo(newsyncBo);
transactionManager.commit();
ToReturn = "OK";
}
/*catch(PersistenceException pe)
{
pe.printStackTrace();
//transactionManager.rollback();
ToReturn = "Problema sul set di dati locali: " + pe.getReason();
}*/
catch(NumberFormatException nf)
{
nf.printStackTrace();
//transactionManager.rollback();
ToReturn = "Problema sul formato di uno o più campi";
}
catch(NullPointerException npe)
{
npe.printStackTrace();
//transactionManager.rollback();
ToReturn = "Uno o più campi risultano non valorizzati o non congruenti.";
}
catch(Exception e)
{
e.printStackTrace();
//transactionManager.rollback();
ToReturn = e.getMessage();
}
return ToReturn;
}+
Hi,
I understand that my previous posts were not so clear as Im trying different solutions at the same time, so I decided to explain in words how Im trying to proceed:
1 I create a new syncbo from datafacade (createemptysyncbo) using the proper sync bo descriptor
2 I call recursively the method: setheaderfieldvalues to evaluate and set the header fields and everything goes well
3 I loop through any element of a proper vector that I initialized to contain child field values, and, for each row I create a new row using rowdescriptor of the 010 child structure.
4 I initialize the field descriptor starting from another vector of child field names
5 I determine the type of any field and call the modifyfieldvalue for each type
6 I begin a new transaction using transactionmanager
7 I insert the row in sync bo, calling insertrow from the sync bo object
8 I commit the transaction, each of these steps are obviously executed more times depending on the loop
9 I begin a new transaction and call datafacade.insertsyncbo and then I commit
The main problem is that the header values of the sync bo just created are properly set, but NOT the child ones, witch are completely NULL..
How shoud I proceed ? .. where is my mistake ?
hello eliana,
you are using the modifyFieldValue method.
this method will only assign the value temporarily into the
Row instance and will not write it into the persistence
object unless you call the method SyncBo.modifyRow(Row);
Row newRow = parentBo.createEmptyRow(RowDescriptor);
newRow.modifyFieldValue(fieldDescriptor0, value0);
newRow.modifyFieldValue(fieldDescriptor1, value1);
newRow.modifyFieldValue(fieldDescriptor2, value2);
<b>parentBo.modifyRow(newRow);</b> //IMPORTANT
this will solve your problem.
regards
jo
Hi Elina,,
use this code template
This is one sample code ...
RowDescriptor itemRow = sbd.getRowDescriptor("010");
Row item = null;
String[] arrayItemfields = getItemFieldNames(syncBoName, "010");
for (int itemCount = 0; itemCount < itemRows.size(); itemCount++) {
item = newsyncBo.createEmptyRow(itemRow);
Vector itemLine = (Vector) itemRows.elementAt(itemCount);
String[] itemLineValues = new String[5];
for (int itemLineValCnt = 0;
itemLineValCnt < 5;
itemLineValCnt++) {
itemLineValues[itemLineValCnt] =
itemLine.elementAt(itemLineValCnt).toString();
}
for (int iCount = 0; iCount < collectItemFields.length; iCount++) {
FieldDescriptor fd =
itemRow.getFieldDescriptor(collectItemFields[iCount]);
if (fd != null) {
setFieldValue(fd, item, itemLineValues[iCount]);
}
}
newsyncBo.insertRow(item);
}
dataFacade.insertSyncBo(newsyncBo);
//Commit the transaction
transactionManager.commit();
Regards
Kishor Gopinathan
Hi Elina,
Suppose u have to add 5 010 item rows to your one SyncBo instance .. then
Then u can pass one vector with 5 elements ,which contain the data for 5 010 item...
here in that sample code .. thats i mentioned..
<b>Vector itemRows = <You have to pass this vector ></b>
then ....
loop through this vector...
SyncBoDescriptor sbd = descriptorFacade.getSyncBoDescriptor(<syncBoName>);
SmartSyncTransactionManager transactionManager;
// Create new syncbo
SyncBo newsyncBo = dataFacade.createEmptySyncBo(sbd);
RowDescriptor itemRow = sbd.getRowDescriptor("010");
Row item = null;
for (int c=0;c<itemRows.size();c++)
{
<b>item = newsyncBo.createEmptyRow(itemRow);</b>
Vector itemRowV = (Vector) itemRows.elementAt(c);
// suppose in ur one row u have 5 fields .. then for getting the values of this individual fileds .. u have to loop through this vector again...
//for storing the values of a particular row
// for easy..
<b>String[] itemLineValues = new String[itemRowV.size()+1];</b>
for(int j=0;j<itemRowV.size();j++)
{
itemLineValues[itemLineValCnt] =
itemRowV.elementAt(itemLineValCnt).toString();
}
String [] fieldNames = getItemFieldNames(syncBoName, "010") // I have mentioned this method in one forum .. for you..
for (int iCount = 0; iCount < fieldNames.length; iCount++) {
FieldDescriptor fd =
itemRow.getFieldDescriptor(fieldNames[iCount]);
if (fd != null) {
setFieldValue(fd, item, itemLineValues[iCount]);
}
}
newsyncBo.insertRow(item);
}
dataFacade.insertSyncBo(newsyncBo);
//Commit the transaction
transactionManager.commit();
}
Regards
Kishor Gopinathan
Hi Elina,
can u explain it clearly...
Regards
Kishor Gopinathan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.