writing entries in DB.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

writing entries in DB.

Prabhakar Pandey
Hello,

This is my entitymodel.xml file

<entity entity-name="Employee" package-name="org.ofbiz.hello1" title="Hello
Person Entity">

      <field name="empId" type="id-ne" ></field>
      <field name="firstName" type="name"></field>
      <field name="lastName" type="name"></field>
      <field name="email" type="name"></field>
      <prim-key field="empId"/>
    </entity>

This is part of EmployeeServices,java

GenericValue employee = delegator.makeValue("Employee");
    employee.put("empId",12);
    employee.put("firstName",firstName);
        employee.put("lastName", lastName);
        employee.put("email", email);


when i am giving hard coded value for empId then its getting stored in DB.
i want to autoassign that field so that i don't have to hard-code the value
again and again ... Any help on this?
Thanks in advance!
Reply | Threaded
Open this post in threaded view
|

Re: writing entries in DB.

Deepak Dixit-2
Hi Prabhakar,

You should have service engine utility.
In OFBiz for CRUD operation we use services. You can write service using entity-auto.
Please refer example/services.xml for more reference.

<service name="createExample" default-entity-name="Example" engine="entity-auto" invoke="create" auth="true">


Thanks & Regards
--
Deepak Dixit
HotWax Media Pvt. Ltd.
www.hotwaxmedia.com
Contact :- +91-98267-54548
Skype  :- deepakdixit

On Jul 13, 2012, at 10:47 AM, Prabhakar Pandey wrote:

> Hello,
>
> This is my entitymodel.xml file
>
> <entity entity-name="Employee" package-name="org.ofbiz.hello1" title="Hello
> Person Entity">
>
>      <field name="empId" type="id-ne" ></field>
>      <field name="firstName" type="name"></field>
>      <field name="lastName" type="name"></field>
>      <field name="email" type="name"></field>
>      <prim-key field="empId"/>
>    </entity>
>
> This is part of EmployeeServices,java
>
> GenericValue employee = delegator.makeValue("Employee");
>    employee.put("empId",12);
>    employee.put("firstName",firstName);
>        employee.put("lastName", lastName);
>        employee.put("email", email);
>
>
> when i am giving hard coded value for empId then its getting stored in DB.
> i want to autoassign that field so that i don't have to hard-code the value
> again and again ... Any help on this?
> Thanks in advance!


smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: writing entries in DB.

Prabhakar Pandey
Also it would be great if any1 could tell me how can i retrieve values from
database using Java services and events only.


On Fri, Jul 13, 2012 at 11:02 AM, Deepak Dixit <[hidden email]
> wrote:

> Hi Prabhakar,
>
> You should have service engine utility.
> In OFBiz for CRUD operation we use services. You can write service using
> entity-auto.
> Please refer example/services.xml for more reference.
>
> <service name="createExample" default-entity-name="Example"
> engine="entity-auto" invoke="create" auth="true">
>
>
> Thanks & Regards
> --
> Deepak Dixit
> HotWax Media Pvt. Ltd.
> www.hotwaxmedia.com
> Contact :- +91-98267-54548
> Skype  :- deepakdixit
>
> On Jul 13, 2012, at 10:47 AM, Prabhakar Pandey wrote:
>
> > Hello,
> >
> > This is my entitymodel.xml file
> >
> > <entity entity-name="Employee" package-name="org.ofbiz.hello1"
> title="Hello
> > Person Entity">
> >
> >      <field name="empId" type="id-ne" ></field>
> >      <field name="firstName" type="name"></field>
> >      <field name="lastName" type="name"></field>
> >      <field name="email" type="name"></field>
> >      <prim-key field="empId"/>
> >    </entity>
> >
> > This is part of EmployeeServices,java
> >
> > GenericValue employee = delegator.makeValue("Employee");
> >    employee.put("empId",12);
> >    employee.put("firstName",firstName);
> >        employee.put("lastName", lastName);
> >        employee.put("email", email);
> >
> >
> > when i am giving hard coded value for empId then its getting stored in
> DB.
> > i want to autoassign that field so that i don't have to hard-code the
> value
> > again and again ... Any help on this?
> > Thanks in advance!
>
>
Reply | Threaded
Open this post in threaded view
|

