Search in sources :

Example 16 with ConnectionFactory

use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.

the class VCellApiMain method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        if (args.length != 2) {
            System.out.println("usage: VCellApiMain javascriptDir port");
            System.exit(1);
        }
        File javascriptDir = new File(args[0]);
        if (!javascriptDir.isDirectory()) {
            throw new RuntimeException("javascriptDir '" + args[0] + "' is not a directory");
        }
        // don't validate
        PropertyLoader.loadProperties();
        lg.debug("properties loaded");
        String portString = args[1];
        // was hard-coded at 8080
        Integer port = null;
        try {
            port = Integer.parseInt(portString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new RuntimeException("failed to parse port argument '" + portString + "'", e);
        }
        lg.trace("connecting to database");
        lg.trace("oracle factory (next)");
        ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory();
        KeyFactory keyFactory = conFactory.getKeyFactory();
        lg.trace("database impl (next)");
        DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
        lg.trace("local db server (next)");
        LocalAdminDbServer localAdminDbServer = new LocalAdminDbServer(conFactory, keyFactory);
        lg.trace("admin db server (next)");
        AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
        lg.trace("messaging service (next)");
        VCMessagingService vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
        vcMessagingService.setDelegate(new VCMessagingDelegate() {

            @Override
            public void onTraceEvent(String string) {
                System.out.println("Trace: " + string);
            }

            @Override
            public void onRpcRequestSent(VCRpcRequest vcRpcRequest, UserLoginInfo userLoginInfo, VCMessage vcRpcRequestMessage) {
                System.out.println("request sent:");
            }

            @Override
            public void onRpcRequestProcessed(VCRpcRequest vcRpcRequest, VCMessage rpcVCMessage) {
                System.out.println("request processed:");
            }

            @Override
            public void onMessageSent(VCMessage message, VCDestination desintation) {
                System.out.println("message sent:");
            }

            @Override
            public void onMessageReceived(VCMessage vcMessage, VCDestination vcDestination) {
                System.out.println("message received");
            }

            @Override
            public void onException(Exception e) {
                System.out.println("Exception: " + e.getMessage());
                e.printStackTrace();
            }
        });
        lg.trace("rest database service (next)");
        RestDatabaseService restDatabaseService = new RestDatabaseService(databaseServerImpl, localAdminDbServer, vcMessagingService);
        lg.trace("rest event service (next)");
        RestEventService restEventService = new RestEventService(vcMessagingService);
        lg.trace("use verifier (next)");
        UserVerifier userVerifier = new UserVerifier(adminDbTopLevel);
        lg.trace("mongo (next)");
        VCMongoMessage.enabled = true;
        VCMongoMessage.serviceStartup(ServiceName.unknown, port, args);
        System.out.println("setting up server configuration");
        lg.trace("register engine (next)");
        Engine.register(true);
        WadlComponent component = new WadlComponent();
        // Server httpServer = component.getServers().add(Protocol.HTTP, 80);
        // Server httpsServer = component.getServers().add(Protocol.HTTPS, 443);
        // Client httpsClient = component.getClients().add(Protocol.HTTPS);
        // Client httpClient = component.getClients().add(Protocol.HTTP);
        lg.trace("adding FILE protcol");
        @SuppressWarnings("unused") Client httpClient = component.getClients().add(Protocol.FILE);
        lg.trace("adding CLAP protcol");
        @SuppressWarnings("unused") Client clapClient = component.getClients().add(Protocol.CLAP);
        lg.trace("adding CLAP https");
        File keystorePath = new File(PropertyLoader.getRequiredProperty(PropertyLoader.vcellapiKeystoreFile));
        String keystorePassword = PropertyLoader.getSecretValue(PropertyLoader.vcellapiKeystorePswd, PropertyLoader.vcellapiKeystorePswdFile);
        try {
            // 
            // keystorePassword may be encrypted with dbPassword, if it is decypt it.
            // 
            String dbPassword = PropertyLoader.getSecretValue(PropertyLoader.dbPasswordValue, PropertyLoader.dbPasswordFile);
            SecretKeyFactory kf = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
            SecretKey key = kf.generateSecret(new PBEKeySpec(dbPassword.toCharArray()));
            Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
            pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(new byte[] { 32, 11, 55, 121, 01, 42, 89, 11 }, 20));
            keystorePassword = new String(pbeCipher.doFinal(DatatypeConverter.parseBase64Binary(keystorePassword)));
        } catch (Exception e) {
            System.out.println("password unhashing didn't work - trying clear text password");
            e.printStackTrace();
        }
        Server httpsServer = component.getServers().add(Protocol.HTTPS, port);
        Series<Parameter> parameters = httpsServer.getContext().getParameters();
        parameters.add("keystorePath", keystorePath.toString());
        parameters.add("keystorePassword", keystorePassword);
        parameters.add("keystoreType", "JKS");
        parameters.add("keyPassword", keystorePassword);
        parameters.add("disabledCipherSuites", "SSL_RSA_WITH_3DES_EDE_CBC_SHA " + "SSL_DHE_RSA_WITH_DES_CBC_SHA " + "SSL_DHE_DSS_WITH_DES_CBC_SHA");
        parameters.add("enabledCipherSuites", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA " + "TLS_DHE_RSA_WITH_AES_128_CBC_SHA " + "TLS_RSA_WITH_AES_128_CBC_SHA " + "TLS_DHE_DSS_WITH_AES_256_CBC_SHA " + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA " + "TLS_RSA_WITH_AES_256_CBC_SHA");
        lg.trace("create config");
        Configuration templateConfiguration = new Configuration();
        templateConfiguration.setObjectWrapper(new DefaultObjectWrapper());
        lg.trace("verify python installation");
        PythonSupport.verifyInstallation(new PythonPackage[] { PythonPackage.COPASI, PythonPackage.LIBSBML, PythonPackage.THRIFT });
        lg.trace("start Optimization Service");
        OptServerImpl optServerImpl = new OptServerImpl();
        optServerImpl.start();
        lg.trace("create app");
        boolean bIgnoreHostProblems = true;
        boolean bIgnoreCertProblems = true;
        User testUser = localAdminDbServer.getUser(TEST_USER);
        // lookup hashed auth credentials in database.
        UserInfo testUserInfo = localAdminDbServer.getUserInfo(testUser.getID());
        HealthService healthService = new HealthService(restEventService, "localhost", port, bIgnoreCertProblems, bIgnoreHostProblems, testUserInfo.userid, testUserInfo.digestedPassword0);
        AdminService adminService = new AdminService(adminDbTopLevel, databaseServerImpl);
        RpcService rpcService = new RpcService(vcMessagingService);
        WadlApplication app = new VCellApiApplication(restDatabaseService, userVerifier, optServerImpl, rpcService, restEventService, adminService, templateConfiguration, healthService, javascriptDir);
        lg.trace("attach app");
        component.getDefaultHost().attach(app);
        System.out.println("component start()");
        lg.trace("start component");
        component.start();
        System.out.println("component ended.");
        lg.trace("component started");
        lg.trace("start VCell Health Monitoring service");
        healthService.start();
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) WadlComponent(org.restlet.ext.wadl.WadlComponent) User(org.vcell.util.document.User) AdminService(org.vcell.rest.admin.AdminService) Server(org.restlet.Server) LocalAdminDbServer(cbit.vcell.modeldb.LocalAdminDbServer) Configuration(freemarker.template.Configuration) VCMessagingDelegate(cbit.vcell.message.VCMessagingDelegate) OptServerImpl(org.vcell.optimization.OptServerImpl) UserInfo(org.vcell.util.document.UserInfo) VCMessagingService(cbit.vcell.message.VCMessagingService) ConnectionFactory(org.vcell.db.ConnectionFactory) VCDestination(cbit.vcell.message.VCDestination) VCMessage(cbit.vcell.message.VCMessage) HealthService(org.vcell.rest.health.HealthService) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) RestDatabaseService(org.vcell.rest.server.RestDatabaseService) Client(org.restlet.Client) SecretKeyFactory(javax.crypto.SecretKeyFactory) SecretKeyFactory(javax.crypto.SecretKeyFactory) KeyFactory(org.vcell.db.KeyFactory) PBEParameterSpec(javax.crypto.spec.PBEParameterSpec) AdminDBTopLevel(cbit.vcell.modeldb.AdminDBTopLevel) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) VCRpcRequest(cbit.vcell.message.VCRpcRequest) SecretKey(javax.crypto.SecretKey) RestEventService(org.vcell.rest.events.RestEventService) WadlApplication(org.restlet.ext.wadl.WadlApplication) RpcService(org.vcell.rest.rpc.RpcService) LocalAdminDbServer(cbit.vcell.modeldb.LocalAdminDbServer) Parameter(org.restlet.data.Parameter) Cipher(javax.crypto.Cipher) UserLoginInfo(org.vcell.util.document.UserLoginInfo) File(java.io.File)

