Package com.mysql.clusterj

Examples of com.mysql.clusterj.Session


        sessionFactory3 = ClusterJHelper.getSessionFactory(modifiedProperties);
        errorIfNotEqual(where + " SessionFactory1 should be the same object as SessionFactory2", true,
                sessionFactory1 == sessionFactory2);
        errorIfNotEqual(where + " SessionFactory1 should be the same object as SessionFactory3", true,
                sessionFactory1 == sessionFactory3);
        Session session1 = sessionFactory1.getSession();
        Employee e1 = session1.find(Employee.class, 0);
        checkSessions(where + " after get session1", sessionFactory1, new Integer[] {1, 0});
        Session session2 = sessionFactory1.getSession();
        Employee e2 = session2.find(Employee.class, 0);
        checkSessions(where + " after get session2", sessionFactory1, new Integer[] {1, 1});
        Session session3 = sessionFactory1.getSession();
        checkSessions(where + " nafter get session3", sessionFactory1, new Integer[] {2, 1});
        Session session4 = sessionFactory1.getSession();
        checkSessions(where + " after get session4", sessionFactory1, new Integer[] {2, 2});
        Session session5 = sessionFactory1.getSession();
        checkSessions(where + " after get session5", sessionFactory1, new Integer[] {3, 2});
        Session session6 = sessionFactory1.getSession();
        checkSessions(where + " after get session6", sessionFactory1, new Integer[] {3, 3});

        session1.close();
        checkSessions(where + " after close session1", sessionFactory1, new Integer[] {2, 3});
        session4.close();
        checkSessions(where + " after close session4", sessionFactory1, new Integer[] {2, 2});
        session5.close();
        checkSessions(where + " after close session5", sessionFactory1, new Integer[] {1, 2});
        Session session7 = sessionFactory1.getSession();
        checkSessions(where + " after get session7", sessionFactory1, new Integer[] {2, 2});
       
        session2.close();
        session3.close();
        session6.close();
        session7.close();
        sessionFactory1.close();
    }
View Full Code Here


                Constants.DEFAULT_PROPERTY_CLUSTER_MAX_TRANSACTIONS);
        CLUSTER_CONNECTION_SERVICE = getStringProperty(props, PROPERTY_CLUSTER_CONNECTION_SERVICE);
        createClusterConnectionPool();
        // now get a Session and complete a transaction to make sure that the cluster is ready
        try {
            Session session = getSession(null);
            session.currentTransaction().begin();
            session.currentTransaction().commit();
            session.close();
        } catch (Exception e) {
            if (e instanceof ClusterJException) {
                logger.warn(local.message("ERR_Session_Factory_Impl_Failed_To_Complete_Transaction"));
                throw (ClusterJException)e;
            }
View Full Code Here

        errorIfNotEqual("Failed to create customers.",
                numberOfThreads * numberOfNewCustomersPerThread + numberOfInitialCustomers, nextCustomerId);
        errorIfNotEqual("Failed to create orders. ",
                numberOfThreads * numberOfNewCustomersPerThread * numberOfNewOrdersPerNewCustomer, nextOrderId);
        // double check the orders to make sure they were updated correctly
        Session session = sessionFactory.getSession();
        QueryDomainType<OrderLine> queryOrderType = session.getQueryBuilder().createQueryDefinition(OrderLine.class);
        queryOrderType.where(queryOrderType.get("orderId").equal(queryOrderType.param("orderId")));
        Query<OrderLine> query = session.createQuery(queryOrderType);       
        for (Order order: orders) {
            int orderId = order.getId();
            // replace order with its persistent representation
            order = session.find(Order.class, orderId);
            double expectedTotal = order.getValue();
            double actualTotal = 0.0d;
            for (OrderLine orderLine: getOrderLines(session, query, orderId)) {
                actualTotal += orderLine.getTotalValue();
            }
View Full Code Here

        private Random myRandom = new Random();

        public void run() {
            // get my own session
            Session session = sessionFactory.getSession();
            QueryDomainType<OrderLine> queryOrderType = session.getQueryBuilder().createQueryDefinition(OrderLine.class);
            queryOrderType.where(queryOrderType.get("orderId").equal(queryOrderType.param("orderId")));
            Query<OrderLine> query = session.createQuery(queryOrderType);
            for (int i = 0; i < numberOfNewCustomersPerThread; ++i) {
                // create a new customer
                createCustomer(session, String.valueOf(Thread.currentThread().getId()));
                for (int j = 0; j < numberOfNewOrdersPerNewCustomer ; ++j) {
                    // create a new order
View Full Code Here

        for (int i = 0; i < 4; ++i) {
            final int id = i;
            pool.submit(new Runnable() {
               
                public void run() {
                    Session session = Manager.getSessionFactory().getSession();
                    Employee entity = session.newInstance(Employee.class); // crash here?
                    entity.setId(id);
                    entity.setAge(id);
                    entity.setMagic(id);
                    entity.setName("Employee " + id);
                    session.currentTransaction().begin();
                    session.persist(entity);
                    session.currentTransaction().commit();
                    return;
                }
            });
        }
        // wait for all threads to complete
View Full Code Here

        }
        pool.shutdownNow();
    }

    private static void insert(int number) {
        Session session = Manager.getSessionFactory().getSession();
        Employee entity = session.newInstance(Employee.class);
        entity.setId(number);
        session.currentTransaction().begin();
        session.persist(entity);
        session.currentTransaction().commit();

        return;
    }
View Full Code Here

TOP

Related Classes of com.mysql.clusterj.Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.