Skip to content

Instantly share code, notes, and snippets.

def dagger_version = "2.16"
//dagger
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
implementation "com.google.dagger:dagger-android:$dagger_version"
implementation "com.google.dagger:dagger-android-support:$dagger_version"
// if you use the support libraries
kapt "com.google.dagger:dagger-android-processor:$dagger_version"
interface NamesApi {
@GET("names")
fun getNamesAfter(@Query("after") afterName : String, @Query("limit") limit: Int) : Call<Array<String>>
}
interface ProductsApi {
@GET("products")
fun searchProducts(@Query("searchTerm") searchTerm: String, @Query("page") page: Int) : Call<ProductsResponse>
@GET
fun getPageOfResults(@Url nextPageUrl: String) : Call<ProductsResponse>
}
@Singleton
class TeamDiffCallback @Inject constructor() : DiffUtil.ItemCallback<Team>() {
override fun areItemsTheSame(oldItem: Team, newItem: Team): Boolean {
return oldItem.teamId == newItem.teamId && oldItem.competitionId == newItem.competitionId
}
override fun areContentsTheSame(oldItem: Team, newItem: Team): Boolean {
return oldItem.name == newItem.name && oldItem.crestUrl == newItem.crestUrl && oldItem.shortName == newItem.shortName
}
class TeamsViewModel @Inject
constructor(private val teamDao: TeamDao) : ViewModel(){
val liveTeamData: LiveData<PagedList<Team>>
init {
val teamsByNameDataSourceFactory = teamDao.loadTeamsByName()
val pagedListConfig = PagedList.Config.Builder()
@Dao
interface TeamDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertTeam(team: Team)
@Query("SELECT * FROM teams order by name ASC")
fun loadTeamsByName() : DataSource.Factory<Integer, Team>
}
docker build \
--build-arg CLOUD_SSL_STORE_PASSWORD_ARG=changeit \
--build-arg CLOUD_SSL_KEY_PASSWORD_ARG=changeit \
--build-arg PAYARA_ADMIN_PASSWORD_ARG=changeit \
--build-arg CLOUD_SQL_PASSWORD_ARG=reallychangeit \
--build-arg CLOUD_SQL_JDBC_URL_ARG=<your-cloud-sql-jdbc-url> \
--build-arg CLOUD_SQL_SERVER_NAME_ARG=<cloud-sql-server-name> \
--build-arg CLOUD_SQL_USERNAME_ARG=<cloud-sql-app-user> \
-t cloud-sql-payara .
@bltuckerdevblog
bltuckerdevblog / postbootscript
Last active January 30, 2018 02:02
Pre and Post boot scripts
#Test that our connection to cloud sql is good
ping-connection-pool --user admin --passwordfile /tmp/password.txt jdbc/cloudsql-pool
#deploy the app
deploy /opt/application.war
@bltuckerdevblog
bltuckerdevblog / cloud_sql_resource.xml
Created January 30, 2018 01:53
example resource.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool name="jdbc/cloudsql-pool"
datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
idle-timeout-in-seconds="150"
is-connection-validation-required="true"
connection-validation-method="auto-commit"
res-type="javax.sql.DataSource" >
@bltuckerdevblog
bltuckerdevblog / Dockerfile
Created January 30, 2018 01:52
payara_cloud_sql_docker_file
FROM openjdk:8-jdk
LABEL author="Brett Tucker"
LABEL version="1.0"
LABEL description="This image will use the pre boot and post boot payara scripts to add a \
google cloud sql datasource to a payara server and then automatically deploy a given war file."