• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to do connection pooling for cmp?

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai every body,
This is vikram,I am having doubt in cmp entity bean..
I am using weblogic server5.0,backend is oracle8.0...
Please Help me how to make connection to database through cmp entity bean..
What are the steps needed to execute...?
And also i don't now how to make connection pool,
Please Help me in this ...
Awaiting for this Reply
Bye from
vikram
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
You have to create pool like this by setting properties file.
Then in weblogic-rdbms-jar.xml you have to set the pool name as given below.
This works for weblogic 5.1 and oracle 8i.
weblogic.jdbc.connectionPool.demoPool=\
url=jdbc racle:thin:@SERVER:1521:ORACLE,\
driver=oracle.jdbc.driver.OracleDriver,\
loginDelaySecs=1,\
initialCapacity=4,\
maxCapacity=50,\
capacityIncrement=2,\
allowShrinking=true,\
shrinkPeriodMins=15,\
refreshMinutes=10,\
testTable=dual,\
props=user=scott;password=tiger
weblogic.jdbc.TXDataSource.weblogic.jdbc.jts.demoPool=demoPool
#
# Add an ACL for the connection pool:
weblogic.allow.reserve.weblogic.jdbc.connectionPool.demoPool=everyone
Pool name setting in weblogic-rdbms-jar.xml
<pool-name>scmsPool</pool-name>
I hope this will solve your problem.
Thanx
Mahesh
 
Mahesh Kulkarni
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
You have to create pool like this by setting properties file.
Then in weblogic-rdbms-jar.xml you have to set the pool name as given below.
This works for weblogic 5.1 and oracle 8i.
weblogic.jdbc.connectionPool.demoPool=\
url=jdbc racle:thin:@SERVER:1521:ORACLE,\
driver=oracle.jdbc.driver.OracleDriver,\
loginDelaySecs=1,\
initialCapacity=4,\
maxCapacity=50,\
capacityIncrement=2,\
allowShrinking=true,\
shrinkPeriodMins=15,\
refreshMinutes=10,\
testTable=dual,\
props=user=scott;password=tiger
weblogic.jdbc.TXDataSource.weblogic.jdbc.jts.demoPool=demoPool
#
# Add an ACL for the connection pool:
weblogic.allow.reserve.weblogic.jdbc.connectionPool.demoPool=everyone
Pool name setting in weblogic-rdbms-jar.xml
<pool-name>demoPool</pool-name>
I hope this will solve your problem.
Thanx
Mahesh
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi vikram
For making the jdbc connectivity with cmp with weblogic server just follow the following steps...
1) In your weblogic.properties file search for
WEBLOGIC DEMO CONNECTION POOL PROPERTIES
here you have to make settings.

weblogic.jdbc.connectionPool.demoPool=\
url=jdbc:odbc:sandeep,\
driver=sun.jdbc.odbc.JdbcOdbcDriver,\
initialCapacity=1,\
maxCapacity=2,\
capacityIncrement=1,\
props=user=scott;password=tiger;server=orcl
# Add a TXDataSource for the connection pool:
weblogic.jdbc.TXDataSource.weblogic.jdbc.jts.demoPool=demoPool
#
# Add an ACL for the connection pool:
weblogic.allow.reserve.weblogic.jdbc.connectionPool.demoPool=everyone

after this save the file.

Then in the deployer after adding all the files you just click on presistance.
There you create the relational database.
There to generate the relational database. you follow the follow the following steps.
You will get fields there.
Click on only those container managed fields which you want them to represent them as relational database.
After that click trhe checkbox weblogic rdbms persistance 5.1.0
You will get three tabed panes.
first will be configuration.
there you give table name which is there in your database.
then give pool name as demoPool.
if any other pool u r creating then give that one.But note that it is case sensitive.
second tabbed pane is field-column map .
this imp. step
here give the column field names from your table.
third tabbed pane is finders.
there you write wlql query.
then save it.
then generate the container and then deploy the bean.
It will work fine.
good luck
sandeep rane
------------------
 
