View Javadoc
1   /*
2   Copyright (c) 2026 James Ahlborn
3   
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7   
8       http://www.apache.org/licenses/LICENSE-2.0
9   
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16  
17  package com.healthmarketscience.jackcess;
18  
19  import java.io.IOException;
20  import java.util.List;
21  
22  /**
23   * The name map of a table, which ms access stores in the {@value
24   * PropertyMap#NAME_MAP_PROP} property of the table.  It holds a record for the
25   * table, a record for each column, and a record for each name which an
26   * expression in the table uses.
27   * <p>
28   * Ms access leaves the records different from the table in some cases: a
29   * table renamed from the navigation pane keeps its old name in the table
30   * record until the next design save, and some tables carry the name map of
31   * another table, with guids which are not their own.  A column name is the
32   * more reliable way to find a column record.
33   *
34   * @author James Ahlborn
35   * @usage _intermediate_class_
36   */
37  public interface TableNameMap extends NameMap
38  {
39    /**
40     * @return the record for the table, or {@code null} if there is none
41     */
42    public Record getTableRecord();
43  
44    /**
45     * @return the column record with the given name (case-insensitive), or
46     *         {@code null} if there is none
47     */
48    public Record getColumnRecord(String name);
49  
50    /**
51     * @return the records for the names which expressions in the table use, in
52     *         the order of the name map
53     */
54    public List<Record> getReferences();
55  
56    /**
57     * Adds a column record before the end record.
58     *
59     * @param name the column name
60     * @param guid the guid of the column, which must be the same as the
61     *             {@value PropertyMap#GUID_PROP} property of the column
62     * @return the new record
63     * @throws IllegalStateException if the name map has no table record
64     * @throws IllegalArgumentException if the guid is not valid
65     */
66    public Record addColumn(String name, String guid);
67  
68    /**
69     * Removes the column record with the given name (case-insensitive).
70     *
71     * @return the removed record, or {@code null} if there is none
72     */
73    public Record removeColumn(String name);
74  
75    /**
76     * Compares the table and column records with the table which holds this
77     * name map.  A column is found by its guid, and by its name when it has no
78     * guid or no record carries it.
79     *
80     * @return every difference, empty if the name map agrees with the table
81     */
82    @Override
83    public List<Mismatch> findMismatches() throws IOException;
84  
85    /**
86     * Writes the name map into the table property and saves the properties of
87     * the table.
88     */
89    public void save() throws IOException;
90  }