gstackoverflow
gstackoverflow

Reputation: 37034

What the reason to use RowSetProvider to obtain RowSetFactory?

I notice that I get same result if I use

    RowSetFactory rowSetFactory = RowSetProvider.newFactory();

and

    rowSetFactory = new RowSetFactoryImpl();

newFactory method implementation:

public static RowSetFactory newFactory()
            throws SQLException {
        // Use the system property first
        RowSetFactory factory = null;
        String factoryClassName = null;
        try {
            trace("Checking for Rowset System Property...");
            factoryClassName = getSystemProperty(ROWSET_FACTORY_NAME);
            if (factoryClassName != null) {
                trace("Found system property, value=" + factoryClassName);
                factory = (RowSetFactory) getFactoryClass(factoryClassName, null, true).newInstance();
            }
        } catch (ClassNotFoundException e) {
            throw new SQLException(
                    "RowSetFactory: " + factoryClassName + " not found", e);
        } catch (Exception e) {
            throw new SQLException(
                    "RowSetFactory: " + factoryClassName + " could not be instantiated: " + e,
                    e);
        }

Here we see that this method returns RowSetFactory which set in system.property.

What the reason to change this system property?

Who does set this property by default?

Upvotes: 1

Views: 620

Answers (1)

Basil Bourque
Basil Bourque

Reputation: 338386

The com.sun.rowset.RowSetFactoryImpl class (see source code) is but one of possibly several concrete implementations of the RowSetFactory interface.

RowSetProvider & RowSetFactory make it easy to find default implementations as well as give you the flexibility to customize for particular implementations.

You can see this in the Javadoc of RowSetProvider.

  • Default:
    RowSetProvider.newFactory()
  • Custom:
    RowSetProvider.newFactory("com.sun.rowset.RowSetFactoryImpl", null)

Upvotes: 0

Related Questions