1 19 20 package org.apache.cayenne.dba; 21 22 import java.sql.DatabaseMetaData ; 23 import java.sql.SQLException ; 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.List ; 27 28 35 class DbAdapterFactoryChain implements DbAdapterFactory { 39 40 List factories; 41 42 DbAdapterFactoryChain(Collection factories) { 43 this.factories = new ArrayList (); 44 this.factories.addAll(factories); 45 } 46 47 51 public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException { 52 53 55 for (int i = factories.size() - 1; i >= 0; i--) { 58 DbAdapterFactory factory = (DbAdapterFactory) factories.get(i); 59 DbAdapter adapter = factory.createAdapter(md); 60 61 if (adapter != null) { 62 return adapter; 63 } 64 } 65 66 return null; 67 } 68 69 72 void clearFactories() { 73 this.factories.clear(); 74 } 75 76 79 void addFactory(DbAdapterFactory factory) { 80 this.factories.add(factory); 81 } 82 } 83 | Popular Tags |