summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2009-05-26 03:34:01 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2009-05-26 03:34:01 +0000
commit9ee53ade6d1056a259a7472fa3ba8116f708a7cb (patch)
tree8b3471c11922786ca32a951e4e1e875b6489bc56
parentfe704cc133fc9b3e78dedeb047bdef85a083978a (diff)
downloadjackcess-9ee53ade6d1056a259a7472fa3ba8116f708a7cb.tar.gz
jackcess-9ee53ade6d1056a259a7472fa3ba8116f708a7cb.zip
add database method to load queries
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@392 f203690c-595d-4dc9-a70b-905162fa7fd2
-rw-r--r--src/java/com/healthmarketscience/jackcess/Column.java9
-rw-r--r--src/java/com/healthmarketscience/jackcess/Database.java67
2 files changed, 74 insertions, 2 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java
index 1d45d02..ea5b9c9 100644
--- a/src/java/com/healthmarketscience/jackcess/Column.java
+++ b/src/java/com/healthmarketscience/jackcess/Column.java
@@ -340,8 +340,13 @@ public class Column implements Comparable<Column> {
}
if(!isVariableLength()) {
- if(getLength() < getType().getFixedSize()) {
- throw new IllegalArgumentException("invalid fixed length size");
+ if(getLength() != getType().getFixedSize()) {
+ if(getLength() < getType().getFixedSize()) {
+ throw new IllegalArgumentException("invalid fixed length size");
+ }
+ LOG.warn("Column length " + getLength() +
+ " longer than expected fixed size " +
+ getType().getFixedSize());
}
} else if(!getType().isLongValue()) {
if(!getType().isValidSize(getLength())) {
diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java
index 75113e1..b8c45d5 100644
--- a/src/java/com/healthmarketscience/jackcess/Database.java
+++ b/src/java/com/healthmarketscience/jackcess/Database.java
@@ -58,6 +58,7 @@ import java.util.Set;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import com.healthmarketscience.jackcess.query.Query;
/**
* An Access database.
@@ -184,13 +185,22 @@ public class Database
private static final String TABLE_SYSTEM_ACES = "MSysACEs";
/** Name of the table that contains table relationships */
private static final String TABLE_SYSTEM_RELATIONSHIPS = "MSysRelationships";
+ /** Name of the table that contains queries */
+ private static final String TABLE_SYSTEM_QUERIES = "MSysQueries";
/** System object type for table definitions */
private static final Short TYPE_TABLE = (short) 1;
+ /** System object type for query definitions */
+ private static final Short TYPE_QUERY = (short) 5;
/** the columns to read when reading system catalog initially */
private static Collection<String> SYSTEM_CATALOG_COLUMNS =
new HashSet<String>(Arrays.asList(CAT_COL_NAME, CAT_COL_TYPE, CAT_COL_ID));
+ /** the columns to read when finding queries */
+ private static Collection<String> SYSTEM_CATALOG_QUERY_COLUMNS =
+ new HashSet<String>(Arrays.asList(CAT_COL_NAME, CAT_COL_TYPE, CAT_COL_ID,
+ CAT_COL_FLAGS));
+
/**
* All of the reserved words in Access that should be escaped when creating
@@ -255,6 +265,8 @@ public class Database
private Table _accessControlEntries;
/** System relationships table (initialized on first use) */
private Table _relationships;
+ /** System queries table (initialized on first use) */
+ private Table _queries;
/** SIDs to use for the ACEs added for new tables */
private final List<byte[]> _newTableSIDs = new ArrayList<byte[]>();
/** for now, "big index support" is optional */
@@ -605,6 +617,61 @@ public class Database
}
/**
+ * Finds all the relationships in the database between the given tables.
+ */
+ public List<Query> getQueries()
+ throws IOException
+ {
+ // the queries table does not get loaded until first accessed
+ if(_queries == null) {
+ _queries = getSystemTable(TABLE_SYSTEM_QUERIES);
+ if(_queries == null) {
+ throw new IOException("Could not find system queries table");
+ }
+ }
+
+ // find all the queries from the system catalog
+ List<Map<String,Object>> queryInfo = new ArrayList<Map<String,Object>>();
+ Map<Integer,List<Query.Row>> queryRowMap =
+ new HashMap<Integer,List<Query.Row>>();
+ for(Map<String,Object> row :
+ Cursor.createCursor(_systemCatalog).iterable(
+ SYSTEM_CATALOG_QUERY_COLUMNS))
+ {
+ String name = (String) row.get(CAT_COL_NAME);
+ if (name != null && TYPE_QUERY.equals(row.get(CAT_COL_TYPE))) {
+ queryInfo.add(row);
+ Integer id = (Integer)row.get(CAT_COL_ID);
+ queryRowMap.put(id, new ArrayList<Query.Row>());
+ }
+ }
+
+ // find all the query rows
+ for(Map<String,Object> row : Cursor.createCursor(_queries)) {
+ Query.Row queryRow = new Query.Row(row);
+ List<Query.Row> queryRows = queryRowMap.get(queryRow.objectId);
+ if(queryRows == null) {
+ LOG.warn("Found rows for query with id " + queryRow.objectId +
+ " missing from system catalog");
+ continue;
+ }
+ queryRows.add(queryRow);
+ }
+
+ // lastly, generate all the queries
+ List<Query> queries = new ArrayList<Query>();
+ for(Map<String,Object> row : queryInfo) {
+ String name = (String) row.get(CAT_COL_NAME);
+ Integer id = (Integer)row.get(CAT_COL_ID);
+ int flags = (Integer)row.get(CAT_COL_FLAGS);
+ List<Query.Row> queryRows = queryRowMap.get(id);
+ queries.add(Query.create(flags, name, queryRows, id));
+ }
+
+ return queries;
+ }
+
+ /**
* Returns a reference to <i>any</i> available table in this access
* database, including system tables.
* <p>