• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DefaultSpearalFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.spearal.DefaultSpearalFactory的典型用法代码示例。如果您正苦于以下问题:Java DefaultSpearalFactory类的具体用法?Java DefaultSpearalFactory怎么用?Java DefaultSpearalFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DefaultSpearalFactory类属于org.spearal包,在下文中一共展示了DefaultSpearalFactory类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testIsProxy

import org.spearal.DefaultSpearalFactory; //导入依赖的package包/类
@Test
public void testIsProxy() throws IOException {
	SpearalFactory clientFactory = new DefaultSpearalFactory(false);
	SpearalFactory serverFactory = new DefaultSpearalFactory();
	
	Person serverPerson1 = new Person("Bla", "Bla");
	
	EntityManager entityManager = entityManagerFactory.createEntityManager();
	PartialEntityResolver resolver = new PartialEntityResolver(entityManager);
	Assert.assertTrue("Simple object", resolver.introspect(serverPerson1).isEmpty());
	
	Contact serverContact1 = new Contact(serverPerson1, "bla", "06");
	serverPerson1.getContacts().add(serverContact1);
	Assert.assertTrue("Graph object", resolver.introspect(serverPerson1).isEmpty());

	Person clientPerson2 = new Person("Bruce", "Willis");
	Person serverPerson2 = clientEncodeServerDecode(clientFactory, serverFactory, clientPerson2, Person.class, "id", "version", "firstName");
	PartialEntityMap map = resolver.introspect(serverPerson2);
	Assert.assertFalse("Proxy object", map.isEmpty());
	serverPerson2 = (Person)resolver.resolve(serverPerson2, map);
	map = resolver.introspect(serverPerson2);
	Assert.assertTrue("Non Proxy object", map.isEmpty());
	
	
	Person clientPerson3 = new Person("Bruce", "Willis");
	Contact clientContact3 = new Contact(clientPerson3, "blo", "06");
	clientPerson3.getContacts().add(clientContact3);
	Person serverPerson3 = clientEncodeServerDecode(clientFactory, serverFactory, clientPerson3, Contact.class, "id", "version", "person", "mobile");
	Assert.assertFalse("Non proxy graph root", serverPerson3 instanceof PartialObjectProxy);
	map = resolver.introspect(serverPerson3);
	Assert.assertFalse("Proxy graph", map.isEmpty());
	serverPerson3 = (Person)resolver.resolve(serverPerson3, map);
	map = resolver.introspect(serverPerson3);
	Assert.assertTrue("Non Proxy graph", map.isEmpty());
	
	entityManager.close();
}
 
开发者ID:spearal,项目名称:spearal-jpa2,代码行数:38,代码来源:TestMergePartial.java


示例2: testIsProxy2

import org.spearal.DefaultSpearalFactory; //导入依赖的package包/类
@Test
public void testIsProxy2() throws Exception {
	SpearalFactory serverFactory = new DefaultSpearalFactory();
	
	Person serverPerson2 = new Person("Blo", "Blo");		
	serverPerson2 = mergeEntity(serverPerson2);
	
	Person serverPerson1 = new Person("Bla", "Bla");
	serverPerson1.setBestFriend(serverPerson2);
	serverPerson1 = mergeEntity(serverPerson1);
	
	serverPerson1 = findEntity(Person.class, serverPerson1.getId());
	EntityManager entityManager = entityManagerFactory.createEntityManager();
	PartialEntityResolver resolver = new PartialEntityResolver(entityManager);
	Assert.assertTrue("Simple object", resolver.introspect(serverPerson1).isEmpty());		
	entityManager.close();
	
	Person incomingPerson1 = new Person("Bla", "Bla");
	incomingPerson1.setId(serverPerson1.getId());
	
	Property[] properties = new Property[2];
	properties[0] = new AnyProperty("id", AbstractEntity.class.getDeclaredField("id"), Person.class.getMethod("getId"), Person.class.getMethod("setId", Long.class));
	properties[1] = new StringProperty("lastName", Person.class.getDeclaredField("lastName"), Person.class.getMethod("getLastName"), Person.class.getMethod("setLastName", String.class));
	Person incomingPerson2 = (Person)new JavassistPartialObjectFactory().instantiatePartial(serverFactory.getContext(), Person.class, properties);
	incomingPerson2.setId(serverPerson2.getId());
	incomingPerson2.setLastName("Toto");
	incomingPerson1.setBestFriend(incomingPerson2);
	
	mergeEntity(incomingPerson1);
	
	serverPerson1 = findEntity(Person.class, serverPerson1.getId());
	Assert.assertEquals("Value updated", "Toto", serverPerson1.getBestFriend().getLastName());
}
 
