APISonar


org.javalite.activejdbc.logging.LogFilter.log

> org > javalite > activejdbc > logging > LogFilter > log
org APIs javalite APIs activejdbc APIs logging APIs LogFilter APIs log APIs

Example 1
private boolean loadStaticMetadata() {
        try {
            Enumeration<URL> urls = Registry.instance().getClass().getClassLoader().getResources("activejdbc_metadata.json");
            staticMetadataStatus = urls.hasMoreElements() ? STATIC_METADATA_LOADED : STATIC_METADATA_CHECKED;
            while(urls.hasMoreElements()) {
                URL url = urls.nextElement();
                LogFilter.log(LOGGER, LogLevel.INFO, "Loading metadata from: {}", url.toExternalForm());
                metaModels.fromJSON(Util.read(url.openStream()));
            }
            return staticMetadataStatus == STATIC_METADATA_LOADED;
        } catch(IOException e) {
            throw new InitException(e);
        }
    }
Example 2
public Object getCache(String group, String key) {
        try {
            createIfMissing(group);
            Cache c = cacheManager.getCache(group);
            return c.get(key) == null ? null : c.get(key).getObjectValue();
        } catch (Exception e) {
            LogFilter.log(LOGGER, LogLevel.WARNING, "{}", e, e);
            return null;
        }
    }
Example 3
public void addCache(String group, String key, Object cache) {
        try (Jedis jedis = jedisPool.getResource()){
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            ObjectOutput objectOutput = new ObjectOutputStream(bout);
            objectOutput.writeObject(cache);
            objectOutput.close();
            byte[] bytes = bout.toByteArray();
            jedis.hset(group.getBytes(), key.getBytes(), bytes);

        } catch (Exception e) {
            LogFilter.log(LOGGER, LogLevel.ERROR, "Failed to add object to cache with group: " + group + " and key: " + key, e);
        }
    }
Example 4
private void createIfMissing(String group) {
        if (cacheManager.getCache(group) == null) {

            synchronized (cacheManager) {
                if (cacheManager.getCache(group) == null) {
                    try {
                        cacheManager.addCache(group);
                    }
                    catch (net.sf.ehcache.ObjectExistsException e) {
                        LogFilter.log(LOGGER, LogLevel.WARNING, "{}", e, e);
                    }
                }
            }
        }
    }
Example 5
void addMetaModel(MetaModel mm, Class<? extends Model> modelClass) {
        Object o = metaModelsByClassName.put(modelClass.getName(), mm);
        if (o != null) {
            LogFilter.log(LOGGER, LogLevel.WARNING, "Double-register: {}: {}", modelClass, o);
        }
        o = metaModelsByTableName.put(mm.getTableName(), mm);
        many2ManyAssociations.addAll(mm.getManyToManyAssociations());
        if (o != null) {
            LogFilter.log(LOGGER, LogLevel.WARNING, "Double-register: {}: {}", mm.getTableName(), o);
        }
    }
Example 6
private DB openContext(InitialContext context, String jndiName) {
        try {
            DataSource ds = (DataSource) context.lookup(jndiName);
            Connection connection = ds.getConnection();
            LogFilter.log(LOGGER, LogLevel.DEBUG, "Opened connection: " + connection);
            ConnectionsAccess.attach(name, connection, jndiName);
            return this;
        } catch (Exception e) {
            throw new InitException("Failed to connect to JNDI name: " + jndiName, e);
        }
    }
Example 7
public void commitTransaction() {
        try {
            Connection c = ConnectionsAccess.getConnection(name);
            if (c == null) {
                throw new DBException("Cannot commit transaction, connection '" + name + "' not available");
            }
            c.commit();
            LogFilter.log(LOGGER, LogLevel.DEBUG, "Transaction committed");
        } catch (SQLException ex) {
            throw new DBException(ex.getMessage(), ex);
        }
    }
Example 8
private DB open(String driver, String url, String user, String password, Properties properties){
        checkExistingConnection(name);
        try {
            Class.forName(driver);
            Connection connection;
            connection = properties == null ?  DriverManager.getConnection(url, user, password)
                    : DriverManager.getConnection(url, properties);
            LogFilter.log(LOGGER, LogLevel.DEBUG, "Opened connection: " + connection);
            ConnectionsAccess.attach(name, connection, url);
            return this;
        } catch (Exception e) {
            throw new InitException("Failed to connect to JDBC URL: " + url + " with user: " + user, e);
        }
    }
Example 9
private void registerModels(String dbName, Set<Class<? extends Model>> modelClasses, String dbType) {
        for (Class<? extends Model> modelClass : modelClasses) {
            MetaModel mm = new MetaModel(dbName, modelClass, dbType);
            metaModels.addMetaModel(mm, modelClass);
            LogFilter.log(LOGGER, LogLevel.INFO, "Registered model: {}", modelClass);
        }
    }
Example 10
static void detach(String dbName){
        LogFilter.log(LOGGER, LogLevel.DEBUG, "Detached connection named: {} from current thread: {}", dbName, getConnectionMap().get(dbName));
        getConnectionMap().remove(dbName);
    }
Example 11
public final void flush(CacheEvent event, boolean propagate){
        doFlush(event);
        if(propagate){
            propagate(event);
        }

            String message = "Cache purged: " + (event.getType() == CacheEvent.CacheEventType.ALL
                    ? "all caches" : "table: " + event.getGroup());
            LogFilter.log(LOGGER, LogLevel.DEBUG, message);
    }
Example 12
protected void addAssociation(Association association) {
        if (!associations.contains(association)) {
            LogFilter.log(LOGGER, LogLevel.INFO, "Association found: {}", association);
            associations.add(association);
        }
    }
Example 13
public Connection detach() {
        Connection connection = ConnectionsAccess.getConnection(name);
        try {
            if (connection == null) {
                throw new DBException("cannot detach connection '" + name + "' because it is not available");
            }
            ConnectionsAccess.detach(name); // let's free the thread from connection
            StatementCache.instance().cleanStatementCache(connection);
        } catch (DBException e) {
            LogFilter.log(LOGGER, LogLevel.ERROR, "Could not close connection! MUST INVESTIGATE POTENTIAL CONNECTION LEAK!", e);
        }
        return connection;
    }
Example 14
static void attach(String dbName, Connection connection, String extraInfo) {
        if(ConnectionsAccess.getConnectionMap().get(dbName) != null){
            throw new InternalException("You are opening a connection " + dbName + " without closing a previous one. Check your logic. Connection still remains on thread: " + ConnectionsAccess.getConnectionMap().get(dbName));
        }
        ConnectionsAccess.getConnectionMap().put(dbName, connection);
        LogFilter.log(LOGGER, LogLevel.DEBUG, "Attached connection named: {}: to current thread: {}. Extra info: {}", dbName, connection, extraInfo);
    }