Instantiating Beehive JdbcControl manually

Common usage pattern for Beehive Jdbc control is:

  • Create DB control class by extending JdbcControl
  • Declare DB control variable in page controller and use @Control annotation to have it automatically instantiated and injected
  • Use the DB control

The above works fine. But what happens if we would like to use our DB control class from within JSP page which is not part of our Beehive application and has no access to our controller?

The following text presents one possible approach.

Custom DB control class:

JAVA:
  1. @ControlExtension
  2. @JdbcControl.ConnectionDataSource(jndiName = "dataSource")
  3. public interface MyDBControl extends JdbcControl {
  4.     @JdbcControl.SQL(
  5.         statement="SELECT * FROM \"SCHEMA\".\"MYTABLE\"")
  6.     public MyObject[] getAllObjects();
  7.     ...
  8. }

Classic approach, instantiate via @Control annotation in controller:

JAVA:
  1. public class MyController extends PageFlowController {
  2.     @Control
  3.     private MyDBControl myControl;
  4.     ...
  5.     //you can now use myControl...

But what if we need to instantiate the DB control class manually? One possible approach might be creating a factory like this:

JAVA:
  1. @ControlReferences({com.dolejsky.MyDBControl.class})
  2. public class MyDBControlFactory {
  3.     public static MyDBControl createDBControl() {
  4.         try {
  5.             ControlBeanContext ctx = new ServletBeanContext();
  6.             MyDBControlBean controlBean =
  7.                 (MyDBControlBean)Controls.instantiate(
  8.                     Thread.currentThread().getContextClassLoader(),
  9.                     "com.dolejsky.MyDBControlBean",
  10.                     null,
  11.                     ctx,
  12.                     null);
  13.             return controlBean;
  14.         } catch (ClassNotFoundException e) {
  15.             //handle it...
  16.         }
  17.         return null;
  18.     }
  19. }

9 Responses to “Instantiating Beehive JdbcControl manually”

  1. WAYNE says:

    PillSpot.org. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices.PillSpot.org. Herbal-supplements@buy.online” rel=”nofollow”>.…

    Categories: Antidepressants.Vitamins/Herbal Supplements.Blood Pressure/Heart.Mental HealthStop SmokingStomach.Pain Relief.Eye Care.Weight Loss.Womens Health.Mens Health.Anti-allergic/Asthma.Anxiety/Sleep Aid.Antidiabetic.Skin Care.Antiviral.Antibi…

  2. FRANCIS says:


    Pillspot.org. Canadian Health&Care.Best quality drugs.No prescription online pharmacy.Special Internet Prices. Low price pills. Order pills online

    Buy:Cialis Professional.Levitra.VPXL.Viagra Soft Tabs.Tramadol.Propecia.Super Active ED Pack.Viagra Super Force.Cialis Super Active+.Cialis Soft Tabs.Viagra Professional.Maxaman.Soma.Cialis.Viagra Super Active+.Zithromax.Viagra….

  3. 1 says:

    18 Accessories Cars 118/ http://04FORDPARTS.US/tag/1 : 1…

    18 Accessories Cars 118/…