Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public static BinaryHandlerSqlTimestamp New()
super(
Timestamp.class,
CustomFields(
CustomField(long.class, "timestamp")
CustomField(long.class, "date"),
CustomField(int.class, "nanos")
)
);
}
Expand All @@ -59,16 +60,6 @@ public static BinaryHandlerSqlTimestamp New()
// methods //
////////////

private static long instanceState(final Timestamp instance)
{
return instance.getTime();
}

private static long binaryState(final Binary data)
{
return data.read_long(0);
}

@Override
public final void store(
final Binary data ,
Expand All @@ -77,22 +68,29 @@ public final void store(
final PersistenceStoreHandler<Binary> handler
)
{
data.storeEntityHeader(Long.BYTES, this.typeId(), objectId);
data.storeEntityHeader(Long.BYTES + Integer.BYTES, this.typeId(), objectId);

// the data content of a date is simple the timestamp long, nothing else
data.store_long(instanceState(instance));
data.store_long(instance.getTime());
data.store_int(Long.BYTES, instance.getNanos());
}

@Override
public final Timestamp create(final Binary data, final PersistenceLoadHandler handler)
{
return new Timestamp(binaryState(data));
long date = data.read_long(0);
int nanos = data.read_int(Long.BYTES);
Timestamp ts = new Timestamp(date);
ts.setNanos(nanos);
return ts;
}

@Override
public final void updateState(final Binary data, final Timestamp instance, final PersistenceLoadHandler handler)
{
instance.setTime(binaryState(data));
long date = data.read_long(0);
int nanos = data.read_int(Long.BYTES);
instance.setTime(date);
instance.setNanos(nanos);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.eclipse.serializer.persistence.binary.java.sql;

/*-
* #%L
* Eclipse Serializer Persistence Binary
* %%
* Copyright (C) 2023 - 2026 MicroStream Software
* %%
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
* #L%
*/

import java.sql.Timestamp;

import org.eclipse.serializer.persistence.binary.types.Binary;
import org.eclipse.serializer.persistence.binary.types.BinaryLegacyTypeHandler;
import org.eclipse.serializer.persistence.types.PersistenceLoadHandler;
import org.eclipse.serializer.persistence.types.PersistenceReferenceLoader;

public class BinaryLegacyTypeHandlerSqlTimestamp extends BinaryLegacyTypeHandler.AbstractCustom<Timestamp>
{
///////////////////////////////////////////////////////////////////////////
// static methods //
///////////////////

public static BinaryLegacyTypeHandlerSqlTimestamp New()
{
return new BinaryLegacyTypeHandlerSqlTimestamp();
}


///////////////////////////////////////////////////////////////////////////
// constructors //
/////////////////

public BinaryLegacyTypeHandlerSqlTimestamp()
{
super(
Timestamp.class,
CustomFields(
CustomField(long.class, "timestamp")
));
}

@Override
public void iterateLoadableReferences(Binary data, PersistenceReferenceLoader iterator)
{
//no-op
}

@Override
public Timestamp create(Binary data, PersistenceLoadHandler handler)
{
return new Timestamp(data.read_long(0));
}

@Override
public void updateState(Binary data, Timestamp instance, PersistenceLoadHandler handler)
{
instance.setTime(data.read_long(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.eclipse.serializer.persistence.binary.java.sql.BinaryHandlerSqlDate;
import org.eclipse.serializer.persistence.binary.java.sql.BinaryHandlerSqlTime;
import org.eclipse.serializer.persistence.binary.java.sql.BinaryHandlerSqlTimestamp;
import org.eclipse.serializer.persistence.binary.java.sql.BinaryLegacyTypeHandlerSqlTimestamp;
import org.eclipse.serializer.persistence.binary.java.time.BinaryHandlerLocalDate;
import org.eclipse.serializer.persistence.binary.java.time.BinaryHandlerMonthDay;
import org.eclipse.serializer.persistence.binary.java.time.BinaryHandlerPeriod;
Expand Down Expand Up @@ -180,7 +181,9 @@ public static final PersistenceCustomTypeHandlerRegistry<Binary> createDefaultCu
.registerTypeHandlers(platformDependentHandlers())
.registerTypeHandlers(customHandlers)
;


defaultCustomTypeHandlerRegistry.registerLegacyTypeHandler(BinaryLegacyTypeHandlerSqlTimestamp.New());

return defaultCustomTypeHandlerRegistry;
}

Expand Down Expand Up @@ -265,8 +268,8 @@ static final void initializeNativeTypeId(

// non-nonsensical handlers required for confused developers
BinaryHandlerSqlDate.New() ,
BinaryHandlerSqlTime.New() ,
BinaryHandlerSqlTimestamp.New(),
BinaryHandlerSqlTime.New() ,
BinaryHandlerSqlTimestamp.New(),

BinaryHandlerOptionalInt.New(),
BinaryHandlerOptionalLong.New(),
Expand Down