ラベル Mirage の投稿を表示しています。 すべての投稿を表示
ラベル Mirage の投稿を表示しています。 すべての投稿を表示

4/15/2012

mirage 1.1.5 and mirage-scala 0.0.4 is now available!

Today, we released Mirage 1.1.5 and mirage-scala 0.0.4!

Mirage is a simple SQL centric database access library and mirage-scala is the wrapper of Mirage for Scala. See the following URL to know about Mirage:

This release contains some important new features for mirage-scala. Mirage update is only small bug fix. So I introduce new features of mirage-scala 0.0.4 in this entry.

Improvement of SqlManager interface

Some methods of SqlManager had a java.lang.Class parameter which specifies the entity class in the previous version. But in mirage-scala 0.0.4, it modified to the generics type parameter.

// Until mirage-scala 0.0.3
val books = sqlManager.getResultList(
  classOf[Book], 
  Sql("SELECT * FROM BOOK"))

// In mirage-scala 0.0.4
val books = sqlManager.getResultList[Book](
  Sql("SELECT * FROM BOOK"))

Improvement of case class entity

mirage-scala can handle case class as the entity. But it required the default constructor as below:

@Table(name="BOOK")
case class Book(
  @(PrimaryKey @field)(generationType = IDENTITY)
  bookId: java.lang.Long,
  bookName: String,
  author: String,
  price: Option[Int]) {

  // This is not required in mirage-scala 0.0.4
  def this() = this(null, null, null, None)

}

The default constructor of case class is not required no longer in mirage-scala 0.0.4.

Wrapping primary key by Pk[T]

In mirage-scala 0.0.4, Pk[T], Id[T] and Auto are added. You can use Pk[T] to wrap the property which corresponds to the primary key. It is useful when the primary key is set by the database. For example, it's auto incremented column.

@Table(name="BOOK")
case class Book(
  @(PrimaryKey @field)(generationType = IDENTITY)
  bookId: Pk[Long],
  bookName: String,
  author: String,
  price: Option[Int])

val book = Book(
  Auto, 
  "Mirage in Action",
  "Naki Takezoe",
  25)

sqlManager.insertEntity(book)

If you have to set the value of the primary key, you can use Id[T] instead of Auto.

@Table(name="BOOK")
case class Book(
  @(PrimaryKey @field)(generationType = APPLICATION)
  bookId: Pk[Long],
  bookName: String,
  author: String,
  price: Option[Int])

val book = Book(
  Id(1), 
  "Mirage in Action",
  "Naki Takezoe",
  25)

sqlManager.insertEntity(book)

Anyway, mirage-scala became more scalanized database access library in 0.0.4. I hope mirage-scala will help your development with Scala!

2/12/2012

Getting Started with mirage-scala

mirage-scala is the simple and powerful library to access RDBMS from Scala. I introduce how to use mirage-scala with sbt.

At first, add the following dependency into your build.sbt:

And create the jdbc.properties and put it on the root of classpath.

Next, you have to create the entity class. mirage-scala supports both of mutable and immutable style as entity class. This is the example of immutable style entity class:

Ready for mirage-scala. Let's try to use it!

You can insert, update and delete a record using SqlManager and entity classes. And also you can select a record by the primary key.

When you must select records by the more complex query, you can do it using 2way-SQL which is the powerful feature of mirage-scala. I would like to write about it in the next entiry.

mirage-scala 0.0.3 is now available!

mirage-scala is the wrapper of Mirage for Scala. It provides the best solution to access RDBMS from Scala.

New features in mirage-scala 0.0.3:

  • Case class (immutable model) is available as entity.
  • Option[T] is available as property type.

By these new features, mirage-scala became the more suitable library for Scala to access RDBMS.

mirage-scala is still under preview release. So any request or feedback welcome!

Mirage 1.1.4 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

