Search in sources :

Example 1 with ConnectionFactory

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;
}
Also used : ConnectionFactory(org.vcell.db.ConnectionFactory)

Example 2 with ConnectionFactory

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;
}
Also used : ConnectionFactory(org.vcell.db.ConnectionFactory) Connection(java.sql.Connection)

Example 3 with ConnectionFactory

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);
}
Also used : ConnectionFactory(org.vcell.db.ConnectionFactory) File(java.io.File) KeyFactory(org.vcell.db.KeyFactory)

Example 4 with ConnectionFactory

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;
}
Also used : RemoteProxyVCellConnectionFactory(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory) ConnectionFactory(org.vcell.db.ConnectionFactory) RemoteProxyVCellConnectionFactory(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory) UserLoginInfo(org.vcell.util.document.UserLoginInfo)

Example 5 with ConnectionFactory

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);
    }
}
Also used : HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) ConnectionFactory(org.vcell.db.ConnectionFactory) TreeSet(java.util.TreeSet) FileFilter(java.io.FileFilter) Pattern(java.util.regex.Pattern) Connection(java.sql.Connection) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

ConnectionFactory (org.vcell.db.ConnectionFactory)26 KeyFactory (org.vcell.db.KeyFactory)15 File (java.io.File)11 SQLException (java.sql.SQLException)9 DatabaseServerImpl (cbit.vcell.modeldb.DatabaseServerImpl)7 IOException (java.io.IOException)7 Connection (java.sql.Connection)7 AdminDBTopLevel (cbit.vcell.modeldb.AdminDBTopLevel)5 ZipFile (java.util.zip.ZipFile)5 VCMessagingService (cbit.vcell.message.VCMessagingService)4 DataAccessException (org.vcell.util.DataAccessException)4 ServerMessagingDelegate (cbit.vcell.message.server.ServerMessagingDelegate)3 ServiceInstanceStatus (cbit.vcell.message.server.ServiceInstanceStatus)3 FileFilter (java.io.FileFilter)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 TreeSet (java.util.TreeSet)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 User (org.vcell.util.document.User)3