extreme scale util class (九)

2014-11-24 08:24:25 · 作者: · 浏览: 2
collisionKey);

}

// below means object has been revised programmatically

resolution = Resolution.REVISE;

System.out.println( message);

} catch (KeyNotFoundException e) {

// e.printStackTrace();

message = String

.format("Arbiter: Key not found while processing collision for key [%s]. Existing object kept. Exception message is %s.\n",

collisionKey, e.getMessage());

System.out.println( message);

} catch (ObjectGridException e) {

message = String

.format("Arbiter: Object Grid exception while processing collision for key [%s]. Existing object kept. Exception message is %s.\n",

collisionKey, e.getMessage());

System.out.println( message);

}

} // end Main branch

} // if collisionData is null

return resolution;

}

/**

* Retrieves object from the database . While doing this carefully tries

* to establish connection as it may become stale

* @param collisionKey

* @return

*/

public UserProfile retriveObjectFromSystemOfRecord(Object collisionKey) {

if (ds == null)

return null;

UserProfile up = new UserProfile();

Connection con = null;

PreparedStatement stmt = null;

String message = null;

// try get connection

boolean success = true;

try {

con = ds.getConnection();

stmt = con.prepareStatement("select 1 from dual");

stmt.execute();

stmt.close();

stmt = null;

success = true;

//System.out.println( "Arbiter: First attempt to select from dual executed fine.");

} catch (SQLException e) {

System.out.println( "Arbiter: select from dual failed");

success = false;

} finally {

if (stmt != null)

try {

stmt.close();

} catch (SQLException e1) {}

if (!success && (con != null)) {

try {

con.close();

con = null;

} catch (SQLException e) {

}

con = null;

System.out.println(

"Arbiter: First attempt to get connection failed. Will try again");

} //if !success

}

//if there were an error lets refresh cache

if (!success)

try {

DSWrapper.refreshCache();

} catch (SQLException e1) {

// TODO Auto-generated catch block

System.out.println(

"Arbiter: refresh cache attempt failed with exception:"

+ e1.getMessage());

}

// if connection still null try again

if (con == null) {

try {

con = ds.getConnection();

stmt = con.prepareStatement("select 1 from dual");

stm