src/main/java/com/aoindustries/dbc/meta/Table.java
public Index getPrimaryKey() throws SQLException {
		synchronized(getPrimaryKeyLock) {
			if(!getPrimaryKeyCached) {
				String pkName = null;
				List<Column> columns = new AutoGrowArrayList<>();
				try (ResultSet results = schema.getCatalog().getMetaData().getMetaData().getPrimaryKeys(schema.getCatalog().getName(), schema.getName(), name)) {
					while(results.next()) {
						String columnName = results.getString("COLUMN_NAME");
						int keySeq = results.getInt("KEY_SEQ");
						String newPkName = results.getString("PK_NAME");
						if(newPkName!=null) {
							if(pkName==null) pkName = newPkName;
							else if(!newPkName.equals(pkName)) throw new SQLException("Mismatched PK_NAME values: "+newPkName+"!="+pkName);
						}
						if(columns.set(keySeq-1, getColumn(columnName))!=null) throw new SQLException("Duplicate key sequence: "+keySeq);
					}
				}
				if(columns.isEmpty()) {
					getPrimaryKeyCache = null;
					getPrimaryKeyCached = true;
				} else {
					// Make sure no gaps in the key sequence
					for(int i=0; i<columns.size(); i++) {
						if(columns.get(i)==null) throw new SQLException("Missing key sequence in index: "+(i+1));
					}
					getPrimaryKeyCache = new Index(this, pkName, IndexType.PRIMARY_KEY, columns);
					getPrimaryKeyCached = true;
				}
			}
			return getPrimaryKeyCache;
		}
	}
public Index getPrimaryKey() throws SQLException {
		synchronized(getPrimaryKeyLock) {
			if(!getPrimaryKeyCached) {
				String pkName = null;
				List<Column> columns = new AutoGrowArrayList<>();
				try (ResultSet results = schema.getCatalog().getMetaData().getMetaData().getPrimaryKeys(schema.getCatalog().getName(), schema.getName(), name)) {
					while(results.next()) {
						String columnName = results.getString("COLUMN_NAME");
						int keySeq = results.getInt("KEY_SEQ");
						String newPkName = results.getString("PK_NAME");
						if(newPkName!=null) {
							if(pkName==null) pkName = newPkName;
							else if(!newPkName.equals(pkName)) throw new SQLException("Mismatched PK_NAME values: "+newPkName+"!="+pkName);
						}
						if(columns.set(keySeq-1, getColumn(columnName))!=null) throw new SQLException("Duplicate key sequence: "+keySeq);
					}
				}
				if(columns.isEmpty()) {
					getPrimaryKeyCache = null;
					getPrimaryKeyCached = true;
				} else {
					// Make sure no gaps in the key sequence
					for(int i=0; i<columns.size(); i++) {
						if(columns.get(i)==null) throw new SQLException("Missing key sequence in index: "+(i+1));
					}
					getPrimaryKeyCache = new Index(this, pkName, IndexType.PRIMARY_KEY, columns);
					getPrimaryKeyCached = true;
				}
			}
			return getPrimaryKeyCache;
		}
	}
public Index getPrimaryKey ( ) throws SQLException { synchronized ( getPrimaryKeyLock ) { if ( ! getPrimaryKeyCached ) { String pkName = null ; List < Column > columns = new AutoGrowArrayList <> ( ) ; try ( ResultSet results = schema . getCatalog ( ) . getMetaData ( ) . getMetaData ( ) . getPrimaryKeys ( schema . getCatalog ( ) . getName ( ) , schema . getName ( ) , name ) ) { while ( results . next ( ) ) { String columnName = results . getString ( "COLUMN_NAME" ) ; int keySeq = results . getInt ( "KEY_SEQ" ) ; String newPkName = results . getString ( "PK_NAME" ) ; if ( newPkName != null ) { if ( pkName == null ) pkName = newPkName ; else if ( ! newPkName . equals ( pkName ) ) throw new SQLException ( "Mismatched PK_NAME values: " + newPkName + "!=" + pkName ) ; } if ( columns . set ( keySeq - 1 , getColumn ( columnName ) ) != null ) throw new SQLException ( "Duplicate key sequence: " + keySeq ) ; } } if ( columns . isEmpty ( ) ) { getPrimaryKeyCache = null ; getPrimaryKeyCached = true ; } else { // Make sure no gaps in the key sequence for ( int i = 0 ; i < columns . size ( ) ; i ++ ) { if ( columns . get ( i ) == null ) throw new SQLException ( "Missing key sequence in index: " + ( i + 1 ) ) ; } getPrimaryKeyCache = new Index ( this , pkName , IndexType . PRIMARY_KEY , columns ) ; getPrimaryKeyCached = true ; } } return getPrimaryKeyCache ; } }
Gets the primary key for this table or <code>null</code> if not found.
Gets the primary key for this table or <code > null< / code > if not found .