Package org.geotools.jdbc

Examples of org.geotools.jdbc.PrimaryKey


        }

        if (columns.isEmpty()) {
            return null;
        } else {
            return new PrimaryKey(table, columns);
        }
    }
View Full Code Here


                finally {
                    dataStore.closeSafe(ps);
                }

                //create the spatial index table
                PrimaryKey pkey = dataStore.getPrimaryKeyFinder()
                    .getPrimaryKey(dataStore, schemaName, tableName, cx);
                if (!(pkey instanceof NullPrimaryKey)) {
                    String indexTableName = tableName + "_" + gd.getLocalName() + "_idx";
                    String hashIndex = indexTableName + "_idx";
                   
                    // drop index hash index if exists
                    StringBuffer sb = new StringBuffer("DROP HASH INDEX ");
                    encodeTableName(schemaName, hashIndex, sb);
                   
                    sql = sb.toString();
                    LOGGER.fine(sql);
                   
                    try {
                        ps = cx.prepareStatement(sql);
                        ps.execute();
                    }
                    catch(SQLException e) {
                        //ignore
                    }
                    finally {
                        dataStore.closeSafe(ps);
                    }
                   
                    // drop index table if exists
                    sb = new StringBuffer("DROP TABLE ");
                    encodeTableName(schemaName, indexTableName, sb);
                   
                    sql = sb.toString();
                    LOGGER.fine(sql);
                   
                    try {
                        ps = cx.prepareStatement(sql);
                        ps.execute();
                    }
                    catch(SQLException e) {
                        //ignore
                    }
                    finally {
                        dataStore.closeSafe(ps);
                    }

                    // create index table
                    sb = new StringBuffer("CREATE MULTISET TABLE ");
                    encodeTableName(schemaName, indexTableName, sb);
                    sb.append("( ");
                   
                    for (PrimaryKeyColumn col : pkey.getColumns()) {
                        encodeColumnName(col.getName(), sb);
                       
                        String typeName = lookupSqlTypeName(cx, schemaName, tableName, col.getName());
                        sb.append(" ").append(typeName).append(" NOT NULL, ");
                    }
                    if (!pkey.getColumns().isEmpty()) {
                        // @todo only looking at first primary key
                        // more multiply keyed tables, this at least ensures some speed
                        sb.append("cellid INTEGER NOT NULL)");
                        sb.append("PRIMARY INDEX (");
                        encodeColumnName(pkey.getColumns().get(0).getName(), sb);
                        sb.append(")");
                    }
                    sql = sb.toString();
                    LOGGER.fine(sql);
                    try {
                       ps = cx.prepareStatement(sql);
                       ps.execute();
                    } finally {
                        dataStore.closeSafe(ps);
                    }

                    // create hash
                    sb = new StringBuffer("CREATE HASH INDEX " + hashIndex + " (cellid) ON " + indexTableName + " ORDER BY (cellid)");
                    sql = sb.toString();
                    LOGGER.fine(sql);
                    try {
                        ps = cx.prepareStatement(sql);
                        ps.execute();
                    } finally {
                        dataStore.closeSafe(ps);
                    }

                    installTriggers(cx,tableName,gd.getLocalName(),indexTableName,pkey.getColumns());
                   
                }
                else {
                    LOGGER.warning("No primary key for " + schemaName + "." + tableName + ". Unable"
                       + " to create spatial index.");
View Full Code Here

TOP

Related Classes of org.geotools.jdbc.PrimaryKey

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.