~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to storage/ndb/clusterj/clusterj-api/src/main/java/com/mysql/clusterj/package.html

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
 
2
<!--
 
3
   Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
 
4
 
 
5
   This program is free software; you can redistribute it and/or modify
 
6
   it under the terms of the GNU General Public License as published by
 
7
   the Free Software Foundation; version 2 of the License.
 
8
 
 
9
   This program is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
   GNU General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License
 
15
   along with this program; if not, write to the Free Software
 
16
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
17
-->
 
18
 
 
19
<html>
 
20
<head>
 
21
<title>com.mysql.clusterj</title>
 
22
</head>
 
23
<body bgcolor="white">
 
24
 
 
25
Provides classes and interfaces for using MySQL Cluster directly from Java.
 
26
<p>
 
27
This package contains three main groups of classes and interfaces:
 
28
<ul>
 
29
<li>A class for bootstrapping
 
30
<li>Interfaces for use in application programs
 
31
<li>Classes to define exceptions
 
32
</ul>
 
33
 
 
34
<h3>Major Interfaces</h3>
 
35
ClusterJ provides these major interfaces for use by application programs:
 
36
{@link com.mysql.clusterj.SessionFactory},
 
37
{@link com.mysql.clusterj.Session},
 
38
{@link com.mysql.clusterj.Transaction},
 
39
{@link com.mysql.clusterj.query.QueryBuilder},
 
40
and
 
41
{@link com.mysql.clusterj.Query}.
 
42
 
 
43
<h3>Bootstrapping</h3>
 
44
 
 
45
The helper class {@link com.mysql.clusterj.ClusterJHelper} contains methods
 
46
for creating the {@link com.mysql.clusterj.SessionFactory}.
 
47
<em>Bootstrapping</em> is the process of identifying a MySQL Cluster and
 
48
obtaining the SessionFactory for use with the cluster. There is one
 
49
SessionFactory per cluster per Java VM.
 
50
<p>
 
51
<h3>SessionFactory</h3>
 
52
 
 
53
The {@link com.mysql.clusterj.SessionFactory} is configured via properties, which identify the
 
54
MySQL Cluster that the application connects to:
 
55
<ul>
 
56
<li>com.mysql.clusterj.connectstring identifies the ndb_mgmd host name and port</li>
 
57
<li>com.mysql.clusterj.connect.retries is the number of retries when connecting</li>
 
58
<li>com.mysql.clusterj.connect.delay is the delay in seconds between connection retries</li>
 
59
<li>com.mysql.clusterj.connect.verbose tells whether to display a message
 
60
to System.out while connecting</li>
 
61
<li>com.mysql.clusterj.connect.timeout.before is the number of seconds to wait
 
62
until the first node responds to a connect request</li>
 
63
<li>com.mysql.clusterj.connect.timeout.after is the number of seconds to wait
 
64
until the last node responds to a connect request</li>
 
65
<li>com.mysql.clusterj.connect.database is the name of the database to use</li>
 
66
</ul>
 
67
 
 
68
<pre>
 
69
    File propsFile = new File("clusterj.properties");
 
70
    InputStream inStream = new FileInputStream(propsFile);
 
71
    Properties props = new Properties();
 
72
    props.load(inStream);
 
73
    SessionFactory sessionFactory = ClusterJHelper.getSessionFactory(props);
 
74
</pre>
 
75
 
 
76
<h3>Session</h3>
 
77
 
 
78
The {@link com.mysql.clusterj.Session} represents the user's individual connection to
 
79
the cluster. It contains methods for:
 
80
<ul>
 
81
<li>finding persistent instances by primary key</li>
 
82
<li>persistent instance factory (newInstance)</li>
 
83
<li>persistent instance life cycle management (persist, remove)</li>
 
84
<li>getting the QueryBuilder</li>
 
85
<li>getting the Transaction (currentTransaction)</li>
 
86
</ul>
 
87
<pre>
 
88
    Session session = sessionFactory.getSession();
 
89
    Employee existing = session.find(Employee.class, 1);
 
90
    if (existing != null) {
 
91
        session.remove(existing);
 
92
    }
 
93
    Employee newemp = session.newInstance(Employee.class);
 
94
    newemp.initialize(2, "Craig", 15, 146000.00);
 
95
    session.persist(newemp);
 
96
</pre>
 
97
 
 
98
<h3>Transaction</h3>
 
99
 
 
100
The {@link com.mysql.clusterj.Transaction} allows users to combine multiple operations
 
101
into a single database transaction. It contains methods to:
 
102
<ul>
 
103
<li>begin a unit of work</li>
 
104
<li>commit changes from a unit of work</li>
 
105
<li>roll back all changes made since the unit of work was begun</li>
 
106
<li>mark a unit of work for rollback only</li>
 
107
<li>get the rollback status of the current unit of work</li>
 
108
</ul>
 
109
<pre>
 
110
    Transaction tx = session.currentTransaction();
 
111
    tx.begin();
 
112
    Employee existing = session.find(Employee.class, 1);
 
113
    Employee newemp = session.newInstance(Employee.class);
 
114
    newemp.initialize(2, "Craig", 146000.00);
 
115
    session.persist(newemp);
 
116
    tx.commit();
 
117
</pre>
 
118
 
 
119
<h3>QueryBuilder</h3>
 
120
 
 
121
The {@link com.mysql.clusterj.query.QueryBuilder} allows users to build queries.
 
122
It contains methods to:
 
123
<ul>
 
124
<li>define the Domain Object Model to query</li>
 
125
<li>compare properties with parameters using:
 
126
<ul>
 
127
<li>equal</li>
 
128
<li>lessThan</li>
 
129
<li>greaterThan</li>
 
130
<li>lessEqual</li>
 
131
<li>greaterEqual</li>
 
132
<li>between</li>
 
133
<li>in</li>
 
134
</ul>
 
135
</li>
 
136
<li>combine comparisons using "and", "or", and "not" operators</li>
 
137
</ul>
 
138
<pre>
 
139
    QueryBuilder builder = session.getQueryBuilder();
 
140
    QueryDomainType&lt;Employee&gt; qemp = builder.createQueryDefinition(Employee.class);
 
141
    Predicate service = qemp.get("yearsOfService").greaterThan(qemp.param("service"));
 
142
    Predicate salary = qemp.get("salary").lessEqual(qemp.param("salaryCap"));
 
143
    qemp.where(service.and(salary));
 
144
    Query&lt;Employee&gt; query = session.createQuery(qemp);
 
145
    query.setParameter("service", 10);
 
146
    query.setParameter("salaryCap", 180000.00);
 
147
    List&lt;Employee&gt; results = query.getResultList();
 
148
</pre>
 
149
</body>
 
150
</html>