Search in sources :

Example 26 with Timestamp

use of java.sql.Timestamp in project hibernate-orm by hibernate.

the class TimeAndTimestampTest method test.

@Test
public void test() {
    doInHibernate(this::sessionFactory, session -> {
        Event event = new Event();
        event.id = 1L;
        event.timeValue = new Time(123);
        event.timestampValue = new Timestamp(456);
        session.persist(event);
    });
    doInHibernate(this::sessionFactory, session -> {
        Event event = session.find(Event.class, 1L);
        assertEquals(123, event.timeValue.getTime() % TimeUnit.DAYS.toMillis(1));
        assertEquals(456, event.timestampValue.getTime() % TimeUnit.DAYS.toMillis(1));
    });
}
Also used : Time(java.sql.Time) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 27 with Timestamp

use of java.sql.Timestamp in project hibernate-orm by hibernate.

the class TypeTest method testTimestampType.

@Test
public void testTimestampType() {
    final long now = System.currentTimeMillis();
    final Timestamp original = new Timestamp(now);
    final Timestamp copy = new Timestamp(now);
    final Timestamp different = new Timestamp(now + 9999);
    runBasicTests(TimestampType.INSTANCE, original, copy, different);
}
Also used : Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 28 with Timestamp

use of java.sql.Timestamp in project databus by linkedin.

the class ORListener method orToAvroType.

/**
   * Given a OR Column, it returns a corresponding Java object that can be inserted into
   * AVRO record
 * @param avroField 
   */
private Object orToAvroType(Column s, Field avroField) throws DatabusException {
    if (s instanceof BitColumn) {
        // This is in  byte order
        BitColumn bc = (BitColumn) s;
        byte[] ba = bc.getValue();
        ByteBuffer b = ByteBuffer.wrap(ba);
        return b;
    } else if (s instanceof StringColumn) {
        StringColumn sc = (StringColumn) s;
        String str = new String(sc.getValue(), StringUtils.DEFAULT_CHARSET);
        return str;
    } else if (s instanceof BlobColumn) {
        BlobColumn bc = (BlobColumn) s;
        byte[] ba = bc.getValue();
        //distinguish between blobs and clobs
        try {
            return new String(ba, StringUtils.DEFAULT_CHARSET);
        } catch (Exception e) {
            return ByteBuffer.wrap(ba);
        }
    } else if (s instanceof DateColumn) {
        DateColumn dc = (DateColumn) s;
        Date d = dc.getValue();
        Long l = d.getTime();
        return l;
    } else if (s instanceof DatetimeColumn) {
        DatetimeColumn dc = (DatetimeColumn) s;
        Date d = dc.getValue();
        //Bug in OR for DateTIme and Time data-types. MilliSeconds is not available for these columns but is set with currentMillis() wrongly.
        Long t1 = (d.getTime() / 1000) * 1000;
        return t1;
    } else if (s instanceof DecimalColumn) {
        DecimalColumn dc = (DecimalColumn) s;
        Object val = Double.valueOf(dc.getValue().doubleValue());
        return val;
    } else if (s instanceof DoubleColumn) {
        DoubleColumn dc = (DoubleColumn) s;
        Double d = dc.getValue();
        return d;
    } else if (s instanceof EnumColumn) {
        EnumColumn ec = (EnumColumn) s;
        Integer i = ec.getValue();
        return i;
    } else if (s instanceof FloatColumn) {
        FloatColumn fc = (FloatColumn) s;
        Float f = fc.getValue();
        return f;
    } else if (s instanceof Int24Column) {
        Int24Column ic = (Int24Column) s;
        Integer i = ic.getValue();
        if (i < 0 && SchemaHelper.getMetaField(avroField, "dbFieldType").contains("UNSIGNED")) {
            i += ORListener.MEDIUMINT_MAX_VALUE;
        }
        return i;
    } else if (s instanceof LongColumn) {
        LongColumn lc = (LongColumn) s;
        Long l = lc.getValue().longValue();
        if (l < 0 && SchemaHelper.getMetaField(avroField, "dbFieldType").contains("UNSIGNED")) {
            l += ORListener.INTEGER_MAX_VALUE;
        }
        return l;
    } else if (s instanceof LongLongColumn) {
        LongLongColumn llc = (LongLongColumn) s;
        BigInteger b = new BigInteger(llc.getValue() + "");
        if (b.compareTo(BigInteger.ZERO) < 0 && SchemaHelper.getMetaField(avroField, "dbFieldType").contains("UNSIGNED")) {
            b = b.add(ORListener.BIGINT_MAX_VALUE);
        }
        return b;
    } else if (s instanceof NullColumn) {
        return null;
    } else if (s instanceof SetColumn) {
        SetColumn sc = (SetColumn) s;
        Long l = sc.getValue();
        return l;
    } else if (s instanceof ShortColumn) {
        ShortColumn sc = (ShortColumn) s;
        Integer i = sc.getValue();
        if (i < 0 && SchemaHelper.getMetaField(avroField, "dbFieldType").contains("UNSIGNED")) {
            i = i + ORListener.SMALLINT_MAX_VALUE;
        }
        return i;
    } else if (s instanceof TimeColumn) {
        TimeColumn tc = (TimeColumn) s;
        Time t = tc.getValue();
        /**
       * There is a bug in OR where instead of using the default year as 1970, it is using 0070.
       * This is a temporary measure to resolve it by working around at this layer. The value obtained from OR is subtracted from "0070-00-01 00:00:00"
       */
        Calendar c = Calendar.getInstance();
        c.set(70, 0, 1, 0, 0, 0);
        // round off the milli-seconds as TimeColumn type has only seconds granularity but Calendar implementation
        // includes milli-second (System.currentTimeMillis() at the time of instantiation)
        long rawVal = (c.getTimeInMillis() / 1000) * 1000;
        long val2 = (t.getTime() / 1000) * 1000;
        long offset = val2 - rawVal;
        return offset;
    } else if (s instanceof TimestampColumn) {
        TimestampColumn tsc = (TimestampColumn) s;
        Timestamp ts = tsc.getValue();
        Long t = ts.getTime();
        return t;
    } else if (s instanceof DatetimeColumn) {
        DatetimeColumn tsc = (DatetimeColumn) s;
        Long t = tsc.getValue().getTime();
        return t;
    } else if (s instanceof Datetime2Column) {
        Datetime2Column tsc = (Datetime2Column) s;
        Long t = tsc.getValue().getTime();
        return t;
    } else if (s instanceof TinyColumn) {
        TinyColumn tc = (TinyColumn) s;
        Integer i = tc.getValue();
        if (i < 0 && SchemaHelper.getMetaField(avroField, "dbFieldType").contains("UNSIGNED")) {
            i = i + ORListener.TINYINT_MAX_VALUE;
        }
        return i;
    } else if (s instanceof YearColumn) {
        YearColumn yc = (YearColumn) s;
        Integer i = yc.getValue();
        return i;
    } else {
        throw new DatabusRuntimeException("Unknown MySQL type in the event" + s.getClass() + " Object = " + s);
    }
}
Also used : BlobColumn(com.google.code.or.common.glossary.column.BlobColumn) SetColumn(com.google.code.or.common.glossary.column.SetColumn) DecimalColumn(com.google.code.or.common.glossary.column.DecimalColumn) Time(java.sql.Time) FloatColumn(com.google.code.or.common.glossary.column.FloatColumn) Timestamp(java.sql.Timestamp) EnumColumn(com.google.code.or.common.glossary.column.EnumColumn) LongColumn(com.google.code.or.common.glossary.column.LongColumn) LongLongColumn(com.google.code.or.common.glossary.column.LongLongColumn) BitColumn(com.google.code.or.common.glossary.column.BitColumn) YearColumn(com.google.code.or.common.glossary.column.YearColumn) TimeColumn(com.google.code.or.common.glossary.column.TimeColumn) StringColumn(com.google.code.or.common.glossary.column.StringColumn) Calendar(java.util.Calendar) TimestampColumn(com.google.code.or.common.glossary.column.TimestampColumn) DatetimeColumn(com.google.code.or.common.glossary.column.DatetimeColumn) ByteBuffer(java.nio.ByteBuffer) Int24Column(com.google.code.or.common.glossary.column.Int24Column) NoSuchSchemaException(com.linkedin.databus2.schemas.NoSuchSchemaException) DatabusException(com.linkedin.databus2.core.DatabusException) DatabusRuntimeException(com.linkedin.databus.core.DatabusRuntimeException) Date(java.util.Date) LongLongColumn(com.google.code.or.common.glossary.column.LongLongColumn) BigInteger(java.math.BigInteger) Datetime2Column(com.google.code.or.common.glossary.column.Datetime2Column) DoubleColumn(com.google.code.or.common.glossary.column.DoubleColumn) DateColumn(com.google.code.or.common.glossary.column.DateColumn) ShortColumn(com.google.code.or.common.glossary.column.ShortColumn) NullColumn(com.google.code.or.common.glossary.column.NullColumn) TinyColumn(com.google.code.or.common.glossary.column.TinyColumn) BigInteger(java.math.BigInteger) DatabusRuntimeException(com.linkedin.databus.core.DatabusRuntimeException)

Example 29 with Timestamp

use of java.sql.Timestamp in project head by mifos.

the class DepositAccountingEntryTest method setupMandatoryForOneTest.

private void setupMandatoryForOneTest(SavingsType savingsType, GLCategoryType bankCategoryType, GLCategoryType savingsCategoryType, FinancialActionConstants financialAction) throws FinancialException {
    when(mockedFinancialActivity.getAccountTrxn()).thenReturn(mockedIncomingTransaction);
    when(mockedIncomingTransaction.getAccount()).thenReturn(mockedSavingsBO);
    when(mockedIncomingTransaction.getDepositAmount()).thenReturn(new Money(currency, depositAmount));
    when(mockedIncomingTransaction.getActionDate()).thenReturn(transactionActionDate.toDate());
    when(mockedIncomingTransaction.getTrxnCreatedDate()).thenReturn(new Timestamp(transactionPostedDate.getMillis()));
    when(mockedIncomingTransaction.getPersonnel()).thenReturn(transactionCreator);
    when(mockedIncomingTransaction.getComments()).thenReturn(comments);
    when(mockedSavingsBO.getSavingsOffering()).thenReturn(mockedSavingsOffering);
    when(mockedSavingsBO.isMandatory()).thenReturn(true);
    when(mockedSavingsOffering.getDepositGLCode()).thenReturn(mockedSavingsDepositGLCode);
    when(mockedSavingsDepositGLCode.getGlcode()).thenReturn(savingsDepositGLCode);
    when(mockedSavingsGLAccount.getGlCode()).thenReturn(savingsDepositGLCode);
    // when(mockedSavingsGLAccount.getCOAHead()) .thenReturn(mockedSavingsGLCategory);
    when(mockedSavingsGLAccount.getTopLevelCategoryType()).thenReturn(savingsCategoryType);
    when(mockedSavingsGLAccount.getAccountName()).thenReturn("Clients Accounts");
    // when(mockedBankGLAccount.getCOAHead()) .thenReturn(mockedBankGLCategory);
    when(mockedBankGLAccount.getTopLevelCategoryType()).thenReturn(bankCategoryType);
    when(mockedBankGLAccount.getAssociatedGlcode()).thenReturn(mockedBankGLCode);
    when(mockedBankGLAccount.getGlCode()).thenReturn(bankGLCode);
    when(mockedBankGLCode.getGlcode()).thenReturn(bankGLCode);
    when(mockedFinancialBusinessService.getGlAccount(savingsDepositGLCode)).thenReturn(mockedSavingsGLAccount);
    when(mockedFinancialBusinessService.getGlAccount(bankGLCode)).thenReturn(mockedBankGLAccount);
    when(mockedFinancialBusinessService.getFinancialAction(financialAction)).thenReturn(mockedFinancialAction);
    when(mockedFinancialAction.getApplicableDebitCharts()).thenReturn(setWith(mockedBankGLAccount));
    when(mockedSavingsType.getId()).thenReturn(savingsType.getValue());
// when(mockedSavingsGLCategory.getCategoryType()).thenReturn(savingsCategoryType);
// when(mockedBankGLCategory.getCategoryType()).thenReturn(bankCategoryType);
}
Also used : Money(org.mifos.framework.util.helpers.Money) Timestamp(java.sql.Timestamp)

Example 30 with Timestamp

