Search in sources :

Example 1 with ListOrderedMap

use of org.apache.commons.collections.map.ListOrderedMap in project symmetric-ds by JumpMind.

the class FirebirdDdlReader method readIndices.

@Override
protected Collection<IIndex> readIndices(Connection connection, DatabaseMetaDataWrapper metaData, String tableName) throws SQLException {
    // Jaybird is not able to read indices when delimited identifiers are
    // turned on, so we gather the data manually using Firebird's system tables
    @SuppressWarnings("unchecked") Map<String, IIndex> indices = new ListOrderedMap();
    StringBuilder query = new StringBuilder();
    query.append("SELECT a.RDB$INDEX_NAME INDEX_NAME, b.RDB$RELATION_NAME TABLE_NAME, b.RDB$UNIQUE_FLAG NON_UNIQUE,");
    query.append(" a.RDB$FIELD_POSITION ORDINAL_POSITION, a.RDB$FIELD_NAME COLUMN_NAME, 3 INDEX_TYPE");
    query.append(" FROM RDB$INDEX_SEGMENTS a, RDB$INDICES b WHERE a.RDB$INDEX_NAME=b.RDB$INDEX_NAME AND b.RDB$RELATION_NAME = ?");
    PreparedStatement stmt = connection.prepareStatement(query.toString());
    ResultSet indexData = null;
    stmt.setString(1, getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn() ? tableName : tableName.toUpperCase());
    try {
        indexData = stmt.executeQuery();
        while (indexData.next()) {
            Map<String, Object> values = readMetaData(indexData, getColumnsForIndex());
            // we have to reverse the meaning of the unique flag
            values.put("NON_UNIQUE", Boolean.FALSE.equals(values.get("NON_UNIQUE")) ? Boolean.TRUE : Boolean.FALSE);
            // and trim the names
            values.put("INDEX_NAME", ((String) values.get("INDEX_NAME")).trim());
            values.put("TABLE_NAME", ((String) values.get("TABLE_NAME")).trim());
            values.put("COLUMN_NAME", ((String) values.get("COLUMN_NAME")).trim());
            readIndex(metaData, values, indices);
        }
    } finally {
        if (indexData != null) {
            indexData.close();
        }
    }
    return indices.values();
}
Also used : IIndex(org.jumpmind.db.model.IIndex) ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with ListOrderedMap

use of org.apache.commons.collections.map.ListOrderedMap in project symmetric-ds by JumpMind.

the class InterbaseDdlReader method readForeignKeys.

@Override
protected Collection<ForeignKey> readForeignKeys(Connection connection, DatabaseMetaDataWrapper metaData, String tableName) throws SQLException {
    @SuppressWarnings("unchecked") Map<String, ForeignKey> fks = new ListOrderedMap();
    ResultSet fkData = null;
    try {
        if (getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn()) {
            // Jaybird has a problem when delimited identifiers are used as
            // it is not able to find the foreign key info for the table
            // So we have to filter manually below
            fkData = metaData.getForeignKeys(getDefaultTablePattern());
            while (fkData.next()) {
                Map<String, Object> values = readMetaData(fkData, getColumnsForFK());
                if (tableName.equals(values.get("FKTABLE_NAME"))) {
                    readForeignKey(metaData, values, fks);
                }
            }
        } else {
            fkData = metaData.getForeignKeys(tableName);
            while (fkData.next()) {
                Map<String, Object> values = readMetaData(fkData, getColumnsForFK());
                readForeignKey(metaData, values, fks);
            }
        }
    } finally {
        if (fkData != null) {
            fkData.close();
        }
    }
    return fks.values();
}
Also used : ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap) ResultSet(java.sql.ResultSet) ForeignKey(org.jumpmind.db.model.ForeignKey)

Example 3 with ListOrderedMap

use of org.apache.commons.collections.map.ListOrderedMap in project jackrabbit by apache.

the class NodeCreationTest method testIllegalChars.

