本文整理汇总了Java中javax.persistence.PersistenceProperty类的典型用法代码示例。如果您正苦于以下问题:Java PersistenceProperty类的具体用法?Java PersistenceProperty怎么用?Java PersistenceProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PersistenceProperty类属于javax.persistence包,在下文中一共展示了PersistenceProperty类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getPersistenceContextProperties
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
private static Map<String, Object> getPersistenceContextProperties(final PersistenceContext persistenceContext) {
final Map<String, Object> properties = new HashMap<>();
for (final PersistenceProperty property : persistenceContext.properties()) {
String propertyValue = property.value();
Matcher matcher = PROPERTY_PATTERN.matcher(propertyValue);
while(matcher.find()) {
String p = matcher.group();
String systemProperty = p.substring(2, p.length() - 1);
propertyValue = propertyValue.replace(p, System.getProperty(systemProperty, p));
}
properties.put(property.name(), propertyValue);
}
return properties;
}
开发者ID:dadrus,项目名称:jpa-unit,代码行数:17,代码来源:JpaUnitContext.java
示例2: createJPARule
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
private static JPARule createJPARule(PersistenceContext ctx, Object test) {
DatabaseConfiguration config = findOnTest(DatabaseConfiguration.class, test);
if (config == null) {
return new JPARule(ctx, H2, DEFAULT_STORAGE, DEFAULT_MODE);
}
switch (config.value()) {
case H2:
return new JPARule(ctx, H2, config.h2().storage(), config.h2().mode());
case UNDEFINED:
default:
Map<String, String> properties = new HashMap<>();
for (PersistenceProperty property : ctx.properties()) {
properties.put(property.name(), property.value());
}
return unitName(ctx.unitName())
.database(UNDEFINED)
.noInternalProperties()
.properties(properties)
.build();
}
}
开发者ID:Tibor17,项目名称:javaee-samples,代码行数:24,代码来源:InjectionRunner.java
示例3: PersistenceElement
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
public PersistenceElement(Member member, AnnotatedElement ae, PropertyDescriptor pd) {
super(member, pd);
PersistenceContext pc = ae.getAnnotation(PersistenceContext.class);
PersistenceUnit pu = ae.getAnnotation(PersistenceUnit.class);
Class<?> resourceType = EntityManager.class;
if (pc != null) {
if (pu != null) {
throw new IllegalStateException("Member may only be annotated with either " +
"@PersistenceContext or @PersistenceUnit, not both: " + member);
}
Properties properties = null;
PersistenceProperty[] pps = pc.properties();
if (!ObjectUtils.isEmpty(pps)) {
properties = new Properties();
for (PersistenceProperty pp : pps) {
properties.setProperty(pp.name(), pp.value());
}
}
this.unitName = pc.unitName();
this.type = pc.type();
this.synchronizedWithTransaction = (synchronizationAttribute == null ||
"SYNCHRONIZED".equals(ReflectionUtils.invokeMethod(synchronizationAttribute, pc).toString()));
this.properties = properties;
}
else {
resourceType = EntityManagerFactory.class;
this.unitName = pu.unitName();
}
checkResourceType(resourceType);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:PersistenceAnnotationBeanPostProcessor.java
示例4: JPARule
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
JPARule(PersistenceContext unit, DB db, H2Storage storage, Mode mode) {
for (PersistenceProperty property : unit.properties()) {
properties.put(property.name(), property.value());
}
unitName = unit.unitName();
this.storage = storage;
this.mode = mode;
this.db = db;
}
开发者ID:Tibor17,项目名称:javaee-samples,代码行数:10,代码来源:JPARule.java
示例5: test
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
@Test
@PersistenceContext(unitName = "table-generator-pu", properties = {
@PersistenceProperty(name = "hibernate.id.new_generator_mappings", value = "true")
})
public void test() throws Exception {
assertThat(em, is(notNullValue()));
}
开发者ID:Tibor17,项目名称:javaee-samples,代码行数:8,代码来源:WithTableGeneratorWithoutRuleTest.java
示例6: PersistenceElement
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
public PersistenceElement(Member member, PropertyDescriptor pd) {
super(member, pd);
AnnotatedElement ae = (AnnotatedElement) member;
PersistenceContext pc = ae.getAnnotation(PersistenceContext.class);
PersistenceUnit pu = ae.getAnnotation(PersistenceUnit.class);
Class<?> resourceType = EntityManager.class;
if (pc != null) {
if (pu != null) {
throw new IllegalStateException("Member may only be annotated with either " +
"@PersistenceContext or @PersistenceUnit, not both: " + member);
}
Properties properties = null;
PersistenceProperty[] pps = pc.properties();
if (!ObjectUtils.isEmpty(pps)) {
properties = new Properties();
for (PersistenceProperty pp : pps) {
properties.setProperty(pp.name(), pp.value());
}
}
this.unitName = pc.unitName();
this.type = pc.type();
this.properties = properties;
}
else {
resourceType = EntityManagerFactory.class;
this.unitName = pu.unitName();
}
checkResourceType(resourceType);
}
开发者ID:deathspeeder,项目名称:class-guard,代码行数:30,代码来源:PersistenceAnnotationBeanPostProcessor.java
示例7: assertEq
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
private static void assertEq(final PersistenceContext annotation, final PersistenceContextAnn wrapper) {
if (annotation.name().length() > 0) {
assertEquals(annotation.name(), wrapper.name());
}
assertEquals(annotation.unitName(), wrapper.unitName());
assertEquals(annotation.type().toString(), wrapper.type());
final Map<String, String> properties = new HashMap<String, String>();
for (final PersistenceProperty property : annotation.properties()) {
properties.put(property.name(), property.value());
}
assertEquals(properties, wrapper.properties());
}
开发者ID:apache,项目名称:tomee,代码行数:14,代码来源:PersistenceContextAnnFactoryTest.java
示例8: persistenceContext
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
private InjectionPoint persistenceContext(String unitName) {
final InjectionPoint ip = mock(InjectionPoint.class);
final Annotated annotated = mock(Annotated.class);
when(ip.getAnnotated()).thenReturn(annotated);
final PersistenceContext annotation = new PersistenceContext() {
@Override
public Class<? extends Annotation> annotationType() {
return null;
}
@Override
public String name() {
return null;
}
@Override
public String unitName() {
return unitName;
}
@Override
public PersistenceContextType type() {
return null;
}
@Override
public SynchronizationType synchronization() {
return null;
}
@Override
public PersistenceProperty[] properties() {
return new PersistenceProperty[0];
}
};
when(annotated.getAnnotation(PersistenceContext.class)).thenReturn(annotation);
return ip;
}
开发者ID:dajudge,项目名称:testee.fi,代码行数:39,代码来源:JpaInjectionServicesTest.java
示例9: testClassWithPersistenceContextWithWithOverwrittenConfiguration
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
@Test
public void testClassWithPersistenceContextWithWithOverwrittenConfiguration() throws Exception {
// GIVEN
final JCodeModel jCodeModel = new JCodeModel();
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
final JFieldVar ruleField = jClass.field(JMod.PUBLIC, JpaUnitRule.class, "rule");
ruleField.annotate(Rule.class);
final JInvocation instance = JExpr._new(jCodeModel.ref(JpaUnitRule.class)).arg(JExpr.direct("getClass()"));
ruleField.init(instance);
final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "em");
final JAnnotationUse jAnnotation = emField.annotate(PersistenceContext.class);
jAnnotation.param("unitName", "test-unit-1");
final JAnnotationArrayMember propArray = jAnnotation.paramArray("properties");
propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.url").param("value",
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.driver").param("value", "org.h2.Driver");
propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.password").param("value", "test");
propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.user").param("value", "test");
final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
jMethod.annotate(Test.class);
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name());
final BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(cut);
final RunListener listener = mock(RunListener.class);
final RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
// WHEN
runner.run(notifier);
// THEN
final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class);
verify(listener).testStarted(descriptionCaptor.capture());
assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
verify(listener).testFinished(descriptionCaptor.capture());
assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
}
开发者ID:dadrus,项目名称:jpa-unit,代码行数:46,代码来源:JpaUnitRuleTest.java
示例10: testClassWithPersistenceContextWithWithOverwrittenConfiguration
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
@Test
public void testClassWithPersistenceContextWithWithOverwrittenConfiguration() throws Exception {
// GIVEN
final JCodeModel jCodeModel = new JCodeModel();
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class);
jAnnotationUse.param("value", JpaUnitRunner.class);
final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "em");
final JAnnotationUse jAnnotation = emField.annotate(PersistenceContext.class);
jAnnotation.param("unitName", "test-unit-1");
final JAnnotationArrayMember propArray = jAnnotation.paramArray("properties");
propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.url").param("value",
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.driver").param("value", "org.h2.Driver");
propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.password").param("value", "test");
propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.user").param("value", "test");
final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
jMethod.annotate(Test.class);
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name());
final JpaUnitRunner runner = new JpaUnitRunner(cut);
final RunListener listener = mock(RunListener.class);
final RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
// WHEN
runner.run(notifier);
// THEN
final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class);
verify(listener).testStarted(descriptionCaptor.capture());
assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
verify(listener).testFinished(descriptionCaptor.capture());
assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
}
开发者ID:dadrus,项目名称:jpa-unit,代码行数:44,代码来源:JpaUnitRunnerTest.java
示例11: properties
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
@Override
public PersistenceProperty[] properties()
{
return new PersistenceProperty[0];
}
开发者ID:satago,项目名称:tapestry-jpa-transactions,代码行数:6,代码来源:PersistenceContextImpl.java
示例12: test
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
@Test
@PersistenceContext(unitName = "table-generator-pu", properties = {
@PersistenceProperty(name = "hibernate.id.new_generator_mappings", value = "true")/*,
@PersistenceProperty(name = "hibernate.id.optimizer.pooled.prefer_lo", value = "false")*/
})
public void test() throws Exception {
nextInsert();
BigInteger id = nextSequenceId();
BigInteger aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
nextInsert();
id = nextSequenceId();
aid = approximatedSequenceId();
assertThat(aid, is(id));
}
开发者ID:Tibor17,项目名称:javaee-samples,代码行数:72,代码来源:WithTableGeneratorTest.java
示例13: method
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
@PersistenceContext(name = "method", unitName = "mu", type = PersistenceContextType.EXTENDED, properties = {
@PersistenceProperty(name = "method1", value = "m1"),
@PersistenceProperty(name = "method2", value = "m2")
})
public void method() {
}
开发者ID:apache,项目名称:tomee,代码行数:7,代码来源:PersistenceContextAnnFactoryTest.java
示例14: setMyMethod
import javax.persistence.PersistenceProperty; //导入依赖的package包/类
@PersistenceContext(unitName = "mymu", type = PersistenceContextType.EXTENDED, properties = {
@PersistenceProperty(name = "myMethod1", value = "mym1"),
@PersistenceProperty(name = "myMethod2", value = "mym2")
})
public void setMyMethod() {
}
开发者ID:apache,项目名称:tomee,代码行数:7,代码来源:PersistenceContextAnnFactoryTest.java
注:本文中的javax.persistence.PersistenceProperty类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论