Trick #1 - Copying Users the Right Way

Today’s trick is pretty simple, and it allows you to copy user accounts from one instance to another with the same password, grants, roles, etc, without using the exp/imp tools.

Everyone knows that you can use “create user username identified by password” to create a new user. What most people don’t know is that you can actually copy the password of a user from one database to another as well.

You wont be able to see the password (sorry hackers), but you can copy it in its encoded form.

Instead of using:

create user test identified by password;

You will use:

create user test identified by values 'encoded password';

The encoded password will actually be the encrypted password stored in the database that is visible to the DBA eye. This is a 16 character password you will find in the DBA_USERS view in the PASSWORD column.

You can also use:

alter user test identified by values 'encoded password';

If you have already created the user and need to change the password to what it might have been on another system.

This is extremely useful for DBAs that are copying their production database to development, or migrating a database from one instance to another. Too often, DBAs are forced to remember the details they have, copy them from the DBA_USERS view, and try to create the new users as close as possible to the original.

But we’re more sophisticated! Instead, we will use the DBMS_METADATA package to pull the user information.

set head off
set pages 0
set long 9999999
select dbms_metadata.get_ddl('USER', username) || '/' usercreate
from dba_users;

USERCREATE
--------------------------------------------------------------

CREATE USER "SYS" IDENTIFIED BY VALUES 'F894844C34402B67'
DEFAULT TABLESPACE "SYSTEM" TEMPORARY TABLESPACE "TEMP"
/

...

Do you want to get all their roles and grants as well? Nothing easier! Look at the following:

SELECT DBMS_METADATA.GET_GRANTED_DDL('ROLE_GRANT','SYS') FROM DUAL;
SELECT DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT','SYS') FROM DUAL;
SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT','SYS') FROM DUAL;

From this, we can form our Unified User Copy-o-matic with the following query:

set head off
set pages 0
set long 9999999
spool user_script.sql
SELECT DBMS_METADATA.GET_DDL('USER', USERNAME) || '/' DDL
FROM DBA_USERS
UNION ALL
SELECT DBMS_METADATA.GET_GRANTED_DDL('ROLE_GRANT', USERNAME) || '/' DDL
FROM DBA_USERS
UNION ALL
SELECT DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT', USERNAME) || '/' DDL
FROM DBA_USERS
UNION ALL
SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT', USERNAME) || '/' DDL
FROM DBA_USERS;
spool off;

And voila! All of our users and grants all in one simple script.

If you would like simple alter commands instead, we can always skip using DBMS_METADATA. Instead, use this query:

