Andre Broers’ personal blog

January 31, 2008

EJB3 + JPA on OC4J with Client

Filed under: 11g, ejb, j2ee, java, jpa, oc4j, oracle — broersa @ 9:08 am

Let’s use the previous JPA sample in an EJB. We start creating a datasource on the OC4J container. Then we create the entities again. After this we use the entities in a Stateless EJB which we will deploy to OC4J 11g. Finally we create a stand-alone client which calls the EJB.

We start with the creation of the datasource. We need a ConnectionPool.

java -jar $OC4J_ADMIN/j2ee/home/admin_client.jar deployer:oc4j:localhost oc4jadmin welcome -CreateJDBCConnectionPool -applicationName default -name HrConnectionPool -factoryClass oracle.jdbc.pool.OracleDataSource -user hr -password hr -url jdbc:oracle:thin:@localhost:1521:orcl

Test the connectionpool:

java -jar $OC4J_ADMIN/j2ee/home/admin_client.jar deployer:oc4j:localhost oc4jadmin welcome
-testConnectionPool -connectionPoolName HrConnectionPool -sqlStatement “select
* from dual” And the datasource:

java -jar $OC4J_ADMIN/j2ee/home/admin_client.jar deployer:oc4j:localhost oc4jadmin welcome -createManagedDataSource -applicationName default -dataSourceName HrDataSource -jndiLocation jdbc/HrDataSource -connectionPoolName HrConnectionPool

After this we create the entities:

/home/broersa/work/CountryApp/CountryJPAEJB/src/com/bekijkhet/entity/Country.java:


package com.bekijkhet.entity;

import java.io.Serializable;
import javax.persistence.*;

@Entity
@Table(name="COUNTRIES")
public class Country implements Serializable {
        private String id;
        private String name;
        private Region region;

        @Id
        @Column(name="COUNTRY_ID")
        public String getId() {
                return id;
        }

        public void setId(String id) {
                this.id = id;
        }

        @Column(name="COUNTRY_NAME")
        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        @ManyToOne(cascade={CascadeType.ALL})
        @JoinColumn(name="REGION_ID",nullable=false)
        public Region getRegion() {
                return region;
        }

        public void setRegion(Region region) {
                this.region = region;
        }
}

/home/broersa/work/CountryApp/CountryJPAEJB/src/com/bekijkhet/entity/Region.java


package com.bekijkhet.entity;

import java.io.Serializable;
import javax.persistence.*;
import static javax.persistence.CascadeType.*;
import static javax.persistence.FetchType.*;

import java.util.List;
import java.util.ArrayList;

@Entity
@Table(name="REGIONS")
public class Region implements Serializable {
        private int id;
        private String name;
        private List<Country> countries = new ArrayList<Country>();;

        @Id
        @Column(name="REGION_ID")
        public int getId() {
                return id;
        }

        public void setId(int id) {
                this.id = id;
        }

        @Column(name="REGION_NAME")
        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL}, mappedBy="region")
        public List<Country> getCountries() {
                return countries;
        }

        public void setCountries(List<Country> newValue) {
                this.countries = newValue;
        }
}

The EJB:/home/broersa/work/CountryApp/CountryJPAEJB/src/com/bekijkhet/country/CountryEJBLocal.java:


package com.bekijkhet.country;

import com.bekijkhet.entity.*;
import java.util.List;

public interface CountryEJBLocal {
  public List<Country> getCountriesByRegion(String region);
  public Region getRegionByCountry(String country);
}

/home/broersa/work/CountryApp/CountryJPAEJB/src/com/bekijkhet/country/CountryEJB.java:


package com.bekijkhet.country;
import java.util.List;
import com.bekijkhet.entity.*;
public interface CountryEJB {
  public List<Country> getCountriesByRegion(String region);
  public Region getRegionByCountry(String country);
  public void addorchangeCountry(Country country) ;
  public void addorchangeRegion(Region region) ;
  public void removeCountry(Country country) ;
  public void removeRegion(Region region) ;
  public List<Region> getAllRegions() ;
  public List<Country> getAllCountries();
}

/home/broersa/work/CountryApp/CountryJPAEJB/src/com/bekijkhet/country/CountryEJBBean.java


package com.bekijkhet.country;
import javax.ejb.Stateless;
import javax.ejb.Remote;
import javax.ejb.Local;

import java.util.List;
import com.bekijkhet.entity.*;
import javax.persistence.*;

@Stateless
@Remote(CountryEJB.class)
@Local(CountryEJBLocal.class)
public class CountryEJBBean implements CountryEJB,CountryEJBLocal {
  @PersistenceContext
  EntityManager em;

  public List<Country> getCountriesByRegion(String region) {
    Query q = em.createQuery("select r from Region r where r.name = :name");
    q.setParameter("name",region);
    Region r = (Region) q.getSingleResult();
//    r.getCountries().size();  // get the LAZY relation
    return r.getCountries();
  }

  public Region getRegionByCountry(String country) {
    Query q = em.createQuery("select c from Country c where c.name = :name");
    q.setParameter("name",country);
    Country c = (Country) q.getSingleResult();
    return c.getRegion();
  }

  public void addorchangeCountry(Country country) {
    em.persist(country);
  }

  public void addorchangeRegion(Region region) {
    em.persist(region);
  }

  public void removeCountry(Country country) {
    Country c = em.merge(country);
    em.remove(c);
  }

  public void removeRegion(Region region) {
    Region r = em.merge(region);
    em.remove(r);
  }

  public List<Region> getAllRegions() {
    Query q = em.createQuery("select r from Region r");
    List<Region> l = q.getResultList();
    return l;
  }

  public List<Country> getAllCountries() {
    Query q = em.createQuery("select c from Country c");
    List<Country> l = q.getResultList();
    return l;
  }
}

We need a persistence descriptor : /home/broersa/work/CountryApp/CountryJPAEJB/src/META-INF/persistence.xml:

<persistence>
  <persistence-unit name="MyPU">
    <jta-data-source>jdbc/HrDataSource</jta-data-source>
  </persistence-unit>
</persistence>

We need the build file:/home/broersa/work/CountryApp/CountryJPAEJB/build.xml:


<project name="CountryJPAEJB" default="dist" basedir=".">
    <description>
        simple example build file
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>

 <path id="files-classpath">
     <!--fileset dir="$HOME/oc4j_client_11110_preview/j2ee/home/lib" >
         <include name="persistence.jar"/>
     </fileset-->
     <pathelement location="/home/broersa/oc4j_client_11110_preview/j2ee/home/lib/persistence.jar"/>
     <pathelement location="/home/broersa/oc4j_client_11110_preview/j2ee/home/lib/ejb.jar"/>
 </path>

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}">
      <classpath refid="files-classpath" />
    </javac>
  </target>

  <target name="dist" depends="compile"
        description="generate the distribution" >
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}"/>
    <copy todir="${build}/META-INF">
                        <fileset dir="src/META-INF">
                                <include name="*" />
                        </fileset>
                   </copy>

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/CountryBean.jar" basedir="${build}"/>
  </target>

  <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>
</project>

We can build and deploy the EJB:type “ant” to build the EJB.use the next command to deploy the ejb:

java -jar $OC4J_ADMIN/j2ee/home/admin_client.jar deployer:oc4j:localhost oc4jadmin welcome -deploy -file $HOME/work/CountryApp/CountryJPAEJB/dist/CountryBean.jar -deploymentName CountryBean

Now this is done we can create the client:

/home/broersa/work/CountryApp/CountryClient/com/bekijkhet/CountryClient.java:


package com.bekijkhet;
import javax.naming.*;
import com.bekijkhet.country.CountryEJB;
import com.bekijkhet.entity.*;
import java.util.Properties;
import java.util.List;

