advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement



Title: Professional EJB
ISBN: 1861005083
US Price: $ 59.99
Canadian Price:
C$ 89.95
UK Price: £ 47.99
© Wrox Press Limited, US and UK.

Reviews : Java Books :
Professional EJB : The EJB 2.0 Entity Model

Deployment Descriptor

This deployment descriptor does not differ at all from an EJB 1.1 deployment descriptor.

<?xml version="1.0"?>
<ejb-jar>

<enterprise-beans>
<entity>

  <ejb-name>Measurement</ejb-name>
  <home>measurements.MeasurementHome</home>
  <remote>measurements.Measurement</remote>
  <ejb-class>measurements.MeasurementEJB</ejb-class>
  <persistence-type>Bean</persistence-type>
  <prim-key-class>java.lang.Long</prim-key-class>
  <reentrant>False</reentrant>
  <resource-ref>
	<res-ref-name>jdbc/DefaultDS</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
  </resource-ref>

</entity>

</enterprise-beans>


<assembly-descriptor>
	<container-transaction>
		<method>
			<ejb-name>Measurement</ejb-name>
			<method-name>*</method-name>
		</method>
	<trans-attribute>Required</trans-attribute>
	</container-transaction>
</assembly-descriptor>
</ejb-jar>

Client

This client creates some sample measurements, and then retrieves some summary data using two methods. First, it uses a finder method and iterates through the bean instances. Second, it uses the home business method that delegates the summary functionality to the database:

	package measurements;

	import java.util.Date;
	import java.util.Random;
	import java.util.Collection;
	import java.util.Iterator;
	import java.rmi.RemoteException;
	import javax.naming.InitialContext;
	import javax.rmi.PortableRemoteObject;
	import javax.ejb.CreateException;

	public class Client {
		private static long currentId = 1;
		private static Random random = new Random();

private static long getNextId() {
	return currentId++;
}

private static void createSampleMeasurements(MeasurementHome mh,
		Date timestamp, String eventName,
		int quantity) throws 
		CreateException, RemoteException {
	for (int iter = 0; iter < quantity; iter++) {
		mh.create(getNextId(), 
		  timestamp, eventName, random.nextDouble());
	}
}

public static void main(String[] args) {
	try {
		InitialContext initial = new InitialContext();
 
		MeasurementHome measurementHome =
		  (MeasurementHome) PortableRemoteObject
			.narrow(initial.lookup("Measurement"), 
		  MeasurementHome.class);

		Date currentTimestamp = new Date();
		createSampleMeasurements(measurementHome, 
			currentTimestamp,
			"TestEvent", 25);

Note: Color coded lines should be on one line, they were split for formatting purposes.

With the first method, we use a finder to iterate through the measurements we care about:

	
	Collection measurements = 
	measurementHome.findInDate(currentTimestamp,
			currentTimestamp);

	double total = 0.0;
	Iterator iter = measurements.iterator();
	while (iter.hasNext()) {
		Measurement measurement =
			(Measurement) 
  		  PortableRemoteObject.narrow(iter.next(),
					Measurement.class);
		total += measurement.getEventMagnitude();
	}
	System.out.println("Results from method one: " + total);

Note: Color coded lines should be on one line, they were split for formatting purposes.

With the second method, we use our home interface method:

		System.out.println("Results from method two: "
		  + measurementHome.totalMagnitudeForRange
			(currentTimestamp,
					currentTimestamp));
		} catch (Exception e) {
			e.printStackTrace();
	}
}
}

Note: Color coded lines should be on one line, they were split for formatting purposes.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs