-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
identity support fix for h2 and derby
- Loading branch information
Showing
16 changed files
with
468 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...base-persistence/src/test/java/org/eclipse/dirigible/database/persistence/test/Offer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2017 SAP and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* Contributors: | ||
* SAP - initial API and implementation | ||
*/ | ||
|
||
package org.eclipse.dirigible.database.persistence.test; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
/** | ||
* The Class Offer. | ||
*/ | ||
@Table(name = "OFFERS") | ||
public class Offer { | ||
|
||
/** The id. */ | ||
@Id | ||
@GeneratedValue(strategy=GenerationType.IDENTITY) | ||
@Column(name = "OFFER_ID", columnDefinition = "BIGINT", nullable = false) | ||
private long id; | ||
|
||
/** The subject. */ | ||
@Column(name = "OFFER_SUBJECT", columnDefinition = "VARCHAR", nullable = false, length = 512) | ||
private String subject; | ||
|
||
/** | ||
* Gets the id. | ||
* | ||
* @return the id | ||
*/ | ||
public long getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* Sets the id. | ||
* | ||
* @param id the new id | ||
*/ | ||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* Gets the subject. | ||
* | ||
* @return the subject | ||
*/ | ||
public String getSubject() { | ||
return subject; | ||
} | ||
|
||
/** | ||
* Sets the subject. | ||
* | ||
* @param subject the new subject | ||
*/ | ||
public void setSubject(String subject) { | ||
this.subject = subject; | ||
} | ||
|
||
} |
192 changes: 192 additions & 0 deletions
192
...pse/dirigible/database/persistence/test/PersistenceManagerGeneratedValueIdentityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/* | ||
* Copyright (c) 2017 SAP and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* Contributors: | ||
* SAP - initial API and implementation | ||
*/ | ||
|
||
package org.eclipse.dirigible.database.persistence.test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
import org.eclipse.dirigible.database.persistence.PersistenceManager; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The Persistence Manager Generated Value Table Test. | ||
*/ | ||
public class PersistenceManagerGeneratedValueIdentityTest extends AbstractPersistenceManagerTest { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(PersistenceManagerGeneratedValueIdentityTest.class); | ||
|
||
/** | ||
* Ordered CRUD tests. | ||
* | ||
* @throws SQLException | ||
* the SQL exception | ||
*/ | ||
@Test | ||
public void orderedCrudTests() throws SQLException { | ||
String database = System.getProperty("database"); | ||
if (database == null) { | ||
database = "derby"; | ||
} | ||
if (!"sybase".equals(database) && !"h2".equals(database) && !"derby".equals(database)) { | ||
logger.warn("Skipped IDENTITY test for database: " + database); | ||
return; | ||
} | ||
|
||
PersistenceManager<Offer> persistenceManager = new PersistenceManager<Offer>(); | ||
Connection connection = null; | ||
try { | ||
connection = getDataSource().getConnection(); | ||
// create table | ||
createTableForPojo(connection, persistenceManager); | ||
// check whether it is created successfully | ||
assertTrue(existsTable(connection, persistenceManager)); | ||
// insert a record in the table for a pojo | ||
insertPojo(connection, persistenceManager); | ||
// insert a record in the table for a pojo | ||
insertSecondPojo(connection, persistenceManager); | ||
// insert a record in the table for a pojo | ||
insertThirdPojo(connection, persistenceManager); | ||
// get the list of all the records | ||
findAllPojo(connection, persistenceManager); | ||
// drop the table | ||
dropTableForPojo(connection, persistenceManager); | ||
} finally { | ||
if (connection != null) { | ||
connection.close(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Creates the table for pojo. | ||
* | ||
* @param connection | ||
* the connection | ||
* @param persistenceManager | ||
* the persistence manager | ||
* @throws SQLException | ||
* the SQL exception | ||
*/ | ||
public void createTableForPojo(Connection connection, PersistenceManager<Offer> persistenceManager) throws SQLException { | ||
persistenceManager.tableCreate(connection, Offer.class); | ||
} | ||
|
||
/** | ||
* Exists table. | ||
* | ||
* @param connection | ||
* the connection | ||
* @param persistenceManager | ||
* the persistence manager | ||
* @return true, if successful | ||
* @throws SQLException | ||
* the SQL exception | ||
*/ | ||
public boolean existsTable(Connection connection, PersistenceManager<Offer> persistenceManager) throws SQLException { | ||
return persistenceManager.tableExists(connection, Offer.class); | ||
} | ||
|
||
/** | ||
* Insert pojo. | ||
* | ||
* @param connection | ||
* the connection | ||
* @param persistenceManager | ||
* the persistence manager | ||
* @throws SQLException | ||
* the SQL exception | ||
*/ | ||
public void insertPojo(Connection connection, PersistenceManager<Offer> persistenceManager) throws SQLException { | ||
Offer offer = new Offer(); | ||
offer.setSubject("Subject 1"); | ||
persistenceManager.insert(connection, offer); | ||
assertNotEquals(0, offer.getId()); | ||
} | ||
|
||
/** | ||
* Insert second pojo. | ||
* | ||
* @param connection | ||
* the connection | ||
* @param persistenceManager | ||
* the persistence manager | ||
* @throws SQLException | ||
* the SQL exception | ||
*/ | ||
public void insertSecondPojo(Connection connection, PersistenceManager<Offer> persistenceManager) throws SQLException { | ||
Offer offer = new Offer(); | ||
offer.setSubject("Subject 2"); | ||
persistenceManager.insert(connection, offer); | ||
} | ||
|
||
/** | ||
* Insert third pojo. | ||
* | ||
* @param connection | ||
* the connection | ||
* @param persistenceManager | ||
* the persistence manager | ||
* @throws SQLException | ||
* the SQL exception | ||
*/ | ||
public void insertThirdPojo(Connection connection, PersistenceManager<Offer> persistenceManager) throws SQLException { | ||
Offer offer = new Offer(); | ||
offer.setSubject("Subject 3"); | ||
persistenceManager.insert(connection, offer); | ||
} | ||
|
||
/** | ||
* Find all pojo. | ||
* | ||
* @param connection | ||
* the connection | ||
* @param persistenceManager | ||
* the persistence manager | ||
* @throws SQLException | ||
* the SQL exception | ||
*/ | ||
public void findAllPojo(Connection connection, PersistenceManager<Offer> persistenceManager) throws SQLException { | ||
List<Offer> list = persistenceManager.findAll(connection, Offer.class); | ||
|
||
assertNotNull(list); | ||
assertFalse(list.isEmpty()); | ||
assertEquals(3, list.size()); | ||
Offer offer = list.get(0); | ||
assertEquals("Subject 1", offer.getSubject()); | ||
|
||
System.out.println(offer.getId()); | ||
|
||
} | ||
|
||
/** | ||
* Drop table for pojo. | ||
* | ||
* @param connection | ||
* the connection | ||
* @param persistenceManager | ||
* the persistence manager | ||
* @throws SQLException | ||
* the SQL exception | ||
*/ | ||
public void dropTableForPojo(Connection connection, PersistenceManager<Offer> persistenceManager) throws SQLException { | ||
persistenceManager.tableDrop(connection, Offer.class); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
modules/database-persistence/src/test/resources/database.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
postgres.driver=org.postgresql.Driver | ||
postgres.url=jdbc:postgresql://<host>:<port>/<database> | ||
postgres.username=postgres | ||
postgres.password= | ||
sybase.driver=com.sybase.jdbc4.jdbc.SybDriver | ||
sybase.url=jdbc:sybase:Tds:<host>:<port> | ||
sybase.username= | ||
sybase.password= | ||
h2.driver=org.h2.Driver | ||
h2.url=jdbc:h2:mem:dirigible;DB_CLOSE_DELAY=-1 | ||
h2.username=sa | ||
h2.password= |
Oops, something went wrong.