You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by "Schultz, Gary T - COMMERCE" <Ga...@Wisconsin.gov> on 2011/01/13 00:40:10 UTC
Database connection
I'm starting work on an application. Normally I would use PHP, but I accidently found Apache Click. Looking at the documentation and examples, it appears easy to use. Maybe I missed it in the documentation, but how do you get data stored in a database?
In a separate email exchange I received a reply from Malcolm Edgar saying the examples use Apache Cayenne ORM framework. Is there an example that elaborates on how this is done? I've never worked with a ORM framework, is the learning curve steep? Any other ORM Frameworks worth looking at?
Sincerely,
Gary Schultz
Web Administrator/Developer
Wisconsin Department of Commerce
________________________________
CONFIDENTIALITY NOTICE: This electronic mail transmission and any accompanying documents may contain confidential and legally privileged information. If you are not the intended recipient, you are strictly prohibited from any disclosure, copying, distribution, or storage of the contents of the information contained in the transmission. If you have received this transmission in error, please notify the sender and delete the message. Thank you.
Re: Database connection
Posted by Gilberto <gi...@gmail.com>.
Hi, Gary!
At the beginning I've tried to do like those experienced java gays told you:
database layer->service layer->web layer(click pages).
I've even created an google project[1] to show every one how to integrate
JPA with Click. But at the end, as a beginner java programmer, I've got
frustrated with that code and now I'm trying to do things more simple.
Learning how to get things together manually.
So, I'm using JPA, mainly Eclipselink[2], which is very easy to setup and
use. Take a look at the EditLegalEntity.java and ViewEditLegalEntity.java
classes[3]. The database setup is done in persistence.xml file[4] and I've
used the EntityManagerContext.java class[5] bootstrap it all.
Hth,
Gilberto
[1]http://code.google.com/p/construtor
[2]http://www.eclipse.org/eclipselink/
[3a]
http://code.google.com/p/construtor/source/browse/trunk/cip/park/src/main/java/park/web/page/EditLegalEntity.java?r=760
[3b]
http://code.google.com/p/construtor/source/browse/trunk/cip/park/src/main/java/park/web/page/ViewLegalEntity.java?r=760
[4]http://www.vogella.de/articles/JavaPersistenceAPI/article.html
[5]
http://code.google.com/p/construtor/source/browse/trunk/cip/park/src/main/java/park/orm/util/EntityManagerContext.java?r=760
2011/1/13 Schultz, Gary T - COMMERCE <Ga...@wisconsin.gov>
> Thanks for the information, I have read the Tomcat jdni resources how to. I
> also found the following to help myself understand:
>
> http://www.datadisk.co.uk/html_docs/java_app/tomcat6/tomcat6_jdbc.htm
>
> http://www.mulesoft.com/tomcat-mysql
>
> I guess my confusion stills exists in how Click is actually referencing the
> data source. In looking at the examples I can't figure it out. Maybe my lack
> of knowledge in ORM is hindering my ability to comprehend this.
>
> - Gary
>
> -----Original Message-----
> From: Bob Schellink [mailto:sabob1@gmail.com]
> Sent: Thursday, January 13, 2011 12:25 AM
> To: user@click.apache.org
> Subject: Re: Database connection
>
> You could manage the JDBC connection yourself or you could let your
> container take care of it for you. However this is dependent on the
> container you use. Here is how to do it in Tomcat:
>
>
> http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#JDBC_Data_Sources
>
> In Java folks generally use a layered approach as can be seen in the Click
> examples, where you have separate packages for your services and pages.
> Other prefer to package by feature where each feature is placed in it's own
> package and will include the Page and Service.
>
> So depending on how you build your app will determine where your JDBC code
> lives. When using JDBC directly the code will live in a special layer just
> for Database access, often called a DAO layer.
>
> But nothing stops you from simply grabbing the JDBC connection in your Page
> and making database calls from there.
>
> Kind regards
>
> Bob
>
> On 13/01/2011 14:21, Schultz, Gary T - COMMERCE wrote:
> > I've worked with JDBC and last programmed in Java about six years ago.
> >
> > Concerning the Click data connection. After getting the JDBC connection
> established in Click application context.xml and web.xml, can I simply call
> the data connection in a Click page class and if so how is that done? Or is
> it more complicated?
> >
> > - Gary
> >
> > ________________________________________
> > From: Bob Schellink [sabob1@gmail.com]
> > Sent: Wednesday, January 12, 2011 6:03 PM
> > To: user@click.apache.org
> > Subject: Re: Database connection
> >
> > Hi Gary,
> >
> > ORMs are sophisticated tools and while they are great tools in
> > enterprise environments, they have steep learning curves. There are
> > many other ORMs besides Cayenne, including Hibernate and the standard
> Java Persistence API or JPA for short.
> >
> > There are also simpler database tools like MyBatis which is more of a
> > database mapping tool than a full blown ORM.
> >
> > While Click examples uses Cayenne you could always use straight JDBC
> which is more low level.
> >
> > WRT how this is done, there is a Cayenne DataContextFilter defined in
> > web.xml which bootstraps the environment. Cayenne has a modeler where
> > you define your DB connection and Cayenne manage these connections for
> > you. Once the DataContext is defined you use it to perform CRUD
> operations using your domain objects.
> >
> > Having a background in PHP myself I'd say that Java is heavily geared
> > towards enterprise and you will find it "heavier" than the scripting
> environment of PHP.
> >
> > Kind regards
> >
> > Bob
> >
> > On 13/01/2011 10:40, Schultz, Gary T - COMMERCE wrote:
> >> I'm starting work on an application. Normally I would use PHP, but I
> accidently found Apache Click.
> >> Looking at the documentation and examples, it appears easy to use.
> >> Maybe I missed it in the documentation, but how do you get data stored
> in a database?
> >>
> >> In a separate email exchange I received a reply from Malcolm Edgar
> >> saying the examples use Apache Cayenne ORM framework. Is there an
> >> example that elaborates on how this is done? I've never worked with a
> ORM framework, is the learning curve steep? Any other ORM Frameworks worth
> looking at?
> >>
> >> Sincerely,
> >>
> >> Gary Schultz
> >> Web Administrator/Developer
> >> Wisconsin Department of Commerce
> >>
> >> ---------------------------------------------------------------------
> >> ------------------------------- CONFIDENTIALITY NOTICE: This
> >> electronic mail transmission and any accompanying documents may
> >> contain confidential and legally privileged information. If you are
> >> not the intended recipient, you are strictly prohibited from any
> >> disclosure, copying, distribution, or storage of the contents of the
> >> information contained in the transmission. If you have received this
> transmission in error, please notify the sender and delete the message.
> Thank you.
> >
> >
> > CONFIDENTIALITY NOTICE: This electronic mail transmission and any
> accompanying documents may contain confidential and legally privileged
> information. If you are not the intended recipient, you are strictly
> prohibited from any disclosure, copying, distribution, or storage of the
> contents of the information contained in the transmission. If you have
> received this transmission in error, please notify the sender and delete the
> message. Thank you.
> >
>
>
Re: Database connection
Posted by Bob Schellink <sa...@gmail.com>.
On 14/01/2011 05:57, Schultz, Gary T - COMMERCE wrote:
> Thanks for the information, I have read the Tomcat jdni resources how to. I also found the following to help myself understand:
>
> http://www.datadisk.co.uk/html_docs/java_app/tomcat6/tomcat6_jdbc.htm
>
> http://www.mulesoft.com/tomcat-mysql
>
> I guess my confusion stills exists in how Click is actually referencing the data source. In looking at the examples I can't figure it out. Maybe my lack of knowledge in ORM is hindering my ability to comprehend this.
Just to clarify, Click is only a view layer and doesn't do any DB work for you. It doesn't reference
the data source. But I think what you mean is how do you lookup the data source yourself?
In your second link they have this:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/[YourResourceName]");
// Here you can use ds
Also note that Click is built on the Servlet API. You can get access to the Servlet API through the
org.apache.click.Context object. In a page do:
Context ctx = getContext();
ctx.getRequest();
ctx.getResponse();
etc.
In a Service object you can get access to the Context object like so:
Context ctx = Context.getThreadLocalContext();
getContext().getRequest();
getContext().getResponse();
Hope this helps.
Kind regards
Bob
RE: Database connection
Posted by "Schultz, Gary T - COMMERCE" <Ga...@Wisconsin.gov>.
Thanks for the information, I have read the Tomcat jdni resources how to. I also found the following to help myself understand:
http://www.datadisk.co.uk/html_docs/java_app/tomcat6/tomcat6_jdbc.htm
http://www.mulesoft.com/tomcat-mysql
I guess my confusion stills exists in how Click is actually referencing the data source. In looking at the examples I can't figure it out. Maybe my lack of knowledge in ORM is hindering my ability to comprehend this.
- Gary
-----Original Message-----
From: Bob Schellink [mailto:sabob1@gmail.com]
Sent: Thursday, January 13, 2011 12:25 AM
To: user@click.apache.org
Subject: Re: Database connection
You could manage the JDBC connection yourself or you could let your container take care of it for you. However this is dependent on the container you use. Here is how to do it in Tomcat:
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#JDBC_Data_Sources
In Java folks generally use a layered approach as can be seen in the Click examples, where you have separate packages for your services and pages. Other prefer to package by feature where each feature is placed in it's own package and will include the Page and Service.
So depending on how you build your app will determine where your JDBC code lives. When using JDBC directly the code will live in a special layer just for Database access, often called a DAO layer.
But nothing stops you from simply grabbing the JDBC connection in your Page and making database calls from there.
Kind regards
Bob
On 13/01/2011 14:21, Schultz, Gary T - COMMERCE wrote:
> I've worked with JDBC and last programmed in Java about six years ago.
>
> Concerning the Click data connection. After getting the JDBC connection established in Click application context.xml and web.xml, can I simply call the data connection in a Click page class and if so how is that done? Or is it more complicated?
>
> - Gary
>
> ________________________________________
> From: Bob Schellink [sabob1@gmail.com]
> Sent: Wednesday, January 12, 2011 6:03 PM
> To: user@click.apache.org
> Subject: Re: Database connection
>
> Hi Gary,
>
> ORMs are sophisticated tools and while they are great tools in
> enterprise environments, they have steep learning curves. There are
> many other ORMs besides Cayenne, including Hibernate and the standard Java Persistence API or JPA for short.
>
> There are also simpler database tools like MyBatis which is more of a
> database mapping tool than a full blown ORM.
>
> While Click examples uses Cayenne you could always use straight JDBC which is more low level.
>
> WRT how this is done, there is a Cayenne DataContextFilter defined in
> web.xml which bootstraps the environment. Cayenne has a modeler where
> you define your DB connection and Cayenne manage these connections for
> you. Once the DataContext is defined you use it to perform CRUD operations using your domain objects.
>
> Having a background in PHP myself I'd say that Java is heavily geared
> towards enterprise and you will find it "heavier" than the scripting environment of PHP.
>
> Kind regards
>
> Bob
>
> On 13/01/2011 10:40, Schultz, Gary T - COMMERCE wrote:
>> I'm starting work on an application. Normally I would use PHP, but I accidently found Apache Click.
>> Looking at the documentation and examples, it appears easy to use.
>> Maybe I missed it in the documentation, but how do you get data stored in a database?
>>
>> In a separate email exchange I received a reply from Malcolm Edgar
>> saying the examples use Apache Cayenne ORM framework. Is there an
>> example that elaborates on how this is done? I've never worked with a ORM framework, is the learning curve steep? Any other ORM Frameworks worth looking at?
>>
>> Sincerely,
>>
>> Gary Schultz
>> Web Administrator/Developer
>> Wisconsin Department of Commerce
>>
>> ---------------------------------------------------------------------
>> ------------------------------- CONFIDENTIALITY NOTICE: This
>> electronic mail transmission and any accompanying documents may
>> contain confidential and legally privileged information. If you are
>> not the intended recipient, you are strictly prohibited from any
>> disclosure, copying, distribution, or storage of the contents of the
>> information contained in the transmission. If you have received this transmission in error, please notify the sender and delete the message. Thank you.
>
>
> CONFIDENTIALITY NOTICE: This electronic mail transmission and any accompanying documents may contain confidential and legally privileged information. If you are not the intended recipient, you are strictly prohibited from any disclosure, copying, distribution, or storage of the contents of the information contained in the transmission. If you have received this transmission in error, please notify the sender and delete the message. Thank you.
>
Re: Database connection
Posted by Andrew Fink <ap...@gmail.com>.
Please don't use raw JDBC.
Use Spring JDBC Templates, MyBatis, JDO or JPA.
raw JDBC is reason why pepole call Java "heavier"
Just try 200MB installation MS .Net and you will see what "heavier" means
;-(
--
View this message in context: http://click.1134972.n2.nabble.com/Database-connection-tp5916597p5917281.html
Sent from the click-user mailing list archive at Nabble.com.
Re: Database connection
Posted by Bob Schellink <sa...@gmail.com>.
You could manage the JDBC connection yourself or you could let your container take care of it for
you. However this is dependent on the container you use. Here is how to do it in Tomcat:
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#JDBC_Data_Sources
In Java folks generally use a layered approach as can be seen in the Click examples, where you have
separate packages for your services and pages. Other prefer to package by feature where each feature
is placed in it's own package and will include the Page and Service.
So depending on how you build your app will determine where your JDBC code lives. When using JDBC
directly the code will live in a special layer just for Database access, often called a DAO layer.
But nothing stops you from simply grabbing the JDBC connection in your Page and making database
calls from there.
Kind regards
Bob
On 13/01/2011 14:21, Schultz, Gary T - COMMERCE wrote:
> I've worked with JDBC and last programmed in Java about six years ago.
>
> Concerning the Click data connection. After getting the JDBC connection established in Click application context.xml and web.xml, can I simply call the data connection in a Click page class and if so how is that done? Or is it more complicated?
>
> - Gary
>
> ________________________________________
> From: Bob Schellink [sabob1@gmail.com]
> Sent: Wednesday, January 12, 2011 6:03 PM
> To: user@click.apache.org
> Subject: Re: Database connection
>
> Hi Gary,
>
> ORMs are sophisticated tools and while they are great tools in enterprise environments, they have
> steep learning curves. There are many other ORMs besides Cayenne, including Hibernate and the
> standard Java Persistence API or JPA for short.
>
> There are also simpler database tools like MyBatis which is more of a database mapping tool than a
> full blown ORM.
>
> While Click examples uses Cayenne you could always use straight JDBC which is more low level.
>
> WRT how this is done, there is a Cayenne DataContextFilter defined in web.xml which bootstraps the
> environment. Cayenne has a modeler where you define your DB connection and Cayenne manage these
> connections for you. Once the DataContext is defined you use it to perform CRUD operations using
> your domain objects.
>
> Having a background in PHP myself I'd say that Java is heavily geared towards enterprise and you
> will find it "heavier" than the scripting environment of PHP.
>
> Kind regards
>
> Bob
>
> On 13/01/2011 10:40, Schultz, Gary T - COMMERCE wrote:
>> I'm starting work on an application. Normally I would use PHP, but I accidently found Apache Click.
>> Looking at the documentation and examples, it appears easy to use. Maybe I missed it in the
>> documentation, but how do you get data stored in a database?
>>
>> In a separate email exchange I received a reply from Malcolm Edgar saying the examples use Apache
>> Cayenne ORM framework. Is there an example that elaborates on how this is done? I've never worked
>> with a ORM framework, is the learning curve steep? Any other ORM Frameworks worth looking at?
>>
>> Sincerely,
>>
>> Gary Schultz
>> Web Administrator/Developer
>> Wisconsin Department of Commerce
>>
>> ----------------------------------------------------------------------------------------------------
>> CONFIDENTIALITY NOTICE: This electronic mail transmission and any accompanying documents may contain
>> confidential and legally privileged information. If you are not the intended recipient, you are
>> strictly prohibited from any disclosure, copying, distribution, or storage of the contents of the
>> information contained in the transmission. If you have received this transmission in error, please
>> notify the sender and delete the message. Thank you.
>
>
> CONFIDENTIALITY NOTICE: This electronic mail transmission and any accompanying documents may contain confidential and legally privileged information. If you are not the intended recipient, you are strictly prohibited from any disclosure, copying, distribution, or storage of the contents of the information contained in the transmission. If you have received this transmission in error, please notify the sender and delete the message. Thank you.
>
RE: Database connection
Posted by "Schultz, Gary T - COMMERCE" <Ga...@Wisconsin.gov>.
I've worked with JDBC and last programmed in Java about six years ago.
Concerning the Click data connection. After getting the JDBC connection established in Click application context.xml and web.xml, can I simply call the data connection in a Click page class and if so how is that done? Or is it more complicated?
- Gary
________________________________________
From: Bob Schellink [sabob1@gmail.com]
Sent: Wednesday, January 12, 2011 6:03 PM
To: user@click.apache.org
Subject: Re: Database connection
Hi Gary,
ORMs are sophisticated tools and while they are great tools in enterprise environments, they have
steep learning curves. There are many other ORMs besides Cayenne, including Hibernate and the
standard Java Persistence API or JPA for short.
There are also simpler database tools like MyBatis which is more of a database mapping tool than a
full blown ORM.
While Click examples uses Cayenne you could always use straight JDBC which is more low level.
WRT how this is done, there is a Cayenne DataContextFilter defined in web.xml which bootstraps the
environment. Cayenne has a modeler where you define your DB connection and Cayenne manage these
connections for you. Once the DataContext is defined you use it to perform CRUD operations using
your domain objects.
Having a background in PHP myself I'd say that Java is heavily geared towards enterprise and you
will find it "heavier" than the scripting environment of PHP.
Kind regards
Bob
On 13/01/2011 10:40, Schultz, Gary T - COMMERCE wrote:
> I'm starting work on an application. Normally I would use PHP, but I accidently found Apache Click.
> Looking at the documentation and examples, it appears easy to use. Maybe I missed it in the
> documentation, but how do you get data stored in a database?
>
> In a separate email exchange I received a reply from Malcolm Edgar saying the examples use Apache
> Cayenne ORM framework. Is there an example that elaborates on how this is done? I've never worked
> with a ORM framework, is the learning curve steep? Any other ORM Frameworks worth looking at?
>
> Sincerely,
>
> Gary Schultz
> Web Administrator/Developer
> Wisconsin Department of Commerce
>
> ----------------------------------------------------------------------------------------------------
> CONFIDENTIALITY NOTICE: This electronic mail transmission and any accompanying documents may contain
> confidential and legally privileged information. If you are not the intended recipient, you are
> strictly prohibited from any disclosure, copying, distribution, or storage of the contents of the
> information contained in the transmission. If you have received this transmission in error, please
> notify the sender and delete the message. Thank you.
CONFIDENTIALITY NOTICE: This electronic mail transmission and any accompanying documents may contain confidential and legally privileged information. If you are not the intended recipient, you are strictly prohibited from any disclosure, copying, distribution, or storage of the contents of the information contained in the transmission. If you have received this transmission in error, please notify the sender and delete the message. Thank you.
Re: Database connection
Posted by Bob Schellink <sa...@gmail.com>.
Hi Gary,
ORMs are sophisticated tools and while they are great tools in enterprise environments, they have
steep learning curves. There are many other ORMs besides Cayenne, including Hibernate and the
standard Java Persistence API or JPA for short.
There are also simpler database tools like MyBatis which is more of a database mapping tool than a
full blown ORM.
While Click examples uses Cayenne you could always use straight JDBC which is more low level.
WRT how this is done, there is a Cayenne DataContextFilter defined in web.xml which bootstraps the
environment. Cayenne has a modeler where you define your DB connection and Cayenne manage these
connections for you. Once the DataContext is defined you use it to perform CRUD operations using
your domain objects.
Having a background in PHP myself I'd say that Java is heavily geared towards enterprise and you
will find it "heavier" than the scripting environment of PHP.
Kind regards
Bob
On 13/01/2011 10:40, Schultz, Gary T - COMMERCE wrote:
> I'm starting work on an application. Normally I would use PHP, but I accidently found Apache Click.
> Looking at the documentation and examples, it appears easy to use. Maybe I missed it in the
> documentation, but how do you get data stored in a database?
>
> In a separate email exchange I received a reply from Malcolm Edgar saying the examples use Apache
> Cayenne ORM framework. Is there an example that elaborates on how this is done? I've never worked
> with a ORM framework, is the learning curve steep? Any other ORM Frameworks worth looking at?
>
> Sincerely,
>
> Gary Schultz
> Web Administrator/Developer
> Wisconsin Department of Commerce
>
> ----------------------------------------------------------------------------------------------------
> CONFIDENTIALITY NOTICE: This electronic mail transmission and any accompanying documents may contain
> confidential and legally privileged information. If you are not the intended recipient, you are
> strictly prohibited from any disclosure, copying, distribution, or storage of the contents of the
> information contained in the transmission. If you have received this transmission in error, please
> notify the sender and delete the message. Thank you.