use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.
the class ChangeEmail method getConnection.
/**
* opens the database connection
* @return database connection
* @throws SQLException
*/
private Connection getConnection() throws SQLException {
if (dbConn == null) {
String dbDriverName = PropertyLoader.getRequiredProperty(PropertyLoader.dbDriverName);
char[] pw = pwField.getPassword();
ConnectionFactory connectionFactory = DatabaseService.getInstance().createConnectionFactory(dbDriverName, EmailList.JDBC_URL, EmailList.USER_ID, new String(pw));
dbConn = connectionFactory.getConnection(new Object());
}
return dbConn;
}
use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.
the class EmailList method getConnection.
/**
* opens the database connection
* @return database connection
* @throws SQLException
*/
private Connection getConnection() throws SQLException {
String dbDriverName = PropertyLoader.getRequiredProperty(PropertyLoader.dbDriverName);
ConnectionFactory connectionFactory = DatabaseService.getInstance().createConnectionFactory(dbDriverName, EmailList.JDBC_URL, USER_ID, password);
Connection conn = connectionFactory.getConnection(new Object());
return conn;
}
use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.
the class StochtestCompareService method main.
public static void main(String[] args) {
try {
if (args.length != 1) {
System.out.println("Usage: StochtestService baseDirectory");
System.exit(-1);
}
File baseDir = new File(args[0]);
if (!baseDir.exists()) {
throw new RuntimeException("base directory " + baseDir.getPath() + " not found");
}
PropertyLoader.loadProperties();
DatabasePolicySQL.bAllowAdministrativeAccess = true;
String driverName = PropertyLoader.getRequiredProperty(PropertyLoader.dbDriverName);
String connectURL = PropertyLoader.getRequiredProperty(PropertyLoader.dbConnectURL);
String dbSchemaUser = PropertyLoader.getRequiredProperty(PropertyLoader.dbUserid);
String dbPassword = PropertyLoader.getSecretValue(PropertyLoader.dbPasswordValue, PropertyLoader.dbPasswordFile);
//
// get appropriate database factory objects
//
ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory(driverName, connectURL, dbSchemaUser, dbPassword);
KeyFactory keyFactory = conFactory.getKeyFactory();
StochtestCompareService stochtestService = new StochtestCompareService(baseDir, conFactory, keyFactory);
while (true) {
stochtestService.compareOne();
}
} catch (Throwable e) {
e.printStackTrace(System.out);
}
System.exit(0);
}
use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.
the class ClientTester method VCellConnectionFactoryInit.
/**
* This method was created in VisualAge.
* @return VCellConnection
* @param args java.lang.String[]
*/
protected static cbit.vcell.server.VCellConnectionFactory VCellConnectionFactoryInit(String[] args, String programName) throws Exception {
if (args.length != 3 && args.length != 4 && args.length != 7) {
System.err.println("usage: " + programName + " -local userid password [driverName connectionURL userid password]");
System.err.println("usage: " + programName + " -jms userid password");
System.err.println("usage: " + programName + " host port userid password");
throw new Exception("cannot connect");
}
cbit.vcell.server.VCellConnectionFactory vcConnFactory = null;
new cbit.vcell.resource.PropertyLoader();
if (args[0].startsWith("-")) {
UserLoginInfo userLoginInfo = new UserLoginInfo(args[1], new UserLoginInfo.DigestedPassword(args[2]));
if (args[0].equalsIgnoreCase("-jms")) {
vcConnFactory = new cbit.vcell.message.server.bootstrap.LocalVCellConnectionFactory(userLoginInfo);
} else if (args[0].equalsIgnoreCase("-local")) {
vcConnFactory = new cbit.vcell.message.server.bootstrap.LocalVCellConnectionFactory(userLoginInfo);
if (args.length == 7) {
ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory(args[3], args[4], args[5], args[6]);
((cbit.vcell.message.server.bootstrap.LocalVCellConnectionFactory) vcConnFactory).setConnectionFactory(conFactory);
}
}
} else {
String apihost = args[0];
Integer apiport = Integer.parseInt(args[1]);
UserLoginInfo userLoginInfo = new UserLoginInfo(args[2], new UserLoginInfo.DigestedPassword(args[3]));
vcConnFactory = new RemoteProxyVCellConnectionFactory(apihost, apiport, userLoginInfo);
}
return vcConnFactory;
}
use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.
the class DBBackupAndClean method deleteSimsFromDiskMethod1.
private static void deleteSimsFromDiskMethod1(String[] args) {
// deleteFileAndLink(new File("/share/apps/vcell3/users/bonniecalizo/SimID_58074590_0_.pbs.sub"));
// if(true) {
// return;
// }
System.out.println("Getting Backuphelper...");
DBBackupHelper dbBackupHelper = new DBBackupHelper(args);
ConnectionFactory connectionFactory = null;
Connection[] conHolder = new Connection[] { null };
String baseFileName = createBaseFileName(dbBackupHelper.dbHostName, dbBackupHelper.dbSrvcName, dbBackupHelper.vcellSchema);
baseFileName = OP_DELSIMSDISK + "_" + baseFileName;
StringBuffer logStringBuffer = new StringBuffer();
Pattern pattern = Pattern.compile("SimID_([0-9]+)[^0-9]*");
// SimID_([0-9]+)[^0-9]*
try {
// //jdbc:oracle:<drivertype>:<username/password>@<database>
// //<database> = <host>:<port>:<SID>
String url = "jdbc:oracle:thin:" + dbBackupHelper.vcellSchema + "/" + dbBackupHelper.password + "@//" + dbBackupHelper.dbHostName + ":1521/" + dbBackupHelper.dbSrvcName;
String dbDriverName = PropertyLoader.getRequiredProperty(PropertyLoader.dbDriverName);
System.out.println("Getting DB connection..." + url.toString() + " " + dbDriverName);
connectionFactory = DatabaseService.getInstance().createConnectionFactory(dbDriverName, url, dbBackupHelper.vcellSchema, dbBackupHelper.password);
String sql = "SELECT simid,userid" + " from vc_simdelfromdisk " + " where" + // " userid='boris' and"+
" status='" + DelSimStatus.init.name() + "'" + " and simid not in (select id from vc_simulation)" + " order by userid";
System.out.println("Doing query... " + sql);
ArrayList<Object[]> deleteTheseSims = executeQuery(refreshConnection(conHolder, connectionFactory), sql, logStringBuffer, true);
System.out.println("Del sim simcount=" + deleteTheseSims.size());
// Organize simIDs by userid
HashMap<String, TreeSet<String>> userSimsMap = new HashMap<>();
for (Object[] objs : deleteTheseSims) {
BigDecimal simID = (BigDecimal) objs[0];
String userid = (String) objs[1];
TreeSet<String> userSims = userSimsMap.get(userid);
if (userSims == null) {
userSims = new TreeSet<String>();
userSimsMap.put(userid, userSims);
}
userSims.add(simID.toString());
}
Iterator<String> userIter = userSimsMap.keySet().iterator();
while (userIter.hasNext()) {
String userID = userIter.next();
TreeSet<String> userSimIDs = userSimsMap.get(userID);
FileFilter deleteTheseFilesFilter = new FileFilter() {
@Override
public boolean accept(File pathname) {
String name = pathname.getName();
Matcher matcher = pattern.matcher(name);
if (matcher.find()) {
String subStr = matcher.group(1);
if (userSimIDs.contains(subStr)) {
return true;
}
}
// }
return false;
}
};
for (String simid : userSimsMap.get(userID)) {
System.out.println(" " + simid);
}
File userDir = new File(dbBackupHelper.exportDir, userID);
File[] deleteTheseFiles = userDir.listFiles(deleteTheseFilesFilter);
HashMap<String, ArrayList<File>> simidToFilesMap = new HashMap<>();
if (deleteTheseFiles != null) {
for (int i = 0; i < deleteTheseFiles.length; i++) {
String name = deleteTheseFiles[i].getName();
Matcher matcher = pattern.matcher(name);
if (matcher.find()) {
String subStr = matcher.group(1);
if (userSimIDs.contains(subStr)) {
ArrayList<File> fileMatchSimIDFile = simidToFilesMap.get(subStr);
if (fileMatchSimIDFile == null) {
fileMatchSimIDFile = new ArrayList<>();
simidToFilesMap.put(subStr, fileMatchSimIDFile);
}
fileMatchSimIDFile.add(deleteTheseFiles[i]);
}
}
// String subStr = name.substring(6, name.indexOf('_', 6));
// if(userSimIDs.contains(subStr)){
// ArrayList<File> fileMatchSimIDFile = simidToFilesMap.get(subStr);
// if(fileMatchSimIDFile == null){
// fileMatchSimIDFile = new ArrayList<>();
// simidToFilesMap.put(subStr, fileMatchSimIDFile);
// }
//
// fileMatchSimIDFile.add(deleteTheseFiles[i]);
// }
}
}
StringBuffer fileMatchSimIDidSB = new StringBuffer();
for (String str : simidToFilesMap.keySet()) {
fileMatchSimIDidSB.append((fileMatchSimIDidSB.length() > 0 ? "," : "") + str);
}
TreeSet<String> simIDsNotMatchFiles = ((TreeSet<String>) userSimsMap.get(userID).clone());
simIDsNotMatchFiles.removeAll(simidToFilesMap.keySet());
// breakup into pieces because oracle limit on lists size
ArrayList<StringBuffer> smallSB = new ArrayList<>();
int simcount = 0;
for (String simid : simIDsNotMatchFiles) {
if (smallSB.size() == 0 || simcount >= 500) {
simcount = 0;
smallSB.add(new StringBuffer());
}
smallSB.get(smallSB.size() - 1).append((smallSB.get(smallSB.size() - 1).length() > 0 ? "," : "") + simid);
simcount++;
}
System.out.println(userID + " SimIDs deleted=" + fileMatchSimIDidSB.toString());
for (int i = 0; i < smallSB.size(); i++) {
System.out.println(userID + " SimIDs Not Found in files=" + smallSB.get(i).toString());
}
for (int i = 0; i < smallSB.size(); i++) {
sql = "update vc_simdelfromdisk set status='" + DelSimStatus.notfound.name() + "' where userid='" + userID + "' and simid in (" + smallSB.get(i).toString() + ")";
executeUpdate(refreshConnection(conHolder, connectionFactory), sql, logStringBuffer);
}
for (String simid : simidToFilesMap.keySet()) {
long totalSize = 0;
ArrayList<File> files = simidToFilesMap.get(simid);
int delCount = 0;
for (File file : files) {
if (file.exists()) {
long fileSize = file.length();
if (deleteFileAndLink(file, logStringBuffer)) {
delCount++;
totalSize += fileSize;
// System.out.println("deleted "+file.getAbsolutePath());
} else {
// System.out.println("fail delete "+file.getAbsolutePath());
}
}
}
String newStatus = DelSimStatus.delsome.name();
if (delCount == 0) {
newStatus = DelSimStatus.delnone.name();
} else if (delCount == files.size()) {
newStatus = DelSimStatus.delall.name();
}
sql = "update vc_simdelfromdisk set status='" + newStatus + "', numfiles=" + files.size() + ", totalsize=" + totalSize + " where userid='" + userID + "' and simid=" + simid;
executeUpdate(refreshConnection(conHolder, connectionFactory), sql, logStringBuffer);
}
}
} catch (Exception e) {
e.printStackTrace();
writeFile(dbBackupHelper.workingDir, baseFileName, e.getClass().getName() + "\n" + e.getMessage(), true, dbBackupHelper.exportDir);
} finally {
closeDB(connectionFactory, conHolder, logStringBuffer);
}
}
Aggregations