Search in sources :

Example 6 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class JdbcPropertyStore method readAllProperties.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, Property<?>> readAllProperties() {
    Map<String, Property<?>> properties = new LinkedHashMap<String, Property<?>>();
    Connection sqlConn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        sqlConn = getDataSource().getConnection();
        ps = buildStatement(sqlConn, getQueryBuilder().getAllProperties());
        rs = ps.executeQuery();
        while (rs.next()) {
            Property<?> ap = JDBC_MAPPER.map(rs);
            properties.put(ap.getName(), ap);
        }
    } catch (SQLException sqlEX) {
        throw new PropertyAccessException("Cannot read properties within database, SQL ERROR", sqlEX);
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
        closeConnection(sqlConn);
    }
    return properties;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcUtils.closeConnection(org.ff4j.utils.JdbcUtils.closeConnection) ResultSet(java.sql.ResultSet) JdbcUtils.closeResultSet(org.ff4j.utils.JdbcUtils.closeResultSet) PropertyAccessException(org.ff4j.exception.PropertyAccessException) PreparedStatement(java.sql.PreparedStatement) Property(org.ff4j.property.Property) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class PropertyStoreMongo method readAllProperties.

/**
 * {@inheritDoc}
 */
public Map<String, Property<?>> readAllProperties() {
    LinkedHashMap<String, Property<?>> mapP = new LinkedHashMap<>();
    for (Document document : getPropertiesCollection().find()) {
        Property<?> prop = PMAPPER.fromStore(document);
        mapP.put(prop.getName(), prop);
    }
    return mapP;
}
Also used : Document(org.bson.Document) Property(org.ff4j.property.Property) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class PropertyStoreNeo4j method readAllProperties.

/**
 * {@inheritDoc}
 */
public Map<String, Property<?>> readAllProperties() {
    Map<String, Property<?>> allProperties = new HashMap<>();
    Transaction tx = graphDb.beginTx();
    // Node with relationships
    Result result = graphDb.execute(QUERY_CYPHER_READ_ALLPROPERTIES);
    while (result.hasNext()) {
        Node node = (Node) result.next().get("p");
        Property<?> current = Neo4jMapper.fromNode2Property(node);
        allProperties.put(current.getName(), current);
    }
    tx.success();
    return allProperties;
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HashMap(java.util.HashMap) Node(org.neo4j.graphdb.Node) Property(org.ff4j.property.Property) Result(org.neo4j.graphdb.Result)

Example 9 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class InMemoryPropertyStoreTest method testInitStores.

@Test
public void testInitStores() {
    new InMemoryPropertyStore(new HashMap<String, Property<?>>());
    InputStream in = getClass().getClassLoader().getResourceAsStream("test-ff4j-features.xml");
    new InMemoryPropertyStore(in);
}
Also used : InMemoryPropertyStore(org.ff4j.property.store.InMemoryPropertyStore) InputStream(java.io.InputStream) PropertyString(org.ff4j.property.PropertyString) Property(org.ff4j.property.Property) Test(org.junit.Test)

Example 10 with Property

use of org.ff4j.property.Property in project ff4j by ff4j.

the class InMemoryPropertyStoreTest method testInvalidXML.

@Test(expected = IllegalArgumentException.class)
public void testInvalidXML() {
    new InMemoryPropertyStore(new HashMap<String, Property<?>>());
    InputStream in = getClass().getClassLoader().getResourceAsStream("invalid.xml");
    new InMemoryPropertyStore(in);
}
Also used : InMemoryPropertyStore(org.ff4j.property.store.InMemoryPropertyStore) InputStream(java.io.InputStream) PropertyString(org.ff4j.property.PropertyString) Property(org.ff4j.property.Property) Test(org.junit.Test)

Aggregations

Property (org.ff4j.property.Property)56 HashMap (java.util.HashMap)20 PropertyString (org.ff4j.property.PropertyString)20 Test (org.junit.Test)20 Feature (org.ff4j.core.Feature)16 Map (java.util.Map)11 InputStream (java.io.InputStream)9 XmlParser (org.ff4j.conf.XmlParser)7 InMemoryPropertyStore (org.ff4j.property.store.InMemoryPropertyStore)7 LinkedHashMap (java.util.LinkedHashMap)6 XmlConfig (org.ff4j.conf.XmlConfig)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 FeatureStore (org.ff4j.core.FeatureStore)4 PropertyAccessException (org.ff4j.exception.PropertyAccessException)4 PropertyStore (org.ff4j.property.store.PropertyStore)4 IOException (java.io.IOException)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 FF4jCacheProxy (org.ff4j.cache.FF4jCacheProxy)3