Class JNDIUtils
java.lang.Object
org.bradfordmiller.simplejndiutils.JNDIUtils
Helper functions for the simple-jndi API
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BooleangetAvailableJndiContexts(InitialContext context) static Connectionstatic io.vavr.control.Either<DataSource,Map<String, String>> getDataSource(String jndi, String context) getDetailsforJndiEntry(InitialContext context, String jndiName, String entry) getEntriesForJndiContext(org.osjava.sj.jndi.MemoryContext memoryContext) static ConnectiongetJndiConnection(String jndiString, String context) static org.osjava.sj.jndi.MemoryContextgetMemoryContextFromInitContext(InitialContext initCtx, String contextName)
-
Constructor Details
-
JNDIUtils
public JNDIUtils()
-
-
Method Details
-
getMemoryContextFromInitContext
public static org.osjava.sj.jndi.MemoryContext getMemoryContextFromInitContext(InitialContext initCtx, String contextName) - Parameters:
initCtx- - context to extract memory context fromcontextName- - name of context being targeted- Returns:
- a nullable memory context based on
initCtxandcontextName
-
getDataSource
public static io.vavr.control.Either<DataSource,Map<String, getDataSourceString>> (String jndi, String context) - Parameters:
jndi- - the jndi name being referencedcontext- - the context being targeted- Returns:
- an Either of a DataSource or a Map based on the
jndiandcontext
-
getConnection
- Parameters:
ds- - the datasource from which a connection is created- Returns:
- a java.sql.Connection
- Throws:
SQLException
-
getJndiConnection
- Parameters:
jndiString- - jndi entry to be looked upcontext- - context to lookup jndi string in- Returns:
- a java.sql connection based on the
jndiStringandcontext - Throws:
SQLException
-
getAvailableJndiContexts
public static List<String> getAvailableJndiContexts(InitialContext context) throws NamingException, IOException - Parameters:
context- a context to find property files for, if null then it uses a new context- Returns:
- a list of property files which comprise the jndi contexts
- Throws:
NamingExceptionIOException
-
getEntriesForJndiContext
public static Map<String,String> getEntriesForJndiContext(org.osjava.sj.jndi.MemoryContext memoryContext) throws NoSuchFieldException, IllegalAccessException - Parameters:
memoryContext- context to lookup entries for- Returns:
- a map of key value pairs from a specific
memoryContext - Throws:
NoSuchFieldExceptionIllegalAccessException
-
getDetailsforJndiEntry
public static Map.Entry<String,String> getDetailsforJndiEntry(InitialContext context, String jndiName, String entry) throws NoSuchFieldException, IllegalAccessException - Parameters:
context- context to look up entryjndiName- jndi to look up in contextentry- entry within jndi to pull entry for- Returns:
- a map entry for a specific
contextand jndijndiNameand the jndientry - Throws:
NoSuchFieldExceptionIllegalAccessException
-
addJndiConnection
public static Boolean addJndiConnection(String jndiName, String context, Map<String, String> values) throws NamingException, IOException, IllegalAccessException, NoSuchFieldException- Parameters:
jndiName- jndi to look up in contextcontext- context to look up entryvalues- map of values to save to the jndi and context- Returns:
- indication that the new jndi connection was saved
- Throws:
NamingExceptionIOExceptionIllegalAccessExceptionNoSuchFieldException
-