当前位置: 首页>>代码示例>>Java>>正文


Java ParameterMode类代码示例

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


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

示例1: calculate

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Test
public void calculate() {
	log.info("... calculate ...");
	EntityManager em = emf.createEntityManager();
       em.getTransaction().begin();
       
	// define the stored procedure
	StoredProcedureQuery query = em.createStoredProcedureQuery("calculate");
	query.registerStoredProcedureParameter("x", Double.class, ParameterMode.IN);
	query.registerStoredProcedureParameter("y", Double.class, ParameterMode.IN);
	query.registerStoredProcedureParameter("sum", Double.class, ParameterMode.OUT);
	
	// set input parameter
	query.setParameter("x", 1.23d);
	query.setParameter("y", 4d);
	
	// call the stored procedure and get the result
	query.execute();
	Double sum = (Double) query.getOutputParameterValue("sum");
	log.info("Calculation result: 1.23 + 4 = " + sum);

       em.getTransaction().commit();
       em.close();
}
 
开发者ID:thjanssen,项目名称:HibernateTips,代码行数:25,代码来源:TestStoredProcedureQuery.java

示例2: testHibernateProcedureCallRefCursor

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Test
public void testHibernateProcedureCallRefCursor() {
    doInJPA(entityManager -> {
        Session session = entityManager.unwrap(Session.class);
        ProcedureCall call = session
            .createStoredProcedureCall("post_comments");
        call.registerParameter(1, void.class, ParameterMode.REF_CURSOR);
        call.registerParameter(2, Long.class, ParameterMode.IN).bindValue(1L);

        Output output = call.getOutputs().getCurrent();
        if (output.isResultSet()) {
            List<Object[]> postComments = ((ResultSetOutput) output).getResultList();
            assertEquals(2, postComments.size());
        }
    });
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:17,代码来源:PostgreSQLStoredProcedureTest.java

示例3: testHibernateProcedureCallOutParameter

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Test
public void testHibernateProcedureCallOutParameter() {
    doInJPA(entityManager -> {
        Session session = entityManager.unwrap(Session.class);
        ProcedureCall call = session.createStoredProcedureCall("getStatistics");
        call.registerParameter("postId", Long.class, ParameterMode.IN).bindValue(1L);
        call.registerParameter("commentCount", Long.class, ParameterMode.OUT);

        Long commentCount = (Long) call.getOutputs().getOutputParameterValue("commentCount");
        assertEquals(Long.valueOf(2), commentCount);
    });
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:13,代码来源:MySQLStoredProcedureTest.java

示例4: AbstractParameterRegistrationImpl

import javax.persistence.ParameterMode; //导入依赖的package包/类
private AbstractParameterRegistrationImpl(
		ProcedureCallImpl procedureCall,
		Integer position,
		String name,
		ParameterMode mode,
		Class<T> type,
		Type hibernateType) {
	this.procedureCall = procedureCall;

	this.position = position;
	this.name = name;

	this.mode = mode;
	this.type = type;

	if ( mode == ParameterMode.REF_CURSOR ) {
		return;
	}

	setHibernateType( hibernateType );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:AbstractParameterRegistrationImpl.java

示例5: extract

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public T extract(CallableStatement statement) {
	if ( mode == ParameterMode.IN ) {
		throw new ParameterMisuseException( "IN parameter not valid for output extraction" );
	}
	else if ( mode == ParameterMode.REF_CURSOR ) {
		throw new ParameterMisuseException( "REF_CURSOR parameters should be accessed via results" );
	}

	try {
		if ( ProcedureParameterExtractionAware.class.isInstance( hibernateType ) ) {
			return (T) ( (ProcedureParameterExtractionAware) hibernateType ).extract( statement, startIndex, session() );
		}
		else {
			return (T) statement.getObject( startIndex );
		}
	}
	catch (SQLException e) {
		throw procedureCall.getSession().getFactory().getSQLExceptionHelper().convert(
				e,
				"Unable to extract OUT/INOUT parameter value"
		);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:AbstractParameterRegistrationImpl.java

示例6: runBackup

import javax.persistence.ParameterMode; //导入依赖的package包/类
/**
 * Creates a Backup of the Database in the directory specified in
 * config.properties.
 *
 * @param name the name of the Backup.
 *
 * @return Backup entinty.
 *
 * @throws QueryTimeoutException if the query should fail.
 * @throws PersistenceException if persisting should fail.
 * @Throws IOException if config.properties is not readable.
 */
public Backup runBackup(String name) throws QueryTimeoutException,
       PersistenceException, IOException {
    Properties props = ServerProperties.getProperties();
    Date date = new Date();
    String path = props.getProperty(dirPropertyKey)
            + name + "_" + getDateAsString(date);

    StoredProcedureQuery query = em.createStoredProcedureQuery(
            "SYSCS_UTIL.SYSCS_BACKUP_DATABASE");
    query.registerStoredProcedureParameter(1, String.class,
            ParameterMode.IN);
    query.setParameter(1, path);
    query.execute();
    log.debug("Backup query executed!");

    Backup backup =  generateBackup(name, path, date, getDirectorySize(new File(path)));

    return backup;
}
 
开发者ID:stefanoberdoerfer,项目名称:exmatrikulator,代码行数:32,代码来源:BackupService.java

示例7: testHibernateProcedureCallMultipleOutParameter

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Test
public void testHibernateProcedureCallMultipleOutParameter() {
    doInJPA(entityManager -> {
        StoredProcedureQuery query = entityManager
            .createStoredProcedureQuery("getStatistics")
            .registerStoredProcedureParameter(
                    "A", Long.class, ParameterMode.OUT)
            .registerStoredProcedureParameter(
                    "B", Long.class, ParameterMode.OUT)
            .registerStoredProcedureParameter(
                    "C", Long.class, ParameterMode.OUT);

        query.execute();

        Long a = (Long) query
                .getOutputParameterValue("A");
        Long b = (Long) query
                .getOutputParameterValue("B");
        Long c = (Long) query
                .getOutputParameterValue("C");
    });
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:23,代码来源:MySQLStoredProcedureTest.java

示例8: testStoredProcedureRefCursor

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Test
public void testStoredProcedureRefCursor() {
    try {
        doInJPA(entityManager -> {
            StoredProcedureQuery query = entityManager.createStoredProcedureQuery("post_comments");
            query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
            query.registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR);
            query.setParameter(1, 1L);

            query.execute();
            List<Object[]> postComments = query.getResultList();
            assertNotNull(postComments);
        });
    } catch (Exception e) {
        assertTrue(Pattern.compile("Dialect .*? not known to support REF_CURSOR parameters").matcher(e.getCause().getMessage()).matches());
    }
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:18,代码来源:MySQLStoredProcedureTest.java

示例9: testFunction

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Test
public void testFunction() {
    try {
        doInJPA(entityManager -> {
            StoredProcedureQuery query = entityManager.createStoredProcedureQuery("fn_count_comments");
            query.registerStoredProcedureParameter("postId", Long.class, ParameterMode.IN);

            query.setParameter("postId", 1L);

            Long commentCount = (Long) query.getSingleResult();
            assertEquals(Long.valueOf(2), commentCount);
        });
    } catch (Exception e) {
        assertTrue(Pattern.compile("PROCEDURE high_performance_java_persistence.fn_count_comments does not exist").matcher(e.getCause().getCause().getMessage()).matches());
    }
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:17,代码来源:MySQLStoredProcedureTest.java

示例10: testStoredProcedureOutParameter

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Test
public void testStoredProcedureOutParameter() {
    doInJPA(entityManager -> {
        StoredProcedureQuery query = entityManager
            .createStoredProcedureQuery("count_comments")
            .registerStoredProcedureParameter(
                "postId", Long.class, ParameterMode.IN)
            .registerStoredProcedureParameter(
                "commentCount", Long.class, ParameterMode.OUT)
            .setParameter("postId", 1L);

        query.execute();

        Long commentCount = (Long) query.getOutputParameterValue("commentCount");
        assertEquals(Long.valueOf(2), commentCount);
    });
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:18,代码来源:SQLServerStoredProcedureTest.java

示例11: testStoredProcedureRefCursor

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Test
public void testStoredProcedureRefCursor() {
    try {
        doInJPA(entityManager -> {
            StoredProcedureQuery query = entityManager
                .createStoredProcedureQuery("post_comments")
            .registerStoredProcedureParameter(1, Long.class, ParameterMode.IN)
            .registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR)
            .setParameter(1, 1L);

            query.execute();
            List<Object[]> postComments = query.getResultList();
            assertNotNull(postComments);
        });
    } catch (Exception e) {
        assertTrue(Pattern.compile("Dialect .*? not known to support REF_CURSOR parameters").matcher(e.getCause().getMessage()).matches());
    }
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:19,代码来源:SQLServerStoredProcedureTest.java

示例12: shouldInvokeStoredProcedureWithOutbound

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Test
public void shouldInvokeStoredProcedureWithOutbound() throws Exception {
    utx.begin();
    StoredProcedureQuery query =
        em.createStoredProcedureQuery("DOUBLE_SP")
        .registerStoredProcedureParameter(
            "P1", Float.class, ParameterMode.IN)
        .registerStoredProcedureParameter(
            "P2", Float.class, ParameterMode.OUT)
        .setParameter("P1", new Float(2.345));
    boolean status = query.execute();
    System.out.printf("****************** status=%s\n", status);
    assertFalse( query.hasMoreResults());
    Double p2 = ( Double)query.getOutputParameterValue("P2");
    System.out.printf("The output P2 was %12.7f\n", p2 );
    utx.commit();
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:18,代码来源:StoredProcedureJPATest2.java

示例13: shouldInvokeStoredProcedureWithOutbound

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Test
public void shouldInvokeStoredProcedureWithOutbound() throws Exception {
    StoredProcedureQuery query =
        em.createStoredProcedureQuery("COMPOUND_INTEREST_SP")
        .registerStoredProcedureParameter(
            "P", Float.class, ParameterMode.IN)
        .registerStoredProcedureParameter(
            "r", Float.class, ParameterMode.IN)
        .registerStoredProcedureParameter(
            "n", Integer.class, ParameterMode.IN)
        .registerStoredProcedureParameter(
            "t", Integer.class, ParameterMode.IN)
        .registerStoredProcedureParameter(
            "A", Float.class, ParameterMode.OUT)
        .setParameter("P", new Float(1500))
        .setParameter("r", new Float(0.043))
        .setParameter("n", new Integer(4))
        .setParameter("t", new Integer(6));
    // P = 1500, r = 0.043 (4.3%), n = 4, and t = 6:
    boolean status = query.execute();
    System.out.printf("****************** status=%s\n", status);
    assertFalse( query.hasMoreResults());
    Double A = ( Double)query.getOutputParameterValue("A");
    System.out.printf("The output A was %12.7f\n", A );
    assertEquals( 1938.84, A, 0.005 );
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:27,代码来源:CompoundInterestRateStoredProcJPATest.java

示例14: shouldInvokeStoredProcedureWithResultSet

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Test
public void shouldInvokeStoredProcedureWithResultSet() throws Exception {
    utx.begin();
    StoredProcedureQuery query =
        em.createStoredProcedureQuery("READ_TAX_SP")
        .registerStoredProcedureParameter(
            "TAX_CODE_ID", Integer.class, ParameterMode.IN)
        .setParameter("TAX_CODE_ID", 101);
    boolean status = query.execute();
    System.out.printf("****************** status=%s\n", status);
    List rs =  query.getResultList();
    assertNotNull(rs);
    System.out.printf("****************** rs=%s\n", rs );
    Object row[] = (Object[])rs.get(0);
    System.out.printf("****************** row=%s\n", row );
    for (int col=0; col<row.length; ++col ) {
        System.out.printf("**** row[%d]=%s\n", col, row[col]  );
    }
    utx.commit();
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:21,代码来源:StoredProcedureJPATest.java

示例15: plainJpa21

import javax.persistence.ParameterMode; //导入依赖的package包/类
@Test
public void plainJpa21() {

	StoredProcedureQuery proc = em.createStoredProcedureQuery("plus1inout");
	proc.registerStoredProcedureParameter(1, Integer.class, ParameterMode.IN);
	proc.registerStoredProcedureParameter(2, Integer.class, ParameterMode.OUT);

	proc.setParameter(1, 1);
	proc.execute();

	assertThat(proc.getOutputParameterValue(2), is((Object) 2));
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:13,代码来源:UserRepositoryIntegrationTests.java


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