Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
CTF
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grzegorz
CTF
Commits
1ea08633
Commit
1ea08633
authored
Feb 20, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first try to cooperate with mongolink
parent
1bd26df1
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
327 additions
and
7 deletions
+327
-7
CTFApplication.java
service/src/main/java/CTFApplication.java
+12
-2
Fruit.java
service/src/main/java/objects/Fruit.java
+39
-0
FruitMongoRepository.java
service/src/main/java/repositories/FruitMongoRepository.java
+33
-0
FruitRepository.java
service/src/main/java/repositories/FruitRepository.java
+6
-0
MongoRepositories.java
service/src/main/java/repositories/MongoRepositories.java
+40
-0
MongoRepository.java
service/src/main/java/repositories/MongoRepository.java
+62
-0
Repositories.java
service/src/main/java/repositories/Repositories.java
+16
-0
Repository.java
service/src/main/java/repositories/Repository.java
+11
-5
MongoConfiguration.java
service/src/main/java/stub/MongoConfiguration.java
+51
-0
Properties.java
service/src/main/java/stub/Properties.java
+57
-0
No files found.
service/src/main/java/CTFApplication.java
View file @
1ea08633
import
api.ExampleResource
;
import
api.ExampleResource
;
import
com.mongodb.client.FindIterable
;
import
com.mongodb.client.FindIterable
;
import
com.mongodb.client.MongoCollection
;
import
database.MongoDatabaseConnector
;
import
database.MongoDatabaseConnector
;
import
io.dropwizard.Application
;
import
io.dropwizard.Application
;
import
io.dropwizard.setup.Environment
;
import
io.dropwizard.setup.Environment
;
import
objects.Fruit
;
import
org.bson.Document
;
import
org.bson.Document
;
import
org.mongolink.MongoSession
;
import
repositories.MongoRepositories
;
import
repositories.Repositories
;
import
stub.MongoConfiguration
;
/**
/**
* Created by gpietrus on 16.02.16.
* Created by gpietrus on 16.02.16.
...
@@ -21,6 +25,12 @@ public class CTFApplication extends Application<ApplicationConfiguration>
...
@@ -21,6 +25,12 @@ public class CTFApplication extends Application<ApplicationConfiguration>
public
static
void
main
(
String
[]
args
)
throws
Exception
public
static
void
main
(
String
[]
args
)
throws
Exception
{
{
new
CTFApplication
().
run
(
args
);
MongoSession
session
=
MongoConfiguration
.
createSession
();
session
.
start
();
Repositories
.
initialise
(
new
MongoRepositories
(
session
));
Repositories
.
fruits
().
add
(
new
Fruit
(
"apple"
));
session
.
stop
();
//new CTFApplication().run(args);
}
}
}
}
service/src/main/java/objects/Fruit.java
0 → 100644
View file @
1ea08633
package
objects
;
import
org.joda.time.DateTime
;
import
java.util.UUID
;
public
class
Fruit
{
@SuppressWarnings
(
"UnusedDeclaration"
)
protected
Fruit
()
{
// for mongolink
}
public
Fruit
(
String
name
)
{
this
.
name
=
name
;
this
.
id
=
UUID
.
randomUUID
();
}
public
UUID
getId
()
{
return
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
DateTime
getCreationDate
()
{
return
creationDate
;
}
private
UUID
id
;
private
String
name
;
private
DateTime
creationDate
=
new
DateTime
();
}
service/src/main/java/repositories/FruitMongoRepository.java
0 → 100644
View file @
1ea08633
/*
* MongoLink, Object Document Mapper for Java and MongoDB
*
* Copyright (c) 2012, Arpinum or third-party contributors as
* indicated by the @author tags
*
* MongoLink is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MongoLink is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with MongoLink. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
repositories
;
import
objects.Fruit
;
import
org.mongolink.MongoSession
;
public
class
FruitMongoRepository
extends
MongoRepository
<
Fruit
>
implements
FruitRepository
{
public
FruitMongoRepository
(
MongoSession
mongoSession
)
{
super
(
mongoSession
);
}
}
service/src/main/java/repositories/FruitRepository.java
0 → 100644
View file @
1ea08633
package
repositories
;
import
objects.Fruit
;
public
interface
FruitRepository
extends
Repository
<
Fruit
>
{
}
\ No newline at end of file
service/src/main/java/repositories/MongoRepositories.java
0 → 100644
View file @
1ea08633
/*
* MongoLink, Object Document Mapper for Java and MongoDB
*
* Copyright (c) 2012, Arpinum or third-party contributors as
* indicated by the @author tags
*
* MongoLink is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MongoLink is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with MongoLink. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
repositories
;
import
org.mongolink.MongoSession
;
public
class
MongoRepositories
extends
Repositories
{
public
MongoRepositories
(
MongoSession
session
)
{
this
.
session
=
session
;
}
@Override
protected
FruitRepository
fruitsRepository
()
{
return
new
FruitMongoRepository
(
session
);
}
private
MongoSession
session
;
}
service/src/main/java/repositories/MongoRepository.java
0 → 100644
View file @
1ea08633
/*
* MongoLink, Object Document Mapper for Java and MongoDB
*
* Copyright (c) 2012, Arpinum or third-party contributors as
* indicated by the @author tags
*
* MongoLink is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MongoLink is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with MongoLink. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
repositories
;
import
org.mongolink.MongoSession
;
import
java.lang.reflect.ParameterizedType
;
import
java.util.List
;
public
abstract
class
MongoRepository
<
T
>
implements
Repository
<
T
>
{
protected
MongoRepository
(
MongoSession
session
)
{
this
.
session
=
session
;
}
@Override
public
T
get
(
Object
id
)
{
return
session
.
get
(
id
,
persistentType
());
}
@Override
public
void
delete
(
T
entity
)
{
session
.
delete
(
entity
);
}
@Override
public
void
add
(
T
entity
)
{
session
.
save
(
entity
);
}
@Override
public
List
<
T
>
all
()
{
return
session
.
getAll
(
persistentType
());
}
protected
final
Class
<
T
>
persistentType
()
{
final
ParameterizedType
superclass
=
(
ParameterizedType
)
getClass
().
getGenericSuperclass
();
return
(
Class
<
T
>)
superclass
.
getActualTypeArguments
()[
0
];
}
protected
final
MongoSession
session
;
}
service/src/main/java/repositories/Repositories.java
0 → 100644
View file @
1ea08633
package
repositories
;
public
abstract
class
Repositories
{
public
static
void
initialise
(
Repositories
instance
)
{
Repositories
.
instance
=
instance
;
}
public
static
FruitRepository
fruits
()
{
return
instance
.
fruitsRepository
();
}
protected
abstract
FruitRepository
fruitsRepository
();
private
static
Repositories
instance
;
}
service/src/main/java/repositories/Repository.java
View file @
1ea08633
package
repositories
;
package
repositories
;
/**
import
java.util.List
;
* Created by gpietrus on 16.02.16.
*/
public
interface
Repository
<
T
>
{
public
class
Repository
{
T
get
(
Object
id
);
void
delete
(
T
entit
é
);
void
add
(
T
entit
é
);
List
<
T
>
all
();
}
}
service/src/main/java/stub/MongoConfiguration.java
0 → 100644
View file @
1ea08633
/*
* MongoLink, Object Document Mapper for Java and MongoDB
*
* Copyright (c) 2012, Arpinum or third-party contributors as
* indicated by the @author tags
*
* MongoLink is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MongoLink is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with MongoLink. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
stub
;
import
org.mongolink.MongoSession
;
import
org.mongolink.MongoSessionManager
;
import
org.mongolink.Settings
;
import
org.mongolink.domain.mapper.ContextBuilder
;
public
class
MongoConfiguration
{
public
static
void
stop
()
{
Singleton
.
INSTANCE
.
mongoSessionManager
.
close
();
}
public
static
MongoSession
createSession
()
{
return
Singleton
.
INSTANCE
.
mongoSessionManager
.
createSession
();
}
private
enum
Singleton
{
INSTANCE
;
private
Singleton
()
{
ContextBuilder
builder
=
new
ContextBuilder
(
"org.mongolink.example.persistence.mapping"
);
mongoSessionManager
=
MongoSessionManager
.
create
(
builder
,
new
Properties
().
addSettings
(
Settings
.
defaultInstance
()));
}
private
final
MongoSessionManager
mongoSessionManager
;
}
}
service/src/main/java/stub/Properties.java
0 → 100644
View file @
1ea08633
package
stub
;
import
org.mongolink.Settings
;
import
java.io.InputStream
;
public
class
Properties
{
public
Settings
addSettings
(
Settings
settings
)
{
return
settings
.
withHost
(
getDBHost
()).
withPort
(
getDBPort
()).
withDbName
(
getDBName
()).
withAuthentication
(
getDBUser
(),
getDBPassword
());
}
public
String
getDBHost
()
{
return
getProperty
(
"db.host"
);
}
public
String
getDBName
()
{
return
getProperty
(
"db.name"
);
}
public
int
getDBPort
()
{
return
Integer
.
valueOf
(
getProperty
(
"db.port"
));
}
public
String
getDBUser
()
{
return
getProperty
(
"db.user"
);
}
public
String
getDBPassword
()
{
return
getProperty
(
"db.password"
);
}
private
String
getProperty
(
String
nom
)
{
return
Config
.
INSTANCE
.
properties
.
getProperty
(
nom
);
}
private
static
enum
Config
{
INSTANCE
;
private
Config
()
{
InputStream
stream
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"conf.properties"
);
properties
=
new
java
.
util
.
Properties
();
try
{
properties
.
load
(
stream
);
stream
.
close
();
}
catch
(
Exception
e
)
{
//
}
}
private
final
java
.
util
.
Properties
properties
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment