Package de.innovationgate.webgate.api

Examples of de.innovationgate.webgate.api.WGInvalidDatabaseException


        Driver driver = null;
        try {
             driver = (Driver) Class.forName(de.innovationgate.webgate.api.hsql.WGDatabaseImpl.DRIVER).newInstance();
        }
        catch (ClassNotFoundException e) {
            throw new WGInvalidDatabaseException("Necessary JDBC driver not found: " + e.getMessage());
        }
        catch (InstantiationException e) {
            throw new WGInvalidDatabaseException("Cannot instantiate neccessary JDBC driver", e);
        }
        catch (IllegalAccessException e) {
            throw new WGInvalidDatabaseException("Cannot instantiate neccessary JDBC driver", e);
        }
       
        // Build hsql path
        String hsqlPath = de.innovationgate.webgate.api.hsql.WGDatabaseImpl.buildHsqlPath(db, path);
        path = "jdbc:hsqldb:" + hsqlPath;
View Full Code Here


            Driver driver;
            try {
                driver = (Driver) Class.forName(WGDatabaseImpl.DRIVER).newInstance();
            }
            catch (Exception e) {
                throw new WGInvalidDatabaseException("Cannot create database bc. of exception when retrieving driver: " + e.getClass().getName() + " - " + e.getMessage());
            }

            // Build props, including the "createIfNotExist"-flag
            Properties props = new Properties();
            props.setProperty("user", masterUser);
            if (masterPassword != null) {
                props.setProperty("password", masterPassword);
            }
           
            // First connect to verify the database does not yet exist
            Connection con;
            try {
                con = driver.connect(jdbcPath, props);
                con.close();
                throw new WGInvalidDatabaseException("Cannot create database bc. it already exists");
            }
            catch (SQLException e) {
                if (e.getErrorCode() != 1049) {
                    throw new WGInvalidDatabaseException("Cannot create database bc. of exception when testing for existence: " + e.getMessage());
                }
            }
           
            // Connect to create
            props.setProperty("createDatabaseIfNotExist", "true");
            try {
                con = driver.connect(jdbcPath, props);
            }
            catch (SQLException e) {
                throw new WGInvalidDatabaseException("Cannot create database bc. of exception on creation: " + e.getClass().getName() + " - " + e.getMessage());
            }
           
            // If script is null retrieve default script
            String script;
            try {
                Reader read = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("de/innovationgate/webgate/api/mysql/wgacs5_mysql.ddl"));
                script = WGUtils.readString(read);
                read.close();
            }
            catch (IOException e) {
                throw new WGInvalidDatabaseException("Cannot create database bc. of exception when reading initialisation script: " + e.getClass().getName() + " - " + e.getMessage());
            }
           

            try {
                con.setAutoCommit(false);
               
                // Execute script
                Iterator statements = WGUtils.deserializeCollection(script, ";", false, new Character('\'')).iterator();
                Statement st = con.createStatement();
                while (statements.hasNext()) {
                   String code = ((String) statements.next()).trim();
                   if (!code.equals("")) {
                       st.addBatch(code);
                   }
                }
                st.executeBatch();
                con.commit();
               
            }
            catch (SQLException e) {
                throw new WGInvalidDatabaseException("Cannot create database bc. of exception when executing initialisation script: " + e.getClass().getName() + " - " + e.getMessage());
            }
            finally {
                try {
                    if (con != null) {
                        con.close();
                    }
                }
                catch (SQLException e) {
                    throw new WGInvalidDatabaseException("Exception when closing connection: " + e.getClass().getName() + " - " + e.getMessage());
                }
            }
           
            DatabaseInformation info = new DatabaseInformation(implClass);
            info.getOptions().put(Database.OPTION_PATH, path);
