6.8.1.4.6.1 明示的引数によって制御される問合せオプション
一部の問合せオプションは、Java APIのメソッドに対する明示的引数によって制御されます。
-
PgqlStatement
のexecuteQuery
メソッドには、タイムアウト(秒単位)、並列度、オプティマイザ動的サンプリング、および最大結果数の明示的引数があります。 -
translateQuery
メソッドには、並列性、オプティマイザ動的サンプリング、および最大結果数の明示的引数があります。また、PgqlPreparedStatement
には、executeQuery
およびtranslateQuery
用にこれらの同じ追加引数が用意されています。
例6-17 PgqlExample10.java
PgqlExample10.java
は、明示的引数によって制御される追加オプションを指定したPGQL問合せの実行を示しています。
import java.sql.Connection;
import oracle.pg.rdbms.pgql.PgqlConnection;
import oracle.pg.rdbms.pgql.PgqlResultSet;
import oracle.pg.rdbms.pgql.PgqlStatement;
import oracle.ucp.jdbc.PoolDataSourceFactory;
import oracle.ucp.jdbc.PoolDataSource;
/**
* This example shows how to execute a PGQL query with various options.
*/
public class PgqlExample10
{
public static void main(String[] args) throws Exception
{
int idx=0;
String host = args[idx++];
String port = args[idx++];
String sid = args[idx++];
String user = args[idx++];
String password = args[idx++];
String graph = args[idx++];
Connection conn = null;
PgqlStatement ps = null;
PgqlResultSet rs = null;
try {
//Get a jdbc connection
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();
pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
pds.setURL("jdbc:oracle:thin:@"+host+":"+port +":"+sid);
pds.setUser(user);
pds.setPassword(password);
conn = pds.getConnection();
// Get a PGQL connection
PgqlConnection pgqlConn = PgqlConnection.getConnection(conn);
pgqlConn.setGraph(graph);
// Create a PgqlStatement
ps = pgqlConn.createStatement();
// Execute query to get a ResultSet object
String pgql =
"SELECT v1.\"fname\" AS fname1, v2.\"fname\" AS fname2 "+
"FROM MATCH (v1)-[:\"friendOf\"]->(v2)";
rs = ps.executeQuery(pgql /* query string */,
100 /* timeout (sec): 0 is default and implies no timeout */,
2 /* parallel: 1 is default */,
6 /* dynamic sampling: 2 is default */,
50 /* max results: -1 is default and implies no limit */,
"" /* options */);
// Print query results
rs.print();
}
finally {
// close the result set
if (rs != null) {
rs.close();
}
// close the statement
if (ps != null) {
ps.close();
}
// close the connection
if (conn != null) {
conn.close();
}
}
}
}
PgqlExample10.java
は、test_graph
(GraphLoaderExample.javaコードを使用してロード可能)に対して次の出力を提供します。
+-----------------+ | FNAME1 | FNAME2 | +-----------------+ | Ray | Susan | | John | Susan | | Bill | John | | Susan | John | | John | Bill | +-----------------+
親トピック: PGQL変換および実行の追加オプション