Package org.geotools.arcsde.session

Examples of org.geotools.arcsde.session.ISession


            return new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>(featureType);
        }

        final String typeName = query.getTypeName();
        ArcSdeVersionHandler versionHandler = getVersionHandler(typeName, transaction);
        ISession session = getSession(transaction);

        FeatureReader<SimpleFeatureType, SimpleFeature> reader;
        try {
            reader = getFeatureReader(query, featureType, session, versionHandler);
        } catch (IOException ioe) {
            session.dispose();
            throw ioe;
        } catch (RuntimeException re) {
            session.dispose();
            throw re;
        }
        return reader;
    }
View Full Code Here


    public ArcSdeFeatureWriter getFeatureWriter(final String typeName, final Filter filter,
            final Transaction transaction) throws IOException {
        final ArcSdeVersionHandler versionHandler = getVersionHandler(typeName, transaction);
        // get the connection the streamed writer content has to work over
        // so the reader and writer share it
        final ISession session = getSession(transaction);

        try {
            final FeatureTypeInfo typeInfo = typeInfoCache.getFeatureTypeInfo(typeName, session);
            if (!typeInfo.isWritable()) {
                throw new DataSourceException(typeName + " is not writable");
            }
            final SimpleFeatureType featureType = typeInfo.getFeatureType();

            final FeatureReader<SimpleFeatureType, SimpleFeature> reader;
            if (Filter.EXCLUDE.equals(filter)) {
                reader = new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>(featureType);
            } else {
                final Query query = new Query(typeName, filter);
                final ISession nonDisposableSession = new SessionWrapper(session) {
                    @Override
                    public void dispose() throws IllegalStateException {
                        // do nothing, we don't want the reader to close the session
                    }
                };
View Full Code Here

        if (featureType.getGeometryDescriptor() == null && !typeInfoCache.isAllowNonSpatialTables()) {
            throw new DataSourceException("This DataStore does not allow FeatureTypes with no "
                    + "geometry attributes");
        }

        final ISession session = getSession(Transaction.AUTO_COMMIT);
        try {
            ArcSDEAdapter.createSchema(featureType, hints, session);
        } finally {
            session.dispose();
        }
        typeInfoCache.reset();
    }
View Full Code Here

            throw new IllegalArgumentException(typeName + " already exists as a FeatureType");
        }

        verifyQueryIsSupported(select);

        final ISession session = getSession(Transaction.AUTO_COMMIT);

        try {
            final PlainSelect qualifiedSelect = SelectQualifier.qualify(session, select);
            // System.out.println(qualifiedSelect);

            final SeQueryInfo queryInfo;
            try {
                LOGGER.fine("creating definition query info");
                queryInfo = QueryInfoParser.parse(session, qualifiedSelect);
            } catch (SeException e) {
                throw new ArcSdeException("Error Parsing select: " + qualifiedSelect, e);
            }
            FeatureTypeInfo typeInfo = ArcSDEAdapter.createInprocessViewSchema(session, typeName,
                    typeInfoCache.getNamesapceURI(), qualifiedSelect, queryInfo);

            typeInfoCache.addInprocessViewInfo(typeInfo);
        } finally {
            session.dispose();
        }
    }
View Full Code Here

    public static void oneTimeSetUp() throws IOException, SeException,
            NoSuchAuthorityCodeException, FactoryException, UnavailableConnectionException {
        testData = new TestData();
        testData.setUp();

        ISession session = testData.getConnectionPool().getSession();
        try {
            InProcessViewSupportTestData.setUp(session, testData);
        } finally {
            session.dispose();
        }
    }