View Full Code Here

        Driver driver = null;
        try {
             driver = (Driver) Class.forName(DRIVER).newInstance();
        }
        catch (ClassNotFoundException e) {
            throw new WGInvalidDatabaseException("Necessary JDBC driver not found: " + e.getMessage());
        }
        catch (InstantiationException e) {
            throw new WGInvalidDatabaseException("Cannot instantiate neccessary JDBC driver", e);
        }
        catch (IllegalAccessException e) {
            throw new WGInvalidDatabaseException("Cannot instantiate neccessary JDBC driver", e);
        }
       
        // Build creations options
        Map creationOptions = db.getCreationOptions();
       
        // Hibernate configuration
        WGDatabase.putDefaultOption(creationOptions, "hibernate.dialect", HSQLDialect.class.getName());
        WGDatabase.putDefaultOption(creationOptions, "hibernate.connection.driver_class", DRIVER);

        if (user == null) {
            user = "sa";
        }
        if (pwd == null) {
            pwd = "";
        }
       
        // Build hsql path
        String hsqlPath = buildHsqlPath(db, path);
        String jdbcPath = "jdbc:hsqldb:" + hsqlPath;
       
        // Create a first connection to the database to do some tests
        Properties props = new Properties();
        props.put("user", user);
        props.put("password", pwd);
        props.put("hsqldb.default_table_type", "cached");
        props.put("shutdown", "true");
        JDBCConnectionProvider conProvider = null;
       
        boolean isInitialized = false;
        boolean migrateToCS5 = false;
        double csVersion = 0;
        try {
            conProvider = new JDBCConnectionProvider(jdbcPath, driver.getClass().getName(), props, false);
            List<String> tables = conProvider.getDatabaseTables();
           
            // Look if the database is empty and we must initialize it
            String contentTable = (String) Groq.selectFrom(tables).whereEqualsIgnoreCase("content").singleValue();
            if (contentTable != null) {
                isInitialized = true;
                if (db.getCreationOptions().containsKey(WGDatabase.COPTION_CONTENT_STORE_VERSION)) {
                   
                    // Look if the desired target format is CS5 (or higher)
                    double targetCsVersion = Double.valueOf((String) db.getCreationOptions().get(WGDatabase.COPTION_CONTENT_STORE_VERSION)).doubleValue();
                    if (targetCsVersion >= WGDatabase.CSVERSION_WGA5) {
                        // Look if the actual format it is lower than CS5. If so we automatically migrate it to that format
                        csVersion = determineCSVersion(conProvider);
                        if (csVersion < WGDatabase.CSVERSION_WGA5) {
                            migrateToCS5 = true;
                            isInitialized = false;
                        }
                    }
                }
            }
        }
        catch (Exception e) {
            throw new WGInvalidDatabaseException("Unable to connect to database", e);
        }
        finally {
            if (conProvider != null) {
                try {
                    conProvider.close();
                }
                catch (JDBCConnectionException e) {
                }
            }
        }
       
        WGDatabase importSource = null;
        if (migrateToCS5) {
            try {
                importSource = prepareCSDump(db, getHsqlBaseFile(path), user, pwd, csVersion);
            }
            catch (Exception e) {
                throw new WGInvalidDatabaseException("Exception while migrating HSQL content store to CS5 format", e);
            }
        }
       
        if (isInitialized == false) {
            WGFactory.getLogger().info("Initializing empty database " + db.getDbReference() + " as a WGA Content Store");
View Full Code Here

        else {
            // Build complete db path
            File dbfile = getHsqlBaseFile(path);
           
            if (dbfile.getParentFile() == null || !dbfile.getParentFile().exists()) {
                throw new WGInvalidDatabaseException("The database path '" + dbfile.getParent() + "' does not exist");
            }

            hsqlPath = "file:" + dbfile.getPath();
           
           
View Full Code Here

        Driver driver;
        try {
            driver = (Driver) Class.forName(DRIVER).newInstance();
        }
        catch (Exception e) {
            throw new WGInvalidDatabaseException("Cannot create database bc. of exception when retrieving driver: " + e.getClass().getName() + " - " + e.getMessage());
        }
   
        // Build props
       
        Properties props = new Properties();
        props.setProperty("hsqldb.default_table_type", "cached");
        props.setProperty("user", user);
        if (pwd != null) {
            props.setProperty("password", pwd);
        }
       
        // Connect to create
        Connection con = null;
        try {
            try {
                con = driver.connect(path, props);
            }
            catch (SQLException e) {
                throw new WGInvalidDatabaseException("Cannot create database bc. of exception on creation: " + e.getClass().getName() + " - " + e.getMessage());
            }
           
            // If script is null retrieve default script
            try {
                if (script == null) {
                    Reader read = new InputStreamReader(WGDatabaseImpl.class.getClassLoader().getResourceAsStream("de/innovationgate/webgate/api/hsql/wgacs5_hsqldb.ddl"));
                    script = WGUtils.readString(read);
                    read.close();
                }
            }
            catch (IOException e) {
                throw new WGInvalidDatabaseException("Cannot create database bc. of exception when reading initialisation script: " + e.getClass().getName() + " - " + e.getMessage());
            }
       
            // Execute script
            con.setAutoCommit(false);
            Iterator statements = WGUtils.deserializeCollection(script, ";", false, new Character('\'')).iterator();
            Statement st = con.createStatement();
            while (statements.hasNext()) {
               String code = ((String) statements.next()).trim();
               if (!code.equals("")) {
                   st.addBatch(code);
               }
            }
            st.executeBatch();
            con.commit();
           
        }
        catch (SQLException e) {
            throw new WGInvalidDatabaseException("Cannot create database bc. of exception when executing initialisation script: " + e.getClass().getName() + " - " + e.getMessage());
        }
        finally {
            try {
                if (con != null) {
                    con.close();
                }
            }
            catch (SQLException e) {
                throw new WGInvalidDatabaseException("Exception when closing connection: " + e.getClass().getName() + " - " + e.getMessage());
            }
        }
    }
View Full Code Here

                        WGFactory.getLogger().info("Exception cloning aclentry", e);
                    }
                }
            }
            catch (WGAPIException e) {
                throw new WGInvalidDatabaseException("Exception while importing HSQL content store to CS5 format", e);
            }
            finally {
                try {
                    _importSource.close();
                }
View Full Code Here

        File dbFile = new File(dir, dbPath);
       
        // Look if already exists
        File propFile = new File(dbFile.getAbsolutePath() + ".properties");
        if (propFile.exists()) {
            throw new WGInvalidDatabaseException("Cannot create database because it already exists");
        }
       
        String hsqlPath = WGDatabaseImpl.buildHsqlPath(null, dbFile.getAbsolutePath());
        String path = "jdbc:hsqldb:" + hsqlPath;
       
View Full Code Here

        Driver driver = null;
        try {
             driver = (Driver) Class.forName(de.innovationgate.webgate.api.hsql.WGDatabaseImpl.DRIVER).newInstance();
        }
        catch (ClassNotFoundException e) {
            throw new WGInvalidDatabaseException("Necessary JDBC driver not found: " + e.getMessage());
        }
        catch (InstantiationException e) {
            throw new WGInvalidDatabaseException("Cannot instantiate neccessary JDBC driver", e);
        }
        catch (IllegalAccessException e) {
            throw new WGInvalidDatabaseException("Cannot instantiate neccessary JDBC driver", e);
        }
       
        // Build hsql path
        String hsqlPath = de.innovationgate.webgate.api.hsql.WGDatabaseImpl.buildHsqlPath(db, path);
        path = "jdbc:hsqldb:" + hsqlPath;
View Full Code Here

        // Register drivers with driver manager
        try {
            Class.forName(DRIVER);
        }
        catch (ClassNotFoundException e) {
            throw new WGInvalidDatabaseException("Necessary JDBC driver not found: " + e.getMessage());
        }
       
        // Build creations options
        Map creationOptions = db.getCreationOptions();
       
View Full Code Here

                status.error = e;
                return;               
            }
            if (db == null) {
                this.addWarning("Could not find database to query: " + this.getDb(), true);
                status.error = new WGInvalidDatabaseException("Could not find database to query: " + this.getDb());
                return;
            }
            if (db.isSessionOpen() == false) {
                this.addWarning("User cannot open database " + this.getDb(), true);
                status.error = new WGAuthorisationException("User cannot open database " + this.getDb());
View Full Code Here

TOP

Related Classes of de.innovationgate.webgate.api.WGInvalidDatabaseException

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.