Provides classes and interfaces for using MySQL Cluster directly from Java.

This package contains three main groups of classes and interfaces:

Major Interfaces

ClusterJ provides these major interfaces for use by application programs: {@link com.mysql.clusterj.SessionFactory}, {@link com.mysql.clusterj.Session}, {@link com.mysql.clusterj.Transaction}, {@link com.mysql.clusterj.query.QueryBuilder}, and {@link com.mysql.clusterj.Query}.

Bootstrapping

The helper class {@link com.mysql.clusterj.ClusterJHelper} contains methods for creating the {@link com.mysql.clusterj.SessionFactory}. Bootstrapping is the process of identifying a MySQL Cluster and obtaining the SessionFactory for use with the cluster. There is one SessionFactory per cluster per Java VM.

SessionFactory

The {@link com.mysql.clusterj.SessionFactory} is configured via properties, which identify the MySQL Cluster that the application connects to:
    File propsFile = new File("clusterj.properties");
    InputStream inStream = new FileInputStream(propsFile);
    Properties props = new Properties();
    props.load(inStream);
    SessionFactory sessionFactory = ClusterJHelper.getSessionFactory(props);

Session

The {@link com.mysql.clusterj.Session} represents the user's individual connection to the cluster. It contains methods for:
    Session session = sessionFactory.getSession();
    Employee existing = session.find(Employee.class, 1);
    if (existing != null) {
        session.remove(existing);
    }
    Employee newemp = session.newInstance(Employee.class);
    newemp.initialize(2, "Craig", 15, 146000.00);
    session.persist(newemp);

Transaction

The {@link com.mysql.clusterj.Transaction} allows users to combine multiple operations into a single database transaction. It contains methods to:
    Transaction tx = session.currentTransaction();
    tx.begin();
    Employee existing = session.find(Employee.class, 1);
    Employee newemp = session.newInstance(Employee.class);
    newemp.initialize(2, "Craig", 146000.00);
    session.persist(newemp);
    tx.commit();

QueryBuilder

The {@link com.mysql.clusterj.query.QueryBuilder} allows users to build queries. It contains methods to:
    QueryBuilder builder = session.getQueryBuilder();
    QueryDomainType<Employee> qemp = builder.createQueryDefinition(Employee.class);
    Predicate service = qemp.get("yearsOfService").greaterThan(qemp.param("service"));
    Predicate salary = qemp.get("salary").lessEqual(qemp.param("salaryCap"));
    qemp.where(service.and(salary));
    Query<Employee> query = session.createQuery(qemp);
    query.setParameter("service", 10);
    query.setParameter("salaryCap", 180000.00);
    List<Employee> results = query.getResultList();