Example 17 with ConnectionFactory

use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.

the class ChangeVCellSchema method main.

/**
 * Insert the method's description here.
 * Creation date: (2/8/2003 12:00:03 AM)
 * @param args java.lang.String[]
 */
public static void main(String[] args) {
    try {
        final String oracle = "oracle";
        final String postgres = "postgres";
        final String usage = "\nUsage: (" + oracle + "|" + postgres + ") url schemaUser schemaUserPassword bPrintOnly\n\n";
        if (args.length != 5) {
            System.out.println(usage);
            System.exit(0);
        }
        String connectURL = args[1];
        String dbSchemaUser = args[2];
        String dbPassword = args[3];
        bPrintOnly = Boolean.valueOf(args[4]).booleanValue();
        // 
        int ok = javax.swing.JOptionPane.showConfirmDialog(new javax.swing.JFrame(), (!bPrintOnly ? "WARNING!\nSCHEMA below will be ALTERED\n" : "\nSCHEMA below will not be ALTERED\n") + "connectURL=" + connectURL + "\nUser=" + dbSchemaUser + "\npassword=" + dbPassword + "\nPrint Only=" + bPrintOnly, "Confirm", javax.swing.JOptionPane.OK_CANCEL_OPTION, javax.swing.JOptionPane.WARNING_MESSAGE);
        if (ok != javax.swing.JOptionPane.OK_OPTION) {
            throw new RuntimeException("Aborted by user");
        }
        ConnectionFactory conFactory = null;
        new cbit.vcell.resource.PropertyLoader();
        if (args[0].equalsIgnoreCase(oracle)) {
            String driverName = "oracle.jdbc.driver.OracleDriver";
            conFactory = DatabaseService.getInstance().createConnectionFactory(driverName, connectURL, dbSchemaUser, dbPassword);
        } else if (args[0].equalsIgnoreCase(postgres)) {
            String driverName = "org.postgresql.Driver";
            conFactory = DatabaseService.getInstance().createConnectionFactory(driverName, connectURL, dbSchemaUser, dbPassword);
        } else {
            System.out.println(usage);
            System.exit(1);
        }
        changeSchema(conFactory, conFactory.getKeyFactory(), conFactory.getDatabaseSyntax());
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
    System.exit(0);
}
Also used : ConnectionFactory(org.vcell.db.ConnectionFactory)

Example 18 with ConnectionFactory

use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.

the class ResultSetCrawler method main.

public static void main(String[] args) {
    ConnectionFactory conFactory = null;
    try {
        boolean SCAN_ONLY = true;
        String singleUsername = null;
        String startingUsername = null;
        String outputDirName = ".";
        String ampliCredName = null;
        String ampliCredPassword = null;
        int count = 0;
        while (count < args.length) {
            if (args[count].equals("-h")) {
                printUsage();
                System.exit(0);
            } else if (args[count].equals("-u")) {
                count++;
                singleUsername = args[count];
            } else if (args[count].equals("-c")) {
                count++;
                startingUsername = args[count];
            } else if (args[count].equals("-o")) {
                count++;
                outputDirName = args[count];
            } else if (args[count].equals("-d")) {
                SCAN_ONLY = false;
            } else if (args[count].equals("-s")) {
                SCAN_ONLY = true;
            } else if (args[count].equals("-y")) {
                count++;
                ampliCredName = args[count];
            } else if (args[count].equals("-z")) {
                count++;
                ampliCredPassword = args[count];
            } else {
                System.out.println("Wrong arguments, see usage below.");
                printUsage();
                System.exit(1);
            }
            count++;
        }
        File outputDir = null;
        if (outputDirName == null) {
            outputDir = new File(".");
        } else {
            outputDir = new File(outputDirName);
            if (!outputDir.exists()) {
                throw new RuntimeException("Outuput directory doesn't exist!");
            }
        }
        PropertyLoader.loadProperties();
        File primaryDataRootDir = new File(PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty));
        File secondaryDataRootDir = new File(PropertyLoader.getRequiredProperty(PropertyLoader.secondarySimDataDirInternalProperty));
        if (primaryDataRootDir.equals(secondaryDataRootDir)) {
            secondaryDataRootDir = null;
        }
        // initialize database
        conFactory = DatabaseService.getInstance().createConnectionFactory();
        KeyFactory keyFactory = conFactory.getKeyFactory();
        AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
        DatabaseServerImpl dbServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
        // 
        // determine the list of users to scan
        // 
        UserInfo[] allUserInfos = adminDbTopLevel.getUserInfos(true);
        HashMap<String, User> usersToScan = new HashMap<String, User>();
        for (UserInfo userInfo : allUserInfos) {
            if (singleUsername != null) {
                // accept only the "singleUser"
                if (userInfo.userid.equals(singleUsername)) {
                    usersToScan.put(userInfo.userid, new User(userInfo.userid, userInfo.id));
                    break;
                }
            } else if (startingUsername != null) {
                // accept all users starting with the "startingUser"
                if (userInfo.userid.compareToIgnoreCase(startingUsername) >= 0) {
                    usersToScan.put(userInfo.userid, new User(userInfo.userid, userInfo.id));
                }
            } else {
                // all users
                usersToScan.put(userInfo.userid, new User(userInfo.userid, userInfo.id));
            }
        }
        // 
        // get list of directories to scan (for selected users on both user data directories)
        // 
        List<File> useDirectoriesToScan = getDirectoriesToScan(usersToScan, primaryDataRootDir, secondaryDataRootDir);
        for (File userDir : useDirectoriesToScan) {
            try {
                if (lg.isTraceEnabled())
                    lg.trace("USER: " + userDir.getName());
                User user = usersToScan.get(userDir.getName());
                // find all the user simulations and external data sets (field data)
                SimulationInfo[] simulationInfos = dbServerImpl.getSimulationInfos(user, false);
                ExternalDataIdentifier[] extDataIDArr = adminDbTopLevel.getExternalDataIdentifiers(user, true);
                // scan this user directory
                scanUserDirectory(userDir, extDataIDArr, simulationInfos, outputDir, SCAN_ONLY, (ampliCredName == null || ampliCredPassword == null ? null : new AmplistorUtils.AmplistorCredential(ampliCredName, ampliCredPassword)));
            } catch (Exception ex) {
                lg.error(ex.getMessage(), ex);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
    } finally {
        try {
            if (conFactory != null) {
                conFactory.close();
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
        System.exit(0);
    }
}
Also used : User(org.vcell.util.document.User) HashMap(java.util.HashMap) UserInfo(org.vcell.util.document.UserInfo) DataAccessException(org.vcell.util.DataAccessException) SQLException(java.sql.SQLException) ConnectionFactory(org.vcell.db.ConnectionFactory) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) File(java.io.File) KeyFactory(org.vcell.db.KeyFactory) SimulationInfo(cbit.vcell.solver.SimulationInfo) AmplistorUtils(cbit.vcell.util.AmplistorUtils)

Example 19 with ConnectionFactory

use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.

the class DBBackupAndClean method deleteSimsFromDisk.

private static void deleteSimsFromDisk(String[] args) {
    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);
        connectionFactory = DatabaseService.getInstance().createConnectionFactory(dbDriverName, url, dbBackupHelper.vcellSchema, dbBackupHelper.password);
        String sql = "SELECT simid,userid" + " from vc_simdelfromdisk " + " where" + // " userid='schaff' and"+
        " status='" + DelSimStatus.init.name() + "'" + " and simid not in (select id from vc_simulation)" + " order by userid";
        ArrayList<Object[]> deleteTheseSims = executeQuery(refreshConnection(conHolder, connectionFactory), sql, logStringBuffer, true);
        // 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<>();
            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 (file.delete()) {
                            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) {
        writeFile(dbBackupHelper.workingDir, baseFileName, e.getClass().getName() + "\n" + e.getMessage(), true, dbBackupHelper.exportDir);
    } finally {
        if (conHolder[0] != null) {
            try {
                conHolder[0].close();
            } catch (Exception e) {
                logStringBuffer.append("\n" + e.getClass().getName() + "\n" + e.getMessage());
            }
        }
        if (connectionFactory != null) {
            try {
                connectionFactory.close();
            } catch (Exception e) {
                logStringBuffer.append("\n" + e.getClass().getName() + "\n" + e.getMessage());
            }
        }
    }
}
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)

Example 20 with ConnectionFactory

use of org.vcell.db.ConnectionFactory in project vcell by virtualcell.

the class DBBackupAndClean method clean.

private static void clean(String[] args) {
    DBBackupHelper dbBackupHelper = new DBBackupHelper(args);
    ConnectionFactory connectionFactory = null;
    Connection con = null;
    String baseFileName = createBaseFileName(dbBackupHelper.dbHostName, dbBackupHelper.dbSrvcName, dbBackupHelper.vcellSchema);
    baseFileName = OP_CLEAN + "_" + baseFileName;
    StringBuffer logStringBuffer = new StringBuffer();
    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);
        connectionFactory = DatabaseService.getInstance().createConnectionFactory(dbDriverName, url, dbBackupHelper.vcellSchema, dbBackupHelper.password);
        con = connectionFactory.getConnection(new Object());
        con.setAutoCommit(false);
        cleanClearVersionBranchPointRef(con, SimulationTable.table, logStringBuffer);
        cleanRemoveUnreferencedSimulations(con, logStringBuffer);
        cleanClearVersionBranchPointRef(con, MathDescTable.table, logStringBuffer);
        cleanRemoveUnreferencedMathDescriptions(con, logStringBuffer);
        cleanRemoveUnReferencedNonSpatialGeometries(con, logStringBuffer);
        cleanClearVersionBranchPointRef(con, SimContextTable.table, logStringBuffer);
        cleanRemoveUnReferencedSimulationContexts(con, logStringBuffer);
        cleanRemoveUnReferencedModels(con, logStringBuffer);
        cleanRemoveUnReferencedSotwareVersions(con, logStringBuffer);
        writeFile(dbBackupHelper.workingDir, baseFileName, logStringBuffer.toString(), false, dbBackupHelper.exportDir);
        File remoteCleanfile = getErrorInfoFile(dbBackupHelper.exportDir, baseFileName, false);
        if (remoteCleanfile.exists()) {
            AmplistorUtils.uploadFile(new URL(getAmplistorDBBackupURL()), remoteCleanfile, null);
        }
    } catch (Exception e) {
        writeFile(dbBackupHelper.workingDir, baseFileName, e.getClass().getName() + "\n" + e.getMessage(), true, dbBackupHelper.exportDir);
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (Exception e) {
                logStringBuffer.append("\n" + e.getClass().getName() + "\n" + e.getMessage());
            }
        }
        if (connectionFactory != null) {
            try {
                connectionFactory.close();
            } catch (Exception e) {
                logStringBuffer.append("\n" + e.getClass().getName() + "\n" + e.getMessage());
            }
        }
    }
}
Also used : ConnectionFactory(org.vcell.db.ConnectionFactory) Connection(java.sql.Connection) ZipFile(java.util.zip.ZipFile) File(java.io.File) URL(java.net.URL) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

ConnectionFactory (org.vcell.db.ConnectionFactory)21 KeyFactory (org.vcell.db.KeyFactory)13 File (java.io.File)8 SQLException (java.sql.SQLException)7 DatabaseServerImpl (cbit.vcell.modeldb.DatabaseServerImpl)4 IOException (java.io.IOException)4 Connection (java.sql.Connection)4 VCMessagingService (cbit.vcell.message.VCMessagingService)3 AdminDBTopLevel (cbit.vcell.modeldb.AdminDBTopLevel)3 ZipFile (java.util.zip.ZipFile)3 ServerMessagingDelegate (cbit.vcell.message.server.ServerMessagingDelegate)2 ServiceInstanceStatus (cbit.vcell.message.server.ServiceInstanceStatus)2 RemoteProxyVCellConnectionFactory (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory)2 LocalAdminDbServer (cbit.vcell.modeldb.LocalAdminDbServer)2 PropertyLoader (cbit.vcell.resource.PropertyLoader)2 AdminDatabaseServer (cbit.vcell.server.AdminDatabaseServer)2 FileFilter (java.io.FileFilter)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 JFrame (javax.swing.JFrame)2