开发者ID:spearal,项目名称:spearal-jpa2,代码行数:34,代码来源:TestMergePartial.java


示例3: testEmbeddedId

import org.spearal.DefaultSpearalFactory; //导入依赖的package包/类
@Test
public void testEmbeddedId() throws Exception {
	Assert.assertNotNull(entityManagerFactory);
	
	EntityWithEmbeddedId entity = new EntityWithEmbeddedId();
	entity.setId(new EntityEmbeddedId("Joe", "Smith"));
	entity.setAge(12);
	entity.setPhones(Arrays.asList("0123456789", "9876543210"));
	
	persistEntity(entity);
	
	entity = new EntityWithEmbeddedId();
	entity.setId(new EntityEmbeddedId("Joe", "Smith"));
	entity.setAge(24);
	
	SpearalFactory clientFactory = new DefaultSpearalFactory(false);
	SpearalFactory serverFactory = new DefaultSpearalFactory();

	entity = clientEncodeServerDecode(clientFactory, serverFactory, entity, EntityWithEmbeddedId.class, "id", "age");
	Assert.assertTrue(entity instanceof PartialObjectProxy);
	Assert.assertFalse(((PartialObjectProxy)entity).$isDefined("phones"));
	try {
		entity.getPhones();
		Assert.fail("Should throw a UndefinedPropertyException");
	}
	catch (UndefinedPropertyException e) {
	}
	
	entity = mergeEntity(entity);
	Assert.assertFalse(entity instanceof PartialObjectProxy);
	Assert.assertNotNull(entity.getPhones());
	Assert.assertFalse(entityManagerFactory.getPersistenceUnitUtil().isLoaded(entity.getPhones()));
	
	entity = findEntity(EntityWithEmbeddedId.class, new EntityEmbeddedId("Joe", "Smith"), "getPhones");
	Assert.assertEquals(24, entity.getAge());
	Assert.assertEquals(Arrays.asList("0123456789", "9876543210"), entity.getPhones());
}
 
开发者ID:spearal,项目名称:spearal-jpa2,代码行数:38,代码来源:TestMergePartial.java


示例4: testNoPartial

import org.spearal.DefaultSpearalFactory; //导入依赖的package包/类
@Test
public void testNoPartial() throws IOException {
	byte[] data = encode(new ChildBean());
	
	SpearalFactory factory = new DefaultSpearalFactory();
	SpearalDecoder decoder = factory.newDecoder(new ByteArrayInputStream(data));
	decoder.readAny();
	
	Assert.assertFalse(decoder.containsPartialObjects());
}
 
开发者ID:spearal,项目名称:spearal-java,代码行数:11,代码来源:TestBean.java


示例5: testIdClass

