I am trying to use the DynamoDBAutoGeneratedTimestamp annotation for generating timestamps for when my records are last updated and when they are created. The annotation currently has 2 strategies, ALWAYS and CREATE.
My initial understanding was that the ALWAYS strategy should update the timestamp every time the record is changed, and the CREATE strategy should set the timestamp only when the record is created. The ALWAYS strategy appears to be working just fine in updating the timestamp each time the record changes; however, the CREATE strategy appears to be behaving exactly the same as the ALWAYS strategy (meaning the timestamp updates each time the record changes).
It is now my understanding that the CREATE strategy doesn't do that, and instead tells the record to generate a timestamp if you're going to write it to the database and the value of the field in the record to be written is null.
This causes the field with the CREATE strategy to always be updated if the record itself is ever updated.
So, are there any easy solutions to this? I could set it myself, of course, but I was wondering if there is some sort of option or config that is not known to me that would address this issue?
Example code:
#DynamoDBTable(tableName = "Foo")
public class Foo {
#DynamoDBAutoGeneratedTimestamp(strategy = DynamoDBAutoGenerateStrategy.CREATE)
private Date createdAt;
#DynamoDBAutoGeneratedTimestamp(strategy = DynamoDBAutoGenerateStrategy.ALWAYS)
private Date updatedAt;
}
Related
In one of my projects, I want to store application start time and end time to GCP Firestore in timestamp format.
I have tried the following things
I tried to save the java DateTime but in the Firestore its storing
as array(Firestore screenshot).
and also I tried to use the FieldValue but it's storing start time and end time as the same.
is there any way I can store time stamp in GCP Firestore with the actual time difference(application start time and end time)
I am storing the below model class by updating the completeAt and startedAt fields(note: I have tried with type FieldValue as well instead of Date).
public class Test{
private Date completeAt
private Date completeAt
}
Regarding the first attempt, completeAt it's not an array, it's an object.
Regarding your second attempt:
Is there any way I can store time stamp in GCP Firestore with the actual time difference(application start time and end time)
Both fields completeAt and startedAt are populated with the correct data type. However, the values are not correct. If you want the startedAt field to hold a Timestamp value when the app starts, then you should perform an update operation right then. As soon as the user stops using the app, perform another update the add the corresponding Timestamp to the completeAt field. In this way, you'll have different values for each field.
I am creating a leave tracker app where I want to store the user ID along with the from date and to date. I am using Amazon's DynamoDB as the database, and the user enters a leave through a custom command.
Eg: apply-leave from-date to-date
I want to avoid duplicate entries in the database. For example, if a user has already applied for a leave between 06-10-2019 to 10-10-2019 and applies for a leave between the same dates again, they should get a message saying that this already exists and a new record should not be created for the same.
However, a user can apply for multiple leaves and two users can take a leave between the same dates.
I tried using a conditional statement as follows:
table.put_item(
Item={
'leave_id': leave_id,
'user_id': user_id,
'from_date': from_date,
'to_date': to_date,
},
ConditionExpression='attribute_not_exists(user_id) AND attribute_not_exists(from_date) AND attribute_not_exists(to_date)'
)
where leave_id is the partition key. However, this does not work and a new row is added every time, even if it is the same dates. I have looked through similar other questions, but haven't been able to understand how to get this configured correctly.
Any ideas on how I should go about this, or if there is a different design that I should follow?
If you are calling your code with the leave_id that doesn't yet exist in the table, the item will always be inserted. If you call your code with leave_id that does already exist in your table you should be getting An error occurred (ConditionalCheckFailedException) when calling the PutItem operation: The conditional request failed error message.
I have two suggestions:
If you don't want to change your table, you can create a secondary index with user_id as the partition key and then query the index for all the items where the given user has some from_date and to_date attributes.
Like this:
table.query(
IndexName='user_id-index',
KeyConditionExpression=Key('user_id').eq(user_id),
FilterExpression=Attr('from_date').exists() & Attr('from_date').exists()
)
Then you will need to check for overlapping leave requests, etc. (eg. leave request that starts before the one that is already in place finishes). After deciding that the leave request is a valid one you will call put_item.
Another suggestion and probably a better one would be to create a composite primary key on your table with user_id as a partition key and leave_id as a sort key. That way you could execute a query for all leave requests from a particular user without the need to create a secondary index.
In our application we're getting initialValues for a form from an API call that returns something like:
{
myDate: "2000-01-01T00:00:00"
}
We then convert that value to a moment and save it to the store and populate initialValues from that. If we then select a new value (say, 2001-01-01, also a moment) and save the form, we read the response back from the api, convert it back to a moment, and throw it back in initialValues. The problem is, now our field is dirty because moment("2001-01-01") !== moment("2001-01-01").
Is our workflow wrong? Is there a better way to handle managing initialState?
The problem is that if moment("2001-01-01") does not equal moment("2001-01-01") then redux-form will always think that the form state has changed if the value for myDate is reinitialized, even though the value used to create the Moment instance is the same.
The fix is simple: Don't store moment objects in the redux store. Instead use a formatted string, like "2000-01-01T00:00:00", or or a number (unix timestamps) to represent datetime information in the redux store. If you need to do operations, like date1.isBefore(date2), you can convert them to Moments temporarily.
I have a large relational Access 2010 database. It is normalized, and includes some union queries that are very slow. I therefore thought I could speed things up by creating some cached fields. For example in tblOrder I would create a CustomerName field. To maintain this cached field I created a Before Change data macro that would dLookup the customer's company name from tblCustomer. It worked great. Then I created an After Update data macro in tblCustomer so when the user changes the Company Name all the child records would automatically be updated. It worked, but then the Before Change data macro fired and the dLookup returned the old Company Name. Any help would be very appreciated.
I made a sample of my problem using the Northwing Database. You can download a copy of it at http://www.thetechmentors.com/freestuff/exerciseFiles/msAccess/DlookupDatamacroProblem.zip
All you need to do is tweak the Before Change data macro on [tblOrder] to do the name lookup only when the [CustomerID] changes in that table. You can do that using the Updated() function like so:
That way when the macro fires as a result of the update performed from the After Update data macro on [tblCustomer], the [tblOrder].[CustomerID] value has not changed so the name lookup is bypassed.
I would like to find the date and time that any schema modification has taken place on a particular database. Modifications are things like tables or columns that have been created, altered, or dropped. It does not include any data that has been inserted, updated, or deleted.
The reason why I need this is because I am writing a .NET utility that depends heavily on the data returned from dbc.tables, dbc.columns, and dbc.indices. Since querying these views can be a very expensive operation, I want to read it all into custom business objects and then serialize the objects to an XML file stored on disk. This way, I can just deserialize the data when I need it unless the database's current_timestamp is greater than or equal to the datetime of the last schema change, at which point I'll refresh the local XML file with the updated schema.
LastAlterTimestamp - If it is equal to CreateTimestamp then object has not been modified since being created or replaced. It is updated when an attribute specific to that data dictionary object was updated.
For example, DBC.Databases.LastAlterTimestamp is not update when a child object (table, view, macro, stored procedure, function, etc.) is added, removed, or altered. It is updated in situations such as when the password, default role, profile, or account is changed.