Package org.h2.engine

Examples of org.h2.engine.ConnectionInfo


                getConnection("jdbc:h2:mem:;init=runscript from 'wrong.file'");
    }

    private void testConnectionInfo() throws Exception {
        Properties info = new Properties();
        ConnectionInfo connectionInfo = new ConnectionInfo(
                "jdbc:h2:mem:test" +
                        ";LOG=2" +
                        ";ACCESS_MODE_DATA=rws" +
                        ";INIT=CREATE this...\\;INSERT that..." +
                        ";IFEXISTS=TRUE",
                info);

        assertEquals("jdbc:h2:mem:test", connectionInfo.getURL());

        assertEquals("2", connectionInfo.getProperty("LOG", ""));
        assertEquals("rws", connectionInfo.getProperty("ACCESS_MODE_DATA", ""));
        assertEquals("CREATE this...;INSERT that...", connectionInfo.getProperty("INIT", ""));
        assertEquals("TRUE", connectionInfo.getProperty("IFEXISTS", ""));
        assertEquals("undefined", connectionInfo.getProperty("CACHE_TYPE", "undefined"));
    }
View Full Code Here


        assertEquals("undefined", connectionInfo.getProperty("CACHE_TYPE", "undefined"));
    }

    private void testName() throws Exception {
        char differentFileSeparator = File.separatorChar == '/' ? '\\' : '/';
        ConnectionInfo connectionInfo = new ConnectionInfo("test" + differentFileSeparator + "subDir");
        File file = new File("test" + File.separatorChar + "subDir");
        assertEquals(file.getCanonicalPath(), connectionInfo.getName());
    }
View Full Code Here

    /**
     * INTERNAL
     */
    public JdbcConnection(String url, Properties info) throws SQLException {
        this(new ConnectionInfo(url, info), true);
    }
