-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
804 additions
and
782 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
# Auto detect text files and perform LF normalization | |||
* text=auto | |||
|
|||
# Custom for Visual Studio | |||
*.cs diff=csharp | |||
*.sln merge=union | |||
*.csproj merge=union | |||
*.vbproj merge=union | |||
*.fsproj merge=union | |||
*.dbproj merge=union | |||
|
|||
# Standard to msysgit | |||
*.doc diff=astextplain | |||
*.DOC diff=astextplain | |||
*.docx diff=astextplain | |||
*.DOCX diff=astextplain | |||
*.dot diff=astextplain | |||
*.DOT diff=astextplain | |||
*.pdf diff=astextplain | |||
*.PDF diff=astextplain | |||
*.rtf diff=astextplain | |||
*.RTF diff=astextplain |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,61 +1,61 @@ | |||
import sbt._ | import sbt._ | ||
import Keys._ | import Keys._ | ||
|
|
||
object Play2MorphiaPluginBuild extends Build { | object Play2MorphiaPluginBuild extends Build { | ||
|
|
||
import Resolvers._ | import Resolvers._ | ||
import Dependencies._ | import Dependencies._ | ||
import BuildSettings._ | import BuildSettings._ | ||
|
|
||
lazy val Play2MorphiaPlugin = Project( | lazy val Play2MorphiaPlugin = Project( | ||
"play2-morphia-plugin", | "play2-morphia-plugin", | ||
file("."), | file("."), | ||
settings = buildSettings ++ Seq( | settings = buildSettings ++ Seq( | ||
libraryDependencies := runtime ++ test, | libraryDependencies := runtime ++ test, | ||
publishMavenStyle := true, | publishMavenStyle := true, | ||
publishTo := Some(githubRepository), | publishTo := Some(githubRepository), | ||
scalacOptions ++= Seq("-Xlint","-deprecation", "-unchecked","-encoding", "utf8"), | scalacOptions ++= Seq("-Xlint","-deprecation", "-unchecked","-encoding", "utf8"), | ||
javacOptions ++= Seq("-encoding", "utf8", "-g"), | javacOptions ++= Seq("-encoding", "utf8", "-g"), | ||
resolvers ++= Seq(DefaultMavenRepository, Resolvers.typesafeRepository, Resolvers.morphiaRepository), | resolvers ++= Seq(DefaultMavenRepository, Resolvers.typesafeRepository, Resolvers.morphiaRepository), | ||
checksums := Nil // To prevent proxyToys downloding fails https://github.com/leodagdag/play2-morphia-plugin/issues/11 | checksums := Nil // To prevent proxyToys downloding fails https://github.com/leodagdag/play2-morphia-plugin/issues/11 | ||
) | ) | ||
).settings() | ).settings() | ||
|
|
||
object Resolvers { | object Resolvers { | ||
val githubRepository = Resolver.file("GitHub Repository", Path.userHome / "dev" / "leodagdag.github.com" / "repository" asFile)(Resolver.mavenStylePatterns) | val githubRepository = Resolver.file("GitHub Repository", Path.userHome / "dev" / "leodagdag.github.com" / "repository" asFile)(Resolver.mavenStylePatterns) | ||
val dropboxRepository = Resolver.file("Dropbox Repository", Path.userHome / "Dropbox" / "Public" / "repository" asFile)(Resolver.mavenStylePatterns) | val dropboxRepository = Resolver.file("Dropbox Repository", Path.userHome / "Dropbox" / "Public" / "repository" asFile)(Resolver.mavenStylePatterns) | ||
val typesafeRepository = "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/" | val typesafeRepository = "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/" | ||
val morphiaRepository = "Morphia Repository" at "http://morphia.googlecode.com/svn/mavenrepo/" | val morphiaRepository = "Morphia Repository" at "http://morphia.googlecode.com/svn/mavenrepo/" | ||
} | } | ||
|
|
||
object Dependencies { | object Dependencies { | ||
val runtime = Seq( | val runtime = Seq( | ||
"com.google.code.morphia" % "morphia" % "1.00-SNAPSHOT", | "com.google.code.morphia" % "morphia" % "1.00-SNAPSHOT", | ||
"com.google.code.morphia" % "morphia-logging-slf4j" % "0.99", | "com.google.code.morphia" % "morphia-logging-slf4j" % "0.99", | ||
"com.google.code.morphia" % "morphia-validation" % "0.99", | "com.google.code.morphia" % "morphia-validation" % "0.99", | ||
"cglib" % "cglib-nodep" % "[2.1_3,)", | "cglib" % "cglib-nodep" % "[2.1_3,)", | ||
"com.thoughtworks.proxytoys" % "proxytoys" % "1.0", | "com.thoughtworks.proxytoys" % "proxytoys" % "1.0", | ||
"play" %% "play" % "2.0.4" % "compile" notTransitive(), | "play" %% "play" % "2.0.4" % "compile" notTransitive(), | ||
("org.springframework" % "spring-core" % "3.0.7.RELEASE" notTransitive()) | ("org.springframework" % "spring-core" % "3.0.7.RELEASE" notTransitive()) | ||
.exclude("org.springframework", "spring-asm") | .exclude("org.springframework", "spring-asm") | ||
.exclude("commons-logging", "commons-logging"), | .exclude("commons-logging", "commons-logging"), | ||
("org.springframework" % "spring-beans" % "3.0.7.RELEASE" notTransitive()) | ("org.springframework" % "spring-beans" % "3.0.7.RELEASE" notTransitive()) | ||
.exclude("org.springframework", "spring-core") | .exclude("org.springframework", "spring-core") | ||
) | ) | ||
val test = Seq( | val test = Seq( | ||
"play" %% "play-test" % "2.0.4" % "test" | "play" %% "play-test" % "2.0.4" % "test" | ||
) | ) | ||
} | } | ||
|
|
||
object BuildSettings { | object BuildSettings { | ||
val buildOrganization = "leodagdag" | val buildOrganization = "leodagdag" | ||
val buildVersion = "0.0.7" | val buildVersion = "0.0.7" | ||
val buildScalaVersion = "2.9.1" | val buildScalaVersion = "2.9.1" | ||
val buildSbtVersion = "0.11.3" | val buildSbtVersion = "0.11.3" | ||
val buildSettings = Defaults.defaultSettings ++ Seq ( | val buildSettings = Defaults.defaultSettings ++ Seq ( | ||
organization := buildOrganization, | organization := buildOrganization, | ||
version := buildVersion, | version := buildVersion, | ||
scalaVersion := buildScalaVersion | scalaVersion := buildScalaVersion | ||
) | ) | ||
} | } | ||
} | } |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,8 +1,8 @@ | |||
logLevel := Level.Warn | logLevel := Level.Warn | ||
|
|
||
// Use for intellij | // Use for intellij | ||
resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/" | resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/" | ||
|
|
||
// Use for intellij | // Use for intellij | ||
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0") | addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0") | ||
|
|
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,81 +1,81 @@ | |||
package leodagdag.play2morphia; | package leodagdag.play2morphia; | ||
|
|
||
import com.google.code.morphia.annotations.Transient; | import com.google.code.morphia.annotations.Transient; | ||
import com.mongodb.BasicDBObject; | import com.mongodb.BasicDBObject; | ||
import com.mongodb.DBObject; | import com.mongodb.DBObject; | ||
import com.mongodb.gridfs.GridFSDBFile; | import com.mongodb.gridfs.GridFSDBFile; | ||
import com.mongodb.gridfs.GridFSInputFile; | import com.mongodb.gridfs.GridFSInputFile; | ||
import org.bson.types.ObjectId; | import org.bson.types.ObjectId; | ||
import play.Logger; | import play.Logger; | ||
|
|
||
import java.io.File; | import java.io.File; | ||
import java.io.IOException; | import java.io.IOException; | ||
import java.io.InputStream; | import java.io.InputStream; | ||
import java.util.UUID; | import java.util.UUID; | ||
|
|
||
public class Blob { | public class Blob { | ||
|
|
||
@Transient | @Transient | ||
private GridFSDBFile gridFSDBFile; | private GridFSDBFile gridFSDBFile; | ||
|
|
||
public Blob() { | public Blob() { | ||
} | } | ||
|
|
||
public Blob(InputStream is, String type) { | public Blob(InputStream is, String type) { | ||
this(); | this(); | ||
set(is, type); | set(is, type); | ||
} | } | ||
|
|
||
public Blob(File inputFile, String type) { | public Blob(File inputFile, String type) { | ||
this(); | this(); | ||
try { | try { | ||
set(inputFile, type); | set(inputFile, type); | ||
} catch (IOException e) { | } catch (IOException e) { | ||
Logger.error(String.format("File not found: %s (%s)", inputFile.getAbsolutePath(), e.getMessage())); | Logger.error(String.format("File not found: %s (%s)", inputFile.getAbsolutePath(), e.getMessage())); | ||
} | } | ||
} | } | ||
|
|
||
public Blob(String id) { | public Blob(String id) { | ||
DBObject queryObj = new BasicDBObject("name", id); | DBObject queryObj = new BasicDBObject("name", id); | ||
gridFSDBFile = MorphiaPlugin.gridFs().findOne(queryObj); | gridFSDBFile = MorphiaPlugin.gridFs().findOne(queryObj); | ||
} | } | ||
|
|
||
void set(File file, String type) throws IOException { | void set(File file, String type) throws IOException { | ||
if (!file.exists()) { | if (!file.exists()) { | ||
Logger.warn(String.format("File not exists: %s", file)); | Logger.warn(String.format("File not exists: %s", file)); | ||
return; | return; | ||
} | } | ||
GridFSInputFile inputFile = MorphiaPlugin.gridFs().createFile(file); | GridFSInputFile inputFile = MorphiaPlugin.gridFs().createFile(file); | ||
inputFile.setContentType(type); | inputFile.setContentType(type); | ||
inputFile.save(); | inputFile.save(); | ||
this.gridFSDBFile = MorphiaPlugin.gridFs().findOne(new ObjectId(inputFile.getId().toString())); | this.gridFSDBFile = MorphiaPlugin.gridFs().findOne(new ObjectId(inputFile.getId().toString())); | ||
} | } | ||
|
|
||
void set(InputStream is, String type) { | void set(InputStream is, String type) { | ||
GridFSInputFile inputFile = MorphiaPlugin.gridFs().createFile(is); | GridFSInputFile inputFile = MorphiaPlugin.gridFs().createFile(is); | ||
inputFile.setContentType(type); | inputFile.setContentType(type); | ||
inputFile.put("name", UUID.randomUUID().toString()); | inputFile.put("name", UUID.randomUUID().toString()); | ||
inputFile.save(); | inputFile.save(); | ||
gridFSDBFile = MorphiaPlugin.gridFs().findOne(new ObjectId(inputFile.getId().toString())); | gridFSDBFile = MorphiaPlugin.gridFs().findOne(new ObjectId(inputFile.getId().toString())); | ||
} | } | ||
|
|
||
public long length() { | public long length() { | ||
return gridFSDBFile == null ? 0 : gridFSDBFile.getLength(); | return gridFSDBFile == null ? 0 : gridFSDBFile.getLength(); | ||
} | } | ||
|
|
||
public String type() { | public String type() { | ||
return gridFSDBFile.getContentType(); | return gridFSDBFile.getContentType(); | ||
} | } | ||
|
|
||
public boolean exists() { | public boolean exists() { | ||
return gridFSDBFile != null && gridFSDBFile.getId() != null; | return gridFSDBFile != null && gridFSDBFile.getId() != null; | ||
} | } | ||
|
|
||
public GridFSDBFile getGridFSFile() { | public GridFSDBFile getGridFSFile() { | ||
return gridFSDBFile; | return gridFSDBFile; | ||
} | } | ||
|
|
||
public static void delete(String name) { | public static void delete(String name) { | ||
MorphiaPlugin.gridFs().remove(new BasicDBObject("name", name)); | MorphiaPlugin.gridFs().remove(new BasicDBObject("name", name)); | ||
} | } | ||
} | } |
Oops, something went wrong.