vikram veera
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai sandeep & mahesh,
Thanks for sending reply...
I done as your guides...
I set connection pool & deploy the bean in weblogic perfectly...
My connection pool look like this..
weblogic.jdbc.connectionPool.demoPool=\
url=jdbc dbc:sample,\
driver=sun.jdbc.odbc.JdbcOdbcDriver,\
initialCapacity=1,\
maxCapacity=2,\
capacityIncrement=1,\
props=user=scott;password=tiger;server=none
# Add a TXDataSource for the connection pool:
weblogic.jdbc.TXDataSource.weblogic.jdbc.jts.demoPool=demoPool
#
# Add an ACL for the connection pool:
weblogic.allow.reserve.weblogic.jdbc.connectionPool.demoPool=everyone

But i have a problem while running a client it through an exception
As given below
javax.ejb.EJBException
at weblogic.rmi.extensions.AbstractRequest.sendReceive(AbstractRequest.java:76)
at ProductBeanHomeImpl_WLStub.create(ProductBeanHomeImpl_WLStub.java:184)
at ProductBeanHomeImpl_ServiceStub.create(Compiled Code)
at Client.main(Compiled Code)
Destroying products..
please help me in the problem what i have to do next.....

My code is given below
Product.java
-------------
import javax.ejb.*;
import java.rmi.RemoteException;
public interface Product extends EJBObject {
// Getter/setter methods for Entity Bean fields
public String getName() throws RemoteException;
public void setName(String name) throws RemoteException;

public String getDescription() throws RemoteException;
public void setDescription(String description) throws RemoteException;
public double getBasePrice() throws RemoteException;
public void setBasePrice(double price) throws RemoteException;

public String getProductID() throws RemoteException;
}

ProductBean.java
==================
import java.sql.*;
import javax.naming.*;
import javax.ejb.*;
import java.util.*;
import java.rmi.RemoteException;

public class ProductBean implements EntityBean {
protected EntityContext ctx;
// Container-managed state fields. Note that they must
// be coderanch.
public String productID;// PK
public String name;
public String description;
public double basePrice;
public ProductBean() {
System.out.println("New Product Entity Bean Java Object created by EJB Container.");
}
//
// Business Logic Methods
//
// Simple getter/setter methods of Entity Bean fields.
public String getName() throws RemoteException {
System.out.println("getName() called.");
return name;
}

public void setName(String name) throws RemoteException {
System.out.println("getName() called.");
this.name = name;
}

public String getDescription() throws RemoteException {
System.out.println("getDescription() called.");
return description;
}

public void setDescription(String description) throws RemoteException {
System.out.println("setDescription() called.");
this.description = description;
}

public double getBasePrice() throws RemoteException {
System.out.println("getBasePrice() called.");
return basePrice;
}

public void setBasePrice(double price) throws RemoteException {
System.out.println("setBasePrice() called.");
this.basePrice = price;
}

public String getProductID() {
System.out.println("getProductID() called.");
return productID;
}
//
// EJB-required methods
//

public void ejbActivate() throws RemoteException {
System.out.println("ejbActivate() called.");
}

public void ejbRemove() throws RemoteException {
System.out.println("ejbRemove() called.");
}

public void ejbPassivate() throws RemoteException {
System.out.println("ejbPassivate () called.");
}

public void ejbLoad() throws RemoteException {
System.out.println("ejbLoad() called.");
}
public void ejbStore() throws RemoteException {
System.out.println("ejbStore() called.");
}

public void setEntityContext(EntityContext ctx) throws RemoteException {
System.out.println("setEntityContext called");
this.ctx = ctx;
}

public void unsetEntityContext() throws RemoteException {
System.out.println("unsetEntityContext called");
this.ctx = null;
}

public void ejbPostCreate(String productID, String name, String description, double basePrice) throws RemoteException {
System.out.println("ejbPostCreate() called");
}

public String ejbCreate(String productID, String name, String description, double basePrice) throws CreateException, RemoteException {
System.out.println("ejbCreate(" + productID + ", " + name + ", " + description + ", " + basePrice + ") called");
this.productID = productID;
this.name = name;
this.description = description;
this.basePrice = basePrice;
return null;
}
// No finder methods - they are implemented by Container
}
ProductHome
==============

