You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by "Sean Xiong (Created) (JIRA)" <ji...@apache.org> on 2011/10/27 02:43:32 UTC

[jira] [Created] (DDLUTILS-272) Can not handle the type of Byte[] and Blob when using PostgreSQL

Can not handle the type of Byte[] and Blob when using PostgreSQL
----------------------------------------------------------------

                 Key: DDLUTILS-272
                 URL: https://issues.apache.org/jira/browse/DDLUTILS-272
             Project: DdlUtils
          Issue Type: Bug
          Components: Core (No specific database)
    Affects Versions: 1.0
            Reporter: Sean Xiong
            Assignee: Thomas Dudziak


DDLUTILS Can not handle the type of Byte[] and Blob when using PostgreSQL.

Exception message with my code:

org.apache.ddlutils.DatabaseOperationException: Error while inserting into the database: Large Objects may not be used in auto-commit mode.
at org.apache.ddlutils.platform.PlatformImplBase.insert(PlatformImplBase.java:1305)
at coredb.database.DatabaseConnection.create(DatabaseConnection.java:295)
at coredb.controller.EntityControllerBase.createEntity(EntityControllerBase.java:105)
at entities.core.gen.EntityBaseGen.Save(EntityBaseGen.java:131)
at test.PresentationTests.populatePresentations(PresentationTests.java:222)
at test.PresentationTests.setUp(PresentationTests.java:253)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at junit.textui.TestRunner.doRun(TestRunner.java:109)
at junit.textui.TestRunner.run(TestRunner.java:77)
at CoreDBTest.main(CoreDBTest.java:44)
Caused by: org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode.
at org.postgresql.largeobject.LargeObjectManager.createLO(LargeObjectManager.java:241)
at org.postgresql.largeobject.LargeObjectManager.createLO(LargeObjectManager.java:228)
at org.postgresql.jdbc2.AbstractJdbc2Statement.setBlob(AbstractJdbc2Statement.java:2851)
at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1762)
at org.postgresql.jdbc3g.AbstractJdbc3gStatement.setObject(AbstractJdbc3gStatement.java:37)
at org.postgresql.jdbc4.AbstractJdbc4Statement.setObject(AbstractJdbc4Statement.java:46)
at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1691)
at org.postgresql.jdbc3.AbstractJdbc3Statement.setObject(AbstractJdbc3Statement.java:1483)
at org.postgresql.jdbc3g.AbstractJdbc3gStatement.setObject(AbstractJdbc3gStatement.java:47)
at org.postgresql.jdbc4.AbstractJdbc4Statement.setObject(AbstractJdbc4Statement.java:69)
at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1724)
at org.apache.ddlutils.platform.PlatformImplBase.setStatementParameterValue(PlatformImplBase.java:2067)
at org.apache.ddlutils.platform.PlatformImplBase.setObject(PlatformImplBase.java:2004)
at org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.setObject(PostgreSqlPlatform.java:240)
at org.apache.ddlutils.platform.PlatformImplBase.insert(PlatformImplBase.java:1289)
... 21 more 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (DDLUTILS-272) Can not handle the type of Byte[] and Blob when using PostgreSQL

Posted by "Sean Xiong (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DDLUTILS-272?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13136650#comment-13136650 ] 

Sean Xiong commented on DDLUTILS-272:
-------------------------------------

My Solution: 
                 1) add a block of code to handle Byte[];
                 2) add a block of code to handle Blob

Affected files: 
                   PlatformImplBase.java of DDLUtils 
         modifications: 
            1)protected void setStatementParameterValue(PreparedStatement statement, int sqlIndex, int typeCode, Object value) throws SQLException; 
       

       /**
	* the following content is designed to handle Byte[] data type in PostgreSQL
        */
        else if (value instanceof Byte[])
        {
        	Byte[] bytes = (Byte[])value;
         	byte[] byteArray = new byte[bytes.length];
        	for(int i = 0; i < bytes.length; i++)
        	{
        		byteArray[i] = new Byte(bytes[i]);
        	}
            statement.setBytes(sqlIndex, byteArray);
        }
        


               else if (value instanceof Blob)
		{
			/**
			 * the following content is designed to handle Blob data type in PostgreSQL
			 */
			LargeObjectManager lobj = ((org.postgresql.PGConnection)statement.getConnection()).getLargeObjectAPI();
			int oid = lobj.create(LargeObjectManager.READ | LargeObjectManager.WRITE);
			LargeObject obj = lobj.open(oid, LargeObjectManager.WRITE);	
			Blob bolbValue  = (Blob) value;
			if(bolbValue.length() > 0)  obj.write(bolbValue.getBytes(1, (int) ((Blob) value).length()));
			else {
				String errorMessage = "The large object(Blob type data) can not be empty : CoreDB team remind you please check the value of Blob type columns";
				throw new Error(errorMessage);
			}
			obj.close();		
			byte [] intByte = new byte [4];
			for (int i = 0; i < 4; i++) 
			{
				intByte[i] = (byte)(oid >> (8 * i));
			}
			statement.setBytes(sqlIndex, intByte);
			
		}

                
> Can not handle the type of Byte[] and Blob when using PostgreSQL
> ----------------------------------------------------------------
>
>                 Key: DDLUTILS-272
>                 URL: https://issues.apache.org/jira/browse/DDLUTILS-272
>             Project: DdlUtils
>          Issue Type: Bug
>          Components: Core (No specific database)
>    Affects Versions: 1.0
>            Reporter: Sean Xiong
>            Assignee: Thomas Dudziak
>              Labels: Blob, Byte[], postgresql
>
> DDLUTILS Can not handle the type of Byte[] and Blob when using PostgreSQL.
> Exception message with my code:
> org.apache.ddlutils.DatabaseOperationException: Error while inserting into the database: Large Objects may not be used in auto-commit mode.
> at org.apache.ddlutils.platform.PlatformImplBase.insert(PlatformImplBase.java:1305)
> at coredb.database.DatabaseConnection.create(DatabaseConnection.java:295)
> at coredb.controller.EntityControllerBase.createEntity(EntityControllerBase.java:105)
> at entities.core.gen.EntityBaseGen.Save(EntityBaseGen.java:131)
> at test.PresentationTests.populatePresentations(PresentationTests.java:222)
> at test.PresentationTests.setUp(PresentationTests.java:253)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
> at junit.framework.TestSuite.runTest(TestSuite.java:232)
> at junit.framework.TestSuite.run(TestSuite.java:227)
> at junit.textui.TestRunner.doRun(TestRunner.java:116)
> at junit.textui.TestRunner.doRun(TestRunner.java:109)
> at junit.textui.TestRunner.run(TestRunner.java:77)
> at CoreDBTest.main(CoreDBTest.java:44)
> Caused by: org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode.
> at org.postgresql.largeobject.LargeObjectManager.createLO(LargeObjectManager.java:241)
> at org.postgresql.largeobject.LargeObjectManager.createLO(LargeObjectManager.java:228)
> at org.postgresql.jdbc2.AbstractJdbc2Statement.setBlob(AbstractJdbc2Statement.java:2851)
> at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1762)
> at org.postgresql.jdbc3g.AbstractJdbc3gStatement.setObject(AbstractJdbc3gStatement.java:37)
> at org.postgresql.jdbc4.AbstractJdbc4Statement.setObject(AbstractJdbc4Statement.java:46)
> at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1691)
> at org.postgresql.jdbc3.AbstractJdbc3Statement.setObject(AbstractJdbc3Statement.java:1483)
> at org.postgresql.jdbc3g.AbstractJdbc3gStatement.setObject(AbstractJdbc3gStatement.java:47)
> at org.postgresql.jdbc4.AbstractJdbc4Statement.setObject(AbstractJdbc4Statement.java:69)
> at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1724)
> at org.apache.ddlutils.platform.PlatformImplBase.setStatementParameterValue(PlatformImplBase.java:2067)
> at org.apache.ddlutils.platform.PlatformImplBase.setObject(PlatformImplBase.java:2004)
> at org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.setObject(PostgreSqlPlatform.java:240)
> at org.apache.ddlutils.platform.PlatformImplBase.insert(PlatformImplBase.java:1289)
> ... 21 more 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira