You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by "Francis De Brabandere (JIRA)" <em...@incubator.apache.org> on 2013/03/06 13:38:14 UTC
[jira] [Comment Edited] (EMPIREDB-176) Value for a column of type
DataType.DATETIME not properly inserted
[ https://issues.apache.org/jira/browse/EMPIREDB-176?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13594659#comment-13594659 ]
Francis De Brabandere edited comment on EMPIREDB-176 at 3/6/13 12:37 PM:
-------------------------------------------------------------------------
{code}
public class DBDatabaseDriverOracleTest {
public static class TestDB extends DBDatabase
{
private final static long serialVersionUID = 1L;
public static class Data extends DBTable
{
private final static long serialVersionUID = 1L;
public final DBTableColumn ID;
public final DBTableColumn SEARCH_TERMS;
public final DBTableColumn IS_LOCAL;
public final DBTableColumn AT_TIME;
public final DBTableColumn FROM_IP;
public Data(DBDatabase db)
{
super("DATA", db);
//SEARCH_TERMS, IS_LOCAL, AT_TIME, FROM_IP
ID = addColumn("ID", DataType.AUTOINC, 0, DataMode.AutoGenerated, "DATA_ID_SEQUENCE");
SEARCH_TERMS = addColumn("SEARCH_TERMS", DataType.TEXT, 0, DataMode.NotNull);
IS_LOCAL = addColumn("IS_LOCAL", DataType.BOOL, 0, DataMode.NotNull);
AT_TIME = addColumn("AT_TIME", DataType.DATETIME, 0, DataMode.NotNull);
FROM_IP = addColumn("FROM_IP", DataType.TEXT, 0, DataMode.NotNull);
setPrimaryKey(ID);
//setTimestampColumn(UPDATE_TIMESTAMP);
}
}
public final Data DATA = new Data(this);
public TestDB()
{
// Define Foreign-Key Relations
}
}
@Test
public void test() throws Exception
{
DBDatabaseDriver driver = new DBDatabaseDriverOracle();
TestDB db = new TestDB();
// set driver using reflection
Field driverField = DBDatabase.class.getDeclaredField("driver");
driverField.setAccessible(true);
driverField.set(db, driver);
ExecutorService service = Executors.newFixedThreadPool(100);
List<Callable<String>> tasks = new ArrayList<Callable<String>>();
for(int i = 0;i<100000;i++)
{
tasks.add(new TestCallable(db));
}
List<Future<String>> results = service.invokeAll(tasks);
for(Future<String> result:results)
{
String value = result.get(10, TimeUnit.SECONDS);
assertTrue(value.contains("TO_DATE"));
}
System.out.println(results.get(0).get().toString());
}
private static class TestCallable implements Callable<String>
{
private final TestDB db;
public TestCallable(final TestDB db)
{
this.db = db;
}
public String call() throws Exception
{
DBCommand command = new DBCommandOracle(db);
command.set(db.DATA.SEARCH_TERMS.to("test"));
command.set(db.DATA.IS_LOCAL.to(true));
command.set(db.DATA.AT_TIME.to(new Date()));
command.set(db.DATA.FROM_IP.to("0.0.0.0"));
String insert = command.getInsert();
return insert;
}
}
{code}
was (Author: francisdb):
{code:java}
public class DBDatabaseDriverOracleTest {
public static class TestDB extends DBDatabase
{
private final static long serialVersionUID = 1L;
public static class Data extends DBTable
{
private final static long serialVersionUID = 1L;
public final DBTableColumn ID;
public final DBTableColumn SEARCH_TERMS;
public final DBTableColumn IS_LOCAL;
public final DBTableColumn AT_TIME;
public final DBTableColumn FROM_IP;
public Data(DBDatabase db)
{
super("DATA", db);
//SEARCH_TERMS, IS_LOCAL, AT_TIME, FROM_IP
ID = addColumn("ID", DataType.AUTOINC, 0, DataMode.AutoGenerated, "DATA_ID_SEQUENCE");
SEARCH_TERMS = addColumn("SEARCH_TERMS", DataType.TEXT, 0, DataMode.NotNull);
IS_LOCAL = addColumn("IS_LOCAL", DataType.BOOL, 0, DataMode.NotNull);
AT_TIME = addColumn("AT_TIME", DataType.DATETIME, 0, DataMode.NotNull);
FROM_IP = addColumn("FROM_IP", DataType.TEXT, 0, DataMode.NotNull);
setPrimaryKey(ID);
//setTimestampColumn(UPDATE_TIMESTAMP);
}
}
public final Data DATA = new Data(this);
public TestDB()
{
// Define Foreign-Key Relations
}
}
@Test
public void test() throws Exception
{
DBDatabaseDriver driver = new DBDatabaseDriverOracle();
TestDB db = new TestDB();
// set driver using reflection
Field driverField = DBDatabase.class.getDeclaredField("driver");
driverField.setAccessible(true);
driverField.set(db, driver);
ExecutorService service = Executors.newFixedThreadPool(100);
List<Callable<String>> tasks = new ArrayList<Callable<String>>();
for(int i = 0;i<100000;i++)
{
tasks.add(new TestCallable(db));
}
List<Future<String>> results = service.invokeAll(tasks);
for(Future<String> result:results)
{
String value = result.get(10, TimeUnit.SECONDS);
assertTrue(value.contains("TO_DATE"));
}
System.out.println(results.get(0).get().toString());
}
private static class TestCallable implements Callable<String>
{
private final TestDB db;
public TestCallable(final TestDB db)
{
this.db = db;
}
public String call() throws Exception
{
DBCommand command = new DBCommandOracle(db);
command.set(db.DATA.SEARCH_TERMS.to("test"));
command.set(db.DATA.IS_LOCAL.to(true));
command.set(db.DATA.AT_TIME.to(new Date()));
command.set(db.DATA.FROM_IP.to("0.0.0.0"));
String insert = command.getInsert();
return insert;
}
}
{code}
> Value for a column of type DataType.DATETIME not properly inserted
> ------------------------------------------------------------------
>
> Key: EMPIREDB-176
> URL: https://issues.apache.org/jira/browse/EMPIREDB-176
> Project: Empire-DB
> Issue Type: Bug
> Components: Core
> Affects Versions: empire-db-2.2.0-incubating, empire-db-2.4.1
> Environment: CentOS 6.2, java 1.6.0_30
> Reporter: Alain Becam
> Priority: Minor
>
> Very rarely, an insert which works fine for most of the time will fail by generating an SQL command with the date in what seems to be a brute toString, without any quote:
> Insert new search terms org.apache.empire.db.exceptions.QueryFailedException: Error executing query INSERT INTO SEARCH_TERMS_LOG( SEARCH_TERMS, IS_LOCAL, AT_TIME, FROM_IP) VALUES ( 'XXXX', 1, Thu Feb 21 10:27:45 CET 2013, '10.11.4.119').
> Native error is INSERT INTO SEARCH_TERMS_LOG( SEARCH_TERMS, IS_LOCAL, AT_TIME, FROM_IP) VALUES ( 'XXXX', 1, Thu Feb 21 10:27:45 CET 2013, '10.11.4.119').
> It does not seems to be a multithreading problem, as the insert are generated from an instantiation of DBRecord.
> The column is also well defined as DataType.DATETIME:
> C_AT_TIME = addColumn("AT_TIME", DataType.DATETIME, 0, DataMode.Nullable);
> I will overload DBDatabaseDriverOracle and extract the relevant part of my code to try to reproduce the error and log the outcome.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira