Browse Source

Add Table methods to access the creation and last modified dates

git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1375 f203690c-595d-4dc9-a70b-905162fa7fd2
tags/jackcess-4.0.2
James Ahlborn 2 years ago
parent
commit
a61e2da7fe

+ 5
- 0
src/changes/changes.xml View File

<author email="javajedi@users.sf.net">Tim McCune</author> <author email="javajedi@users.sf.net">Tim McCune</author>
</properties> </properties>
<body> <body>
<release version="4.0.2" date="TBD">
<action dev="jahlborn" type="update">
Add Table methods to access the creation and last modified dates.
</action>
</release>
<release version="4.0.1" date="2021-06-21"> <release version="4.0.1" date="2021-06-21">
<action dev="jahlborn" type="fix"> <action dev="jahlborn" type="fix">
Ignore trailing spaces when creating text index entries. Ignore trailing spaces when creating text index entries.

+ 16
- 0
src/main/java/com/healthmarketscience/jackcess/Table.java View File

package com.healthmarketscience.jackcess; package com.healthmarketscience.jackcess;


import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
*/ */
public PropertyMap getProperties() throws IOException; public PropertyMap getProperties() throws IOException;


/**
* @return the created date for this table if available
* @usage _general_method_
*/
public LocalDateTime getCreatedDate() throws IOException;

/**
* Note: jackcess <i>does not automatically update the modified date of a
* Table</i>.
*
* @return the last updated date for this table if available
* @usage _general_method_
*/
public LocalDateTime getUpdatedDate() throws IOException;

/** /**
* @return All of the Indexes on this table (unmodifiable List) * @return All of the Indexes on this table (unmodifiable List)
* @usage _intermediate_method_ * @usage _intermediate_method_

+ 1
- 1
src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java View File

return dtc.getDateTimeFactory().toDateDouble(value, dtc); return dtc.getDateTimeFactory().toDateDouble(value, dtc);
} }


private static LocalDateTime toLocalDateTime(
static LocalDateTime toLocalDateTime(
Object value, DateTimeContext dtc) { Object value, DateTimeContext dtc) {
if(value instanceof TemporalAccessor) { if(value instanceof TemporalAccessor) {
return temporalToLocalDateTime((TemporalAccessor)value, dtc); return temporalToLocalDateTime((TemporalAccessor)value, dtc);

+ 23
- 0
src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java View File

import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
/** the columns to read when getting object propertyes */ /** the columns to read when getting object propertyes */
private static Collection<String> SYSTEM_CATALOG_PROPS_COLUMNS = private static Collection<String> SYSTEM_CATALOG_PROPS_COLUMNS =
new HashSet<String>(Arrays.asList(CAT_COL_ID, CAT_COL_PROPS)); new HashSet<String>(Arrays.asList(CAT_COL_ID, CAT_COL_PROPS));
/** the columns to read when grabbing dates */
private static Collection<String> SYSTEM_CATALOG_DATE_COLUMNS =
new HashSet<String>(Arrays.asList(CAT_COL_ID,
CAT_COL_DATE_CREATE, CAT_COL_DATE_UPDATE));


/** regex matching characters which are invalid in identifier names */ /** regex matching characters which are invalid in identifier names */
private static final Pattern INVALID_IDENTIFIER_CHARS = private static final Pattern INVALID_IDENTIFIER_CHARS =
objectId, SYSTEM_CATALOG_PROPS_COLUMNS), owner); objectId, SYSTEM_CATALOG_PROPS_COLUMNS), owner);
} }


LocalDateTime getCreateDateForObject(int objectId) throws IOException {
return getDateForObject(objectId, CAT_COL_DATE_CREATE);
}

LocalDateTime getUpdateDateForObject(int objectId) throws IOException {
return getDateForObject(objectId, CAT_COL_DATE_UPDATE);
}

private LocalDateTime getDateForObject(int objectId, String dateCol)
throws IOException {
Row row = _tableFinder.getObjectRow(objectId, SYSTEM_CATALOG_DATE_COLUMNS);
if(row == null) {
return null;
}
Object date = row.get(dateCol);
return ((date != null) ? ColumnImpl.toLocalDateTime(date, this) : null);
}

private Integer getDbParentId() throws IOException { private Integer getDbParentId() throws IOException {
if(_dbParentId == null) { if(_dbParentId == null) {
// need the parent id of the databases objects // need the parent id of the databases objects

+ 11
- 0
src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java View File

import java.nio.BufferOverflowException; import java.nio.BufferOverflowException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.time.LocalDateTime;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
return _props; return _props;
} }


@Override
public LocalDateTime getCreatedDate() throws IOException {
return getDatabase().getCreateDateForObject(_tableDefPageNumber);
}

@Override
public LocalDateTime getUpdatedDate() throws IOException {
return getDatabase().getUpdateDateForObject(_tableDefPageNumber);
}

/** /**
* @return all PropertyMaps for this table (and columns) * @return all PropertyMaps for this table (and columns)
* @usage _advanced_method_ * @usage _advanced_method_

+ 19
- 0
src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java View File

} }
} }


public void testTableDates() throws Exception {
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
Table table = open(testDB).getTable("Table1");
String expectedCreateDate = null;
String expectedUpdateDate = null;
if(testDB.getExpectedFileFormat() == FileFormat.V1997) {
expectedCreateDate = "2010-03-05T14:48:26.420";
expectedUpdateDate = "2010-03-05T14:48:26.607";
} else {
expectedCreateDate = "2004-05-28T17:51:48.701";
expectedUpdateDate = "2006-07-24T09:56:19.701";
}
System.out.println("FOO " + testDB.getExpectedFileFormat() + " " +
table.getCreatedDate() + " " +
table.getUpdatedDate());
assertEquals(expectedCreateDate, table.getCreatedDate().toString());
assertEquals(expectedUpdateDate, table.getUpdatedDate().toString());
}
}
private static void checkRawValue(String expected, Object val) private static void checkRawValue(String expected, Object val)
{ {
if(expected != null) { if(expected != null) {

Loading…
Cancel
Save