use of javax.naming.Reference in project datanucleus-rdbms by datanucleus.
the class SharedPoolDataSource method getReference.
/**
* Returns a <code>SharedPoolDataSource</code> {@link Reference}.
*/
@Override
public Reference getReference() throws NamingException {
Reference ref = new Reference(getClass().getName(), SharedPoolDataSourceFactory.class.getName(), null);
ref.add(new StringRefAddr("instanceKey", getInstanceKey()));
return ref;
}
use of javax.naming.Reference in project datanucleus-rdbms by datanucleus.
the class DriverAdapterCPDS method getReference.
// ----------------------------------------------------------------------
// Referenceable implementation
/**
* <CODE>Referenceable</CODE> implementation.
*/
@Override
public Reference getReference() throws NamingException {
// this class implements its own factory
String factory = getClass().getName();
Reference ref = new Reference(getClass().getName(), factory, null);
ref.add(new StringRefAddr("description", getDescription()));
ref.add(new StringRefAddr("driver", getDriver()));
ref.add(new StringRefAddr("loginTimeout", String.valueOf(getLoginTimeout())));
ref.add(new StringRefAddr("password", getPassword()));
ref.add(new StringRefAddr("user", getUser()));
ref.add(new StringRefAddr("url", getUrl()));
ref.add(new StringRefAddr("poolPreparedStatements", String.valueOf(isPoolPreparedStatements())));
ref.add(new StringRefAddr("maxIdle", String.valueOf(getMaxIdle())));
ref.add(new StringRefAddr("timeBetweenEvictionRunsMillis", String.valueOf(getTimeBetweenEvictionRunsMillis())));
ref.add(new StringRefAddr("numTestsPerEvictionRun", String.valueOf(getNumTestsPerEvictionRun())));
ref.add(new StringRefAddr("minEvictableIdleTimeMillis", String.valueOf(getMinEvictableIdleTimeMillis())));
ref.add(new StringRefAddr("maxPreparedStatements", String.valueOf(getMaxPreparedStatements())));
return ref;
}
use of javax.naming.Reference in project datanucleus-rdbms by datanucleus.
the class BasicDataSourceFactory method getObjectInstance.
// -------------------------------------------------- ObjectFactory Methods
/**
* <p>Create and return a new <code>BasicDataSource</code> instance. If no
* instance can be created, return <code>null</code> instead.</p>
*
* @param obj The possibly null object containing location or
* reference information that can be used in creating an object
* @param name The name of this object relative to <code>nameCtx</code>
* @param nameCtx The context relative to which the <code>name</code>
* parameter is specified, or <code>null</code> if <code>name</code>
* is relative to the default initial context
* @param environment The possibly null environment that is used in
* creating this object
*
* @exception Exception if an exception occurs creating the instance
*/
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
// that specify a class name of "javax.sql.DataSource"
if (obj == null || !(obj instanceof Reference)) {
return null;
}
Reference ref = (Reference) obj;
if (!"javax.sql.DataSource".equals(ref.getClassName())) {
return null;
}
// Check property names and log warnings about obsolete and / or unknown properties
final List<String> warnings = new ArrayList<>();
final List<String> infoMessages = new ArrayList<>();
validatePropertyNames(ref, name, warnings, infoMessages);
for (String warning : warnings) {
log.warn(warning);
}
for (String infoMessage : infoMessages) {
log.info(infoMessage);
}
Properties properties = new Properties();
for (String propertyName : ALL_PROPERTIES) {
RefAddr ra = ref.get(propertyName);
if (ra != null) {
String propertyValue = ra.getContent().toString();
properties.setProperty(propertyName, propertyValue);
}
}
return createDataSource(properties);
}
use of javax.naming.Reference in project kernel by exoplatform.
the class HikariDataSourceFactory method getObjectInstance.
/**
* {@inheritDoc}
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
if ((obj == null) || !(obj instanceof Reference)) {
return null;
}
Reference ref = (Reference) obj;
if (!"javax.sql.DataSource".equals(ref.getClassName())) {
return null;
}
Properties properties = new Properties();
for (int i = 0; i < ref.size(); i++) {
String propertyName = ref.get(i).getType();
RefAddr ra = ref.get(propertyName);
if (ra != null) {
String propertyValue = ra.getContent().toString();
properties.setProperty(propertyName, propertyValue);
}
}
return createDataSource(properties);
}
use of javax.naming.Reference in project kernel by exoplatform.
the class InitialContextBinder method bind.
/**
* Constructs references from params, binds in initial contexts and persists list of all binded
* references into file.
*
* @param bindName
* bind name
* @param className
* class name
* @param factory
* factory name
* @param factoryLocation
* factory location
* @param refAddr
* map of references's properties
*
* @throws NamingException
* if error occurs due to binding
* @throws XMLStreamException
* @throws FileNotFoundException
*/
public void bind(String bindName, String className, String factory, String factoryLocation, Map<String, String> refAddr) throws NamingException, FileNotFoundException, XMLStreamException {
Reference reference = new Reference(className, factory, factoryLocation);
for (Map.Entry<String, String> entry : refAddr.entrySet()) {
reference.add(new StringRefAddr(entry.getKey(), entry.getValue()));
}
bindInternally(bindName, reference);
saveBindings();
}
Aggregations