public class CountryClient {
  public static void main(String[] args) {
    try {
      Properties props = new Properties();
      props.put("java.naming.factory.initial","com.evermind.server.ApplicationClientInitialContextFactory");
      props.put("java.naming.provider.url","ormi://localhost/CountryBean");
      props.put("java.naming.security.principal","oc4jadmin");
      props.put("java.naming.security.credentials","welcome");
      InitialContext ctx = new InitialContext(props);
      CountryEJB h = (CountryEJB)ctx.lookup("CountryEJBBean");

      System.out.println("The Netherlands has region: " + h.getRegionByCountry("Netherlands").getName());
      List<Country> l1 = h.getCountriesByRegion("Europe");
      System.out.println("Europe has the following countries:");
      for (Country c : l1) {
       System.out.println("  " + c.getName());
      }
      System.out.println("All regions:");
      List<Region> l2 = h.getAllRegions();
      for (Region r : l2) {
       System.out.println("  " + r.getName());
      }
      System.out.println("All countries:");
      List<Country> l3 = h.getAllCountries();
      for (Country c2 : l3) {
       System.out.println("  " + c2.getName() + " - " + c2.getRegion().getName());
      }

      Region r3 = new Region();
      r3.setName("MyRegion1");
      r3.setId(1001);
      Country c3 = new Country();
      c3.setName("MyCountry1");
      c3.setId("31");
      c3.setRegion(r3);
      r3.getCountries().add(c3);
      h.addorchangeCountry(c3);

      Region r4 = new Region();
      r4.setName("MyRegion2");
      r4.setId(1002);
      Country c4 = new Country();
      c4.setName("MyCountry2");
      c4.setId("32");
      c4.setRegion(r4);
      r4.getCountries().add(c4);
      h.addorchangeRegion(r4);

      System.out.println("All regions:");
      List<Region> l5 = h.getAllRegions();
      for (Region r5 : l5) {
       System.out.println("  " + r5.getName());
      }
      System.out.println("All countries:");
      List<Country> l6 = h.getAllCountries();
      for (Country c6 : l6) {
       System.out.println("  " + c6.getName() + " - " + c6.getRegion().getName());
      }
    }
    catch (Exception e) {
      System.out.println(e);
      e.printStackTrace();
    }
  }
}

/home/broersa/work/CountryApp/CountryClient/com/bekijkhet/META-INF/application-client.xml:

<?xml version="1.0" encoding="UTF-8"?>
<application-client version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd">
  <display-name>CountryClient</display-name>
  <description>test</description>
</application-client>

Compile the client:javac -cp $OC4J_HOME/j2ee/home/oc4jclient.jar:/home/broersa/work/CountryApp/CountryJPAEJB/dist/CountryBean.jar:. -d . CountryClient.javaAnd test the client:java -cp $OC4J_HOME/j2ee/home/oc4jclient.jar:/home/broersa/work/CountryApp/CountryJPAEJB/dist/CountryBean.jar:. com.bekijkhet.CountryClient

The Netherlands has region: Europe
Europe has the following countries:
Belgium
Switzerland
Germany
Denmark
France
Italy
Netherlands
United Kingdom
All regions:
Europe
Americas
Asia
Middle East and Africa
All countries:
Argentina – Americas
Australia – Asia
Belgium – Europe
Brazil – Americas
Canada – Americas
Switzerland – Europe
China – Asia
Germany – Europe
Denmark – Europe
Egypt – Middle East and Africa
France – Europe
HongKong – Asia
Israel – Middle East and Africa
India – Asia
Italy – Europe
Japan – Asia
Kuwait – Middle East and Africa
Mexico – Americas
Nigeria – Middle East and Africa
Netherlands – Europe
Singapore – Asia
United Kingdom – Europe
United States of America – Americas
Zambia – Middle East and Africa
Zimbabwe – Middle East and Africa
All regions:
Europe
Americas
Asia
Middle East and Africa
MyRegion1
MyRegion2
All countries:
MyCountry1 – MyRegion1
MyCountry2 – MyRegion2
Argentina – Americas
Australia – Asia
Belgium – Europe
Brazil – Americas
Canada – Americas
Switzerland – Europe
China – Asia
Germany – Europe
Denmark – Europe
Egypt – Middle East and Africa
France – Europe
HongKong – Asia
Israel – Middle East and Africa
India – Asia
Italy – Europe
Japan – Asia
Kuwait – Middle East and Africa
Mexico – Americas
Nigeria – Middle East and Africa
Netherlands – Europe
Singapore – Asia
United Kingdom – Europe
United States of America – Americas
Zambia – Middle East and Africa
Zimbabwe – Middle East and Africa