Re: writing entries in DB.

Rishi Solanki
Prabhakar,

Use GenericDelegator class methods for doing so.
Not sure if you go thru the practice application tutorial -
https://cwiki.apache.org/OFBIZ/ofbiz-tutorial-a-beginners-development-guide.html

--
Rishi Solanki


On Fri, Jul 13, 2012 at 11:54 AM, Prabhakar Pandey <[hidden email]>wrote:

> Also it would be great if any1 could tell me how can i retrieve values from
> database using Java services and events only.
>
>
> On Fri, Jul 13, 2012 at 11:02 AM, Deepak Dixit <
> [hidden email]
> > wrote:
>
> > Hi Prabhakar,
> >
> > You should have service engine utility.
> > In OFBiz for CRUD operation we use services. You can write service using
> > entity-auto.
> > Please refer example/services.xml for more reference.
> >
> > <service name="createExample" default-entity-name="Example"
> > engine="entity-auto" invoke="create" auth="true">
> >
> >
> > Thanks & Regards
> > --
> > Deepak Dixit
> > HotWax Media Pvt. Ltd.
> > www.hotwaxmedia.com
> > Contact :- +91-98267-54548
> > Skype  :- deepakdixit
> >
> > On Jul 13, 2012, at 10:47 AM, Prabhakar Pandey wrote:
> >
> > > Hello,
> > >
> > > This is my entitymodel.xml file
> > >
> > > <entity entity-name="Employee" package-name="org.ofbiz.hello1"
> > title="Hello
> > > Person Entity">
> > >
> > >      <field name="empId" type="id-ne" ></field>
> > >      <field name="firstName" type="name"></field>
> > >      <field name="lastName" type="name"></field>
> > >      <field name="email" type="name"></field>
> > >      <prim-key field="empId"/>
> > >    </entity>
> > >
> > > This is part of EmployeeServices,java
> > >
> > > GenericValue employee = delegator.makeValue("Employee");
> > >    employee.put("empId",12);
> > >    employee.put("firstName",firstName);
> > >        employee.put("lastName", lastName);
> > >        employee.put("email", email);
> > >
> > >
> > > when i am giving hard coded value for empId then its getting stored in
> > DB.
> > > i want to autoassign that field so that i don't have to hard-code the
> > value
> > > again and again ... Any help on this?
> > > Thanks in advance!
> >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: writing entries in DB.

mateen.ahmed
In reply to this post by Deepak Dixit-2

//you have to keep the input values in map like
Map createPersonCtx = UtilMisc.toMap("empId",empId,"firstname", firstName, "lastname", lastName,"email",email);
//then make the value
GenericValue genEmp = delegator.makeValue("Employee");
//keep the value in the map
genEmp.putAll(createPersonCtx);
try {
//save it in the database
    GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
    delegator.createOrStore(employee);
} catch (GenericEntityException e) {
    e.printStackTrace();
}

NOTE: you have to import the following
import java.util.Map;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.base.util.UtilMisc;
Reply | Threaded
Open this post in threaded view
|

Re: writing entries in DB.

mateen.ahmed
Hello,


       What should i reply

Regards,
Mateen

On Sat, Jan 24, 2015 at 2:28 PM, mateen.ahmed [via OFBiz] <[hidden email]> wrote:

//you have to keep the input values in map like
Map createPersonCtx = UtilMisc.toMap("empId",empId,"firstname", firstName, "lastname", lastName,"email",email);
//then make the value
GenericValue genEmp = delegator.makeValue("Employee");
//keep the value in the map
genEmp.putAll(createPersonCtx);
try {
//save it in the database
    GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
    delegator.createOrStore(employee);
} catch (GenericEntityException e) {
    e.printStackTrace();
}

NOTE: you have to import the following
import java.util.Map;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.base.util.UtilMisc;



If you reply to this email, your message will be added to the discussion below:
http://ofbiz.135035.n4.nabble.com/writing-entries-in-DB-tp4634782p4662284.html
To unsubscribe from writing entries in DB., click here.
NAML