View Full Code Here

     *
     * @throws Exception
     */
    @Test
    public void testApiOrderBy() throws Exception {
        ISession session = store.getSession(Transaction.AUTO_COMMIT);

        SeSqlConstruct sqlConstruct = new SeSqlConstruct();
        String[] tables = { InProcessViewSupportTestData.MASTER, InProcessViewSupportTestData.CHILD };
        sqlConstruct.setTables(tables);
        String where = InProcessViewSupportTestData.CHILD + ".MASTER_ID = "
                + InProcessViewSupportTestData.MASTER + ".ID";
        sqlConstruct.setWhere(where);

        // tricky part is that SHAPE column must always be the last one
        String[] propertyNames = { InProcessViewSupportTestData.MASTER + ".ID AS myid2",
                InProcessViewSupportTestData.MASTER + ".NAME AS MNAME",
                InProcessViewSupportTestData.CHILD + ".ID",
                InProcessViewSupportTestData.CHILD + ".NAME",
                InProcessViewSupportTestData.CHILD + ".DESCRIPTION",
                InProcessViewSupportTestData.MASTER + ".SHAPE" };
        final int shapeIndex = 5;
        final int expectedCount = 7;

        final SeQueryInfo queryInfo = new SeQueryInfo();
        queryInfo.setConstruct(sqlConstruct);
        queryInfo.setColumns(propertyNames);
        queryInfo.setByClause(" ORDER BY " + InProcessViewSupportTestData.CHILD + ".ID DESC");

        final Integer[] expectedChildIds = { new Integer(7), new Integer(6), new Integer(5),
                new Integer(4), new Integer(3), new Integer(2), new Integer(1) };

        // final int[] expectedShapeIndicators = { SeRow.SE_IS_NOT_NULL_VALUE, // child7
        // SeRow.SE_IS_REPEATED_FEATURE, // child6
        // SeRow.SE_IS_REPEATED_FEATURE, // child5
        // SeRow.SE_IS_REPEATED_FEATURE, // child4
        // SeRow.SE_IS_NOT_NULL_VALUE, // child3
        // SeRow.SE_IS_REPEATED_FEATURE, // child2
        // SeRow.SE_IS_NOT_NULL_VALUE // child1
        // };

        final SeQuery query = session.issue(new Command<SeQuery>() {

            @Override
            public SeQuery execute(ISession session, SeConnection connection) throws SeException,
                    IOException {
                SeQuery query = new SeQuery(connection);
                query.prepareQueryInfo(queryInfo);
                query.execute();
                return query;
            }
        });

        try {
            SdeRow row = session.fetch(query);

            int count = 0;
            final int childIdIndex = 2;
            while (row != null) {
                // duplicate shapes are not returned by arcsde.
                // in that case indicator has the value
                // SeRow.SE_IS_REPEATED_FEATURE
                int indicator = row.getIndicator(shapeIndex);
                Integer childId = row.getInteger(childIdIndex);
                assertEquals(expectedChildIds[count], childId);

                // this seems to be DB dependent, on SQLSever repeated shapes have
                // SeRow.SE_IS_REPEATED_FEATURE
                // indicator, on Oracle they're returned as SE_IS_NOT_NULL_VALUE
                // assertEquals("at index " + count, expectedShapeIndicators[count], indicator);

                if (SeRow.SE_IS_NOT_NULL_VALUE == indicator) {
                    Object shape = row.getObject(shapeIndex);
                    assertTrue(shape.getClass().getName(), shape instanceof SeShape);
                }

                count++;
                row = session.fetch(query);
            }
            assertEquals(expectedCount, count);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            session.dispose();
        }
    }
View Full Code Here

     *             query.prepareQueryInfo(queryInfo);
     */
    @Test
    @Ignore
    public void testApiAlias() throws Exception {
        ISession session = store.getSession(Transaction.AUTO_COMMIT);

        SeSqlConstruct sqlConstruct = new SeSqlConstruct();
        String[] tables = { InProcessViewSupportTestData.MASTER + " MASTER",
                InProcessViewSupportTestData.CHILD + " CHILD" };
        sqlConstruct.setTables(tables);
        String where = "CHILD.MASTER_ID = MASTER.ID";
        sqlConstruct.setWhere(where);

        // tricky part is that SHAPE column must always be the last one
        String[] propertyNames = { "MASTER.ID", "CHILD.NAME", "MASTER.SHAPE" };

        final int shapeIndex = 2;
        final int expectedCount = 7;

        final SeQueryInfo queryInfo = new SeQueryInfo();
        queryInfo.setConstruct(sqlConstruct);
        queryInfo.setColumns(propertyNames);

        final SeQuery query = session.issue(new Command<SeQuery>() {
            @Override
            public SeQuery execute(ISession session, SeConnection connection) throws SeException,
                    IOException {
                SeQuery query = new SeQuery(connection);
                query.prepareQueryInfo(queryInfo);
                query.execute();
                return query;
            }
        });

        try {
            SdeRow row = session.fetch(query);
            int count = 0;
            while (row != null) {
                // we would expect SeShape being returned from shapeIndex, but
                // ArcSDE returns shape id
                if (SeRow.SE_IS_NOT_NULL_VALUE == row.getIndicator(shapeIndex)) {
                    Object shape = row.getObject(shapeIndex);
                    // assertTrue(shape.getClass().getName(), shape instanceof
                    // SeShape);
                    assertFalse(shape.getClass().getName(), shape instanceof SeShape);
                }
                count++;
                row = session.fetch(query);
            }
            assertEquals(expectedCount, count);
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        } finally {
            session.dispose();
        }
    }