use of java.sql.Timestamp in project head by mifos.

the class DepositAccountingEntryTest method setupVoluntaryForOneTest.

private void setupVoluntaryForOneTest(SavingsType savingsType, GLCategoryType bankCategoryType, GLCategoryType savingsCategoryType, FinancialActionConstants financialAction) throws FinancialException {
    when(mockedFinancialActivity.getAccountTrxn()).thenReturn(mockedIncomingTransaction);
    when(mockedIncomingTransaction.getAccount()).thenReturn(mockedSavingsBO);
    when(mockedIncomingTransaction.getDepositAmount()).thenReturn(new Money(currency, depositAmount));
    when(mockedIncomingTransaction.getActionDate()).thenReturn(transactionActionDate.toDate());
    when(mockedIncomingTransaction.getTrxnCreatedDate()).thenReturn(new Timestamp(transactionPostedDate.getMillis()));
    when(mockedIncomingTransaction.getPersonnel()).thenReturn(transactionCreator);
    when(mockedIncomingTransaction.getComments()).thenReturn(comments);
    when(mockedSavingsBO.getSavingsOffering()).thenReturn(mockedSavingsOffering);
    when(mockedSavingsBO.isMandatory()).thenReturn(false);
    when(mockedSavingsBO.isVoluntary()).thenReturn(true);
    when(mockedSavingsOffering.getDepositGLCode()).thenReturn(mockedSavingsDepositGLCode);
    when(mockedSavingsDepositGLCode.getGlcode()).thenReturn(savingsDepositGLCode);
    when(mockedSavingsGLAccount.getGlCode()).thenReturn(savingsDepositGLCode);
    // when(mockedSavingsGLAccount.getCOAHead()) .thenReturn(mockedSavingsGLCategory);
    when(mockedSavingsGLAccount.getTopLevelCategoryType()).thenReturn(savingsCategoryType);
    when(mockedSavingsGLAccount.getAccountName()).thenReturn("Clients Accounts");
    // when(mockedBankGLAccount.getCOAHead()) .thenReturn(mockedBankGLCategory);
    when(mockedBankGLAccount.getTopLevelCategoryType()).thenReturn(bankCategoryType);
    when(mockedBankGLAccount.getAssociatedGlcode()).thenReturn(mockedBankGLCode);
    when(mockedBankGLAccount.getGlCode()).thenReturn(bankGLCode);
    when(mockedBankGLCode.getGlcode()).thenReturn(bankGLCode);
    when(mockedFinancialBusinessService.getGlAccount(savingsDepositGLCode)).thenReturn(mockedSavingsGLAccount);
    when(mockedFinancialBusinessService.getGlAccount(bankGLCode)).thenReturn(mockedBankGLAccount);
    when(mockedFinancialBusinessService.getFinancialAction(financialAction)).thenReturn(mockedFinancialAction);
    when(mockedFinancialAction.getApplicableDebitCharts()).thenReturn(setWith(mockedBankGLAccount));
    when(mockedSavingsType.getId()).thenReturn(savingsType.getValue());
// when(mockedSavingsGLCategory.getCategoryType()).thenReturn(savingsCategoryType);
// when(mockedBankGLCategory.getCategoryType()).thenReturn(bankCategoryType);
}
Also used : Money(org.mifos.framework.util.helpers.Money) Timestamp(java.sql.Timestamp)

Aggregations

Timestamp (java.sql.Timestamp)3153 Test (org.junit.Test)526 Date (java.util.Date)458 PreparedStatement (java.sql.PreparedStatement)450 SQLException (java.sql.SQLException)367 ResultSet (java.sql.ResultSet)353 BigDecimal (java.math.BigDecimal)351 ArrayList (java.util.ArrayList)236 Date (java.sql.Date)218 Connection (java.sql.Connection)216 HashMap (java.util.HashMap)201 GenericValue (org.apache.ofbiz.entity.GenericValue)194 Calendar (java.util.Calendar)184 Time (java.sql.Time)173 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)167 Delegator (org.apache.ofbiz.entity.Delegator)157 SimpleDateFormat (java.text.SimpleDateFormat)150 IOException (java.io.IOException)129 Locale (java.util.Locale)129 Map (java.util.Map)111