January 28, 2008

Stand Alone JPA client using Oracle 11g Database HR schema

Filed under: 11g, java, jpa, oc4j, oracle — broersa @ 7:14 pm

In this sample we will create a stand alone java app which uses the JPA (Toplink) api to connect to the HR sample schema in a Oracle database.

The hr schema must be unlocked and database must be accessible via the network.

We will start with the persistence.xml file.

/home/broersa/work/CountryApp/CountryJPA/build/META-INF/persistence.xml


<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="default">
    <provider>
        oracle.toplink.essentials.PersistenceProvider
    </provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="toplink.logging.level" value="INFO"/>
        <property name="toplink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
        <property name="toplink.jdbc.url" value="jdbc:oracle:thin:centos.bekijkhet.com:l521:orcl"/>
        <property name="toplink.jdbc.password" value="hr"/>
        <property name="toplink.jdbc.user" value="hr"/>
    </properties>
</persistence-unit>
</persistence>

After this the entities which represent the database objects. I choose the regions and countries tables.

/home/broersa/work/CountryApp/CountryJPA/src/com/bekijkhet/entity/Region.java

package com.bekijkhet.entity;

import java.io.Serializable;
import javax.persistence.*;
import static javax.persistence.CascadeType.*;

import java.util.List;
import java.util.ArrayList;

@Entity
@Table(name="REGIONS")
public class Region implements Serializable {
        private int id;
        private String name;
        private List<Country> countries = new ArrayList<Country>();;

        @Id
        @Column(name="REGION_ID")
        public int getId() {
                return id;
        }

        public void setId(int id) {
                this.id = id;
        }

        @Column(name="REGION_NAME")
        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        @OneToMany(cascade={CascadeType.ALL}, mappedBy="region")
        public List<Country> getCountries() {
                return countries;
        }

        public void setCountries(List<Country> newValue) {
                this.countries = newValue;
        }
}

/home/broersa/work/CountryApp/CountryJPA/src/com/bekijkhet/entity/Country.java

package com.bekijkhet.entity;

import java.io.Serializable;
import javax.persistence.*;

@Entity
@Table(name="COUNTRIES")
public class Country implements Serializable {
        private String id;
        private String name;
        private Region region;

        @Id
        @Column(name="COUNTRY_ID")
        public String getId() {
                return id;
        }

        public void setId(String id) {
                this.id = id;
        }

        @Column(name="COUNTRY_NAME")
        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        @ManyToOne()
        @JoinColumn(name="REGION_ID",nullable=false)
        public Region getRegion() {
                return region;
        }

        public void setRegion(Region region) {
                this.region = region;
        }
}

 Compile the entities:

cd /home/broersa/work/CountryApp/CountryJPA