View Full Code Here

            // avoid using the Engine class to avoid deadlocks
            Properties p = new Properties();
            String userName =  getUser();
            p.setProperty("user", userName);
            p.setProperty("password", getPassword());
            ConnectionInfo ci = new ConnectionInfo("jdbc:h2:" + testDatabase + ";FILE_LOCK=NO;TRACE_LEVEL_FILE=0", p);
            Database database = new Database(ci, null);
            // close the database
            Session session = database.getSystemSession();
            session.prepare("shutdown immediately").update();
            database.removeSession(null);
            // everything OK - return
            return;
        } catch (DbException e) {
            SQLException e2 = DbException.toSQLException(e);
            int errorCode = e2.getErrorCode();
            if (errorCode == ErrorCode.WRONG_USER_OR_PASSWORD) {
                return;
            } else if (errorCode == ErrorCode.FILE_ENCRYPTION_ERROR_1) {
                return;
            }
            e.printStackTrace(System.out);
        } catch (Exception e) {
            // failed
            int errorCode = 0;
            if (e instanceof SQLException) {
                errorCode = ((SQLException) e).getErrorCode();
            }
            if (errorCode == ErrorCode.WRONG_USER_OR_PASSWORD) {
                return;
            } else if (errorCode == ErrorCode.FILE_ENCRYPTION_ERROR_1) {
                return;
            }
            e.printStackTrace(System.out);
        }
        System.out.println("begin ------------------------------ " + writeCount);
        try {
            Recover.execute(fileName.substring(0, fileName.lastIndexOf('/')), null);
        } catch (SQLException e) {
            // ignore
        }
        testDatabase += "X";
        try {
            IOUtils.copy(fileName, testDatabase + Constants.SUFFIX_PAGE_FILE);
            // avoid using the Engine class to avoid deadlocks
            Properties p = new Properties();
            ConnectionInfo ci = new ConnectionInfo("jdbc:h2:" + testDatabase + ";FILE_LOCK=NO", p);
            Database database = new Database(ci, null);
            // close the database
            database.removeSession(null);
        } catch (Exception e) {
            int errorCode = 0;
View Full Code Here

        Object o = info.get("password");
        if (o != null && o instanceof char[]) {
            i2.put("password", StringUtils.cloneCharArray((char[]) o));
        }
        info = i2;
        ConnectionInfo ci = new ConnectionInfo(url, info);
        if (ci.isRemote() || !ci.isPersistent()) {
            return null;
        }
        String name = ci.getName();
        if (IOUtils.exists(name + ".h2.db")) {
            return null;
        }
        if (!IOUtils.exists(name + ".data.db")) {
            return null;
        }
        if (ci.removeProperty("NO_UPGRADE", false)) {
            return connectWithOldVersion(url, info);
        }
        synchronized (DbUpgrade.class) {
            upgrade(ci, info);
            return null;
View Full Code Here

                Properties info = new Properties();
                info.put("MODE", "PostgreSQL");
                info.put("USER", userName);
                info.put("PASSWORD", password);
                String url = "jdbc:h2:" + databaseName;
                ConnectionInfo ci = new ConnectionInfo(url, info);
                String baseDir = server.getBaseDir();
                if (baseDir == null) {
                    baseDir = SysProperties.getBaseDir();
                }
                if (baseDir != null) {
                    ci.setBaseDir(baseDir);
                }
                if (server.getIfExists()) {
                    ci.setProperty("IFEXISTS", "TRUE");
                }
                conn = new JdbcConnection(ci, false);
                // can not do this because when called inside
                // DriverManager.getConnection, a deadlock occurs
                // conn = DriverManager.getConnection(url, userName, password);
View Full Code Here

    /**
     * INTERNAL
     */
    public JdbcConnection(String url, Properties info) throws SQLException {
        this(new ConnectionInfo(url, info), true);
    }
View Full Code Here

                String baseDir = server.getBaseDir();
                if (baseDir == null) {
                    baseDir = SysProperties.getBaseDir();
                }
                db = server.checkKeyAndGetDatabaseName(db);
                ConnectionInfo ci = new ConnectionInfo(db);
                if (baseDir != null) {
                    ci.setBaseDir(baseDir);
                }
                if (server.getIfExists()) {
                    ci.setProperty("IFEXISTS", "TRUE");
                }
                ci.setOriginalURL(originalURL);
                ci.setUserName(transfer.readString());
                ci.setUserPasswordHash(transfer.readBytes());
                ci.setFilePasswordHash(transfer.readBytes());
                int len = transfer.readInt();
                for (int i = 0; i < len; i++) {
                    ci.setProperty(transfer.readString(), transfer.readString());
                }
                session = Engine.getInstance().createSession(ci);
                transfer.setSession(session);
                transfer.writeInt(SessionRemote.STATUS_OK);
                transfer.writeInt(clientVersion);
                transfer.flush();
                server.addConnection(threadId, originalURL, ci.getUserName());
                trace("Connected");
            } catch (Throwable e) {
                sendError(e);
                stop = true;
            }
View Full Code Here

     *
     * @param factory the cursor factory
     * @return a connection to this database
     */
    public static H2Database create(H2Database.CursorFactory factory) {
        ConnectionInfo ci = new ConnectionInfo("mem:");
        Database db = new Database(ci, null);
        Session s = db.getSystemSession();
        return new H2Database(s, factory);
    }
View Full Code Here

     * @param factory the cursor factory
     * @param flags 0, or a combination of OPEN_READONLY and CREATE_IF_NECESSARY
     * @return a connection to this database
     */
    public static H2Database openDatabase(String path, H2Database.CursorFactory factory, int flags) {
        ConnectionInfo ci = new ConnectionInfo(path);
        if ((flags & OPEN_READWRITE) != 0) {
            // TODO readonly connections
        }
        if ((flags & CREATE_IF_NECESSARY) == 0) {
            ci.setProperty("IFEXISTS", "TRUE");
        }
        ci.setProperty("FILE_LOCK", "FS");
        Database db = new Database(ci, null);
        Session s = db.getSystemSession();
        return new H2Database(s, factory);
    }
View Full Code Here

TOP

Related Classes of org.h2.engine.ConnectionInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.