6.9.5.1.2 カスケード削除の無効化
グラフから頂点を削除すると、その入力と出力のエッジもすべて自動的に削除されます。
フラグを設定するexecute
のoptions
引数でフラグDELETE_CASCADE=F
を使用するか、Javaコマンド・ラインでフラグDoracle.pg.rdbms.pgql.autoCommit=false
を設定すると、カスケード削除をオフにできます。入力エッジまたは出力エッジのある頂点が削除され、カスケード削除がオフになっている場合は、実行しようとしている安全でない操作について警告するエラーがスローされます。
例6-29 カスケード削除の無効化
PgqlExample22.java
は、カスケード削除がオフの場合に出力エッジのある頂点を削除しようとします。
import java.sql.Connection;
import oracle.pg.rdbms.pgql.PgqlConnection;
import oracle.pg.rdbms.pgql.PgqlStatement;
import oracle.pg.rdbms.pgql.PgqlToSqlException;
import oracle.ucp.jdbc.PoolDataSourceFactory;
import oracle.ucp.jdbc.PoolDataSource;
/**
* This example shows the use of DELETE_CASCADE flag.
*/
public class PgqlExample22
{
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;
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();
conn.setAutoCommit(false);
// Get a PGQL connection
PgqlConnection pgqlConn = PgqlConnection.getConnection(conn);
pgqlConn.setGraph(graph);
// Create a PgqlStatement
ps = pgqlConn.createStatement();
// Delete all the vertices with output edges
// This will throw an error
String pgql =
"DELETE v "+
" FROM MATCH (v) -[e]-> ()";
ps.execute(pgql, /* query string */
"", /* query options */
"DELETE_CASCADE=F" /* modify options */);
}
catch (PgqlToSqlException ex){
System.out.println("Error in execution: " + ex.getMessage());
}
finally {
// close the statement
if (ps != null) {
ps.close();
}
// close the connection
if (conn != null) {
conn.close();
}
}
}
}
PgqlExample22.java
では、少なくともエッジが1つあるグラフの場合、次に示す出力が得られます。
Error in execution: Attempting to delete vertices with incoming/outgoing edges. Drop edges first or turn on DELETE_CASCADE option
親トピック: PGQL文実行の追加オプション