openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r1031240 - in /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql: ./ BlobColumnEntity.java TestBlobColumnType.java
Date Thu, 04 Nov 2010 20:58:09 GMT
Author: mikedd
Date: Thu Nov  4 20:58:09 2010
New Revision: 1031240

URL: http://svn.apache.org/viewvc?rev=1031240&view=rev
Log:
OPENJPA-1870 OPENJPA-740: adding testcase

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/BlobColumnEntity.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestBlobColumnType.java
  (with props)

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/BlobColumnEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/BlobColumnEntity.java?rev=1031240&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/BlobColumnEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/BlobColumnEntity.java
Thu Nov  4 20:58:09 2010
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.blob.mysql;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+
+@Entity
+public class BlobColumnEntity {
+    @Id
+    private int id;
+
+    @Lob
+    @Column(length = 20)
+    protected byte[] smallLob;
+
+    @Lob
+    @Column(length = 300)
+    protected byte[] oldLob;
+    
+    @Lob
+    @Column(length = 66000)
+    protected byte[] medLob;
+    
+    @Lob
+    @Column(length = 16777216)
+    protected byte[] longLob;
+    
+    @Lob
+    protected byte[] defaultLob;
+
+    /**
+     * Not suitable for all databases
+     */
+    @Lob
+    @Column(columnDefinition = "BINARY(32)")
+    protected byte[] definedLob;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public byte[] getSmallLob() {
+        return smallLob;
+    }
+
+    public void setSmallLob(byte[] smallLob) {
+        this.smallLob = smallLob;
+    }
+
+    public byte[] getMedLob() {
+        return medLob;
+    }
+
+    public void setMedLob(byte[] medLob) {
+        this.medLob = medLob;
+    }
+
+    public byte[] getLongLob() {
+        return longLob;
+    }
+
+    public void setLongLob(byte[] longLob) {
+        this.longLob = longLob;
+    }
+
+    public byte[] getDefaultLob() {
+        return defaultLob;
+    }
+
+    public void setDefaultLob(byte[] defaultLob) {
+        this.defaultLob = defaultLob;
+    }
+
+    public byte[] getDefinedLob() {
+        return definedLob;
+    }
+
+    public void setDefinedLob(byte[] definedLob) {
+        this.definedLob = definedLob;
+    }
+
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/BlobColumnEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestBlobColumnType.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestBlobColumnType.java?rev=1031240&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestBlobColumnType.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestBlobColumnType.java
Thu Nov  4 20:58:09 2010
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.blob.mysql;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.Table;
+import org.apache.openjpa.jdbc.sql.MySQLDictionary;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * Testcase for MySQL Blob types. OPENJPA-740 introduced intelligent column type for BLOBs,
OPENJPA-1870 refined it a
+ * bit.  
+ */
+public class TestBlobColumnType extends SingleEMFTestCase {
+
+    private static boolean _firstRun=true;
+    private boolean _runTest = false; // only test with MySQL 
+
+    public void setUp() throws Exception {
+        
+        // create EMF solely to obtain a DBDictionary.
+        // need to do this without BlobColumnEntity.class since it contains a column definition
which might
+        // not work with all databases. 
+        super.setUp((Object) null);
+        if (!(getDBDictionary() instanceof MySQLDictionary)) {
+            // normal teardown will take care of the EMF.
+            return;
+        }
+        
+        // remove the EMF
+        tearDown();
+        
+        _runTest = true;
+        super.setUp(BlobColumnEntity.class, DROP_TABLES, "openjpa.jdbc.SchemaFactory", "native");
+        
+        if(_firstRun) { 
+            emf.createEntityManager().close(); // trigger table creation.
+            _firstRun = false; 
+        }
+    }
+
+    private Column getCol(String name) { 
+        ClassMapping mapping = getMapping(BlobColumnEntity.class);
+
+        Table t = mapping.getTable();
+        Column col = t.getColumn(DBIdentifier.newIdentifier(name, DBIdentifierType.COLUMN,
true));
+        assertNotNull(col);
+        return col;
+    }
+    
+    public void testSmallLob() {
+        if (_runTest) {
+            assertEquals(MySQLDictionary.tinyBlobTypeName, getCol("smallLob").getTypeIdentifier().getName());
+        }
+    }
+    
+    public void testMedLob() {
+        if (_runTest) {
+            assertEquals(MySQLDictionary.mediumBlobTypeName, getCol("medLob").getTypeIdentifier().getName());
+        }
+    }
+    
+    public void testLongBlob() {
+        if (_runTest) {
+            assertEquals(MySQLDictionary.longBlobTypeName, getCol("longLob").getTypeIdentifier().getName());
+        }
+    }
+    
+    public void testOldLob() {
+        if (_runTest) {
+            assertEquals(getDBDictionary().blobTypeName, getCol("oldLob").getTypeIdentifier().getName());
+        }
+    }
+    
+    public void testDefaultLob() {
+        if (_runTest) {
+            assertEquals(getDBDictionary().blobTypeName, getCol("defaultLob").getTypeIdentifier().getName());
+        }
+    }
+    
+    public void testDefinedLob() {
+        if (_runTest) {
+            assertEquals("BINARY", getCol("definedLob").getTypeIdentifier().getName());
+        }
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestBlobColumnType.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message