javac -cp /home/broersa/oc4j_client_11110_preview/j2ee/home/lib/persistence.jar:build -d build src/com/bekijkhet/entity/*.java

After this the client app:

/home/broersa/work/CountryApp/CountryJPA/src/com/bekijkhet/client/Client.java:


package com.bekijkhet.client;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;

import java.util.List;

import com.bekijkhet.entity.*;

public class Client {
  private static EntityManagerFactory emf;
  private static EntityManager em;

  public static void main(String[] args) {

    emf = Persistence.createEntityManagerFactory("default");
    em = emf.createEntityManager();

    // Find a country with region
    Query q1 = em.createQuery("select c from Country c where c.id = :id");
    q1.setParameter("id","NL");
    Country c1 = (Country) q1.getSingleResult();
    System.out.println(c1.getName() + " - " + c1.getRegion().getName());

    // Find a region with countries
    Query q2 = em.createQuery("select r from Region r where r.id = :id");
    q2.setParameter("id",1);
    Region r2 = (Region) q2.getSingleResult();
    System.out.println(r2.getName());
    List<Country> l2 = r2.getCountries();
    for (Country c2 : l2) {
      System.out.println("  " + c2.getName());
    }

    // Add a region with two countries
    em.getTransaction().begin();
    Region r3 = new Region();
    r3.setId(1001);
    r3.setName("MyRegion1");
    Country c31 = new Country();
    c31.setId("31");
    c31.setName("MyCountry31");
    c31.setRegion(r3);
    r3.getCountries().add(c31);
    Country c32 = new Country();
    c32.setId("32");
    c32.setName("MyCountry32");
    c32.setRegion(r3);
    r3.getCountries().add(c32);

    em.persist(r3);
    em.getTransaction().commit();

    // List the added region with countries
    Query q4 = em.createQuery("select r from Region r where r.id = :id");
    q4.setParameter("id",1001);
    Region r4 = (Region) q4.getSingleResult();
    System.out.println(r4.getName());
    List<Country> l4 = r4.getCountries();
    for (Country c4 : l4) {
      System.out.println("  " + c4.getName());
    }

    // Change the country names
    em.getTransaction().begin();
    Query q5 = em.createQuery("select r from Region r where r.id = :id");
    q5.setParameter("id",1001);
    Region r5 = (Region) q5.getSingleResult();
    List<Country> l5 = r5.getCountries();
    for (Country c5 : l5) {
      c5.setName(c5.getName()+"-changed");
    }
    em.getTransaction().commit();

    // List the added region with countries
    Query q6 = em.createQuery("select r from Region r where r.id = :id");
    q6.setParameter("id",1001);
    Region r6 = (Region) q6.getSingleResult();
    System.out.println(r6.getName());
    List<Country> l6 = r6.getCountries();
    for (Country c6 : l6) {
      System.out.println("  " + c6.getName());
    }

    // Remove samples
    // Remove a single detail
    em.getTransaction().begin();
    Query q7 = em.createQuery("select r from Region r where r.id = :id");
    q7.setParameter("id",1001);
    Region r7 = (Region) q7.getSingleResult();
    System.out.println(r7.getName());
    List<Country> l7 = r7.getCountries();
    em.remove(l7.get(1));
    em.getTransaction().commit();

    // Remove samples
    // Remove the whole region
    em.getTransaction().begin();
    Query q8 = em.createQuery("select r from Region r where r.id = :id");
    q8.setParameter("id",1001);
    Region r8 = (Region) q8.getSingleResult();
    System.out.println(r8.getName());
    em.remove(r8);
    em.getTransaction().commit();

    em.close();

  }
}

compile and run:

cd /home/broersa/work/CountryApp/CountryJPA

javac -cp /home/broersa/oc4j_client_11110_preview/j2ee/home/lib/persistence.jar:build -d build src/com/bekijkhet/client/*.java

java -cp /home/broersa/oc4j_client_11110_preview/j2ee/home/lib/persistence.jar:/home/broersa/toplink_11.1.1.0_071214_preview-3/lib/java/api/toplink.jar:/home/broersa/myclasses/ojdbc6.jar:build -javaagent:/home/broersa/toplink_11.1.1.0_071214_preview-3/lib/java/internal/toplink-essentials-agent.jar com.bekijkhet.client.Client

[TopLink Info]: 2008.01.28 08:09:38.718–ServerSession(9519074)–TopLink, version: Oracle TopLink Essentials – 2.0 (Build SNAPSHOT (06/04/2007))
[TopLink Info]: 2008.01.28 08:09:41.744–ServerSession(9519074)–file:/home/broersa/work/CountryApp/CountryJPA/build/-default login successful
Netherlands – Europe
Europe
Belgium
Switzerland
Germany
Denmark
France
Italy
Netherlands
United Kingdom
MyRegion1
MyCountry31
MyCountry32
MyRegion1
MyCountry31-changed
MyCountry32-changed
MyRegion1
MyRegion1

Create OC4J 11 client environment

Filed under: 11g, linux, oc4j — broersa @ 6:40 pm

After some new installs over here I have a new Oracle VMware server based on Centos 5. I installed the oc4j 11 standalone server as the oracle user. This article describes how to create a client environment to build applications and deploy them to the remote oc4j.

I installed under root the package ant ( yum install ant ).

I installed under root the latest jdk in /usr/local (jdk-6u4-linux-i586.bin)

I added the JAVA_HOME to my .bash_profile

I added the $JAVA_HOME/bin to my PATH in the .bash_profile (in front of the rest)

In my home dir I created a directory oc4j_client_11110_preview in which I unzipped the oc4j_client_11110_preview.zip.

I added the OC4J_HOME to my .bash_profile

In my home dir I created a directory toplink_11.1.1.0_071214_preview-3 in which I unzipped the toplink_11.1.1.0_071214_preview-3.zip.

I added the TOPLINK_HOME to my .bash_profile

In my home dir I created a directory oc4j_admin_client_11110_preview in which I unzipped the oc4j_admin_client_11110_preview.zip.

I added the OC4J_ADMIN to my .bash_profile

In my home dir I created a directory myclasses wherin I downloaded ojdbc6.jar from Oracle JDBC download page.

now I have the needed jar libraries.

January 11, 2008

Installing Flash in Ubuntu Gutsy

Filed under: linux, ubuntu — broersa @ 7:12 pm

Due to a bug#173890 it is not possible to install the flash player. A new package can be obtained from :

http://launchpadlibrarian.net/10761023/flashplugin-nonfree_9.0.115.0ubuntu2_i386.deb

usb wireless md40900 dongle on ubuntu gutsy with WPA2

Filed under: linux, ubuntu, usb, wireless — broersa @ 9:23 am

After installing ubuntu gutsy I discovered that my usb wireless wasn’t working. I solved the problem with the following steps:

first download the windows driver from www.medion.de  :

http://www1.medion.de/site/service_~u~_support/treiber_~u~_updates/?op=detail&id=1853&type=treiber&lang=de

extract the driver and put it on a memory stick. When the downloaded exe is started it will extract the drivers to c:\Medion . Copy the c:\Medion\Driver directory including 4 files on the memory stick. The files should start with WlanUIG.* .

Now install the software:

sudo apt-get install ndiswrapper-common
sudo apt-get install –force-yes ndiswrapper-util

add the following lines to /etc/modprobe.d/blacklist because these drivers won’t work:


blacklist islsm_pci
blacklist islsm
blacklist islsm_usb
blacklist prism2_usb
blacklist rtl8187
blacklist r8187b
blacklist r8187
blacklist prism54usb
blacklist prism54pci
blacklist p54usb
blacklist p54pci

Now it is time to install the ndis drivers. Insert the memorystick in the machine. It will be mounted on /media/disk1 in my situation. cd to the directory /media/disk1/Driver and issue the following statements:

sudo ndiswrapper -i WlanUIG.inf
sudo ndiswrapper -l

wlanuig : driver installed
device (0CDE:0006) present (alternate driver: p54usb)

sudo modprobe ndiswrapper
dmesg
[   63.799356] ndiswrapper version 1.45 loaded (smp=yes)
[   63.926769] usb 5-3.4: reset high speed USB device using ehci_hcd and address 6
[   64.047713] ndiswrapper: driver wlanuig (,11/15/2004, 3.03.13.0) loaded
[   65.846130] wlan0: ethernet device 00:60:b3:b3:0a:78 using NDIS driver: wlanuig, version: 0×3030d, NDIS version: 0×501, vendor: ‘NB 802.11g Wireless LAN USB Adapter(3886)’, 0CDE:0006.F.conf
[   65.846188] wlan0: encryption modes supported: WEP; TKIP with WPA, WPA2, WPA2PSK; AES/CCMP with WPA, WPA2, WPA2PSK
[   65.846231] usbcore: registered new interface driver ndiswrapper

sudo ndiswrapper -m        //this will load the ndiswrapper module at startup.

Now it is time to configure the new wlan0 interface with the network-admin application in the Ubuntu GUI.

After all the parameter are set your /etc/network/interfaces file should look like this:


auto lo
iface lo inet loopback

iface wlan0 inet dhcp
wireless-essid <your ssid>   #this line I had to add due to a Bug#403316
wpa-psk <your key>
wpa-driver wext
wpa-key-mgmt WPA-PSK
wpa-proto WPA2
wpa-ssid <your ssid>

auto wlan0

I had to add one line the interfaces file manually.

after this I issued a:
sudo /etc/init.d/networking stop
sudo /etc/init.d/networking start

And my wireless usb dongle does the job. (After a reboot it comes up automatic)

January 10, 2008

Regenerate Database Console repository

Filed under: 11g, database, oracle — broersa @ 2:50 pm

After an installation of a new Oracle Home and complete restore of the database it is nescesary to regenerate the Database Console repository to use the Enterprise Manager.

[oracle@centos ~]$ . oraenv
ORACLE_SID = [orcl] ? orcl
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1 is /u01/app/oracle

create a password file:

orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=<password>

and check the parameter remote_login_password:

[oracle@centos db_1]$ sqlplus / as sysdba

SQL*Plus: Release 11.1.0.6.0 – Production on Thu Jan 10 19:15:47 2008

Copyright (c) 1982, 2007, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 – Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show parameter password

NAME TYPE VALUE
———————————— ———– ——————————
remote_login_passwordfile string EXCLUSIVE
SQL>

if this is not exclusive, change it and restart the database. After this you can connect as sysdba over tns.

It is nescesary to recreate the repository because with the reintall of oracle we lost the repository key. which is located in the oracle_home. First thing to do is drop the repository:

[oracle@centos db_1]$ emca -deconfig dbcontrol db -repos drop

STARTED EMCA at Jan 10, 2008 8:12:36 PM
EM Configuration Assistant, Version 11.1.0.5.0 Production
Copyright (c) 2003, 2005, Oracle. All rights reserved.

Enter the following information:
Database SID: orcl
Listener port number: 1521
Password for SYSMAN user:
Do you wish to continue? [yes(Y)/no(N)]: y
Jan 10, 2008 8:12:46 PM oracle.sysman.emcp.EMConfig perform
INFO: This operation is being logged at /u01/app/oracle/cfgtoollogs/emca/orcl/emca_2008_01_10_20_12_36.log.
Jan 10, 2008 8:12:48 PM oracle.sysman.emcp.util.DBControlUtil stopOMS
INFO: Stopping Database Control (this may take a while) …
Jan 10, 2008 8:13:01 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Dropping the EM repository (this may take a while) …
Jan 10, 2008 8:20:33 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully dropped
Enterprise Manager configuration completed successfully
FINISHED EMCA at Jan 10, 2008 8:21:04 PM
[oracle@centos db_1]$

Now we can recreate the repository.

[oracle@centos db_1]$ emca -config dbcontrol db -repos create

STARTED EMCA at Jan 10, 2008 8:24:25 PM
EM Configuration Assistant, Version 11.1.0.5.0 Production
Copyright (c) 2003, 2005, Oracle. All rights reserved.

Enter the following information:
Database SID: orcl
Listener port number: 1521
Password for DBSNMP user:
Password for SYSMAN user:
Email address for notifications (optional): <my mail>
Outgoing Mail (SMTP) server for notifications (optional): centos.bekijkhet.com
—————————————————————–

You have specified the following settings

Database ORACLE_HOME ……………. /u01/app/oracle/product/11.1.0/db_1

Local hostname ……………. centos.bekijkhet.com
Listener port number ……………. 1521
Database SID ……………. orcl
Email address for notifications …………… <my mail>
Outgoing Mail (SMTP) server for notifications …………… centos.bekijkhet.com

—————————————————————–
Do you wish to continue? [yes(Y)/no(N)]: y
Jan 10, 2008 8:24:50 PM oracle.sysman.emcp.EMConfig perform
INFO: This operation is being logged at /u01/app/oracle/cfgtoollogs/emca/orcl/emca_2008_01_10_20_24_25.log.
Jan 10, 2008 8:24:54 PM oracle.sysman.emcp.EMReposConfig createRepository
INFO: Creating the EM repository (this may take a while) …
Jan 10, 2008 8:38:28 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully created
Jan 10, 2008 8:38:57 PM oracle.sysman.emcp.EMReposConfig uploadConfigDataToRepository
INFO: Uploading configuration data to EM repository (this may take a while) …
Jan 10, 2008 8:42:16 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Uploaded configuration data successfully
Jan 10, 2008 8:42:25 PM oracle.sysman.emcp.util.DBControlUtil configureSoftwareLib
INFO: Software library configured successfully.
Jan 10, 2008 8:42:25 PM oracle.sysman.emcp.EMDBPostConfig configureSoftwareLibrary
INFO: Deploying Provisioning archives …
Jan 10, 2008 8:42:49 PM oracle.sysman.emcp.EMDBPostConfig configureSoftwareLibrary
INFO: Provisioning archives deployed successfully.
Jan 10, 2008 8:42:49 PM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
INFO: Securing Database Control (this may take a while) …
Jan 10, 2008 8:43:17 PM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
INFO: Database Control secured successfully.
Jan 10, 2008 8:43:17 PM oracle.sysman.emcp.util.DBControlUtil startOMS
INFO: Starting Database Control (this may take a while) …
Jan 10, 2008 8:45:47 PM oracle.sysman.emcp.EMDBPostConfig performConfiguration
INFO: Database Control started successfully
Jan 10, 2008 8:45:47 PM oracle.sysman.emcp.EMDBPostConfig performConfiguration
INFO: >>>>>>>>>>> The Database Control URL is https://centos.bekijkhet.com:1158/em <<<<<<<<<<<
Jan 10, 2008 8:46:42 PM oracle.sysman.emcp.EMDBPostConfig invoke
WARNING:
************************  WARNING  ************************

Management Repository has been placed in secure mode wherein Enterprise Manager data will be encrypted.  The encryption key has been placed in the file: /u01/app/oracle/product/11.1.0/db_1/centos.bekijkhet.com_orcl/sysman/config/emkey.ora.   Please ensure this file is backed up as the encrypted data will become unusable if this file is lost.

***********************************************************
Enterprise Manager configuration completed successfully
FINISHED EMCA at Jan 10, 2008 8:46:42 PM
[oracle@centos db_1]$

Be sure to backup your system including the emkey.ora file!

January 9, 2008

Restore 11g database from only a flash recovery area

Filed under: 11g, oracle, rman — broersa @ 3:26 pm

In my home situation I have a server (sandbox) which changes frequently. I had an oracle 10g database on it which was backup’d every day to the flash_recovery_area with the default settings from enterprise manager. Nothing special in it, so when I reinstalled the server the only thing I did was save a tar from the flash_recovery_area. Must be enough.

After reinstalling the server I used the following to restore the database.

First I installed a fresh 11g oracle home.

The commands I isued are the following:

export ORACLE_SID=orcl

rman target /

startup nomount

restore spfile from autobackup db_recovery_file_dest=’<restored flash recovery dir>’ db_name=’orcl’;

restore controlfile from autobackup db_recovery_file_dest=’<restored flash recovery dir>’ db_name=’orcl’;

copy the controlfile from the dbs directory to the destinations in the spfile.

create the $ORACLE_BASE/admin/orcl/adump directory.

create the $ORACLE_BASE/oradata/orcl directory.

copy the flash_recovery_area to the original location.

in rman:

startup force mount;

restore database;

recover database;

alter database open resetlogs;

now the database is up and running. Now it is time to configure and start the listener with netca.

After this we have to regenerate the enterprise manager repository. This will be covered in the next blog.

Blog at WordPress.com.