View Full Code Here

     *
     * @throws Exception
     */
    @Test
    public void testApiGroupBy() throws Exception {
        ISession session = store.getSession(Transaction.AUTO_COMMIT);

        SeSqlConstruct sqlConstruct = new SeSqlConstruct();
        String[] tables = { InProcessViewSupportTestData.MASTER, InProcessViewSupportTestData.CHILD };
        sqlConstruct.setTables(tables);
        String where = InProcessViewSupportTestData.CHILD + ".MASTER_ID = "
                + InProcessViewSupportTestData.MASTER + ".ID";
        sqlConstruct.setWhere(where);

        // tricky part is that SHAPE column must always be the last one
        String[] propertyNames = { InProcessViewSupportTestData.MASTER + ".ID",
                InProcessViewSupportTestData.CHILD + ".NAME" /*
                                                              * , MASTER + ".SHAPE"
                                                              */
        };

        // final int shapeIndex = 5;
        final int expectedCount = 6;

        final SeQueryInfo queryInfo = new SeQueryInfo();
        queryInfo.setConstruct(sqlConstruct);
        queryInfo.setColumns(propertyNames);

        String groupBy = InProcessViewSupportTestData.MASTER + ".ID, "
                + InProcessViewSupportTestData.CHILD + ".NAME, "
                + InProcessViewSupportTestData.MASTER + ".SHAPE";

        queryInfo.setByClause(" GROUP BY " + groupBy + " ORDER BY "
                + InProcessViewSupportTestData.CHILD + ".NAME DESC");

        // final int[] expectedShapeIndicators = { SeRow.SE_IS_NOT_NULL_VALUE,
        // // child6
        // // (&&
        // // child7)
        // SeRow.SE_IS_REPEATED_FEATURE, // child5
        // SeRow.SE_IS_REPEATED_FEATURE, // child4
        // SeRow.SE_IS_NOT_NULL_VALUE, // child3
        // SeRow.SE_IS_REPEATED_FEATURE, // child2
        // SeRow.SE_IS_NOT_NULL_VALUE // child1
        // };

        SeQuery query = session.issue(new Command<SeQuery>() {
            @Override
            public SeQuery execute(ISession session, SeConnection connection) throws SeException,
                    IOException {
                SeQuery query = new SeQuery(connection);
                query.prepareQueryInfo(queryInfo);
                query.execute();
                return query;
            }
        });
        try {
            SdeRow row = session.fetch(query);
            int count = 0;
            while (row != null) {
                // duplicate shapes are not returned by arcsde.
                // in that case indicator has the value
                // SeRow.SE_IS_REPEATED_FEATURE
                // int indicator = row.getIndicator(shapeIndex);

                // assertEquals("at index " + count,
                // expectedShapeIndicators[count], indicator);

                count++;
                row = session.fetch(query);
            }
            assertEquals(expectedCount, count);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            session.dispose();
        }
    }
View Full Code Here

     *
     * @throws Exception
     */
    @Test
    public void testApiPlainSql() throws Exception {
        ISession session = store.getSession(Transaction.AUTO_COMMIT);

        final String plainQuery = "SELECT " + InProcessViewSupportTestData.MASTER + ".ID, "
                + InProcessViewSupportTestData.MASTER + ".SHAPE, "
                + InProcessViewSupportTestData.CHILD + ".NAME  FROM "
                + InProcessViewSupportTestData.MASTER + " INNER JOIN "
                + InProcessViewSupportTestData.CHILD + " ON " + InProcessViewSupportTestData.CHILD
                + ".MASTER_ID = " + InProcessViewSupportTestData.MASTER + ".ID";

        final int shapeIndex = 1;
        final int expectedCount = 7;
        final SeQuery query = session.issue(new Command<SeQuery>() {

            @Override
            public SeQuery execute(ISession session, SeConnection connection) throws SeException,
                    IOException {
                SeQuery query = new SeQuery(connection);
                query.prepareSql(plainQuery);
                query.execute();
                return query;
            }
        });

        try {
            SdeRow row = session.fetch(query);
            int count = 0;
            while (row != null) {
                Object shape = row.getObject(shapeIndex);
                assertTrue(shape instanceof Integer); // returns int instead
                // of shape
                count++;
                row = session.fetch(query);
            }
            assertEquals(expectedCount, count);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            session.dispose();
        }
    }
View Full Code Here

     * </ul>
     * </p>
     */
    public void commit() throws IOException {
        failIfClosed();
        final ISession session = this.session;

        final Command<Void> commitCommand = new Command<Void>() {
            @Override
            public Void execute(ISession session, SeConnection connection) throws SeException,
                    IOException {

                try {
                    session.commitTransaction();
                    session.startTransaction();
                } catch (IOException se) {
                    LOGGER.log(Level.WARNING, se.getMessage(), se);
                    throw se;
                }
                return null;
            }
        };

        try {
            session.issue(commitCommand);
        } catch (IOException e) {
            throw e;
        }
    }
View Full Code Here

TOP

Related Classes of org.geotools.arcsde.session.ISession

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.