Skip to content

Commit

Permalink
Fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
ccleve committed May 26, 2018
1 parent 277baab commit 0f33aca
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 8 deletions.
17 changes: 11 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.dieselpoint</groupId>
<artifactId>norm</artifactId>
<name>Norm</name>
<version>0.8.1</version>
<version>0.8.2</version>
<packaging>jar</packaging>

<description>An extremely lightweight data access layer over JDBC</description>
Expand Down Expand Up @@ -49,6 +49,7 @@
<!-- Here's the explanation for all this: http://central.sonatype.org/pages/apache-maven.html -->
<!-- "mvn install" to do a build -->
<!-- "mvn clean deploy" to do an actual release to central -->
<!-- Look in my local notes/norm project for more -->

<distributionManagement>
<snapshotRepository>
Expand All @@ -61,7 +62,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -83,7 +84,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<version>3.0.0</version>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
<additionalOptions>-Xdoclint:none</additionalOptions>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down Expand Up @@ -135,20 +140,20 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.6.1</version>
<version>3.1.0</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
<version>8.0.11</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.0.0</version>
<version>42.2.2</version>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/dieselpoint/norm/ColumnOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* Specify the order of the columns. Is used in the create table sql.
* @ColumnOrder({"name","address", ...})
* ColumnOrder({"name","address", ...})
*
* @author ccleve
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ public void populateGeneratedKey(ResultSet generatedKeys, Object insertRow) {
if (prop == null) {
throw new DbException("The database table has an autogenerated key, but the pojo doesn't have a field with a @GeneratedValue annotation.");
}
boolean isInt = prop.dataType.isAssignableFrom(int.class); // int or long
// is it an int or a long?
boolean isInt = prop.dataType.isAssignableFrom(int.class) || prop.dataType.isAssignableFrom(Integer.class);

Object newKey;

Expand Down
112 changes: 112 additions & 0 deletions src/test/java/com/dieselpoint/norm/TestGeneratedId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.dieselpoint.norm;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.dieselpoint.norm.Database;


public class TestGeneratedId {

static String DB_DRIVER_CLASS_NAME = "org.postgresql.ds.PGSimpleDataSource";
static String DB_SERVER_NAME = "localhost";
static String DB_DATABASE = "testdb";
static String DB_USERNAME = "postgres";
static String DB_PASSWORD = "rootpassword";

private Database db;

@Before
public void setUp() {
System.setProperty("norm.dataSourceClassName", DB_DRIVER_CLASS_NAME);
System.setProperty("norm.serverName", DB_SERVER_NAME);
System.setProperty("norm.databaseName", DB_DATABASE);
System.setProperty("norm.user", DB_USERNAME);
System.setProperty("norm.password", DB_PASSWORD);

db = new Database();
}

@Test
public void testCreate() {
NormPojo np = new NormPojo();
np.setId("MyID");
np.setName("My name");
db.insert(np);
Assert.assertNotNull(np.getDatabaseId());
}

@Test
public void testRetrieval() {
List<NormPojo> npList = null;
npList = db.results(NormPojo.class);
Assert.assertNotNull(npList);
Assert.assertTrue(npList.size() > 0);
}

@Table(name = "pojo")
public static class NormPojo {

/** Database record ID. */
private Integer databaseId;

/** Unique identifier of the object. */
private String id;

/** Human readable name. */
private String name;

/**
* @return the id
*/
@Column(name = "object_id", unique = true)
public String getId() {
return id;
}

/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}

/**
* @return the name
*/
@Column(name = "name")
public String getName() {
return name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

@Id
@GeneratedValue
@Column(name = "id")
public Integer getDatabaseId() {
return databaseId;
}

public void setDatabaseId(Integer databaseId) {
this.databaseId = databaseId;
}

}



}

0 comments on commit 0f33aca

Please sign in to comment.