import org.spearal.DefaultSpearalFactory; //导入依赖的package包/类
@Test
public void testIdClass() throws Exception {
	Assert.assertNotNull(entityManagerFactory);
	
	ManagedType<?> managedType = entityManagerFactory.getMetamodel().managedType(EntityWithIdClass.class);
	int idsCount = 0;
	for (SingularAttribute<?, ?> attribute : managedType.getSingularAttributes()) {
		if (attribute.isId())
			idsCount++;
	}
	Assert.assertEquals(2, idsCount);
	
	EntityWithIdClass entity = new EntityWithIdClass();
	entity.setFirstName("Jim");
	entity.setLastName("Hall");
	entity.setAge(12);
	entity.setPhones(Arrays.asList("0123456789", "9876543210"));
	
	persistEntity(entity);
	
	entity = new EntityWithIdClass();
	entity.setFirstName("Jim");
	entity.setLastName("Hall");
	entity.setAge(24);
	
	SpearalFactory clientFactory = new DefaultSpearalFactory(false);
	SpearalFactory serverFactory = new DefaultSpearalFactory();

	entity = clientEncodeServerDecode(clientFactory, serverFactory, entity, EntityWithIdClass.class, "firstName", "lastName", "age");
	Assert.assertTrue(entity instanceof PartialObjectProxy);
	Assert.assertFalse(((PartialObjectProxy)entity).$isDefined("phones"));
	try {
		entity.getPhones();
		Assert.fail("Should throw a UndefinedPropertyException");
	}
	catch (UndefinedPropertyException e) {
	}
	
	entity = mergeEntity(entity);
	Assert.assertFalse(entity instanceof PartialObjectProxy);
	Assert.assertNotNull(entity.getPhones());
	Assert.assertFalse(entityManagerFactory.getPersistenceUnitUtil().isLoaded(entity.getPhones()));
	
	entity = findEntity(EntityWithIdClass.class, new EntityIdClass("Jim", "Hall"), "getPhones");
	Assert.assertEquals(24, entity.getAge());
	Assert.assertEquals(Arrays.asList("0123456789", "9876543210"), entity.getPhones());
}
 
开发者ID:spearal,项目名称:spearal-jpa2,代码行数:48,代码来源:TestMergePartial.java


示例6: initDefaultSpearalFactory

import org.spearal.DefaultSpearalFactory; //导入依赖的package包/类
@PostConstruct
private void initDefaultSpearalFactory() {
	if (spearalFactory == null || spearalFactory.isUnsatisfied())
		this.defaultFactory = new DefaultSpearalFactory();
}
 
开发者ID:spearal,项目名称:spearal-jaxrs,代码行数:6,代码来源:SpearalFactoryContextResolver.java


示例7: testClassNotFoundBean

import org.spearal.DefaultSpearalFactory; //导入依赖的package包/类
@SuppressWarnings("boxing")
@Test
public void testClassNotFoundBean() throws IOException {
	SimpleBean bean = new SimpleBean(true, 1, 0.1, "blabla");
	
	SpearalFactory serverFactory = new DefaultSpearalFactory();
	serverFactory.getContext().configure(new AliasStrategy() {
		
		@Override
		public String alias(Class<?> cls) {
			return "org.error." + cls.getSimpleName();
		}
		
		@Override
		public String unalias(String aliasedClassName) {
			return aliasedClassName;
		}
	});
	
	SpearalFactory clientFactory = new DefaultSpearalFactory();

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	SpearalEncoder encoder = serverFactory.newEncoder(baos);
	encoder.writeAny(bean);
	
	byte[] bytes = baos.toByteArray();
	
	ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
	SpearalDecoder decoder = clientFactory.newDecoder(bais);
	decoder.printAny(clientFactory.newPrinter(printStream));
	printStream.println();
	
	bais.reset();
	decoder = clientFactory.newDecoder(bais);
	ClassNotFound clientBean = (ClassNotFound)decoder.readAny();
	
	Assert.assertEquals(
		clientBean.getClassNotFoundDescription(),
		"org.error.SimpleBean#booleanValue,doubleValue,intValue,stringValue"
	);
	Assert.assertEquals(bean.isBooleanValue(), clientBean.get("booleanValue"));
	Assert.assertEquals(Long.valueOf(bean.getIntValue()), clientBean.get("intValue"));
	Assert.assertEquals(bean.getDoubleValue(), clientBean.get("doubleValue"));
	Assert.assertEquals(bean.getStringValue(), clientBean.get("stringValue"));
	
	bais.reset();
	decoder = clientFactory.newDecoder(bais);
	SimpleBean copy = decoder.readAny(SimpleBean.class);
	Assert.assertEquals(bean, copy);
}
 
