Thursday, June 28, 2012

Default Transaction Attribute for EJBs

Default transaction attributes differ from container to container.
In Weblogic Server, default transaction attribute for MDB is NotSupported however for all other EJBs is Supports for version 10.0 onwards - if no attribute value is specified for trans-attribute in the ejb deployment descriptor.

Container-Managed Transaction Elements in ejb-jar.xml (WebLogic Server 10.x)

Element: transaction-type
Description: Allowable values are Bean or Container.
Default: None, EJB 2.x requires this attribute to be specified.


Element: trans-attribute
Description: 
Specifies how the container manages the transaction boundaries when delegating a method invocation to an enterprise bean's business method. Allowable values are:
  • NotSupported
  • With the NotSupported value, when an entity bean runs in an unspecified transaction, if a transaction exists, the EJB container suspends the transaction; when an entity bean runs in an unspecified transaction, and no transaction exists, the EJB container takes no action.
  • Supports
  • With the Supports value, when an entity bean runs in an unspecified transaction, if a transaction exists, the EJB container uses the current transaction; when an entity bean runs in an unspecified transaction, and no transaction exists, the EJB container takes no action.
  • Required
  • RequiresNew
  • Mandatory
  • Never
  • With the Never value, when an entity bean runs in an unspecified transaction, if a transaction exists, the EJB container throws an exception; when an entity bean runs in an unspecified transaction, and no transaction exists, the EJB container takes no action.
Note: In in pre-9.0 releases of WebLogic Server, the EJB container would start a new transaction when no transaction existed and the value of trans-attribute was NotSupportedSupports, and Never. Set entity-always-uses-transaction inweblogic-ejb-jar.xml to True if you want the EJB container to behave as it did in pre-9.0 releasesof WebLogic Server and create a new transaction.

Because clients do not provide a transaction context for calls to an MDB, MDBs that use container-managed transactions must have trans-attribute of Required.


Default: If not specified, the EJB container issues a warning, and usesNotSupported for MDBs and Supportsfor other types of EJBs.

Element: transaction-scope
Description: 
This optional element specifies whether an enterprise bean requires distributed transactions for its methods or whether the local transaction optimization may be used.
Allowable values are Local and Distributed.

Default: If not specified, the container assumes that distributed transactions must be used.


Reference: http://docs.oracle.com/cd/E11035_01/wls100/ejb/implementing.html#wp1150418

Tuesday, April 24, 2012

Return List of Dynamic object types from Method

Sometimes we want to convert the list of objects into a desired data type list. Here is one simple example which returns a list of objects into list of Strings, assuming that all the objects will be of type String.


// method with generic return type
public <T> List<T> getMyList(Class<T> elementType, List objList)
{
    List<T> list = new ArrayList<T>();
    
    for(Object obj : objList)
    list.add(elementType.cast(obj));
    
    return list;
}

// calling the method
getMyList(String.class, objList);

Monday, April 9, 2012

Creating 10.3.4 WebLogic Portal domain with different port number


Follow the steps below after Domain Configuration Wizard is completed:

1. add the following two lines in setDomainEnv.cmd with appropriate port number.
@REM Following line customized to change the port for derby
set DERBY_CMD_LINE_ARGS=-p=1529

2. Start the derby database with different port number as follows:
C:\portal-10.3.4\wlserver_10.3\common\bin\startDerby.cmd -p=1529

3. Modify database.properites with new port as follows:
derby.url=jdbc:derby://localhost:1529/weblogic_eval;create=true
derby.driver=org.apache.derby.jdbc.ClientDriver

4. Run the db script C:\portal-10.3.4\user_projects\domains\ngx_domain01\create_db.cmd

5. Modify startWeblogic.cmd as follows:
@REM Start Derby

set DERBY_DEBUG_LEVEL=0
echo #############################################################
echo DERBY_CMD_LINE_ARGS=%DERBY_CMD_LINE_ARGS%
echo #############################################################
if "%DERBY_FLAG%"=="true" (
call "%WL_HOME%\common\derby\bin\startNetworkServer.cmd" %DERBY_CMD_LINE_ARGS% >"%DOMAIN_HOME%\derby.log" 2>&1

)

6. Modify stopWeblogic.cmd as follows:
echo #############################################################
echo DERBY_CMD_LINE_ARGS=%DERBY_CMD_LINE_ARGS%
echo #############################################################
if "%DERBY_FLAG%"=="true" (
call "%WL_HOME%\common\derby\bin\stopNetworkServer.cmd" %DERBY_CMD_LINE_ARGS% >"%DOMAIN_HOME%\derbyShutdown.log" 2>&1
echo Derby server stopped.
)

7. Change the following line in config.xml for the appropriate port
jdbc:derby://localhost:1529/weblogic_eval

This is optional:
8. Change the port number in jdbc/p13nProfileDataSource-jdbc.xml folder

WebLogic Portal 10.3.4 vs WebLogic Portal 10.3.2

Few differences between WLP 10.3.4 & WLP 10.3.2:
1. First and foremost, its seems its a minor change in the version but its not. You need to install the entire WebLogic Portal 10.3.4 version and create new portal domains in 10.3.4 version to deploy your upgraded portal applications.

2. 10.3.4 uses Apache Derby database as default while 10.3.2 uses pointbase as default

3. Domain configuration wizard in 10.3.4 version is not a 100% wizard, meaning you need to start the derby database manually before checking the box "Run Scripts" while going through wizard - and Oracle is still calling this a wizard.

4. Creating two or more portal domains in WLP 10.3.4 cannot be simply achieved by changing the port numbers for Derby database, as changing port number for db configuration in wizard will not change the server start/stop scripts to listed to different port for Derby database - lot of changes are needed.
Note: Watch for upcoming postings for creating more than one portal domains.

5. Spring 3.0 version is recommended how ever applications can still use 2.5.x versions.

6. A new datasource p13nProfileDataSource-jdbc.xml is created as part of domain creation, which is not at all used - as per Oracle.

7. Eclipse has a new version 3.6.1

8. So many new types of project can be created using Eclipse "New" wizard.

9. Few ui issues are fixed in WebLogic Server Console e.g. "Ordering Authentication Providers"
and more to discover...

Good to know about these when using TFS


These points are helpful when using Microsoft TFS as enterprise repository:

1. We need to specify different labels for different projects i.e. more than one projects cannot be labelled with same label.
(TFS Eclipse client in windows doesn't throw any error while labelling different projects with same label and it works in windows however while trying to get labelled code in Linux,  it does not work)

2. Checking in code - While updating any code in TFS, make sure that the code with right label has been checked out. And after checking in, make sure the new code is labelled with the right label.

3. Deleting files from TFS - Even if the files can be deleted from TFS, they stay no matter what.
If a file XYZ is labelled and need to be deleted then label has to be removed from file XYZ and then deleted.
(File XYZ will still be available to labels other than for what it is deleted)

4. Adding and deleting folder structure is not straight forward - so take more time in designing and finalizing the folder structure. Once it is finalized then only add to TFS.

5. Adding multiple files to an existing label is again not straight forward, take more time and it requires more concentration to avoid any mistake by missing a required file to apply label. Its always better to apply label to the parent folder and then remove label from unwanted files.

6. Using "Microsoft Visual Studio 2010" has some advantages and is flexible to work with when comparing with Eclipse plugin for TFS.

Thursday, February 2, 2012

Maven build on winows and unix


Windows paths differ from that of unix, linux, solaris, aix and sometimes it becomes challange to use one pom.xml for building on two different os.
Here is how one maven script can be used for building applications on windows and unix environments:



<profiles>
    <profile>
        <id>windows</id>
        <activation>
        <os>
            <family>windows</family>
        </os>
        </activation>
        <properties>
            <!-- windows based properties here -->
        </properties>
    </profile>
    <profile>
        <id>non-windows</id>
        <activation>
        <os>
            <family>!windows</family>
        </os>
        </activation>
        <properties>
            <!-- unix based properties here -->
        </properties>
    </profile>
</profiles>

Date Time for Maven Builds

Print/View Datetime stamp in Maven
Since Maven 2.1 M1 version, here is how you can get the datetime stamp while using maven build scripts:
Define a property named "maven.build.timestamp.format" with some legitimate value i.e. "yyyyMMdd.HHmm" and property named "maven.build.timestamp" will be available to use.

Example here:



<properties>
<maven.build.timestamp.format>yyyyMMdd.HHmm</maven.build.timestamp.format>
<CurrentDateTime>${maven.build.timestamp}</CurrentDateTime>
</properties>

Tuesday, December 20, 2011

Internet Explorer Options

To remove all tools and status bars use -k option
Example: iexplore.exe -k http://www.google.com/

Wednesday, October 26, 2011

Helpful WLST Commands (Windows OS)


Open the WLST Prompt
Open command prompt and cd to weblogic server domain
Set the required classpaths by executing the setDomainEnv.cmd from domain/bin folder
java weblogic.WLST

Connect to the server
connect(‘username’, ‘password’,’AdminServer’)
This will connect to the server running on localhost:7001 by default, optionally these parameters can also be passed.

List applications including shared libraries
listApplications()

Deploy commands for shared library
deploy('shared-library-name',path='JAR/WAR/EAR full path', libraryModule='true')


Deploy commands for application
deploy('application-name',path='Application full path', libraryModule='false')

Undeploy applications/shared libraries
undeploy(‘application-name/shared-lib-name’)

Help command
help(), help('commandName')

Exit command
exit()

Disconnect command
disconnect()