import javax.ejb.*;
import java.rmi.RemoteException;
import java.util.Enumeration;

public interface ProductHome extends EJBHome {

Product create(String productID, String name, String description, double basePrice) throws CreateException, RemoteException;
// Finder methods. These are implemented by the
// container. You can customize the functionality of
// these methods by using the EJB Container tools.
public Product findByPrimaryKey(String key) throws FinderException, RemoteException;
public Enumeration findByName(String name) throws FinderException, RemoteException;
public Enumeration findByDescription(String description) throws FinderException, RemoteException;
public Enumeration findByBasePrice(double basePrice) throws FinderException, RemoteException;
public Enumeration findExpensiveProducts(double minPrice) throws FinderException, RemoteException;
public Enumeration findCheapProducts(double maxPrice) throws FinderException, RemoteException;
public Enumeration findAllProducts() throws FinderException, RemoteException;
}
ProductPk.java
==============
//package com.wiley.compBooks.roman.entity.product;
import java.io.Serializable;

public class ProductPK implements java.io.Serializable {

public String productID;
public ProductPK(String productID) {
this.productID = productID;
}
public ProductPK() {
}
public String toString() {
return productID.toString();
}
}
Client.java
=============
//package com.wiley.compBooks.roman.entity.product;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import java.io.*;
import java.util.Enumeration;
import java.util.*;
/**
* Client test application on a Container-Managed Entity Bean, Product.
*/
public class Client {
public static void main(String[] args) {
ProductHome home = null;
try {
Properties props= new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
Context ctx=new InitialContext(props);
home = (ProductHome) ctx.lookup("ProductHome");
home.create("123-456-7890", "P5-350", "350MhzPentium", 200);
home.create("123-456-7891", "P5-400", "400MhzPentium", 300);
home.create("123-456-7892", "P5-450", "450MhzPentium", 400);
home.create("123-456-7893", "SD-64", "64MBSDRAM", 50);
home.create("123-456-7894", "SD-128", "128MBSDRAM", 100);
home.create("123-456-7895", "SD-256", "256MBSDRAM", 200);
/*
* Find a Product, and print out it's description
*/
Enumeration enum = home.findByName("SD-64");
System.out.println("The following product descriptions match the product name SD-64:");
while (enum.hasMoreElements()) {
Product prod = (Product) enum.nextElement();
System.out.println(prod.getDescription());
}
System.out.println("Calling finder to find all products that cost $200");
enum = home.findByBasePrice(200);
while (enum.hasMoreElements()) {
Product prod = (Product) enum.nextElement();
System.out.println(prod.getDescription());
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (home != null) {
try {
System.out.println("Destroying products..");

/*
* Find all the products
*/
Enumeration enum = home.findAllProducts();
while (enum.hasMoreElements()) {
try {
Product prod = (Product) enum.nextElement();
if (prod.getProductID().startsWith("123")) {
prod.remove();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
Finder script syntax look like this...
(=name $name)
(=description $description)
(=basePrice $basePrice)
(>basePrice $minPrice)
(<basePrice $minPrice)>
i set it in weblogic server...
Deploy bean in weblogic5.1 is perfect...
there is no problem in this...
I have a problem while running client...

Please help me in this problem
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
vikram,
i could only take a quick glance at ur client code but it appears as if u r tring to retrieve a record that u created in the same transaction.
Try to create the records in a method and then after they have been created try and retrieve them.
That might help. lemme know if it did.
Thanks
Anup
reply
    Bookmark Topic Watch Topic
  • New Topic