public void testIllegalChars() throws RepositoryException, NotExecutableException {
    createUserManager(2, true, 2);
    UserImpl u = (UserImpl) uMgr.createUser("z", "z");
    save(s);
    // remember the z-folder for later removal
    toRemove.add((NodeImpl) u.getNode().getParent().getParent());
    String zu = Text.escapeIllegalJcrChars("z*");
    String zur = Text.escapeIllegalJcrChars("z*r");
    Map<String, String> m = new ListOrderedMap();
    // test illegal JCR chars in uid
    // on level 2
    m.put("z*rich", "/z/" + zu + "/" + Text.escapeIllegalJcrChars("z*rich"));
    m.put("z*riq", "/z/" + zu + "/" + Text.escapeIllegalJcrChars("z*riq"));
    // still on level 2 (too short for 3)
    m.put("z*", "/z/" + zu + "/" + zu);
    // on level 3
    m.put("z*rik", "/z/" + zu + "/" + zur + "/" + Text.escapeIllegalJcrChars("z*rik"));
    m.put("z*.ri", "/z/" + zu + "/" + Text.escapeIllegalJcrChars("z*.") + "/" + Text.escapeIllegalJcrChars("z*.ri"));
    for (String uid : m.keySet()) {
        u = (UserImpl) uMgr.createUser(uid, uid);
        save(s);
        assertEquals(usersPath + m.get(uid), u.getNode().getPath());
        Authorizable ath = uMgr.getAuthorizable(uid);
        assertNotNull("User with id " + uid + " must exist.", ath);
        assertFalse("User with id " + uid + " must not be a group.", ath.isGroup());
    }
    // test for groups as well
    GroupImpl gr = (GroupImpl) uMgr.createGroup(new TestPrincipal("z[x]"));
    save(s);
    // remember the z-folder for later removal
    toRemove.add((NodeImpl) gr.getNode().getParent().getParent());
    assertEquals("z[x]", gr.getID());
    String expectedPath = groupsPath + "/z/" + Text.escapeIllegalJcrChars("z[") + "/" + Text.escapeIllegalJcrChars("z[x]");
    assertEquals(expectedPath, gr.getNode().getPath());
    Authorizable ath = uMgr.getAuthorizable(gr.getID());
    assertNotNull(ath);
    assertTrue(ath.isGroup());
    // test if conflicting authorizables are detected.
    try {
        uMgr.createUser("z[x]", "z[x]");
        save(s);
        fail("A group \"z[x]\" already exists.");
    } catch (AuthorizableExistsException e) {
    // success
    }
    try {
        uMgr.createGroup(new TestPrincipal("z*rik"));
        save(s);
        fail("A user \"z*rik\" already exists");
    } catch (AuthorizableExistsException e) {
    // success
    }
}
Also used : AuthorizableExistsException(org.apache.jackrabbit.api.security.user.AuthorizableExistsException) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable)

Example 4 with ListOrderedMap

use of org.apache.commons.collections.map.ListOrderedMap in project jackrabbit by apache.

the class NodeCreationTest method testFindById.

/**
     * Find by ID must succeed.
     *
     * @throws RepositoryException
     */
public void testFindById() throws RepositoryException, NotExecutableException {
    createUserManager(2, true, 2);
    UserImpl u = (UserImpl) uMgr.createUser("z", "z");
    save(s);
    // remember the z-folder for later removal
    toRemove.add((NodeImpl) u.getNode().getParent().getParent());
    assertEquals(usersPath + "/z/zz/z", u.getNode().getPath());
    Map<String, String> m = new ListOrderedMap();
    // potential conflicting uid
    m.put("zzz", "/z/zz/zzz/zzz");
    // max-size (2) is reached
    m.put("zzzuerich", "/z/zz/zzz/zzzuerich");
    m.put("zzuerich", "/z/zz/zzu/zzuerich");
    // too short for expanded folders
    m.put("zz", "/z/zz/zz");
    for (String uid : m.keySet()) {
        u = (UserImpl) uMgr.createUser(uid, uid);
        save(s);
        assertEquals(usersPath + m.get(uid), u.getNode().getPath());
        User us = (User) uMgr.getAuthorizable(uid);
        assertNotNull(us);
        assertEquals(uid, us.getID());
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap)

Example 5 with ListOrderedMap

use of org.apache.commons.collections.map.ListOrderedMap in project jackrabbit by apache.

the class NodeCreationTest method testChangedDefaultLevel.

/**
     * Having 3 default levels -> test uids again.
     *
     * @throws RepositoryException
     */
public void testChangedDefaultLevel() throws RepositoryException, NotExecutableException {
    createUserManager(3, false, 1);
    UserImpl u = (UserImpl) uMgr.createUser("z", "z");
    save(s);
    // remember the z-folder for later removal
    toRemove.add((NodeImpl) u.getNode().getParent().getParent().getParent());
    assertEquals(usersPath + "/z/zz/zzz/z", u.getNode().getPath());
    Map<String, String> m = new ListOrderedMap();
    m.put("zz", "/z/zz/zzz/zz");
    m.put("zzz", "/z/zz/zzz/zzz");
    m.put("zzzz", "/z/zz/zzz/zzzz");
    m.put("zH", "/z/zH/zHH/zH");
    m.put("zHzh", "/z/zH/zHz/zHzh");
    m.put("z_Hz", "/z/z_/z_H/z_Hz");
    m.put("zÏrich", "/z/zÏ/zÏr/zÏrich");
    for (String uid : m.keySet()) {
        u = (UserImpl) uMgr.createUser(uid, uid);
        save(s);
        assertEquals(usersPath + m.get(uid), u.getNode().getPath());
        Authorizable az = uMgr.getAuthorizable(uid);
        assertNotNull(az);
    }
}
Also used : ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable)

Aggregations

ListOrderedMap (org.apache.commons.collections.map.ListOrderedMap)7 ResultSet (java.sql.ResultSet)4 PreparedStatement (java.sql.PreparedStatement)3 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)2 IIndex (org.jumpmind.db.model.IIndex)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AuthorizableExistsException (org.apache.jackrabbit.api.security.user.AuthorizableExistsException)1 User (org.apache.jackrabbit.api.security.user.User)1 TestPrincipal (org.apache.jackrabbit.core.security.TestPrincipal)1 ForeignKey (org.jumpmind.db.model.ForeignKey)1