New features in Mirage 1.1.4:

  • Added RailsLikeNameConverter as an optional NameConverter.
  • Added FieldPropertyExtractor as an optional implementation of PropertyExtractor.
  • BugFix: Avoid depending on JDBC 4.0 (Java6) API in DefaultValueType
  • Chopping semicolon from the end of the SQL file.
  • Improve: Avoid using type Exception/RuntimeException to make interfaces intension revealing
  • Added SqlManagerImpl#setValueTypes to make it easier to configure valueTypes using Spring framework
  • BugFix: PropertyExtractor extracts static or final field
  • Improvement: DefaultResultEntityCreator just reqires no-argument constructor. It really doesn't matter if the constructor is public.
  • Improvement: Make ValueType parameterized. If you implement custom ValueTypes, these is not compatible in this version.
  • Added BreakIterationException to discontinue iteration search.
  • BugFix: @Column is available for the select query.

Since this version, we provide a source code cross reference generated by Sorcerer. It generates so rich HTML based cross reference which provide references search like Eclipse. See the follwing URL:

I hope Mirage helps your development. Enjoy!

8/07/2011

Mirage 1.1.3 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

New features in Mirage 1.1.3:

This release contains the first release of mirage-scala. This is a wrapper of Mirage for Scala.

I have tested so many features and patterns in mirage-scala. However I couldn't believe how interface is best for mirage-scala. So I decided to release with minimum features in the first release. mirage-scala has not enough features now, however it will be expanded in the future.

I hope Mirage helps your development. Enjoy!

7/15/2011

mirage-scala: Scala binding of Mirage

I started working for mirage-scala that is Scala binding of Mirage. mirage-scala works as wrapper of Mirage and provides the best interface to access to the database using Mirage for Scala.

This is a simple example to query using mirage-scala:

// A class that mapped to ResultList
class Book (
  val bookId: Int,
  val bookName: String,
  val author: String,
  val price: Int
)

// get Session and SqlManager
val session: Session = SessionFactory.getSession()
val sqlManager: SqlManager = session.getSqlManager()

// begin transaction
session.begin()

try {
  val books: List[Book] = sqlManager.getResultList(
    classOf[Book], Sql("""
      SELECT BOOK_ID, BOOK_NAME, AUTHOR, PRICE
      FROM BOOK
      /*IF author!=null*/
        WHERE AUTHOR = /*author*/
      /*END*/
    """), Map("author"->"Naoki Takezoe"))
  
  books.foreach { book =>
    println("bookId: " + book.bookId)
    println("bookName: " + book.bookName)
    println("author: " + book.author)
    println("price: " + book.price)
    println("--")
  }
  
  // commit transaction
  session.commit()
} catch {
  // rollback transaction
  ex: Exception => session.rollback()
}

A most important feature of Mirage is dynamic SQL template named 2waySQL. In Mirage, you have to create it as an external file on the classpath. However in mirage-scala, you can write it inline using multi-line string literal. Of course, you can also use an external file as following:

val result: List[Book] = sqlManager.getResultList(
  classOf[Book], 
  SqlFile("META-INF/selectBooks.sql"), 
  Map("author"->"Naoki Takezoe"))

mirage-scala is still under development. I'm evaluating APIs feaibility. So APIs might be changed considerably in the release version.

5/01/2011

Mirage 1.1.2 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

New features in Mirage 1.1.2:

This release does not contain so big new features. However it can be used in more large fields such as small web applications by connection-pooling in standalone usage.

I wish that Mirage helps your development. Enjoy!

1/15/2011

Unit Testting in Mirage

In the unit-testing for database access code, some testing frameworks such as DbUnit are available. However, as you know, to maintain test data is very painful.

Mirage proposes lightweight unit-testing without database for database access code. It's based on string matching of executed SQL and expected SQL. Executed SQLs don't reach to the database actually, they are intercepted and recorded to MirageTestContext by using MockSqlManager.

You can verify executed SQLs and these parameters through MirageTestContext as below:

@Test
public void testGetBookById(){
  // set MockSqlManager to the test target
  BookService bookService = new BookService();
  bookService.setSqlManager(new MockSqlManager());

  // configure results which would be 
  // returned by MockSqlManager.
  Book book = new Book();
  book.setBookName("Mirage in Action");

  MirageTestContext.addResult(book);

  // execute
  Book result = bookService.getBookById(new Long(100));

  // assert returned object
  assertEquals("Mirage in Action", book.getName);

  // verify the number of executed SQL
  MirageTestContext.verifySqlCount(1);

  // verify the executed SQL
  MirageTestContext.verifySqlByRegExp(0,
    "SELECT .* FROM BOOK " + 
    "WHERE ID = ? ORDER BY ID ASC", // verify SQL
    new Long(100)); // verify Parameters
}

