Package de.innovationgate.webgate.api

Examples of de.innovationgate.webgate.api.WGInvalidDatabaseException


    if (this.driverName != null && this.driverName.equals("")) {
      this.driverName = null;
    }
   
    if (this.driverName == null && this.path.startsWith("jdbc:")) {
      throw new WGInvalidDatabaseException("No jdbc driver specified for database \"" + path + "\". Add database option \"Driver\" with name of driver class.");
    }
   

    // Default props
    Properties props = new Properties();
    props.put("autocommit", "true");

    // Gather configured JDBC props
        Map creationOptions =  db.getCreationOptions();
        Iterator optsIt = creationOptions.keySet().iterator();
        while (optsIt.hasNext()) {
            String option = (String) optsIt.next();
            if (option.startsWith(("jdbc."))) {
                props.put(option.substring(5), creationOptions.get(option));
            }
        }
       
        // Set login props
        if (user != null && !user.equals("")) {
            props.put("user", user);
            if (pwd != null) {
              props.put("password", pwd);        
            }
        }
       
        // Set dbkey property so we see DBCP metrics via JMX
        props.put("dbcp.dbkey", db.getDbReference());
   
    try {
            _connProvider = new JDBCConnectionProvider(path, driverName, props, true);
        }
        catch (JDBCConnectionException e) {
            throw new WGInvalidDatabaseException("Exception setting up JDBC connection", e);
        }
   
    return this.openSession(MasterLoginAuthSession.getInstance(), pwd, true);

  }
View Full Code Here


        Configuration conf = new Configuration();
        try {
            if (db.getCreationOptions().containsKey(DBOPTION_MAPPINGFILE)) {
                File mappingFile = new File((String) db.getCreationOptions().get(DBOPTION_MAPPINGFILE));
                if (!mappingFile.exists() || !mappingFile.isFile()) {
                    throw new WGInvalidDatabaseException("Configured mapping file '" + db.getCreationOptions().get(DBOPTION_MAPPINGFILE) + "' does not exist or is no valid file.");
                }
                conf.addFile(mappingFile);
            }
            else if (db.getCreationOptions().containsKey(DBOPTION_MAPPINGRESOURCE)) {
                conf.addResource((String) db.getCreationOptions().get(DBOPTION_MAPPINGRESOURCE), this.getClass().getClassLoader());
            }
            else if (_ddlVersion == WGDatabase.CSVERSION_WGA5) {
               
                if (version.getPatchLevel() >= 3) {
                    conf.addResource(HIBERNATE_V5_P3_MAPPING_FILE, this.getClass().getClassLoader());
                }
                else if (version.getPatchLevel() >= 2) {
                    conf.addResource(HIBERNATE_V5_P2_MAPPING_FILE, this.getClass().getClassLoader());
                }
                else {
                    conf.addResource(HIBERNATE_V5_MAPPING_FILE, this.getClass().getClassLoader());
                }
            }
            else if (_ddlVersion == WGDatabase.CSVERSION_WGA4_1) {
                conf.addResource(HIBERNATE_V41_MAPPING_FILE, this.getClass().getClassLoader());
            } else {
              conf.addResource(HIBERNATE_V3_MAPPING_FILE, this.getClass().getClassLoader());
            }
        }
        catch (MappingException e) {
            throw new WGInvalidDatabaseException("Exception parsing hibernate mapping", e);
        }

        Properties props = new Properties();
        if (path.startsWith("jdbc:")) {
            props.put("hibernate.connection.url", path);
            putDefaultConPoolProps(props);
        }
        else {
            props.put("hibernate.connection.datasource", path);
        }

        if (user != null || pwd != null) {
            props.put("hibernate.connection.username", WGUtils.getValueOrDefault(user, ""));
            props.put("hibernate.connection.password", WGUtils.getValueOrDefault(pwd, ""));
        }
       
        if (db.getCreationOptions().containsKey("Driver")) {
            props.put("hibernate.connection.driver_class", db.getCreationOptions().get("Driver"));
        }
       
        // Move old Hibernate2 packages to Hibernate3 packages
        Iterator dbOptionsIt = db.getCreationOptions().keySet().iterator();
        while (dbOptionsIt.hasNext()) {
            Object key = dbOptionsIt.next();
            String value = (String) db.getCreationOptions().get(key);
            if (value != null && value.startsWith("net.sf.hibernate.")) {
                value = "org.hibernate." + value.substring(17);
                db.getCreationOptions().put(key, value);
            }
        }

        props.put(Environment.ISOLATION, String.valueOf(Connection.TRANSACTION_READ_COMMITTED));
        //props.put(Environment.QUERY_SUBSTITUTIONS, "true 1, false 0");

        props.putAll(db.getCreationOptions());
        conf.addProperties(props);
       
        // Create session factory
        try {
            _sessionFactory = conf.buildSessionFactory();
        }
        catch (HibernateException e) {
            throw new WGInvalidDatabaseException("Error creating session factory: " + e.getMessage(), e);
        }

        // parse masterPersistenceTimeout
        if (db.getCreationOptions().containsKey(COPTION_MASTERPERSISTENCE_TIMEOUT)) {
          _masterPersistenceTimeout = Long.parseLong((String)db.getCreationOptions().get(COPTION_MASTERPERSISTENCE_TIMEOUT));
        }

        // parse HQL query default type
        String hqlType = (String) db.getCreationOptions().get(COPTION_HQL_FETCH_TYPE);
        if (hqlType != null) {
            _hqlLazyByDefault = hqlType.equals(HQL_FETCHTYPE_LAZY);
        }
       
        // open session
        WGUserAccess accessLevel;
        try {
            accessLevel = openSession(MasterLoginAuthSession.getInstance(), pwd, true);
        }
        catch (WGUnavailableException e) {
            throw new WGInvalidDatabaseException("Error opening initial session", e);
        }
        catch (WGBackendException e) {
            throw new WGInvalidDatabaseException("Error opening initial session", e);
        }
        if (accessLevel.getAccessLevel() <= WGDatabase.ACCESSLEVEL_NOACCESS) {
            try {
                close();
            }
View Full Code Here

                }
            }
           
        }
        catch (JDBCConnectionException e) {
            throw new WGInvalidDatabaseException("Exception connecting to database on path " + path, e);
        }
        catch (SQLException e) {
            throw new WGInvalidDatabaseException("Exception connecting to database on path " + path, e);
        }

    }
View Full Code Here

    // Build JDBC Connection Creator
    try {
            _connProvider = new JDBCConnectionProvider(path, (String) db.getCreationOptions().get(COPTION_DRIVER), props, true);
        }
        catch (JDBCConnectionException e3) {
            throw new WGInvalidDatabaseException("Exception setting up JDBC connection", e3);
        }
   
    // Gather other options
    try {
      if (creationOptions.containsKey("ResultSetType")) {
        _resultSetType = Integer.parseInt((String) creationOptions.get("ResultSetType"));
      }
    }
    catch (NumberFormatException e2) {
      throw new WGInvalidDatabaseException("Cannot parse db option 'ResultSetType' as integer: " + _resultSetType);
    }
       
    // Gather meta data
    try {
      Connection connection = getConnection();
      if (connection == null) {
        throw new WGInvalidDatabaseException("Unable to get connection");
      }
     
     
      DatabaseMetaData dbMeta = connection.getMetaData();
      ResultSet resultSet = dbMeta.getTables(null, null, null, new String[] {"TABLE", "VIEW", "GLOBAL TEMPORARY", "LOCAL TEMPORARY"});
      startResultSet(resultSet);
      while (resultSet.next()) {
     
        TableName tableName = new TableName(resultSet);
        ResultSet keyResultSet = dbMeta.getPrimaryKeys(tableName.getCatalog(), tableName.getSchema(), tableName.getName());
        List keyColumns = new ArrayList();
        startResultSet(keyResultSet);
        while(keyResultSet.next()) {
          keyColumns.add(keyResultSet.getString("COLUMN_NAME").toLowerCase());
        }
       
        if (keyColumns.size() > 0) {
          _tables.put(tableName.getCompleteName().toLowerCase(), keyColumns);
        }
        keyResultSet.close();

      }
      resultSet.close();
     
      _server = dbMeta.getDatabaseProductName() + " Version " + dbMeta.getDatabaseProductVersion();
      _title = _server;
    }
    catch (SQLException e) {
      throw new WGInvalidDatabaseException("SQL Error building connection to path " + path + ": " + e.getMessage());
    }
   
    // Last changed update process
    int refreshSeconds = 60;
    if (creationOptions.containsKey(COPTION_REFRESH)) {
View Full Code Here

    }

    private WGDatabase getDesignDB() throws WGAPIException {
       
            if (_designDB == null) {
                throw new WGInvalidDatabaseException("The configured design database '" + _designDBKey + "' is not connected");
            }
       
            if (!_designDB.isSessionOpen()) {
                crossLogin(_slaveDB, _designDB);
            }
View Full Code Here

    ClassLoader classLoader = WGFactory.getImplementationLoader();
    if (db.getCreationOptions().containsKey(COPTION_BEAN_JARFILE)) {
      String jarPath = (String) db.getCreationOptions().get(COPTION_BEAN_JARFILE);
      File jarFile = new File(jarPath);
      if (!jarFile.exists()) {
        throw new WGInvalidDatabaseException("Cannot find jarfile '" + jarPath + "'");
      }
      try {
        classLoader = new URLClassLoader(new URL[] { jarFile.toURL() }, WGFactory.getImplementationLoader());
      }
      catch (MalformedURLException e2) {
        throw new WGInvalidDatabaseException("Cannot build URL to jarfile '" + jarPath + "'");
      }
    }
       
    // Fetch the bean class
    try {
      _beanClass = classLoader.loadClass(path);
    }
    catch (ClassNotFoundException e) {
      throw new WGInvalidDatabaseException("Unknown bean class");
    }
   
    if (_beanClass.isInterface()) {
      throw new WGInvalidDatabaseException("Cannot use bean class because it is an interface");
    }
   
    int modifiers = _beanClass.getModifiers();
    if (Modifier.isAbstract(modifiers)) {
      throw new WGInvalidDatabaseException("Cannot use bean class because it is an abstract class");
    }
   
    // Look, if there is creation handler determined. Else use DefaultBeanCreationHandler
    if (db.getCreationOptions().containsKey(COPTION_CREATION_HANDLER)) {
      String creationHandlerStr = (String) db.getCreationOptions().get(COPTION_CREATION_HANDLER);
      try {
        Class creationHandlerClass =  classLoader.loadClass(creationHandlerStr);
        _creationHandler = (BeanCreationHandler) creationHandlerClass.newInstance();
      }
      catch (ClassNotFoundException e1) {
        throw new WGInvalidDatabaseException("Cannot find class for bean creation handler: " + creationHandlerStr);
      }
      catch (InstantiationException e) {
        throw new WGInvalidDatabaseException("Cannot instantiate bean creation handler because it either is abstract or an interface: " + creationHandlerStr);
      }
      catch (IllegalAccessException e) {
        throw new WGInvalidDatabaseException("Cannot find class for bean creation handler because the constructor used is not public: " + creationHandlerStr);
      }
    }
    else {
      _creationHandler = new DefaultBeanCreationHandler();
    }
   
   
    // Initialize the creation handler
    try {
      _creationHandler.init(_beanClass, this);
    }
    catch (SecurityException e1) {
      throw new WGInvalidDatabaseException("The java security manager prohibits introspection of the bean class");
    }
    catch (NoSuchMethodException e1) {
      throw new WGInvalidDatabaseException("The needed constructor was not found: " + e1.getMessage());
    }
   
   
    // Fetchmode parsing
    if (db.getCreationOptions().containsKey(COPTION_ONE_BEAN_PER)) {
View Full Code Here

   
    public WGDatabase openDatabase(Class<? extends WGDatabaseCore> implClass, Map<String,String> options) throws WGAPIException, ModuleDependencyException {
       
        ServerDatabaseRetriever retriever = fetchServerDatabaseRetriever(implClass);
        if (retriever == null) {
            throw new WGInvalidDatabaseException("The database implementation class '" + implClass.getName() + "' is not suitable for database server type '" + getClass().getName() + "'");
        }
        return retriever.openDatabase(implClass, this, options, false);
       
    }
View Full Code Here

   
    public WGDatabase prepareDatabase(Class<? extends WGDatabaseCore> implClass, Map<String,String> options) throws WGAPIException, ModuleDependencyException {
       
        ServerDatabaseRetriever retriever = fetchServerDatabaseRetriever(implClass);
        if (retriever == null) {
            throw new WGInvalidDatabaseException("The database implementation class '" + implClass.getName() + "' is not suitable for database server type '" + getClass().getName() + "'");
        }
        return retriever.openDatabase(implClass, this, options, true);
       
    }
View Full Code Here

   
    public DatabaseInformation createDatabase(Class<? extends WGDatabaseCore> implClass, Map<String,String> options) throws WGAPIException, ModuleDependencyException {
       
        ServerDatabaseRetriever retriever = fetchServerDatabaseRetriever(implClass);
        if (retriever == null) {
            throw new WGInvalidDatabaseException("The database implementation class '" + implClass.getName() + "' is not suitable for database server type '" + getClass().getName() + "'");
        }
       
        if (!retriever.isCreatable()) {
            throw new WGInvalidDatabaseException("The database implementation class '" + implClass.getName() + "' is not creatable on database server type '" + getClass().getName() + "'");
        }
       
        return retriever.createDatabase(implClass, this, options);
       
    }
View Full Code Here

    private ServerDatabaseRetriever fetchServerDatabaseRetriever(Class<? extends WGDatabaseCore> implClass) throws WGInvalidDatabaseException, ModuleDependencyException {
        // Find the module definition
        ModuleDefinition dbModuleDef = fetchDatabaseModuleDefinition(implClass);
        if (dbModuleDef == null) {
            throw new WGInvalidDatabaseException("Module definition of database implementation class '" + implClass.getName() + "' cannot be found");
        }
       
        return fetchServerDatabaseRetriever(dbModuleDef);
    }
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.