select 'alter user ' || username ||
' identified by values ''' || password || ''';'
from dba_users;

Note that in the case above, there are three single quotes to the left and right of password. Don’t use double quotes.

That’s it for today; a rather easy trick that you can use many times during your DBA career. If you already knew this trick, don’t worry! There’s more to come, the rest a bit more advanced and a bit more obscure. Join me tomorrow and we’ll talk about how to transform any query into any other on the back-end, sometimes with very amusing results!

Ref : http://www.oraclealchemist.com/news/trick-1-copying-users-the-right-way/

Struts Tiles JSF MyFaces migration or integration

Migration or integration of an existing Struts Tiles application to JSF

In a project I had a Struts Tiles based application which should be migrated to JSF. As JSF implementation we had chosen MyFaces.

Struts Tiles is a nice templating solution. You can define a website layout for example a header, footer and and body and place your content in these parts. Here you can find a basic tutorial.

The first information, I came across was outdated. It proposed the use of a TilesServlet to integrate not to migrate Struts Tiles. This was long before Tiles were integrated into Struts. Please be aware that the following Tiles home page is outdated as well.

After further readings, I came across two options

Struts Tiles -> JSF migration

An alternative to Struts Tiles seems to be Facelets. It looks a little bit like Tapestry and could be used as alternative to Struts Tiles. I did not follow these option but you may try it if you like.

Struts Tiles and JSF integration

Integration has the advantage that there is only little rework of Tiles web pages required. Support for Struts Tiles is provided by the MyFaces Tomahawk project.
MyFaces and Struts Tiles integration

The MyFaces project formerly had example applications in the download. I found these examples in the archiv area. They might be a little outdated but at least for the Struts Tiles integration these examples were perfect.

Here is a quick walk through


1) Add the Tiles view handler to your faces-config.xml.
<application>
<view-handler>org.apache.myfaces.tomahawk.application.jsp.JspTilesViewHandlerImpl</view-handler>
</application>

2) Rename the name of tiles definitons to someName.tiles
<definition name="/searchResults.tiles" extends="myBaseTemplate">
<put name="body" value="/searchResults.jspx">
</put>

3) Migrate your JSPs to JSF.

In template files you frequently have to add the following to insert a tile into the template. flush=false is important,
<f:subview id="body">
<tiles:insert attribute="body" flush="false">
</tiles:insert>
</f:subview>

Alternatives to JSF and Struts Tiles

I found a number of articles comparing JSF with Tapestry. I would like to invite you to try this framework as well. What I like about Tapestry is that you can create your templates with simple HTML editors.

Some pointers:

http://www.thoughtsabout.net/blog/archives/000052.html
http://sandbox.sourcelabs.com/kosta/web_ui_compare/readme/index.html
http://wiki.osafoundation.org/bin/view/Projects/WebFrameworkComparison
hhttp://www.theserverside.com/tt/articles/article.tss?l=JavaOne_Day4
http://www.theserverside.com/tt/articles/article.tss?l=JSFTapestry

Ref : laliluna website

Open Source Aspect-Oriented Frameworks in Java

AspectJ
AspectJ is a seamless aspect-oriented extension to the Java programming language, Java platform compatible and easy to learn and use. AspectJ enables the clean modularization of crosscutting concerns such as: error checking and handling, synchronization, context-sensitive behavior, performance optimizations, monitoring and logging, debugging support, multi-object protocols.

AspectWerkz
AspectWerkz is a dynamic, lightweight and high-performant AOP framework for Java. AspectWerkz offers both power and simplicity and will help you to easily integrate AOP in both new and existing projects. AspectWerkz utilizes runtime bytecode modification to weave your classes at runtime. It hooks in and weaves classes loaded by any class loader except the bootstrap class loader. It has a rich and highly orthogonal join point model. Aspects, advices and introductions are written in plain Java and your target classes can be regular POJOs. You have the possibility to add, remove and re-structure advice as well as swapping the implementation of your introductions at runtime. Your aspects can be defined using either an XML definition file or using runtime attributes.

Nanning
Nanning Aspects is a simple yet scaleable aspect-oriented framework for Java.
Go To Nanning

JBossAOP
JBossAOP allows you to apply interceptor technology and patterns to plain Java classes and Dynamic Proxies. It includes:

  • Java Class Interception. Field, constructor, and method interception, public, private, protected, and package protected, static and class members.
  • Fully compositional pointcuts caller side for methods and constructors, control flow, annotations.
  • Aspect classes Advices can be incapsulated in scoped Java classes
  • Hot-Deploy. Interceptors can be deployed, undeployed, and redeployed at runtime for both dynamic proxies and classes.(working)
  • Introductions. The ability to add any arbitrary interface to a Java class. Either an interceptor or a 'mixin' class can service method calls for the attached interfaces.
  • Dynamic Proxies. The ability to define a dynamic proxy and an interceptor chain for it. Proxies can either be created from an existing class, or from a set of interfaces ala java.lang.reflect.Proxy.
  • Metadata and Attribute Programming. The ability to define and attach metadata configuration to your classes or dynamic proxies. Interceptors can be triggered when metadata is added to a class. We also have Metadata Chains, the ability to define defaults at the cluster and application level, as well as the ability to override configuration at runtime for a specific method call.
  • Dynamic AOP. All aspected objects can be typecasted to an AOP api. You can do things like add/remove new interceptors to a specific instance or add/remove instance configuration/metadata at runtime.

dynaop
dynaop, a proxy-based Aspect-Oriented Programming (AOP) framework, enhances Object-Oriented (OO) design in the following areas: code reuse decomposition dependency reduction

CAESAR
CAESAR is a new aspect-oriented programming language compatible to Java, that is, all Java programs will run with CAESAR.

EAOP
Event-based Aspect-Oriented Programming (EAOP) for Java. EAOP 1.0 realizes the EAOP model through the following characteristics:
  • Expressive crosscuts: execution points can be represented by events and crosscuts can be expressed which denote arbitrary relations between events.
  • Explicit aspect composition: Aspects may be combined using a (extensible) set of aspect composition operators.
  • Aspects of aspects: Aspects may be applied to other aspects.
  • Dynamic aspect management: Aspects may be instantiated, composed and destroyed at runtime.

JAC
JAC (Java Aspect Components) is a project consisting in developing an aspect-oriented middleware layer.

DynamicAspects
DynamicAspects enables you to do aspect-oriented programming in pure Java. Using the "instrumentation" and "agent" features introduced with Sun JDK 1.5, aspects can be installed and deinstalled during runtime!

PROSE
The PROSE system (PROSE stands for PROgrammable extenSions of sErvices) is a dynamic weaving tool (allows inserting and withdrawing aspects to and from running applications) PROSE aspects are regular JAVA objects that can be sent to and be received from computers on the network. Signatures can be used to guarantee their integrity. Once an aspect has been inserted in a JVM, any occurrence of the events of interest results in the execution of the corresponding aspect advice. If an aspect is withdrawn from the JVM, the aspect code is discarded and the corresponding interception(s) will no longer take place.

Ref: http://java-source.net/

The Open Road: Looking Ahead to Java 7

The JDK 7 Project

The JDK7 project on java.net is the first place to look for Java 7 updates. This project releases binary snapshots of Java 7 every two weeks. If you want to try out a new feature of Java 7, downloading a binary is the easiest way to get yourself up and running. (Note that the JDK7 project is not the same thing as the OpenJDK; more on that below.)

Each new binary snapshot includes a list of bugs fixed and features added. It is still early in the Java 7 development cycle, and so far, the change lists for these early builds have been pretty dull. They have included updates to Javadoc comments, fixes for obscure regressions, and incomprehensible tweaks to the hotspot VM, but very little in the way of new APIs to try out.

As I write this, the current snapshot is "build 16." The most notable changes in b16, in my opinion, are additions to the java.util.Currency class. That class now has a static getAvailableCurrencies() method, and instances have getDisplayName() and getNumericCode() methods to complement getSymbol() and getCurrencyCode(). You can read about these new methods in the Javadoc. A new version of the API docs is generated for each snapshot release. You can always find the current version at download.java.net/jdk7/docs/api .

The JDK7 project also releases source code snapshots, under the Java Research License (or JRL). The JRL is intended for use by universities and researchers and is not a true open source license. If you're interested in these sources, you'll probably want to read the build instructions. This source is also available (read-only) through Subversion, but you'll need to have the jdk.researcher role added to your java.net ID.

Incidentally, the ongoing development of updates for Java 6 is handled with equal transparency at jdk6.dev.java.net. Java 6u2 has recently been released, so watch this space for development of update 3.

The OpenJDK Project

The OpenJDK project is a completely different entity from the JDK7 project. Given that they both release source-code snapshots of Java 7, however, it can be hard to tell them apart. Here, in a nutshell, are the differences between the two projects:

  • The JDK7 project is Sun's open (as in transparent) Java development process, controlled by Sun, with most development done by Sun's internal engineering team.
  • The OpenJDK project is the Java community's open (as in free software) source development project to create a completely free/open source implementation of the JDK. The OpenJDK is controlled by a governance board. Sun's engineers participate in the OpenJDK project, but contributions from outside developers are actively solicited.

If you're an open source advocate or activist, you may be interested in all the gory OpenJDK licensing and governance details in the open source Java FAQ and the OpenJDK legal page.

Sun has already released all of their own Java code under the GPLv2 license. There remain, however, a few pieces of the JDK that Sun licensed from other commercial vendors. Thus, the primary initial purpose of the OpenJDK project is to develop open source alternatives to that encumbered code, so that a completely open source version of Java can be released. This is a great place to get involved if you like low-level coding: there are projects set up to work on an audio engine, a framebuffer toolkit, a font scaler, and a graphics rasterizer.

OpenJDK is an umbrella for many subgroups and the subprojects they run. The current list of groups and projects is in a column running down the left-hand side of the OpenJDK home page. As you can tell from the preliminary list of projects above, the 2D Graphics group is currently the most active one.

We can expect more OpenJDK projects as development of Java 7 gains momentum. Currently, the only Java 7 project is the Modules project, which aims to create open source implementations of JSR 277 and JSR 294.

OpenJDK source code is available as source code snapshots that follow the same build numbering scheme and release schedule as the JDK7 project. You can also browse or download the source with Subversion. In addition to downloading sources, you'll also have to download a complete (but non-functional) binary snapshot (linked from the same page as the sources), from which encumbered code can be copied in binary form. Before you start downloading, bear in mind that official instructions for building the OpenJDK have not yet been published. (If you are a NetBeans user, however, you may be able to use your IDE to build the OpenJDK.)

Java 7 Release Schedule

Open sourcing Java and creating the OpenJDK infrastructure has apparently taken quite a bit of work for Sun, and this brings us to the bad news. Sun typically aims to release new versions of Java at 18-month intervals. Java 6 was released in fall 2006. The original Java 7 schedule, therefore, called for a release in spring 2008. Given that the current builds available from the JDK7 project have integrated no major new features, we obviously aren't even close to a beta release. Danny Coward, who will be the spec lead for the Java 7 JSR, now says that they're aiming for a release in January 2009, about 16 months from now.

Java 7 Features

Back in the fall of 2006 there was a lot of talk about what features might be included in Java 7. Coward listed some possibilities in September, and detailed some of them (PDF) in November 2006.

With these semi-official feature lists as a starting point, Alex Miller has been tracking development and discussion of possible Java 7 features at his Pure Danger Tech blog. Alex's Java 7 site is probably the best and most current Java 7 resource out there.

The truth is, however, that we really don't know what will be in Java 7. The speculation from last fall is still just speculation, and given the amount of schedule slippage since that time, there are likely to be changes, possibly significant changes, to Danny's original lists. What we're waiting for is his submission of the Java 7 platform JSR. When published, this JSR should reveal the features that Sun is targeting for Java 7. He says that we should expect a JSR to be released "over the next couple of months." He admits, however, that he's been saying that for some time now.

Language Changes for Java 7?

A September 2006 post suggested that Sun would propose "a small set" of changes to the Java language. Candidates then under consideration were:

  • Language-level XML support
  • Closures
  • Block constructs
  • Strings in switch statements
  • Language support for BigDecimal
  • Java property support
  • Lightweight method references
  • Extensions to the annotation mechanisms

The possibility of languages changes aroused a lot of interest. Various closure proposals were floated and discussed at length, with the discussions culminating in a face-to-face meeting of the principals at JavaOne '07. Adding support for property access without getter and setter methods was also much debated. Recently, however, discussion of new language features has quieted down. Faced with the reality of the schedule slippage, Neal Gafter (former javac maintainer, and one of the primary advocates for Java closures) predicts that Java 7 will either be delayed until late 2009 or that language changes will be deferred until Java 8.

As a further reality check on adding features to a mature language, read Alex Buckley's blog. Alex is the new maintainer for the Java Language Specification, and as such, he will be intimately involved with any language changes. Although he hasn't written much, everything Alex has posted on his blog is interesting.

Projects of Interest

Until we see a formal Java 7 JSR, and until we start seeing more significant code being checked into the JDK7 and OpenJDK projects, we'll have to content ourselves with projects that are being developed independently. The following projects have code available to download and try out now:

The Swing application framework (JSR 296) and the Beans Binding (JSR 295) projects aim to simplify Swing development.

The Measures and Units project (JSR 275) is developing a library for working with quantities and the units with which they are measured. This library uses Java generics to allow static type checking of unit compatibility. This JSR has just completed its early draft review, and a new implementation, incorporating changes based on that review, should be released soon. While this JSR did not appear on last fall's list of candidates for inclusion in Java 7, the spec lead hopes this small library makes it into core Java.

The Date/Time API (JSR 310) aims to comprehensively solve the date and time representation problems that have plagued the Java platform. Work on this JSR is very transparent (there is a wiki and an open mailing list) and discussion and development are active and ongoing. Preliminary (but unstable) code is available to try out. The developers hope to have their work included in Java 7.

Doug Lea is working on a Java 7 update to the JSR 166 java.util.concurrent utilities. His fork/join package is a concurrency framework for cleanly dividing tasks up for efficient concurrent execution on the multicore CPUs of the future. An implementation is available as is an academic paper (PDF) about the framework.

As mentioned earlier in the article, the OpenJDK Modules project is an implementation of JSR 277 and JSR 294, both of which are expected to be part of Java 7. A partial implementation is available at the main OpenJDK download page. At this point, it is a source-only release and you must build the JDK from scratch to try it out. I'll write about this project when there is a binary snapshot to try.

I hope to cover some or all of these projects in future installments of this column. Your suggestions for projects to cover are welcome in the comments below.

Resources

Ref: Java.net website

GWT 1.4 release and out of beta

It's a really big day for Google Web Toolkit: GWT 1.4 is now available -- and, with more than a million downloads under our belt, GWT is no longer in beta!

What's new in GWT 1.4?

There's lots and lots of cool new stuff in GWT 1.4, so it's hard to know where to start. How about application performance?! This release includes several breakthroughs that make your compiled GWT code significantly smaller and faster. Many users are reporting that after a simple recompile with 1.4, their applications are up to 30% smaller and 20%-50% faster. And startup time in particular is now highly optimized thanks to a new bootstrapping technique and the availability of image bundles. To see the new hotness in action, try visiting the new-and-improved Mail sample a few times. It's darn fast the very first time you visit it, but subsequent visits are insanely fast. That's because, in addition to a fast initial startup, GWT code uses a clever caching technique to prevent applications from making unnecessary HTTP requests. As Joel Webber (Tech Lead of GWT Core Libraries) would say, "The fastest HTTP requests are those that do not, in fact, occur."

Here's a broad overview of the major enhancements:


New widgets and libraries
  • RichTextArea, HorizontalSplitPanel and VerticalSplitPanel, SuggestBox, DisclosurePanel, PushButton, ToggleButton, and an enhanced Image widget make advanced applications easier than ever.
  • ImageBundle automatically consolidates multiple images into a single HTTP request.
  • NumberFormat and DateTimeFormat make easy work of complex internationalization and localization.
  • You can finally use java.lang.Serializable with GWT RPC, and the GWT RPC server-side subsystem is no longer intimately tied to servlets. You can easily wire it into any Java back-end infrastructure. Spring fans, rejoice.
  • A new JUnit-based benchmarking subsystem makes measuring and comparing the speed of code snippets as easy as writing unit tests.
New deployment options and optimizations
  • Adding GWT modules to an HTML page is now simple: just add a tag.
  • You can now include GWT modules across domains. Note that including scripts from other sites that you don't fully trust is a big security risk.
  • External JavaScript files referenced from your GWT module load synchronously now, so script ready-functions are no longer needed.
  • Auto-generated RPC whitelist files are now produced during compilation to help catch accidentally responding with objects that compiled GWT client code wouldn't be able to deserialize.
  • The GWT distribution now includes a DTD for the GWT module XML format, making it easier to configure modules in an DTD-aware XML editor.

Additional details on these new features and bugfixes are in the blog post announcing the original GWT 1.4 Release Candidate.

For all you GWT veterans ready to download GWT 1.4, see the new FAQ section "How do I upgrade to GWT 1.4?" for step-by-step instructions on the update.

And for anyone totally new to GWT, on behalf of the awesomely cool developer community and the GWT engineering team at Google, welcome!