As you see, you can also configure return values of MockSqlManager using MirageTestContext if it's necessary. You can write your test case more simple by static importing of MirageTestContext members.

Please note, the purpose of this way is not to verify whether executed SQLs are correct. It helps to find influence which is not anticipated by modification of database access code. So it requires to current database access code and SQLs are correct.

If your purpose of unit-testing for database access code is matches this concept, Mirage will decrease a cost of unit-testing and maintaining them very much.

Mirage 1.1.0 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

New features in Mirage 1.1.0:

Primary key generation support

  • @PrimaryKey annotation has new attributes generationType and generator. The generationType attribute supports GenerationType.APPLICATION, GenerationType.IDENTIY and GenerationType.SEQAUENCE.
  • The persistent attribute of @PrimaryKey annotation has been removed.

Improvement of unit testing support

New ConnectionProvider and Dialect

I wish that Mirage helps your development. Enjoy!

1/02/2011

Mirage 1.0.6 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

Here is the list of changes in Mirage 1.0.6:

  • Unit Testing support
    • Added MockSqlManager which is used in unit testing instead of SqlManager. See details about Unit Testing support at the UnitTest section.
  • Ant Task

In addition, Apache Click example is updated which contains examples of TestCase using MockSqlManager. You can get it from the download page.

I wish that Mirage helps your development. Enjoy!

10/05/2010

Mirage 1.0.5 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

Here is the list of changes in Mirage 1.0.5:

  • Add new methods to SqlManager for batch insert/update/delete entities:
    • SqlManager#insertBatch()
    • SqlManager#updateBatch()
    • SqlManager#deleteBatch()
  • BugFix: NullPointerException which is caused in conversion from NULL column value to java.util.Date.
  • Possible to specify @In, @Out, @InOut, @ResultSet for setter / getter method.
  • Add new annotations @Table, @Column. These annotation are used to specify table and column name.
  • Entity Generation Tool (Experimental). See the EntityGen Javadoc to know how to use it.

In addition, Apache Click example is updated to use Apache Click 2.2.0 and Mirage 1.0.5. You can get it from the download page.

I wish that Mirage helps your development. Enjoy!

9/28/2010

Mailing list for Mirage is now available!

Mailing list for Mirage is now available.

You can subscribe this list at the following page:
http://lists.sourceforge.jp/mailman/listinfo/amateras-mirage

And Mirage 1.0.5 which contains some new features such as batch updating and entity generation tool and also new click-mirage-examples would be released soon!

9/04/2010

Mirage 1.0.4 Released!

Mirage 1.0.4 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

Here is the list of changes in Mirage 1.0.4:

  • JavaSE 5 support (Mirage 1.0.3 and before work with only JavaSE 6)
  • BugFix: Map which contains null properties causes NullPointerException in SqlManager#executeUpdate()
  • BugFix: When the column value is NULL then Mirage sets the default value of primitive types to entity wrapper type properties.
  • Add new methods to SqlManager for direct sql execution:
    • SqlManager#getResultListBySql()
    • SqlManager#getSingleResultBySql()
    • SqlManager#iterateBySql()
    • SqlManager#executeUpdatySql()

I wish that Mirage helps your development. Enjoy!

6/15/2010

Mirage 1.0.3 Released

Mirage 1.0.3 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

Here is the list of changes in this release:

  • Iteration search per a record using cursor.
  • Stored procedure / function support.
  • BugFix about SqlManager#insertEntity().

Please see also my past entries about new features in Mirage 1.0.3.

I wish that Mirage helps your development. Enjoy!

6/03/2010

Mirage supports stored procedure/function

The next version of Mirage will support stored procedure/function. We added new methods to call them to SqlManager in the SVN trunk.

Here is an example to call stored function in Mirage:

// Creates parameter object which give to stored function
GetCountParam param = new GetCountParam();
param.deptId = 1;
...
// Calls a stored function and get a result value.
Long count = sqlManager.call(Long.class, "get_emp_count", param);

Fields of the parameter class has annotation such as @In, @Out, @InOut and @ResultSet. These annotations mean parameter type.

