Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Жарков Андрей 496 miniORM #75

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ workbench.xmi
*.swp
.settings
.checkstyle
twitter4j.properties
key.txt
Empty file added projects/andreyzharkov/java
Empty file.
97 changes: 97 additions & 0 deletions projects/andreyzharkov/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>ru.mipt.diht.students</groupId>
<artifactId>andreyzharkov</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>andreyzharkov</name>
<url>http://maven.apache.org</url>

<ciManagement>
<system>Travis CI</system>
<url>https://travis-ci.org/KhurtinDN/fizteh-java-2015</url>
</ciManagement>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<parent>
<groupId>ru.mipt.diht.students</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.190</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[4.0,)</version>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-stream</artifactId>
<version>[4.0,)</version>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.48</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>ru.mipt.diht.students.andreyzharkov.miniORM.DatabaseService</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ru.mipt.diht.students.andreyzharkov.miniORM;

import com.google.common.base.CaseFormat;
import ru.mipt.diht.students.andreyzharkov.miniORM.annotations.Column;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
* Created by Андрей on 17.12.2015.
*/
@SuppressWarnings("Duplicates")
public class AnnotatedField {
private String columnName;
private Field field;

private static final Map<Class, String> SQL_TYPE;

static {
SQL_TYPE = new HashMap<>();
SQL_TYPE.put(Integer.class, "INT");
SQL_TYPE.put(Long.class, "INT");
SQL_TYPE.put(Byte.class, "INT");
SQL_TYPE.put(Short.class, "INT");
SQL_TYPE.put(Double.class, "DOUBLE");
SQL_TYPE.put(Float.class, "DOUBLE");
SQL_TYPE.put(String.class, "VARCHAR(10)");
SQL_TYPE.put(Character.class, "VARCHAR(10)");
SQL_TYPE.put(Integer.TYPE, "INT");
SQL_TYPE.put(Long.TYPE, "INT");
SQL_TYPE.put(Byte.TYPE, "INT");
SQL_TYPE.put(Short.TYPE, "INT");
SQL_TYPE.put(Double.TYPE, "DOUBLE");
SQL_TYPE.put(Float.TYPE, "DOUBLE");
SQL_TYPE.put(Character.TYPE, "VARCHAR(10)");
}

public final String getColumnName() {
return columnName;
}

public final Field getField() {
return field;
}

public final String getSqlType() throws DatabaseServiceException {
if (SQL_TYPE.get(field.getType()) == null) {
throw new DatabaseServiceException(columnName + " doesn't have good sql name!");
}
return SQL_TYPE.get(field.getType());
}

public AnnotatedField(Field fild) {
this.field = fild;
Column column = field.getAnnotation(Column.class);
columnName = column.name();
if (columnName.equals("")) {
columnName = field.getName();
columnName = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, columnName);
}
}
}
Loading