本文整理汇总了Java中javax.naming.Context.bind方法的典型用法代码示例。如果您正苦于以下问题:Java Context.bind方法的具体用法?Java Context.bind怎么用?Java Context.bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.Context
的用法示例。
在下文中一共展示了Context.bind方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldApplyMigrations
import javax.naming.Context; //导入方法依赖的package包/类
@Test
public void shouldApplyMigrations() throws Exception {
//bind the datasources
DataSource migrationdataSource = pg.getPostgresDatabase();
DataSource userdataSource = pg.getPostgresDatabase();
//bind to context
Context ctx = new InitialContext();
ctx.bind("java:test/datasources/migrationDS", migrationdataSource);
ctx.bind("java:test/datasources/testDS", userdataSource);
try (DrinkWaterApplication app = DrinkWaterApplication.create("jndi-datastore-test",
options().use(JndiDataStoreConfiguration.class).autoStart())) {
JndiSqlDataStore store = app.getStore("test");
store.executeNoQuery("INSERT INTO contact(id, first_name, last_name) VALUES (2 , 'Jean-Marc', 'Canon');");
try (Connection c = store.getConnection()) {
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT * from contact");
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
}
}
}
示例2: shouldLogEventInDatabase
import javax.naming.Context; //导入方法依赖的package包/类
@Test
public void shouldLogEventInDatabase() throws Exception {
//bind the datasources
DataSource migrationdataSource = pg.getPostgresDatabase();
DataSource userdataSource = pg.getPostgresDatabase();
//bind to context
Context ctx = new InitialContext();
ctx.bind("java:test/datasources/migrationDS", migrationdataSource);
ctx.bind("java:test/datasources/testDS", userdataSource);
try (DrinkWaterApplication app = DrinkWaterApplication.create("datastore-event-test",
options().use(SqlDataStoreEventLoggerTestConfiguration.class).autoStart())) {
JndiSqlDataStore store = app.getStore("test");
String result = httpGetString(String.format("http://localhost:%s/test/echo?message=hello",
app.getServiceProperty("test", RestService.REST_PORT_KEY))).result();
assertThat(result).isEqualTo("hello");
app.stop();
try (Connection c = store.getConnection()) {
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT count(*) from trace");
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
}
}
}
示例3: createIndexerQueue
import javax.naming.Context; //导入方法依赖的package包/类
protected static FifoJMSQueue createIndexerQueue() throws NamingException,
JMSException {
enableJndiMock();
Context jndiContext = new InitialContext();
// static queue required since hibernate listener caches queue object
FifoJMSQueue indexerQueue = new FifoJMSQueue();
jndiContext.bind("jms/bss/indexerQueueFactory",
initMockFactory(indexerQueue));
jndiContext.bind("jms/bss/indexerQueue", indexerQueue);
return indexerQueue;
}
示例4: contextTest
import javax.naming.Context; //导入方法依赖的package包/类
@Test
public void contextTest() throws NamingException {
DataSource mockDataSource = (DataSource) Proxy.newProxyInstance(getClass().getClassLoader(),
new Class[] { DataSource.class }, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return null;
}
});
Context context = new InitialContext();
context.bind("java:/DefaultDS", mockDataSource);
}
示例5: rebind
import javax.naming.Context; //导入方法依赖的package包/类
/**
* Rebinds object obj to name name . If there is existing binding it will be overwritten.
*
* @param name name of the object to rebind.
* @param obj object to add. Can be null.
* @throws NoPermissionException if this context has been destroyed
* @throws InvalidNameException if name is empty or is CompositeName that spans more than one
* naming system
* @throws NotContextException if name has more than one atomic name and intermediate context is
* not found
* @throws NamingException if any other naming error occurs
*
*/
public void rebind(Name name, Object obj) throws NamingException {
checkIsDestroyed();
Name parsedName = getParsedName(name);
if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
throw new InvalidNameException(
LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
}
String nameToBind = parsedName.get(0);
if (parsedName.size() == 1) {
ctxMaps.put(nameToBind, obj);
} else {
Object boundObject = ctxMaps.get(nameToBind);
if (boundObject instanceof Context) {
/*
* Let the subcontext bind the object.
*/
((Context) boundObject).bind(parsedName.getSuffix(1), obj);
} else {
if (boundObject == null) {
// Create new subcontext and let it do the binding
Context sub = createSubcontext(nameToBind);
sub.bind(parsedName.getSuffix(1), obj);
} else {
throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0
.toLocalizedString(boundObject));
}
}
}
}
示例6: shouldRetrievebeanFromJndi
import javax.naming.Context; //导入方法依赖的package包/类
@Test
public void shouldRetrievebeanFromJndi() throws NamingException {
Context ctx = new InitialContext();
ctx.bind("hello", "world");
Object result = ctx.lookup("hello");
assertThat(result).isEqualTo("world");
}