If the function returns ResultSet, use SqlManager#callForList() instead of SqlManager#call().

Please wait for the next release of Mirage!

5/09/2010

Large results processing in Mirage

The next release of Mirage is 1.0.3. It contains some new features. Today, I write about iteration search which is one of them.

SqlManager#getResultList() creates all entity instances and returns a list which contains them. If SQL returns a large result, it causes OutOfMemory.

In these case, you should use SqlManager#iterate() instead of SqlManager#getResultList().

Integer result = sqlManager.iterate(
  Book.class,
  new IterationCallback<Book, Integer>() {

    private int result;

    @Override public Integer iterate(Book entity) {
      result = result + entity.price;
      return result;
    }

  },
  SQL_PREFIX + "SqlManagerImplTest_selectBooks.sql");

SqlManager#iterate() accepts IterationCallback and invoke it per record. The return value of SqlManager#iterate() is a last returned value from IterationCallback.

Iteration search would be available in Mirage 1.0.3.

5/08/2010

Mirage 1.0.2 Released!

Mirage 1.0.2 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

1.0.2 is a maintenance release. Here is the list of changes in this release:

  • Dependency to Spring Framework and Guice became optional.
  • Dependency to the pached OGNL changed to OGNL 2.7.3.
  • BugFix about BLOB support.

BLOB support in 1.0.1 does not work because it contains a serious bug. This bug was fixed in 1.0.2 and dependencies was reviewed and modified to minimum.

And also Mirage with Apache Click example is released. You can get it from the download page.

I wish that Mirage helps your development. Enjoy!

5/02/2010

Mirage and Apache Click Example

I started to make a sample application to use Mirage with Apache Click.

This sample application has not been completed yet. However you can checkout source code from the following URL using Subversion.

You can build a war file using Maven. Please execute following commands in command prompt.

$ svn co http://svn.sourceforge.jp/svnroot/amateras/mirage/trunk/mirage-click-example/
$ cd mirage-click-example
$ mvn package

Then you can find mirage-click-example.war in the /target directory.

Put it into the application server such as Tomcat and access http://localhost:8080/mirage-click-example/ using your browser.

Mirage 1.0.1 Released!

Mirage is a simple SQL centric database access library. Today, I've just released Mirage 1.0.1. It's already available.

See the following URL to know about Mirage:

Here is the list of new features in this release:

  • Use java.util.logging instead of slf4j / logback to remove them from dependency.
  • Simple example and documentation for Google Guice integration.
  • It's possible to specify a transient property by transient modifier instead of @Transient annotation.
  • Add new method SqlManager#findEntity(Class clazz, Object... id)
  • Add new method SqlManager#getCount(String sqlPath[, Object param])
  • ValueType interface to add custome value type support
  • BLOB support

Mirage is still not enough to use in complex systems. So we would improve it as much as possible soon.

4/20/2010

Mirage: Simple SQL Centric DB Access Library

Today, I released Mirage ver 1.0.0.

Mirage is a simple SQL centric database access library. It has a following two features:

  • 2WaySQL
    The main feature of Mirage is 2WaySQL. This makes plain old SQL template, and it is executable using any SQL client tools because parameters and conditions are written as SQL comment.
  • SQL less Update
    Generally, update processing are simpler than search processing. However, especially, large INSERT SQL brings us the considerable pain. In the Mirage, you can insert / update / delete records using entity class (without SQL).

The main feature of Mirage is 2WaySQL. This makes plain old SQL template. See the following example:

SELECT * FROM BOOK
/*BEGIN*/
  WHERE
  /*IF author != null */
        AUTHOR = /*author*/'Naoki Takezoe'
  /*END*/
  /*IF minPrice != null */
    AND PRICE >= /*minPrice*/20
  /*END*/
  /*IF maxPrice != null */
    AND PRICE <= /*maxPrice*/100
  /*END*/
/*END*/
ORDER BY BOOK_ID ASC

Mirage processes this SQL template and executes it using PreparedStatement at runtime. And this SQL template is exacutable even it is on SQL client tools such as SQL*Plus(Oracle) or psql(PostgreSQL). So it makes easy to test SQL.

See details about Mirage at our web site. I would also talk about Mirage in this blog.