开发者ID:spearal,项目名称:spearal-java,代码行数:51,代码来源:TestAliasedBean.java


示例8: encode

import org.spearal.DefaultSpearalFactory; //导入依赖的package包/类
protected byte[] encode(Object o) throws IOException {
	return encode(new DefaultSpearalFactory(), null, o);
}
 
开发者ID:spearal,项目名称:spearal-java,代码行数:4,代码来源:AbstractSpearalTestUnit.java


示例9: decode

import org.spearal.DefaultSpearalFactory; //导入依赖的package包/类
protected Object decode(byte[] bytes) throws IOException {
	return decode(new DefaultSpearalFactory(), bytes, null);
}
 
开发者ID:spearal,项目名称:spearal-java,代码行数:4,代码来源:AbstractSpearalTestUnit.java


示例10: testMergeProxy

import org.spearal.DefaultSpearalFactory; //导入依赖的package包/类
@Test
public void testMergeProxy() throws Exception {
	Assert.assertNotNull(entityManagerFactory);
	
	Person clientPerson = new Person("Bruce", "Willis");
	
	// Do not load any services here (pseudo-client application).
	SpearalFactory clientFactory = new DefaultSpearalFactory(false);
	SpearalFactory serverFactory = new DefaultSpearalFactory();
	
	Person serverPerson = clientEncodeServerDecodeMerge(clientFactory, serverFactory, clientPerson, Person.class, "id", "version", "firstName");		
	
	Assert.assertNotNull("Id not null", serverPerson.getId());
	Assert.assertEquals("Version 0", Long.valueOf(0L), serverPerson.getVersion());
	
	serverPerson = findEntity(Person.class, serverPerson.getId());
	
	Assert.assertEquals("Person firstName", clientPerson.getFirstName(), serverPerson.getFirstName());
	
	clientPerson.setId(serverPerson.getId());
	clientPerson.backdoorSetVersion(serverPerson.getVersion());
	clientPerson.setFirstName("John");
	clientPerson.setLastName("McLane");
	
	serverPerson = clientEncodeServerDecodeMerge(clientFactory, serverFactory, clientPerson, Person.class, "id", "version", "firstName");
	
	Assert.assertEquals("Person firstName", clientPerson.getFirstName(), serverPerson.getFirstName());
	
	serverPerson = findEntity(Person.class, serverPerson.getId());
	
	Assert.assertEquals("Person firstName", clientPerson.getFirstName(), serverPerson.getFirstName());
	Assert.assertEquals("Version 1", Long.valueOf(1L), serverPerson.getVersion());
	
	Person clientFriend = new Person("Hans", "Gruber");
	clientPerson.backdoorSetVersion(serverPerson.getVersion());
	clientPerson.setBestFriend(clientFriend);
	
	serverPerson = clientEncodeServerDecodeMerge(clientFactory, serverFactory, clientPerson, Person.class, "id", "version", "firstName", "bestFriend");
	
	Assert.assertEquals("Friend firstName", clientFriend.getFirstName(), serverPerson.getBestFriend().getFirstName());
	Assert.assertEquals("Version 0", Long.valueOf(0L), serverPerson.getBestFriend().getVersion());
	
	serverPerson = findEntity(Person.class, serverPerson.getId());
	Assert.assertEquals("Version 2", Long.valueOf(2L), serverPerson.getVersion());
}
 
开发者ID:spearal,项目名称:spearal-jpa2,代码行数:46,代码来源:TestMergePartial.java



注:本文中的org.spearal.DefaultSpearalFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CassandraOperation类代码示例发布时间:2022-05-16
下一篇:
Java ElementMinimize类代码示例发布时间:2022-05-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap