Skip to content

Commit

Permalink
Updates for Cayenne 3.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrg committed Dec 6, 2014
1 parent 59dac6c commit faeb3fe
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 180 deletions.
2 changes: 1 addition & 1 deletion FetchingObjects/Aggregates/pom.xml
Expand Up @@ -10,7 +10,7 @@
<url>https://github.com/mrg/cbe</url>

<properties>
<cayenne.version>3.0.2</cayenne.version>
<cayenne.version>3.1</cayenne.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
@@ -1,14 +1,20 @@
package cbe.fetching;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.math.BigDecimal;
import java.net.URISyntaxException;
import java.sql.SQLException;

import org.apache.cayenne.access.DataContext;
import org.apache.cayenne.configuration.server.ServerRuntime;
import org.apache.cayenne.exp.ExpressionFactory;
import org.apache.cayenne.query.SelectQuery;
import org.h2.tools.RunScript;

import cbe.fetching.model.Book;
import cbe.fetching.utilities.AggregateUtils;
import cbe.fetching.utilities.Populator;

/**
* Cayenne By Example - https://github.com/mrg/cbe
Expand All @@ -17,13 +23,18 @@
*/
public class Aggregates
{
public static void main(String[] arguments)
public static void main(String[] arguments) throws FileNotFoundException, SQLException, URISyntaxException
{
// Populate the database.
Populator.populateDatabase();
// Create a Cayenne ServerRuntime with our Cayenne Model.
ServerRuntime runtime = new ServerRuntime("cayenne-cbe.xml");

// Create a new DataContext. This will also initialize the Cayenne
// Framework.
DataContext dataContext = (DataContext) runtime.getContext();

// Create a new DataContext for the queries.
DataContext dataContext = DataContext.createDataContext();
// Populate the database.
FileReader data = new FileReader(new File(Aggregates.class.getClassLoader().getResource("data.sql").toURI()));
RunScript.execute(runtime.getDataSource("cbe").getConnection(), data);

// Create a Query for Book records.
SelectQuery query = new SelectQuery(Book.class);
Expand Down

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions FetchingObjects/Aggregates/src/main/resources/Books.txt

This file was deleted.

This file was deleted.

17 changes: 17 additions & 0 deletions FetchingObjects/Aggregates/src/main/resources/cayenne-cbe.xml
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<domain project-version="6">
<map name="cbe"/>

<node name="cbe"
factory="org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory"
schema-update-strategy="org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"
>
<map-ref name="cbe"/>
<data-source>
<driver value="org.h2.Driver"/>
<url value="jdbc:h2:mem:cbe"/>
<connectionPool min="1" max="10"/>
<login/>
</data-source>
</node>
</domain>
13 changes: 0 additions & 13 deletions FetchingObjects/Aggregates/src/main/resources/cayenne.xml

This file was deleted.

@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
project-version="3.0.0.1">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
project-version="6">
<property name="defaultLockType" value="optimistic"/>
<property name="defaultPackage" value="cbe.fetching.model"/>
<db-entity name="BOOKS">
<db-attribute name="AUTHOR" type="VARCHAR" length="75"/>
<db-attribute name="BOOK_PRICE" type="NUMERIC" length="6" scale="2"/>
<db-attribute name="ID" type="BIGINT" isPrimaryKey="true" isMandatory="true"/>
<db-attribute name="ID" type="BIGINT" isPrimaryKey="true" isGenerated="true" isMandatory="true"/>
<db-attribute name="TITLE" type="VARCHAR" length="75"/>
</db-entity>
<obj-entity name="Book" className="cbe.fetching.model.Book" lock-type="optimistic" dbEntityName="BOOKS">
Expand Down
16 changes: 16 additions & 0 deletions FetchingObjects/Aggregates/src/main/resources/data.sql
@@ -0,0 +1,16 @@
insert into books
(author, title, book_price)
values
('Arthur C. Clarke', '2001: A Space Odyssey', 10.20),
('Suzanne Collins', 'The Hunger Games', 5.01),
('Robert Heinlein', 'Stranger in a Strange Land', 12.24),
('J. K. Rowling', 'Harry Potter and the Sorcerer''s Stone', 8.79),
('J. R. R. Tolkien', 'The Hobbit', 16.50),
('Tad Williams', 'The Dragonbone Chair', 10.85),
('Dan Brown', 'The Da Vinci Code', 11.21),
('Nelson Mandela', 'Conversations with Myself', 12.48),
('Salman Rushdie', 'The Satanic Verses', 10.88),
('Caralyn Buehner', 'Snowmen at Night', 9.10),
('J. R. R. Tolkien', 'The Fellowship of the Ring', 9.20),
('J. R. R. Tolkien', 'The Two Towers', 8.76),
('J. R. R. Tolkien', 'The Return of the King', 8.76);

0 comments on commit faeb3fe

Please sign in to comment.