├── .gitignore ├── README.md ├── pom.xml ├── xultimate-context-support ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── danielli │ │ └── xultimate │ │ ├── context │ │ ├── dfs │ │ │ ├── DistributedFileSystemException.java │ │ │ └── fastdfs │ │ │ │ ├── AbstractStorageClientCallback.java │ │ │ │ ├── AbstractStorageClientReturnedCallback.java │ │ │ │ ├── StorageClientCallback.java │ │ │ │ ├── StorageClientReturnedCallback.java │ │ │ │ ├── support │ │ │ │ ├── ClientGlobalInitializer.java │ │ │ │ └── StorageClientTemplate.java │ │ │ │ └── util │ │ │ │ └── FastDFSUtils.java │ │ ├── format │ │ │ ├── FormatException.java │ │ │ ├── Formatter.java │ │ │ ├── FormatterUtils.java │ │ │ └── support │ │ │ │ ├── FreeMarkerTemplateFormatter.java │ │ │ │ ├── HTTLEngineFormatter.java │ │ │ │ ├── MessageFormatter.java │ │ │ │ ├── SpelFormatter.java │ │ │ │ ├── StringTemplateV3Formatter.java │ │ │ │ ├── StringTemplateV4Formatter.java │ │ │ │ └── VelocityEngineFormatter.java │ │ ├── kvStore │ │ │ ├── AbstractKeyValueStoreTemplate.java │ │ │ ├── KeyValueStoreException.java │ │ │ ├── db │ │ │ │ ├── KeyValueIterator.java │ │ │ │ ├── KeyValueStore.java │ │ │ │ ├── KeyValueStoreException.java │ │ │ │ ├── serializer │ │ │ │ │ └── Serializer.java │ │ │ │ └── support │ │ │ │ │ ├── RocksDbKeyValueStore.java │ │ │ │ │ └── SerializableKeyValueStore.java │ │ │ ├── memcached │ │ │ │ ├── AbstractMemcachedTemplate.java │ │ │ │ ├── MemcachedException.java │ │ │ │ └── xmemcached │ │ │ │ │ ├── BaseSerializingTranscoder.java │ │ │ │ │ ├── SerializingTranscoder.java │ │ │ │ │ ├── XMemcachedClient.java │ │ │ │ │ ├── callback │ │ │ │ │ ├── CallbackLockConfig.java │ │ │ │ │ ├── SelectObjectCallback.java │ │ │ │ │ ├── SelectObjectListCallback.java │ │ │ │ │ └── XMemcachedClientCallback.java │ │ │ │ │ ├── spring │ │ │ │ │ ├── XMemcache.java │ │ │ │ │ ├── XMemcachedCache.java │ │ │ │ │ └── XMemcachedCacheManager.java │ │ │ │ │ ├── support │ │ │ │ │ ├── MemcachedLimiterFactory.java │ │ │ │ │ ├── MemcachedLockFactory.java │ │ │ │ │ └── XMemcachedClientTemplate.java │ │ │ │ │ └── util │ │ │ │ │ └── XMemcachedClientUtils.java │ │ │ └── redis │ │ │ │ ├── AbstractRedisTemplate.java │ │ │ │ ├── RedisException.java │ │ │ │ └── jedis │ │ │ │ ├── JedisCallback.java │ │ │ │ ├── ShardedJedisCallback.java │ │ │ │ ├── support │ │ │ │ ├── JedisTemplate.java │ │ │ │ └── ShardedJedisTemplate.java │ │ │ │ └── util │ │ │ │ ├── JedisPoolUtils.java │ │ │ │ └── ShardedJedisPoolUtils.java │ │ └── scheduling │ │ │ └── quartz │ │ │ ├── MethodInvokingJobDetailFactoryBean.java │ │ │ └── util │ │ │ └── SchedulerUtils.java │ │ ├── jdbc │ │ └── support │ │ │ └── incrementer │ │ │ ├── JedisMaxValueIncrementer.java │ │ │ └── ShardedJedisMaxValueIncrementer.java │ │ ├── mail │ │ └── EmailAddressBuilder.java │ │ └── ui │ │ ├── freemarker │ │ └── FreeMarkerTemplateUtils.java │ │ ├── httl │ │ └── HTTLEngineUtils.java │ │ ├── stringtemplate │ │ ├── v3 │ │ │ └── StringTemplateUtils.java │ │ └── v4 │ │ │ └── StringTemplateUtils.java │ │ └── velocity │ │ └── VelocityEngineUtils.java │ └── test │ ├── java │ ├── com │ │ └── thimbleware │ │ │ └── jmemcached │ │ │ └── protocol │ │ │ └── MemcachedCommandHandler.java │ └── org │ │ ├── danielli │ │ └── xultimate │ │ │ ├── context │ │ │ ├── dfs │ │ │ │ └── fastdfs │ │ │ │ │ ├── DownloadFileWriter.java │ │ │ │ │ ├── Monitor.java │ │ │ │ │ ├── Test.java │ │ │ │ │ ├── Test1.java │ │ │ │ │ ├── TestAppender.java │ │ │ │ │ ├── TestAppender1.java │ │ │ │ │ ├── TestClient.java │ │ │ │ │ ├── TestClient1.java │ │ │ │ │ ├── TestLoad.java │ │ │ │ │ └── UploadLocalFileSender.java │ │ │ ├── format │ │ │ │ └── FormatterTest.java │ │ │ ├── kvStore │ │ │ │ ├── memcached │ │ │ │ │ ├── CacheService.java │ │ │ │ │ ├── MemcachedDaemon.java │ │ │ │ │ ├── MemcachedDaemonTest.java │ │ │ │ │ └── xmemcached │ │ │ │ │ │ ├── Person.java │ │ │ │ │ │ └── XMemcachedClientTest.java │ │ │ │ └── redis │ │ │ │ │ └── jedis │ │ │ │ │ ├── Person.java │ │ │ │ │ └── ShardedJedisTemplateTest.java │ │ │ ├── mail │ │ │ │ ├── JavaMailSenderTest.java │ │ │ │ └── template │ │ │ │ │ └── hello_world.httl │ │ │ └── scheduling │ │ │ │ └── quartz │ │ │ │ ├── ExampleBusinessObject.java │ │ │ │ ├── SchedulerTest.java │ │ │ │ └── SimpleJob.java │ │ │ └── jdbc │ │ │ └── support │ │ │ └── incrementer │ │ │ └── ShardedJedisMaxValueIncrementerTest.java │ │ └── quartz │ │ └── impl │ │ └── jdbcjobstore │ │ ├── StdJDBCDelegate.java │ │ └── StdRowLockSemaphore.java │ └── resources │ ├── applicationContext-dao-base.xml │ ├── applicationContext-service-config.xml │ ├── applicationContext-service-crypto.xml │ ├── dfs │ └── fastdfs │ │ ├── README │ │ ├── applicationContext-service-fastdfs.xml │ │ └── fdfs_client.conf │ ├── formatter │ └── applicationContext-service-formatter.xml │ ├── kvStore │ ├── applicationContext-service-serializer.xml │ ├── memcached │ │ ├── applicationContext-service-memcached-daemon.xml │ │ └── applicationContext-service-memcached.xml │ └── redis │ │ ├── README │ │ └── applicationContext-service-redis.xml │ ├── mail │ ├── applicationContext-service-mail.xml │ ├── file1.zip │ ├── file2.doc │ ├── img01.png │ ├── mail.properties │ └── mail.properties.bak │ └── quartz │ ├── applicationContext-dao-quartz.xml │ ├── applicationContext-service-quartz.xml │ ├── quartz.properties │ └── tables_mysql_innodb.sql ├── xultimate-context ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── danielli │ │ └── xultimate │ │ └── context │ │ ├── chardet │ │ ├── CharsetDetector.java │ │ ├── CharsetDetectorException.java │ │ ├── cpdetector │ │ │ └── InputStreamCharsetDetector.java │ │ ├── icu4j │ │ │ └── InputStreamCharsetDetector.java │ │ ├── jchardet │ │ │ ├── DefaultCharsetDetectionObserver.java │ │ │ └── InputStreamCharsetDetector.java │ │ ├── juniversalchardet │ │ │ ├── DefaultCharsetListener.java │ │ │ └── InputStreamCharsetDetector.java │ │ └── support │ │ │ ├── AbstractCharsetDetector.java │ │ │ ├── FileCharsetDetector.java │ │ │ └── URLCharsetDetector.java │ │ ├── codec │ │ ├── Decoder.java │ │ ├── DecoderException.java │ │ ├── Encoder.java │ │ ├── EncoderException.java │ │ └── support │ │ │ ├── AbstractCoder.java │ │ │ ├── Base64Codec.java │ │ │ ├── ByteArrayStringCoder.java │ │ │ ├── HexCodec.java │ │ │ ├── StringStringCoder.java │ │ │ └── URLCodec.java │ │ ├── crypto │ │ ├── Decryptor.java │ │ ├── DecryptorException.java │ │ ├── Encryptor.java │ │ ├── EncryptorException.java │ │ └── support │ │ │ ├── AbstractCryptor.java │ │ │ ├── AsymmetricAlgorithmsCryptor.java │ │ │ ├── StringStringCryptor.java │ │ │ └── SymmetricAlgorithmsCryptor.java │ │ ├── i18n │ │ ├── Message.java │ │ ├── MessageType.java │ │ └── MessageUtils.java │ │ ├── image │ │ ├── AbstractImageTemplate.java │ │ ├── ImageCompositeTemplate.java │ │ ├── ImageCropTemplate.java │ │ ├── ImageException.java │ │ ├── ImageInfoException.java │ │ ├── ImageInfoTemplate.java │ │ ├── ImageResizeTemplate.java │ │ ├── awt │ │ │ ├── ImageUtils.java │ │ │ └── support │ │ │ │ ├── ImageCompositeTemplateImpl.java │ │ │ │ ├── ImageCropTemplateImpl.java │ │ │ │ ├── ImageInfoTemplateImpl.java │ │ │ │ └── ImageResizeTemplateImpl.java │ │ ├── im4java │ │ │ ├── AbstractIm4javaImageTemplate.java │ │ │ ├── ImageCommandPostProcessor.java │ │ │ └── support │ │ │ │ ├── ImageCompositeTemplateImpl.java │ │ │ │ ├── ImageCropTemplateImpl.java │ │ │ │ ├── ImageInfoTemplateImpl.java │ │ │ │ ├── ImageResizeTemplateImpl.java │ │ │ │ └── RunCommandPostProcessor.java │ │ └── model │ │ │ ├── GeometryOperator.java │ │ │ ├── Gravity.java │ │ │ ├── ImageCoordinate.java │ │ │ ├── ImageFormat.java │ │ │ ├── ImageGeometry.java │ │ │ ├── ImageGeometryCoordinate.java │ │ │ ├── ImageInfo.java │ │ │ └── ImageSize.java │ │ ├── image2 │ │ ├── AbstractImageTemplate.java │ │ ├── ImageCompositeTemplate.java │ │ ├── ImageCropTemplate.java │ │ ├── ImageException.java │ │ ├── ImageInfoException.java │ │ ├── ImageInfoTemplate.java │ │ ├── ImageResizeTemplate.java │ │ ├── awt │ │ │ ├── ImageUtils.java │ │ │ └── support │ │ │ │ ├── ImageCompositeTemplateImpl.java │ │ │ │ ├── ImageCropTemplateImpl.java │ │ │ │ ├── ImageInfoTemplateImpl.java │ │ │ │ └── ImageResizeTemplateImpl.java │ │ ├── config │ │ │ ├── DefaultImageResource.java │ │ │ ├── GeometryOperator.java │ │ │ ├── Gravity.java │ │ │ ├── ImageCoordinate.java │ │ │ ├── ImageFormat.java │ │ │ ├── ImageGeometry.java │ │ │ ├── ImageGeometryCoordinate.java │ │ │ ├── ImageInfo.java │ │ │ ├── ImageResource.java │ │ │ ├── ImageSize.java │ │ │ └── WrapperImageResource.java │ │ └── im4java │ │ │ ├── AbstractIm4javaImageTemplate.java │ │ │ ├── ImageCommandPostProcessor.java │ │ │ └── support │ │ │ ├── ImageCompositeTemplateImpl.java │ │ │ ├── ImageCropTemplateImpl.java │ │ │ ├── ImageInfoTemplateImpl.java │ │ │ ├── ImageResizeTemplateImpl.java │ │ │ └── RunCommandPostProcessor.java │ │ ├── net │ │ └── netty │ │ │ ├── codec │ │ │ ├── JavaObjectCodec.java │ │ │ ├── RpcKryoObjectCodec.java │ │ │ ├── RpcProtobufObjectCodec.java │ │ │ └── RpcProtostuffObjectCodec.java │ │ │ └── support │ │ │ ├── BootstrapFactoryBean.java │ │ │ ├── ServerBootstrapFactoryBean.java │ │ │ └── SocketChannelInitializerFactoryBean.java │ │ ├── performance │ │ ├── AbstractMonitoringInterceptor.java │ │ ├── AbstractStopWatchMonitoringInterceptor.java │ │ ├── AbstractTraceInterceptor.java │ │ ├── PerformanceMonitor.java │ │ ├── PerformanceMonitorForEachMethodInterceptor.java │ │ └── PerformanceMonitorForOneMethodInterceptor.java │ │ ├── support │ │ └── EncryptPropertyPlaceholderConfigurer.java │ │ └── util │ │ ├── ApplicationContextUtils.java │ │ └── BeanFactoryContext.java │ └── test │ ├── java │ └── org │ │ └── danielli │ │ └── xultimate │ │ └── context │ │ ├── chardet │ │ ├── FileCharsetDetectorTest.java │ │ └── URLCharsetDetectorTest.java │ │ ├── codec │ │ ├── Base64CodecTest.java │ │ ├── HexCodecTest.java │ │ └── URLCodecTest.java │ │ ├── config │ │ ├── Boss.java │ │ ├── Car.java │ │ ├── CustomCarEditor.java │ │ └── CustomCardEditorTest.java │ │ ├── crypto │ │ ├── AESCryptorTest.java │ │ └── RSACryptorTest.java │ │ ├── event │ │ ├── EventTest.java │ │ ├── Log1Listener.java │ │ ├── Log2Listener.java │ │ └── LogEvent.java │ │ ├── i18n │ │ └── MessageTest.java │ │ ├── image │ │ ├── ImageCompositeTemplateTest.java │ │ ├── ImageCropTemplateTest.java │ │ ├── ImageInfoTemplateTest.java │ │ └── ImageResizeTemplateTest.java │ │ ├── image2 │ │ ├── ImageCompositeTemplateTest.java │ │ ├── ImageCropTemplateTest.java │ │ ├── ImageInfoTemplateTest.java │ │ └── ImageResizeTemplateTest.java │ │ ├── performance │ │ ├── PerformanceMonitorForEachMethodInterceptorTest.java │ │ ├── PerformanceMonitorForOneMethodInterceptorTest.java │ │ ├── biz │ │ │ └── TestBiz.java │ │ └── service │ │ │ └── TestService.java │ │ ├── support │ │ └── EncryptPropertyPlaceholderConfigurerTest.java │ │ └── util │ │ └── ApplicationContextUtilsTest.java │ └── resources │ ├── applicationContext-config.xml │ ├── applicationContext-service-codec.xml │ ├── applicationContext-service-config.xml │ ├── applicationContext-service-crypto.xml │ ├── applicationContext-service-event.xml │ ├── applicationContext-service-util.xml │ ├── chardet │ ├── applicationContext-service-chardet.xml │ └── test.txt │ ├── i18n │ ├── applicationContext-service-i18n.xml │ ├── test_en_US.properties │ └── test_zh_CN.properties │ ├── image │ ├── applicationContext-service-image.xml │ ├── go-home.png │ └── test.jpg │ ├── image2 │ ├── applicationContext-service-image.xml │ ├── go-home.png │ └── test.jpg │ ├── performance │ ├── applicationContext-service-performance-each.xml │ └── applicationContext-service-performance-one.xml │ └── support │ ├── applicationContext-service-support.xml │ └── test.properties ├── xultimate-core ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── danielli │ │ │ └── xultimate │ │ │ ├── core │ │ │ ├── ClassTypeSupporter.java │ │ │ ├── compression │ │ │ │ ├── Compressor.java │ │ │ │ ├── CompressorException.java │ │ │ │ ├── Decompressor.java │ │ │ │ ├── DecompressorException.java │ │ │ │ └── support │ │ │ │ │ ├── GZipCompressor.java │ │ │ │ │ ├── NullCompressor.java │ │ │ │ │ └── SnappyJavaCompressor.java │ │ │ ├── io │ │ │ │ ├── AbstractObjectInput.java │ │ │ │ ├── AbstractObjectOutput.java │ │ │ │ └── support │ │ │ │ │ ├── JavaObjectInput.java │ │ │ │ │ ├── JavaObjectOutput.java │ │ │ │ │ ├── RpcKryoObjectInput.java │ │ │ │ │ ├── RpcKryoObjectOutput.java │ │ │ │ │ ├── RpcProtobufObjectInput.java │ │ │ │ │ ├── RpcProtobufObjectOutput.java │ │ │ │ │ ├── RpcProtostuffObjectInput.java │ │ │ │ │ ├── RpcProtostuffObjectOutput.java │ │ │ │ │ ├── UnicodeInputStream.java │ │ │ │ │ └── UnicodeReader.java │ │ │ ├── json │ │ │ │ ├── JSONException.java │ │ │ │ ├── JSONTemplate.java │ │ │ │ ├── JsonUtils.java │ │ │ │ ├── ValueType.java │ │ │ │ ├── fastjson │ │ │ │ │ ├── FastJSONTemplate.java │ │ │ │ │ └── ValueTypeAdapter.java │ │ │ │ └── jackson │ │ │ │ │ ├── JacksonTemplate.java │ │ │ │ │ └── ValueTypeAdapter.java │ │ │ ├── serializer │ │ │ │ ├── AbstractClassTypeSupporterSerializer.java │ │ │ │ ├── ClassTypeSupporterSerializer.java │ │ │ │ ├── Deserializer.java │ │ │ │ ├── DeserializerException.java │ │ │ │ ├── RpcSerializer.java │ │ │ │ ├── Serializer.java │ │ │ │ ├── SerializerException.java │ │ │ │ ├── java │ │ │ │ │ ├── JavaObjectSerializer.java │ │ │ │ │ └── util │ │ │ │ │ │ └── SerializerUtils.java │ │ │ │ ├── kryo │ │ │ │ │ ├── KryoGenerator.java │ │ │ │ │ ├── RpcKryoSerializer.java │ │ │ │ │ └── support │ │ │ │ │ │ ├── DefaultKryoGenerator.java │ │ │ │ │ │ ├── KryoContext.java │ │ │ │ │ │ └── ThreadLocalKryoGenerator.java │ │ │ │ └── protostuff │ │ │ │ │ ├── RpcProtobufSerializer.java │ │ │ │ │ ├── RpcProtostuffSerializer.java │ │ │ │ │ ├── support │ │ │ │ │ └── ProtobufClassTypeNotSupporter.java │ │ │ │ │ └── util │ │ │ │ │ └── LinkedBufferUtils.java │ │ │ └── support │ │ │ │ ├── DefaultClassTypeNotSupporter.java │ │ │ │ └── DefaultClassTypeSupporter.java │ │ │ └── util │ │ │ ├── ArrayUtils.java │ │ │ ├── Assert.java │ │ │ ├── BooleanUtils.java │ │ │ ├── CharUtils.java │ │ │ ├── CharsetUtils.java │ │ │ ├── EnumUtils.java │ │ │ ├── StringUtils.java │ │ │ ├── builder │ │ │ ├── BuildType.java │ │ │ ├── Buildable.java │ │ │ ├── CompareToBuilderUtils.java │ │ │ ├── EqualsBuilderUtils.java │ │ │ ├── HashCodeBuilderUtils.java │ │ │ └── ToStringBuilderUtils.java │ │ │ ├── collections │ │ │ ├── CollectionUtils.java │ │ │ ├── ListBuilder.java │ │ │ ├── MapBuilder.java │ │ │ ├── MapUtils.java │ │ │ └── SetBuilder.java │ │ │ ├── crypto │ │ │ ├── AsymmetricAlgorithms.java │ │ │ ├── CipherUtils.java │ │ │ ├── CryptoException.java │ │ │ ├── DigestUtils.java │ │ │ ├── MessageDigestAlgorithms.java │ │ │ └── SymmetricAlgorithms.java │ │ │ ├── exception │ │ │ └── ExceptionUtils.java │ │ │ ├── io │ │ │ ├── FileUtils.java │ │ │ ├── FilenameUtils.java │ │ │ └── IOUtils.java │ │ │ ├── math │ │ │ ├── NumberUtils.java │ │ │ └── RandomNumberUtils.java │ │ │ ├── performance │ │ │ └── PerformanceMonitor.java │ │ │ ├── pinyin │ │ │ ├── PinyinCallback.java │ │ │ └── PinyinUtils.java │ │ │ ├── reflect │ │ │ ├── AnnotationUtils.java │ │ │ ├── BeanUtils.java │ │ │ └── ClassUtils.java │ │ │ ├── thread │ │ │ └── ThreadUtils.java │ │ │ └── time │ │ │ ├── ChineseCalendarGB.java │ │ │ ├── DateUtils.java │ │ │ ├── DurationFormatUtils.java │ │ │ └── stopwatch │ │ │ ├── StopWatch.java │ │ │ ├── StopWatchContext.java │ │ │ ├── StopWatchState.java │ │ │ ├── StopWatchSummary.java │ │ │ └── support │ │ │ ├── AbstractStopWatchSummary.java │ │ │ ├── AdvancedStopWatchSummary.java │ │ │ ├── DefaultStopWatchSummary.java │ │ │ └── SimpleStopWatchSummary.java │ └── resources │ │ ├── log4j2.sync.xml │ │ ├── log4j2.xml │ │ ├── logback.xml │ │ └── org │ │ └── ocpsoft │ │ └── prettytime │ │ └── i18n │ │ └── Resources_zh_CN.properties │ └── test │ ├── java │ └── org │ │ └── danielli │ │ └── xultimate │ │ ├── DateTimeTest.java │ │ ├── PrettyTimeTest.java │ │ ├── ProxyTest.java │ │ ├── SiftingAppenderTest.java │ │ ├── core │ │ ├── compression │ │ │ └── CompressorTest.java │ │ ├── json │ │ │ └── JSONTemplateTest.java │ │ └── serializer │ │ │ ├── JavaSerializingTest.java │ │ │ ├── KryoSerializingTest.java │ │ │ ├── ProtobufSerializingTest.java │ │ │ ├── ProtostuffSerializingTest.java │ │ │ ├── SerializerTest.java │ │ │ ├── User.java │ │ │ ├── kryo │ │ │ └── LocalKryoSerializer.java │ │ │ ├── protostuff │ │ │ ├── LocalProtobufSerializer.java │ │ │ └── LocalProtostuffSerializer.java │ │ │ └── support │ │ │ ├── BaseTypeDeserializer.java │ │ │ ├── BaseTypeSerializer.java │ │ │ ├── DeserializerFactory.java │ │ │ └── SerializerFactory.java │ │ └── util │ │ ├── builder │ │ ├── CompareToBuilderUtilsTest.java │ │ ├── Employee.java │ │ ├── EqualsBuilderUtilsTest.java │ │ ├── HashCodeBuilderUtilsTest.java │ │ ├── Manager.java │ │ ├── Person.java │ │ └── ToStringBuilderUtilsTest.java │ │ ├── crypto │ │ ├── CipherUtilsTest.java │ │ └── DigestUtilsTest.java │ │ ├── math │ │ └── NumberUtilsTest.java │ │ ├── performance │ │ └── PerformanceMonitorTest.java │ │ ├── pinyin │ │ └── PinyinUtilsTest.java │ │ ├── reflect │ │ ├── BeanUtilsTest.java │ │ └── ReflectTest.java │ │ └── time │ │ ├── ChineseCalendarGBTest.java │ │ └── StopWatchTest.java │ └── resources │ ├── applicationContext-service-compression.xml │ ├── applicationContext-service-json.xml │ ├── applicationContext-service-serializer.xml │ └── source ├── xultimate-jdbc ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── danielli │ │ │ └── xultimate │ │ │ ├── jdbc │ │ │ ├── datasource │ │ │ │ └── lookup │ │ │ │ │ ├── DataSourceContext.java │ │ │ │ │ ├── RoutingDataSource.java │ │ │ │ │ └── RoutingProxyDataSourceFactoryBean.java │ │ │ ├── support │ │ │ │ └── incrementer │ │ │ │ │ ├── AbstractDataFieldMaxValueIncrementer.java │ │ │ │ │ ├── AbstractKeyMaxValueIncrementer.java │ │ │ │ │ ├── AbstractSequenceMaxValueIncrementer.java │ │ │ │ │ ├── H2SequenceMaxValueIncrementer.java │ │ │ │ │ ├── MySQLMaxValueIncrementer.java │ │ │ │ │ └── OracleSequenceMaxValueIncrementer.java │ │ │ └── type │ │ │ │ ├── CodeEnum.java │ │ │ │ ├── CodeEnums.java │ │ │ │ └── StateSet.java │ │ │ └── transaction │ │ │ ├── ChainedTransactionManager.java │ │ │ ├── MultiTransactionStatus.java │ │ │ ├── RoutingDataSourceTransactionManager.java │ │ │ ├── SpringTransactionSynchronizationManager.java │ │ │ └── SynchronizationManager.java │ └── webapp │ │ └── WEB-INF │ │ └── web.xml │ └── test │ ├── java │ └── org │ │ └── danielli │ │ └── xultimate │ │ ├── jdbc │ │ ├── DataSourceTest.java │ │ ├── support │ │ │ └── incrementer │ │ │ │ └── DataFieldMaxValueIncrementerTest.java │ │ └── type │ │ │ └── StateSetTest.java │ │ └── transaction │ │ ├── ChainedTransactionManagerTest.java │ │ ├── biz │ │ ├── OtherBiz.java │ │ ├── UserBiz.java │ │ └── impl │ │ │ ├── OtherBizImpl.java │ │ │ └── UserBizImpl.java │ │ ├── dao │ │ ├── OtherDAO.java │ │ ├── UserDAO.java │ │ └── impl │ │ │ ├── OtherDAOImpl.java │ │ │ └── UserDAOImpl.java │ │ └── service │ │ ├── UserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ ├── applicationContext-dao-base.xml │ ├── applicationContext-dao-datasource.xml │ ├── applicationContext-service-config.xml │ ├── applicationContext-service-crypto.xml │ ├── primaryKey │ ├── applicationContext-dao-primaryKey.xml │ ├── databases.properties │ ├── primary_key_1_destroy.sql │ ├── primary_key_1_init.sql │ ├── primary_key_2_destroy.sql │ └── primary_key_2_init.sql │ └── transaction │ ├── applicationContext-service-transaction.xml │ ├── other_destroy.sql │ ├── other_init.sql │ ├── user_destroy.sql │ └── user_init.sql ├── xultimate-orm ├── pom.xml ├── xultimate-hibernate │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── danielli │ │ │ │ └── xultimate │ │ │ │ └── orm │ │ │ │ └── jpa │ │ │ │ ├── DefaultGenericBiz.java │ │ │ │ ├── GenericBiz.java │ │ │ │ ├── GenericDAO.java │ │ │ │ ├── config │ │ │ │ ├── DatabaseNamingStrategy.java │ │ │ │ ├── DatabaseNamingStrategyModel.java │ │ │ │ ├── ProxyInitializer.java │ │ │ │ ├── SessionCallback.java │ │ │ │ ├── SessionFactoryUtils.java │ │ │ │ └── support │ │ │ │ │ └── HibernateProxyInitializer.java │ │ │ │ ├── ds │ │ │ │ ├── ComparsionOperator.java │ │ │ │ ├── Item.java │ │ │ │ ├── ItemsSpecification.java │ │ │ │ ├── LogicalOperator.java │ │ │ │ ├── Value.java │ │ │ │ ├── ValueUtils.java │ │ │ │ └── support │ │ │ │ │ ├── GenericValue.java │ │ │ │ │ ├── Pair.java │ │ │ │ │ └── StringValue.java │ │ │ │ └── id │ │ │ │ ├── DateEntity.java │ │ │ │ ├── IDEntity.java │ │ │ │ ├── NormsEntity.java │ │ │ │ ├── NormsListener.java │ │ │ │ └── VersionEntity.java │ │ └── webapp │ │ │ └── WEB-INF │ │ │ └── web.xml │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── danielli │ │ │ └── xultimate │ │ │ └── orm │ │ │ └── jpa │ │ │ ├── BaseEntity.java │ │ │ ├── area │ │ │ ├── AreaServiceImplTest.java │ │ │ ├── biz │ │ │ │ ├── AreaBiz.java │ │ │ │ └── impl │ │ │ │ │ └── AreaBizImpl.java │ │ │ ├── dao │ │ │ │ ├── AreaDAO.java │ │ │ │ ├── AreaDAOExt.java │ │ │ │ └── AreaDAOImpl.java │ │ │ ├── domain │ │ │ │ ├── Area.java │ │ │ │ └── AreaEntityListener.java │ │ │ └── service │ │ │ │ ├── AreaService.java │ │ │ │ └── impl │ │ │ │ └── AreaServiceImpl.java │ │ │ └── cache │ │ │ ├── CacheUsage.java │ │ │ └── domain │ │ │ ├── Address.java │ │ │ └── Person.java │ │ └── resources │ │ ├── README │ │ ├── applicationContext-dao-base.xml │ │ ├── applicationContext-dao-generic.xml │ │ ├── applicationContext-service-config.xml │ │ ├── applicationContext-service-crypto.xml │ │ ├── applicationContext-service-generic.xml │ │ ├── applicationContext-service-util.xml │ │ ├── databases.properties │ │ └── orm.properties └── xultimate-mybatis │ ├── pom.xml │ └── src │ ├── main │ └── java │ │ └── org │ │ └── danielli │ │ └── xultimate │ │ └── orm │ │ └── mybatis │ │ ├── MyBatisRepository.java │ │ ├── SqlSessionFactoryBean.java │ │ ├── ds │ │ ├── ComparsionOperator.java │ │ ├── Item.java │ │ ├── LogicalOperator.java │ │ ├── Value.java │ │ ├── ValueUtils.java │ │ └── support │ │ │ ├── GenericValue.java │ │ │ ├── Pair.java │ │ │ └── StringValue.java │ │ └── type │ │ ├── AbstractNullParameterTypeHandler.java │ │ ├── BigDecimalTypeHandler.java │ │ ├── BooleanTypeHandler.java │ │ ├── ClobNullParameterTypeHandler.java │ │ ├── CodeEnumOrdinalTypeHandler.java │ │ ├── IntegerNullParameterTypeHandler.java │ │ ├── LongNullParameterTypeHandler.java │ │ ├── ReverseStringNullParameterTypeHandler.java │ │ ├── StateSetTypeHandler.java │ │ └── StringNullParameterTypeHandler.java │ └── test │ ├── java │ └── org │ │ └── danielli │ │ └── xultimate │ │ └── orm │ │ └── mybatis │ │ ├── area │ │ ├── AreaServiceImplTest.java │ │ ├── PerformanceTest.java │ │ ├── biz │ │ │ ├── AreaBiz.java │ │ │ └── impl │ │ │ │ └── AreaBizImpl.java │ │ ├── dao │ │ │ └── AreaDAO.java │ │ └── service │ │ │ ├── AreaService.java │ │ │ └── impl │ │ │ └── AreaServiceImpl.java │ │ ├── po │ │ ├── Area.java │ │ ├── TestPo.java │ │ └── e │ │ │ ├── Sex.java │ │ │ └── TestEnum.java │ │ └── type │ │ ├── NetworkUtils.java │ │ ├── TestPoServiceTest.java │ │ ├── biz │ │ ├── TestPoBiz.java │ │ └── impl │ │ │ └── TestPoBizImpl.java │ │ ├── dao │ │ └── TestPoDAO.java │ │ └── service │ │ ├── TestPoService.java │ │ └── impl │ │ └── TestPoServiceImpl.java │ └── resources │ ├── README │ ├── applicationContext-dao-base.xml │ ├── applicationContext-dao-generic.xml │ ├── applicationContext-dao-generic.xml.bak │ ├── applicationContext-service-config.xml │ ├── applicationContext-service-crypto.xml │ ├── applicationContext-service-generic.xml │ ├── databases.properties │ ├── mybatis │ ├── AreaDAO.xml │ ├── TestPoDAO.xml │ └── mybatis-3-mapper.dtd │ └── mybatis_init.sql ├── xultimate-shard ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── danielli │ │ │ └── xultimate │ │ │ └── shard │ │ │ ├── Action.java │ │ │ ├── Filter.java │ │ │ ├── Operator.java │ │ │ ├── ShardInfoGenerator.java │ │ │ ├── ShardUtils.java │ │ │ ├── dto │ │ │ └── ShardInfo.java │ │ │ ├── mybatis │ │ │ ├── MyBatisShardInfoGenerator.java │ │ │ ├── biz │ │ │ │ ├── PartitionedTableIntervalBiz.java │ │ │ │ ├── VirtualSocketBindRecordBiz.java │ │ │ │ ├── VirtualTableBiz.java │ │ │ │ ├── VirtualTableIntervalBiz.java │ │ │ │ └── impl │ │ │ │ │ ├── PartitionedTableIntervalBizImpl.java │ │ │ │ │ ├── VirtualSocketBindRecordBizImpl.java │ │ │ │ │ ├── VirtualTableBizImpl.java │ │ │ │ │ └── VirtualTableIntervalBizImpl.java │ │ │ └── dao │ │ │ │ ├── PartitionedTableIntervalDAO.java │ │ │ │ ├── VirtualSocketBindRecordDAO.java │ │ │ │ ├── VirtualTableDAO.java │ │ │ │ └── VirtualTableIntervalDAO.java │ │ │ └── po │ │ │ ├── PartitionedTable.java │ │ │ ├── PartitionedTableInterval.java │ │ │ ├── VirtualDatabase.java │ │ │ ├── VirtualSocket.java │ │ │ ├── VirtualSocketBindRecord.java │ │ │ ├── VirtualTable.java │ │ │ └── VirtualTableInterval.java │ └── resources │ │ └── mybatis │ │ ├── PartitionedTableDAO.xml │ │ ├── PartitionedTableIntervalDAO.xml │ │ ├── VirtualSocketBindRecordDAO.xml │ │ ├── VirtualSocketDAO.xml │ │ ├── VirtualTableDAO.xml │ │ ├── VirtualTableIntervalDAO.xml │ │ └── mybatis-3-mapper.dtd │ └── test │ ├── java │ └── org │ │ └── danielli │ │ └── xultimate │ │ └── shard │ │ └── ShardInfoGeneratorTest.java │ └── resources │ ├── applicationContext-dao-base.xml │ ├── applicationContext-service-config.xml │ ├── applicationContext-service-crypto.xml │ ├── primaryKey │ ├── applicationContext-dao-primaryKey.xml │ ├── databases.properties │ ├── primary_key_1_destroy.sql │ └── primary_key_1_init.sql │ └── shard │ ├── applicationContext-dao-generic.xml │ ├── applicationContext-dao-shard.xml │ ├── applicationContext-service-generic.xml │ ├── applicationContext-service-memcached.xml │ ├── applicationContext-service-serializer.xml │ ├── databases.properties │ └── shard_db_init.sql ├── xultimate-test ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── danielli │ │ │ └── xultimate │ │ │ └── test │ │ │ ├── vo │ │ │ └── User.java │ │ │ └── web │ │ │ ├── controller │ │ │ ├── AnalysisController.java │ │ │ └── UserController.java │ │ │ └── converter │ │ │ └── UserConverter.java │ ├── resources │ │ ├── applicationContext-service-i18n.xml │ │ ├── applicationContext-service-util.xml │ │ ├── applicationContext-servlet.xml │ │ ├── shell │ │ │ └── mysql │ │ │ │ ├── analyze.sh │ │ │ │ └── collect.sh │ │ └── test_zh_CN.properties │ └── webapp │ │ ├── META-INF │ │ └── context.xml │ │ ├── WEB-INF │ │ ├── template │ │ │ ├── error │ │ │ │ └── throwable.httl │ │ │ └── httl │ │ │ │ ├── analysis │ │ │ │ ├── mysql_status.httl │ │ │ │ └── tprofiler_topmethod.httl │ │ │ │ ├── error.httl │ │ │ │ ├── param1.httl │ │ │ │ ├── param2.httl │ │ │ │ ├── param2_error.httl │ │ │ │ └── test1.httl │ │ └── web.xml │ │ └── resources │ │ ├── highcharts │ │ ├── exporting.js │ │ └── highcharts.js │ │ └── js │ │ ├── jquery-2.0.3.js │ │ └── jquery.form.js │ └── test │ ├── java │ ├── CharTest.java │ └── org │ │ └── danielli │ │ └── xultimate │ │ ├── test │ │ ├── custom │ │ │ ├── CharacterTest.java │ │ │ ├── ErrorTest.java │ │ │ ├── IntegerDecodeTest.java │ │ │ ├── RuntimeConstantPoolOOMTest.java │ │ │ ├── audition │ │ │ │ ├── Count.java │ │ │ │ ├── QuickSort.java │ │ │ │ ├── ThreadIncDec.java │ │ │ │ └── ThreadReadWrite.java │ │ │ └── cglib │ │ │ │ ├── Action.java │ │ │ │ ├── CglibClass.java │ │ │ │ ├── CglibInterface.java │ │ │ │ ├── callback │ │ │ │ ├── DefaultActionInvocationHandler.java │ │ │ │ └── DefaultActionMethodInterceptor.java │ │ │ │ └── support │ │ │ │ └── DefaultAction.java │ │ ├── io │ │ │ ├── aio │ │ │ │ ├── Client.java │ │ │ │ ├── ClientWithHandler.java │ │ │ │ ├── Server.java │ │ │ │ └── ServerWithHandler.java │ │ │ └── nio │ │ │ │ ├── Client.java │ │ │ │ └── Server.java │ │ ├── jvm │ │ │ ├── chapter2 │ │ │ │ ├── DirectMemoryOOM.java │ │ │ │ ├── HeapOOM.java │ │ │ │ ├── JavaMethodAreaOOM.java │ │ │ │ ├── JavaVMStackOOM.java │ │ │ │ ├── JavaVMStackSOF.java │ │ │ │ ├── RuntimeConstantPoolOOM.java │ │ │ │ └── RuntimeConstantPoolOOM1.java │ │ │ ├── chapter3 │ │ │ │ ├── FinalizeEscapeGC.java │ │ │ │ ├── GCSample1.java │ │ │ │ ├── GCSample2.java │ │ │ │ ├── GCSample3.java │ │ │ │ ├── GCSample4.java │ │ │ │ ├── GCSample5.java │ │ │ │ └── ReferenceCountingGC.java │ │ │ ├── chapter4 │ │ │ │ ├── JConsoleSample1.java │ │ │ │ ├── JConsoleSample2.java │ │ │ │ └── JConsoleSample3.java │ │ │ └── chapter8 │ │ │ │ └── ClassLoaderTest.java │ │ └── thread │ │ │ ├── CountDownLatchCase.java │ │ │ ├── CyclicBarrierCase.java │ │ │ ├── ExchangerCase.java │ │ │ ├── LongCase.java │ │ │ ├── SemaphoreCase.java │ │ │ ├── SynchronousQueueCase.java │ │ │ ├── VolatileCase.java │ │ │ ├── atom │ │ │ └── AtomicInteger.java │ │ │ ├── disruptor │ │ │ ├── LongEvent.java │ │ │ ├── LongEventCase.java │ │ │ ├── LongEventFactory.java │ │ │ ├── LongEventHandler.java │ │ │ ├── LongEventProducer.java │ │ │ └── LongEventProducerWithTranslator.java │ │ │ ├── forkjoin │ │ │ ├── CalculatorTest.java │ │ │ └── SortTaskTest.java │ │ │ └── linkedhashmap │ │ │ └── ConcurrentLinkedHashMapTest.java │ │ └── testexample │ │ ├── UserControllerTest.java │ │ ├── junit │ │ ├── GroupTest.java │ │ └── support │ │ │ ├── ConstructorTest.java │ │ │ ├── ExampleTest.java │ │ │ └── ExceptionTest.java │ │ └── mock │ │ └── support │ │ ├── User.java │ │ ├── UserService.java │ │ ├── UserServiceImpl.java │ │ └── UserServiceMockTest.java │ └── resources │ ├── lock │ └── README │ └── threadpool │ └── README ├── xultimate-web ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── danielli │ │ │ └── xultimate │ │ │ ├── context │ │ │ └── config │ │ │ │ └── StringToFileArrayPropertyEditor.java │ │ │ ├── util │ │ │ └── io │ │ │ │ └── ResourceUtils.java │ │ │ └── web │ │ │ ├── context │ │ │ └── response │ │ │ │ ├── GzipResponseStream.java │ │ │ │ └── GzipResponseWrapper.java │ │ │ ├── filter │ │ │ └── GzipCompressFilter.java │ │ │ ├── listener │ │ │ └── LoggerHostListener.java │ │ │ └── util │ │ │ ├── BrowserCacheGenerator.java │ │ │ ├── CookieGenerator.java │ │ │ ├── HtmlUtils.java │ │ │ ├── MobileChecker.java │ │ │ ├── NetworkUtils.java │ │ │ ├── PasswordCallback.java │ │ │ ├── PropertyCallback.java │ │ │ ├── RememberMeService.java │ │ │ ├── ServletRequestUtils.java │ │ │ ├── ShortURLGenerator.java │ │ │ └── WebUtils.java │ └── webapp │ │ └── WEB-INF │ │ └── web.xml │ └── test │ ├── java │ └── org │ │ └── danielli │ │ └── xultimate │ │ └── web │ │ └── RestTemplateTest.java │ └── resources │ ├── applicationContext-web-cache.xml │ ├── applicationContext-web-cookie.xml │ ├── applicationContext-web-rememberme.xml │ ├── applicationContext-web-rest.xml │ └── cookie.properties └── xultimate-webmvc ├── pom.xml └── src └── main └── java └── org └── danielli └── xultimate └── web ├── filter ├── BrowseLimiterFilter.java └── BrowserCacheFilter.java └── servlet ├── i18n └── RequestContextInterceptor.java └── view └── httl └── HttlViewResolver.java /.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | .project 3 | .classpath 4 | 5 | .idea 6 | *.ipr 7 | *.iml 8 | *.iws 9 | 10 | .DS_Store 11 | Thumbs.db 12 | 13 | *.class 14 | 15 | target 16 | 17 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/dfs/DistributedFileSystemException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.dfs; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 分布式文件系统异常。 7 | * 8 | * @author Daniel Li 9 | * @since 19 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class DistributedFileSystemException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = -5363328862858087052L; 15 | 16 | public DistributedFileSystemException(String message) { 17 | super(message); 18 | } 19 | 20 | public DistributedFileSystemException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/dfs/fastdfs/support/ClientGlobalInitializer.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.dfs.fastdfs.support; 2 | 3 | import org.csource.fastdfs.ClientGlobal; 4 | import org.springframework.beans.factory.InitializingBean; 5 | import org.springframework.core.io.Resource; 6 | 7 | /** 8 | * 客户端配置初始化器。 9 | * 10 | * @author Daniel Li 11 | * @since 19 Jun 2013 12 | */ 13 | public class ClientGlobalInitializer implements InitializingBean { 14 | 15 | private Resource configResource; 16 | 17 | /** 18 | * 设置客户端配置资源。 19 | * 20 | * @param configResource 客户端配置资源。 21 | */ 22 | public void setConfigResource(Resource configResource) { 23 | this.configResource = configResource; 24 | } 25 | 26 | /** 27 | * 初始化配置信息。 28 | */ 29 | @Override 30 | public void afterPropertiesSet() throws Exception { 31 | ClientGlobal.init(configResource.getFile().getAbsolutePath()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/format/FormatException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.format; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 格式化异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class FormatException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = 2303266621170729888L; 15 | 16 | public FormatException(String message) { 17 | super(message); 18 | } 19 | 20 | public FormatException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/format/Formatter.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.format; 2 | 3 | /** 4 | * 格式化器。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | * 9 | * @param 原始源。 10 | * @param

源始源参数。 11 | * @param 目标源。 12 | */ 13 | public interface Formatter { 14 | 15 | /** 16 | * 格式化。 17 | * 18 | * @param source 原始源。 19 | * @param parameter 源始源参数。 20 | * @return 目标源。 21 | * @throws FormatException 格式化异常,会对格式化过程中出现的异常封装并抛出。 22 | */ 23 | T format(S source, P parameter) throws FormatException; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/format/FormatterUtils.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.format; 2 | 3 | import org.danielli.xultimate.context.format.support.MessageFormatter; 4 | 5 | /** 6 | * 格式化工具类。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | */ 11 | public class FormatterUtils { 12 | 13 | /** 14 | * 格式化。 15 | * 16 | * @param source 原始源。 17 | * @param parameter 源始源参数。 18 | * @return 目标源。 19 | * @throws FormatException 格式化异常,会对格式化过程中出现的异常封装并抛出。 20 | */ 21 | public static String format(String source, Object... parameter) throws FormatException { 22 | return MessageFormatter.FORMATTER.format(source, parameter); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/format/support/MessageFormatter.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.format.support; 2 | 3 | import java.text.MessageFormat; 4 | 5 | import org.danielli.xultimate.context.format.FormatException; 6 | import org.danielli.xultimate.context.format.Formatter; 7 | 8 | /** 9 | * 格式化器。是{@link MessageFormat}的实现。 10 | * 11 | * @author Daniel Li 12 | * @since 18 Jun 2013 13 | * @see Formatter 14 | * @see MessageFormat 15 | */ 16 | public class MessageFormatter implements Formatter { 17 | 18 | public static final MessageFormatter FORMATTER = new MessageFormatter(); 19 | 20 | private MessageFormatter() { 21 | } 22 | 23 | @Override 24 | public String format(String source, Object[] parameter) throws FormatException { 25 | try { 26 | return MessageFormat.format(source, parameter); 27 | } catch (Exception e) { 28 | throw new FormatException(e.getMessage(), e); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/format/support/StringTemplateV3Formatter.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.format.support; 2 | 3 | import java.util.Map; 4 | 5 | import org.antlr.stringtemplate.StringTemplate; 6 | import org.danielli.xultimate.context.format.FormatException; 7 | import org.danielli.xultimate.context.format.Formatter; 8 | import org.danielli.xultimate.ui.stringtemplate.v3.StringTemplateUtils; 9 | 10 | /** 11 | * 格式化器。是StringTemplate 3.x版本的实现。 12 | * 13 | * @author Daniel Li 14 | * @since 18 Jun 2013 15 | * @see Formatter 16 | */ 17 | public class StringTemplateV3Formatter implements Formatter, String> { 18 | 19 | @Override 20 | public String format(String source, Map parameter) throws FormatException { 21 | StringTemplate template = new StringTemplate(source); 22 | return StringTemplateUtils.processTemplateIntoString(template, parameter); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/format/support/StringTemplateV4Formatter.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.format.support; 2 | 3 | import java.util.Map; 4 | 5 | import org.danielli.xultimate.context.format.FormatException; 6 | import org.danielli.xultimate.context.format.Formatter; 7 | import org.danielli.xultimate.ui.stringtemplate.v4.StringTemplateUtils; 8 | import org.stringtemplate.v4.ST; 9 | 10 | /** 11 | * 格式化器。是StringTemplate 4.x版本的实现。 12 | * 13 | * @author Daniel Li 14 | * @since 18 Jun 2013 15 | * @see Formatter 16 | */ 17 | public class StringTemplateV4Formatter implements Formatter, String> { 18 | 19 | @Override 20 | public String format(String source, Map parameter) throws FormatException { 21 | ST template = new ST(source); 22 | return StringTemplateUtils.processTemplateIntoString(template, parameter); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/AbstractKeyValueStoreTemplate.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore; 2 | 3 | /** 4 | * 抽象K/V存储模板类。主要提供异常处理功能。 5 | * 6 | * @author Daniel Li 7 | * @since 19 Jun 2013 8 | */ 9 | public abstract class AbstractKeyValueStoreTemplate { 10 | 11 | /** 12 | * 处理异常。 13 | * 14 | * @param e 异常。 15 | */ 16 | protected abstract void handleException(KeyValueStoreException e); 17 | 18 | /** 19 | * 包装异常。 20 | * @param e 实际异常。 21 | * @return 包装后的异常。 22 | */ 23 | protected abstract KeyValueStoreException wrapperException(Exception e); 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/KeyValueStoreException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * K/V存储异常。 7 | * 8 | * @author Daniel Li 9 | * @since 19 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public abstract class KeyValueStoreException extends NestedRuntimeException { 13 | private static final long serialVersionUID = -5363328862858087052L; 14 | 15 | public KeyValueStoreException(String message) { 16 | super(message); 17 | } 18 | 19 | public KeyValueStoreException(String message, Throwable cause) { 20 | super(message, cause); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/db/KeyValueIterator.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.db; 2 | 3 | import java.util.Iterator; 4 | 5 | /** 6 | * K/V迭代器。 7 | * 8 | * @author Daniel Li 9 | * @since 13 September 2015 10 | */ 11 | public interface KeyValueIterator extends Iterator> { 12 | 13 | void close(); 14 | 15 | /** 16 | * K/V元素。 17 | * 18 | * @author Daniel Li 19 | * @since 13 September 2015 20 | */ 21 | public class Entry { 22 | 23 | private final K key; 24 | private final V value; 25 | 26 | public Entry(K key, V value) { 27 | this.key = key; 28 | this.value = value; 29 | } 30 | 31 | public K getKey() { 32 | return this.key; 33 | } 34 | 35 | public V getValue() { 36 | return this.value; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/db/KeyValueStore.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.db; 2 | 3 | import org.danielli.xultimate.context.kvStore.KeyValueStoreException; 4 | 5 | import java.util.Comparator; 6 | import java.util.List; 7 | 8 | /** 9 | * K/V存储。 10 | * 11 | * @author Daniel Li 12 | * @since 13 September 2015 13 | */ 14 | public interface KeyValueStore { 15 | 16 | V get(K key) throws KeyValueStoreException; 17 | 18 | void put(K key, V value) throws KeyValueStoreException; 19 | 20 | void putAll(List> entries) throws KeyValueStoreException; 21 | 22 | void remove(K key) throws KeyValueStoreException; 23 | 24 | KeyValueIterator range(K from, K to, Comparator comparator); 25 | 26 | KeyValueIterator all(); 27 | 28 | void close(); 29 | 30 | void flush() throws KeyValueStoreException; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/db/KeyValueStoreException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.db; 2 | 3 | /** 4 | * K/V存储异常。 5 | * 6 | * @author Daniel Li 7 | * @since 13 September 2015 8 | */ 9 | public class KeyValueStoreException extends RuntimeException { 10 | 11 | public KeyValueStoreException(Throwable cause) { 12 | super(cause); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/db/serializer/Serializer.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.db.serializer; 2 | 3 | /** 4 | * 序列化器。 5 | * 6 | * @author Daniel Li 7 | * @since 13 September 2015 8 | */ 9 | public interface Serializer { 10 | 11 | byte[] serialize(T value); 12 | 13 | T deserializer(byte[] bytes); 14 | } 15 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/memcached/AbstractMemcachedTemplate.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.memcached; 2 | 3 | import org.danielli.xultimate.context.kvStore.AbstractKeyValueStoreTemplate; 4 | import org.danielli.xultimate.context.kvStore.KeyValueStoreException; 5 | 6 | /** 7 | * 抽象Memcached模板类。主要提供异常记录功能。 8 | * 9 | * @author Daniel Li 10 | * @since 19 Jun 2013 11 | */ 12 | public abstract class AbstractMemcachedTemplate extends AbstractKeyValueStoreTemplate { 13 | 14 | /** 15 | * 抛出异常。 16 | */ 17 | @Override 18 | protected void handleException(KeyValueStoreException e) { 19 | throw e; 20 | } 21 | 22 | @Override 23 | protected MemcachedException wrapperException(Exception e) { 24 | if (e instanceof MemcachedException) { 25 | return (MemcachedException) e; 26 | } 27 | return new MemcachedException(e.getMessage(), e); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/memcached/MemcachedException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.memcached; 2 | 3 | import org.danielli.xultimate.context.kvStore.KeyValueStoreException; 4 | 5 | /** 6 | * Memcached异常。 7 | * 8 | * @author Daniel Li 9 | * @since 19 Jun 2013 10 | * @see KeyValueStoreException 11 | */ 12 | public class MemcachedException extends KeyValueStoreException { 13 | 14 | private static final long serialVersionUID = 1723710559096203019L; 15 | 16 | public MemcachedException(String message) { 17 | super(message); 18 | } 19 | 20 | public MemcachedException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/memcached/xmemcached/callback/XMemcachedClientCallback.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.memcached.xmemcached.callback; 2 | 3 | import org.danielli.xultimate.context.kvStore.memcached.xmemcached.XMemcachedClient; 4 | 5 | 6 | /** 7 | * XMemcached回调。 8 | * 9 | * @author Daniel Li 10 | * @since 19 Jun 2013 11 | * 12 | * @param 回调返回值。 13 | */ 14 | public interface XMemcachedClientCallback { 15 | 16 | /** 17 | * 回调实现。 18 | * 19 | * @param xMemcachedClient XMemcached客户端。 20 | * @return 回调返回值。 21 | * @exception Exception 任何可能出现的异常。 22 | */ 23 | T doInXMemcached(XMemcachedClient xMemcachedClient) throws Exception; 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/redis/AbstractRedisTemplate.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.redis; 2 | 3 | import org.danielli.xultimate.context.kvStore.AbstractKeyValueStoreTemplate; 4 | import org.danielli.xultimate.context.kvStore.KeyValueStoreException; 5 | 6 | /** 7 | * 抽象Redis模板类。主要提供异常记录功能。 8 | * 9 | * @author Daniel Li 10 | * @since 19 Jun 2013 11 | */ 12 | public abstract class AbstractRedisTemplate extends AbstractKeyValueStoreTemplate { 13 | 14 | /** 15 | * 抛出异常。 16 | */ 17 | @Override 18 | protected void handleException(KeyValueStoreException e) throws RedisException { 19 | throw e; 20 | } 21 | 22 | @Override 23 | protected RedisException wrapperException(Exception e) { 24 | if (e instanceof RedisException) { 25 | return (RedisException) e; 26 | } 27 | return new RedisException(e.getMessage(), e); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/redis/RedisException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.redis; 2 | 3 | import org.danielli.xultimate.context.kvStore.KeyValueStoreException; 4 | 5 | /** 6 | * Redis异常。 7 | * 8 | * @author Daniel Li 9 | * @since 19 Jun 2013 10 | * @see KeyValueStoreException 11 | */ 12 | public class RedisException extends KeyValueStoreException { 13 | 14 | private static final long serialVersionUID = 1723710559096203019L; 15 | 16 | public RedisException(String message) { 17 | super(message); 18 | } 19 | 20 | public RedisException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/redis/jedis/JedisCallback.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.redis.jedis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | 5 | /** 6 | * Jedis回调。 7 | * 8 | * @author Daniel Li 9 | * @since 19 Jun 2013 10 | * 11 | * @param 回调返回值。 12 | */ 13 | public interface JedisCallback { 14 | 15 | /** 16 | * 回调实现。 17 | * 18 | * @param jedis Jedis客户端。 19 | * @return 回调返回值。 20 | * @exception Exception 任何可能出现的异常。 21 | */ 22 | T doInJedis(Jedis jedis) throws Exception; 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/redis/jedis/ShardedJedisCallback.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.redis.jedis; 2 | 3 | import redis.clients.jedis.ShardedJedis; 4 | 5 | /** 6 | * ShardedJedis回调。 7 | * 8 | * @author Daniel Li 9 | * @since 19 Jun 2013 10 | * 11 | * @param 回调返回值。 12 | */ 13 | public interface ShardedJedisCallback { 14 | 15 | /** 16 | * 回调实现。 17 | * 18 | * @param shardedJedis Jedis客户端。 19 | * @return 回调返回值。 20 | * @exception Exception 任何可能出现的异常。 21 | */ 22 | T doInShardedJedis(ShardedJedis shardedJedis) throws Exception; 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/context/kvStore/redis/jedis/util/JedisPoolUtils.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.redis.jedis.util; 2 | 3 | import org.danielli.xultimate.context.kvStore.redis.jedis.JedisCallback; 4 | import org.danielli.xultimate.context.kvStore.redis.jedis.JedisCallback; 5 | 6 | import redis.clients.jedis.Jedis; 7 | import redis.clients.jedis.JedisPool; 8 | 9 | /** 10 | * JedisPool工具类。 11 | * 12 | * @author Daniel Li 13 | * @since 19 Jun 2013 14 | */ 15 | public class JedisPoolUtils { 16 | 17 | /** 18 | * 执行回调。 19 | * 20 | * @param jedisPool Jedis客户端。 21 | * @param jedisReturnedCallback 回调。 22 | * @return 回调返回值。 23 | * @exception Exception 任何可能出现的异常。 24 | */ 25 | public static T execute(JedisPool jedisPool, JedisCallback jedisReturnedCallback) throws Exception { 26 | Jedis jedis = null; 27 | try { 28 | jedis = jedisPool.getResource(); 29 | return jedisReturnedCallback.doInJedis(jedis); 30 | } finally{ 31 | if (jedis != null) { 32 | jedisPool.returnResource(jedis); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/ui/httl/HTTLEngineUtils.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.ui.httl; 2 | 3 | import httl.Template; 4 | 5 | import java.text.ParseException; 6 | import java.util.Map; 7 | 8 | /** 9 | * Utility class for working with a HTTL Engine. 10 | * Provides convenience methods to merge a HTTL template with a model. 11 | * 12 | * @author Daniel Li 13 | * @since 18 Jun 2013 14 | */ 15 | public class HTTLEngineUtils { 16 | 17 | /** 18 | * Merge the specified HTTL template with the given model into a String. 19 | * @see org.springframework.mail.MailPreparationException 20 | */ 21 | public static String processTemplateIntoString(Template template, Map model) throws ParseException { 22 | return (String) template.evaluate(model); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/ui/stringtemplate/v3/StringTemplateUtils.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.ui.stringtemplate.v3; 2 | 3 | import java.util.Map; 4 | 5 | import org.antlr.stringtemplate.StringTemplate; 6 | 7 | /** 8 | * StringTemplate V3模板处理工具。 9 | * 10 | * @author Daniel Li 11 | * @since 18 Jun 2013 12 | */ 13 | public class StringTemplateUtils { 14 | 15 | /** 16 | * 处理模板为字符串。 17 | * 18 | * @param template 模板。 19 | * @param model 数据模型。 20 | * @return 字符串。 21 | */ 22 | public static String processTemplateIntoString(StringTemplate template, Map model) { 23 | template.setAttributes(model); 24 | return template.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /xultimate-context-support/src/main/java/org/danielli/xultimate/ui/stringtemplate/v4/StringTemplateUtils.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.ui.stringtemplate.v4; 2 | 3 | import java.util.Map; 4 | 5 | import org.stringtemplate.v4.ST; 6 | 7 | /** 8 | * StringTemplate V4模板处理工具。 9 | * 10 | * @author Daniel Li 11 | * @since 18 Jun 2013 12 | */ 13 | public class StringTemplateUtils { 14 | /** 15 | * 处理模板为字符串。 16 | * 17 | * @param template 模板。 18 | * @param model 数据模型。 19 | * @return 字符串。 20 | */ 21 | public static String processTemplateIntoString(ST template, Map model) { 22 | for (Map.Entry entry : model.entrySet()) { 23 | template.add(entry.getKey(), entry.getValue()); 24 | } 25 | return template.render(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /xultimate-context-support/src/test/java/org/danielli/xultimate/context/kvStore/memcached/CacheService.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.memcached; 2 | 3 | import org.springframework.cache.annotation.CacheEvict; 4 | import org.springframework.cache.annotation.Cacheable; 5 | 6 | public class CacheService { 7 | 8 | @Cacheable(value="user", key="#userId") 9 | public String addUser(Integer userId, String userName) { 10 | System.out.println(userId + ":" + userName); 11 | return userName; 12 | } 13 | 14 | @Cacheable(value="user", key="#userId") 15 | public String getUserNameById(Integer userId) { 16 | System.out.println(userId); 17 | return "Name"; 18 | } 19 | 20 | @CacheEvict(value="user",key="#userId") 21 | public void deleteUser(Integer userId) { 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context-support/src/test/java/org/danielli/xultimate/context/kvStore/memcached/xmemcached/Person.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.memcached.xmemcached; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Person implements Serializable { 6 | 7 | private static final long serialVersionUID = -1738355062692076549L; 8 | 9 | private String name; 10 | 11 | private Integer age; 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | 21 | public Integer getAge() { 22 | return age; 23 | } 24 | 25 | public void setAge(Integer age) { 26 | this.age = age; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /xultimate-context-support/src/test/java/org/danielli/xultimate/context/kvStore/redis/jedis/Person.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.kvStore.redis.jedis; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Person implements Serializable { 6 | 7 | private static final long serialVersionUID = -1738355062692076549L; 8 | 9 | private String name; 10 | 11 | private Integer age; 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | 21 | public Integer getAge() { 22 | return age; 23 | } 24 | 25 | public void setAge(Integer age) { 26 | this.age = age; 27 | } 28 | } -------------------------------------------------------------------------------- /xultimate-context-support/src/test/java/org/danielli/xultimate/context/mail/template/hello_world.httl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Hello World, ${userName}! 8 | 9 | -------------------------------------------------------------------------------- /xultimate-context-support/src/test/java/org/danielli/xultimate/context/scheduling/quartz/ExampleBusinessObject.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.scheduling.quartz; 2 | 3 | import java.util.Date; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | public class ExampleBusinessObject { 9 | 10 | private static Logger logger = LoggerFactory.getLogger(ExampleBusinessObject.class); 11 | 12 | public void doIt() { 13 | logger.info("{}", new Date()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /xultimate-context-support/src/test/resources/dfs/fastdfs/README: -------------------------------------------------------------------------------- 1 | Copyright (C) 2008 Happy Fish / YuQing 2 | 3 | FastDFS Java Client API may be copied only under the terms of 4 | the BSD license. 5 | Please visit the FastDFS Home Page for more detail. 6 | English language: http://english.csource.org/ 7 | Chinese language: http://www.csource.org/ 8 | 9 | 10 | The jar file is compiled by JDK1.5, you can download the last version 11 | from google code: http://code.google.com/p/fastdfs/downloads/list 12 | 13 | run the FastDFS Java Client test: 14 | java -cp org.csource.fastdfs.test.TestClient 15 | 16 | eg.: 17 | java -cp fastdfs_client_v1.22.jar org.csource.fastdfs.test.TestClient fdfs_client.conf c:\windows\system32\notepad.exe 18 | 19 | or: 20 | java -cp fastdfs_client_v1.22.jar org.csource.fastdfs.test.TestClient fdfs_client.conf /usr/include/stdlib.h 21 | 22 | 23 | run the FastDFS monitor: 24 | java -cp org.csource.fastdfs.test.Monitor 25 | 26 | eg.: 27 | java -cp fastdfs_client_v1.22.jar org.csource.fastdfs.test.Monitor fdfs_client.conf 28 | -------------------------------------------------------------------------------- /xultimate-context-support/src/test/resources/dfs/fastdfs/fdfs_client.conf: -------------------------------------------------------------------------------- 1 | connect_timeout = 2 2 | network_timeout = 30 3 | charset = ISO8859-1 4 | # http.tracker_http_port = 8080 5 | http.anti_steal_token = no 6 | http.secret_key = FastDFS1234567890 7 | 8 | tracker_server = 192.168.10.103:22122 9 | -------------------------------------------------------------------------------- /xultimate-context-support/src/test/resources/kvStore/redis/README: -------------------------------------------------------------------------------- 1 | 一.Sharded 2 | TreeMap nodes = new TreeMap(); 3 | void initialize(List shards) 4 | 遍历shards,索引为i 5 | 如果shardInfo的getName()方法为空,循环160 * shardInfo.getWeight()次,索引为n,根据算法计算"SHARD-" + i + "-NODE-" + n的hash值,将hash值和shardInfo存入nodes中。 6 | 否则循环160 * shardInfo.getWeight()次,索引为n,根据算法计算shardInfo.getName() + "*" + shardInfo.getWeight() + n的hash值,将hash值和shardInfo存入nodes中。 7 | S getShardInfo(byte[] key) 8 | 计算算法计算key的hash值,调用nodes.tailMap(hash)得到SortedMap tail。 9 | 如果tail的个数为0,则返回nodes中第一个key对应的ShardInfo。 10 | 否则返回tail中第一个key对应的ShardInfo。 -------------------------------------------------------------------------------- /xultimate-context-support/src/test/resources/mail/file1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daniellitoc/xultimate-toolkit/d3224632489626e7ab5a708821f4189c5e6d8764/xultimate-context-support/src/test/resources/mail/file1.zip -------------------------------------------------------------------------------- /xultimate-context-support/src/test/resources/mail/file2.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daniellitoc/xultimate-toolkit/d3224632489626e7ab5a708821f4189c5e6d8764/xultimate-context-support/src/test/resources/mail/file2.doc -------------------------------------------------------------------------------- /xultimate-context-support/src/test/resources/mail/img01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daniellitoc/xultimate-toolkit/d3224632489626e7ab5a708821f4189c5e6d8764/xultimate-context-support/src/test/resources/mail/img01.png -------------------------------------------------------------------------------- /xultimate-context-support/src/test/resources/mail/mail.properties: -------------------------------------------------------------------------------- 1 | mail.host=localhost 2 | mail.port=6025 3 | mail.protocol=smtp 4 | mail.auth=true 5 | mail.username=c67594724f6a768e9865d1fa29f29513cfb8086f2b35a7c3a9bb05c066b4ba70 6 | mail.password=c67594724f6a768e9865d1fa29f29513cfb8086f2b35a7c3a9bb05c066b4ba70 7 | mail.debug=true -------------------------------------------------------------------------------- /xultimate-context-support/src/test/resources/mail/mail.properties.bak: -------------------------------------------------------------------------------- 1 | mail.host=smtp.gmail.com 2 | mail.port=465 3 | mail.protocol=smtps 4 | mail.auth=true 5 | mail.username=c67594724f6a768e9865d1fa29f29513cfb8086f2b35a7c3a9bb05c066b4ba70 6 | mail.password=c67594724f6a768e9865d1fa29f29513cfb8086f2b35a7c3a9bb05c066b4ba70 7 | mail.debug=true -------------------------------------------------------------------------------- /xultimate-context-support/src/test/resources/quartz/quartz.properties: -------------------------------------------------------------------------------- 1 | #=============================================================== 2 | # Quartz Scheduler Clustered Database Configuration 3 | #=============================================================== 4 | datasource.quartz.jdbc.driver=com.mysql.jdbc.Driver 5 | datasource.quartz.jdbc.url=jdbc:mysql://127.0.0.1:3306/quartz_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull 6 | datasource.quartz.jdbc.username=1f226dc04f6dbe1d89a36e1800cd9b28 7 | datasource.quartz.jdbc.password=1f226dc04f6dbe1d89a36e1800cd9b28 8 | datasource.quartz.pool.maxActive=20 9 | datasource.quartz.pool.minIdle=10 -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/chardet/CharsetDetector.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.chardet; 2 | 3 | import java.nio.charset.Charset; 4 | import java.util.Set; 5 | 6 | /** 7 | * 字符集检测器。 8 | * 9 | * @author Daniel Li 10 | * @since 18 Jun 2013 11 | * 12 | * @param 输入源。 13 | */ 14 | public interface CharsetDetector { 15 | 16 | /** 17 | * 检测指定输入源的字符集。 18 | * 19 | * @param source 输入源。 20 | * @return 字符集集合。 21 | * @throws CharsetDetectorException 检测过程中的出现的异常,都由{@link CharsetDetectorException }封装并抛出。 22 | */ 23 | Set detect(S source) throws CharsetDetectorException; 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/chardet/CharsetDetectorException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.chardet; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 字符集检测器异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class CharsetDetectorException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = 2303266621170729888L; 15 | 16 | public CharsetDetectorException(String message) { 17 | super(message); 18 | } 19 | 20 | public CharsetDetectorException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/chardet/support/FileCharsetDetector.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.chardet.support; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | 7 | import org.danielli.xultimate.context.chardet.CharsetDetectorException; 8 | import org.danielli.xultimate.util.io.FileUtils; 9 | 10 | /** 11 | * 文件类字符集检测器。 12 | * 13 | * @author Daniel Li 14 | * @since 18 Jun 2013 15 | * @see AbstractCharsetDetector 16 | */ 17 | public class FileCharsetDetector extends AbstractCharsetDetector { 18 | 19 | @Override 20 | public InputStream createInputStream(File source) throws CharsetDetectorException { 21 | try { 22 | return FileUtils.openInputStream(source); 23 | } catch (IOException e) { 24 | throw new CharsetDetectorException(e.getMessage(), e); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/chardet/support/URLCharsetDetector.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.chardet.support; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.net.URL; 6 | 7 | import org.danielli.xultimate.context.chardet.CharsetDetectorException; 8 | 9 | /** 10 | * URL类字符集检测器。 11 | * 12 | * @author Daniel Li 13 | * @since 18 Jun 2013 14 | * @see AbstractCharsetDetector 15 | */ 16 | public class URLCharsetDetector extends AbstractCharsetDetector { 17 | 18 | @Override 19 | public InputStream createInputStream(URL source) throws CharsetDetectorException { 20 | try { 21 | return source.openStream(); 22 | } catch (IOException e) { 23 | throw new CharsetDetectorException(e.getMessage(), e); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/codec/Decoder.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.codec; 2 | 3 | /** 4 | * 解码器。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | * 9 | * @param 原始源。 10 | * @param 目标源。 11 | */ 12 | public interface Decoder { 13 | 14 | /** 15 | * 解码。 16 | * 17 | * @param source 原始源。 18 | * @return 目标源。 19 | * @throws DecoderException 解码异常,在解码过程中出现的任何异常都会使用{@link DecoderException}封装并抛出。 20 | */ 21 | T decode(S source) throws DecoderException; 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/codec/DecoderException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.codec; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 解码异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class DecoderException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = 8862452193888553128L; 15 | 16 | public DecoderException(String message) { 17 | super(message); 18 | } 19 | 20 | public DecoderException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/codec/Encoder.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.codec; 2 | 3 | /** 4 | * 编码器。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | * 9 | * @param 原始源。 10 | * @param 目标源。 11 | */ 12 | public interface Encoder { 13 | 14 | /** 15 | * 编码。 16 | * 17 | * @param source 原始源。 18 | * @return 目标源。 19 | * @throws EncoderException 编码异常,在编码过程中出现的任何异常都会使用{@link EncoderException}封装并抛出。 20 | */ 21 | T encode(S source) throws EncoderException; 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/codec/EncoderException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.codec; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 编码异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class EncoderException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = 8862452193888553128L; 15 | 16 | public EncoderException(String message) { 17 | super(message); 18 | } 19 | 20 | public EncoderException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/codec/support/ByteArrayStringCoder.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.codec.support; 2 | 3 | import org.danielli.xultimate.context.codec.DecoderException; 4 | import org.danielli.xultimate.context.codec.EncoderException; 5 | 6 | /** 7 | * 处理{@link String}到{@link byte[]}类型的编码和解码器。 8 | * 9 | * @author Daniel Li 10 | * @since 18 Jun 2013 11 | * @see AbstractCoder 12 | */ 13 | public class ByteArrayStringCoder extends AbstractCoder { 14 | 15 | @Override 16 | public String encode(byte[] source) throws EncoderException { 17 | return new String(innerEncode(source)); 18 | } 19 | 20 | @Override 21 | public byte[] decode(String source) throws DecoderException { 22 | return innerDecode(source.toCharArray()); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/codec/support/StringStringCoder.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.codec.support; 2 | 3 | import org.danielli.xultimate.context.codec.DecoderException; 4 | import org.danielli.xultimate.context.codec.EncoderException; 5 | import org.danielli.xultimate.util.StringUtils; 6 | 7 | /** 8 | * 处理{@link String}到{@link String}类型的编码和解码器。 9 | * 10 | * @author Daniel Li 11 | * @since 18 Jun 2013 12 | * @see AbstractCoder 13 | */ 14 | public class StringStringCoder extends AbstractCoder { 15 | 16 | @Override 17 | public String encode(String source) throws EncoderException { 18 | return StringUtils.newStringUtf8(innerEncode(StringUtils.getBytesUtf8(source))); 19 | } 20 | 21 | @Override 22 | public String decode(String source) throws DecoderException { 23 | return StringUtils.newStringUtf8(innerDecode(StringUtils.getBytesUtf8(source))); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/codec/support/URLCodec.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.codec.support; 2 | 3 | import org.danielli.xultimate.context.codec.Decoder; 4 | import org.danielli.xultimate.context.codec.DecoderException; 5 | import org.danielli.xultimate.context.codec.Encoder; 6 | import org.danielli.xultimate.context.codec.EncoderException; 7 | 8 | 9 | /** 10 | * URL编码和解码器。处理byte[]到byte[]类型。 11 | * 12 | * @author Daniel Li 13 | * @since 18 Jun 2013 14 | * @see Encoder 15 | * @see Decoder 16 | */ 17 | public class URLCodec implements Encoder, Decoder { 18 | 19 | @Override 20 | public byte[] decode(byte[] source) throws DecoderException { 21 | try { 22 | return org.apache.commons.codec.net.URLCodec.decodeUrl(source); 23 | } catch (Exception e) { 24 | throw new DecoderException(e.getMessage(), e); 25 | } 26 | } 27 | 28 | @Override 29 | public byte[] encode(byte[] source) throws EncoderException { 30 | try { 31 | return org.apache.commons.codec.net.URLCodec.encodeUrl(null, source); 32 | } catch (Exception e) { 33 | throw new EncoderException(e.getMessage(), e); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/crypto/Decryptor.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.crypto; 2 | 3 | /** 4 | * 解密器。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | * 9 | * @param 原始源。 10 | * @param 目标源。 11 | */ 12 | public interface Decryptor { 13 | 14 | /** 15 | * 解密。 16 | * 17 | * @param source 原始源。 18 | * @return 目标源。 19 | * @throws DecryptorException 解密异常,在解密过程中出现的任何异常都会使用{@link DecryptorException}封装并抛出。 20 | */ 21 | T decrypt(S source) throws DecryptorException; 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/crypto/DecryptorException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.crypto; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 解密异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class DecryptorException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = 8862452193888553128L; 15 | 16 | public DecryptorException(String message) { 17 | super(message); 18 | } 19 | 20 | public DecryptorException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/crypto/Encryptor.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.crypto; 2 | 3 | /** 4 | * 加密器。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | * 9 | * @param 原始源。 10 | * @param 目标源。 11 | */ 12 | public interface Encryptor { 13 | 14 | /** 15 | * 加密。 16 | * 17 | * @param source 原始源。 18 | * @return 目标源。 19 | * @throws EncryptorException 编码异常,在编码过程中出现的任何异常都会使用{@link EncryptorException}封装并抛出。 20 | */ 21 | T encrypt(S source) throws EncryptorException; 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/crypto/EncryptorException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.crypto; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 加密异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class EncryptorException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = 8862452193888553128L; 15 | 16 | public EncryptorException(String message) { 17 | super(message); 18 | } 19 | 20 | public EncryptorException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/i18n/Message.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.i18n; 2 | 3 | /** 4 | * 消息体。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | */ 9 | public class Message { 10 | 11 | /** 消息类型 */ 12 | protected MessageType type; 13 | 14 | /** 消息内容 */ 15 | protected T content; 16 | 17 | public Message(MessageType type, T content) { 18 | this.type = type; 19 | this.content = content; 20 | } 21 | 22 | /** 23 | * 获取消息类型。 24 | * 25 | * @return 消息类型。 26 | */ 27 | public MessageType getType() { 28 | return type; 29 | } 30 | 31 | /** 32 | * 获取消息内容。 33 | * 34 | * @return 消息内容。 35 | */ 36 | public T getContent() { 37 | return content; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/i18n/MessageType.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.i18n; 2 | 3 | /** 4 | * 消息类型。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | */ 9 | public enum MessageType { 10 | 11 | /** 错误类型 */ 12 | ERROR, 13 | 14 | /** 警告类型 */ 15 | WARN, 16 | 17 | /** 成功类型 */ 18 | SUCCESS; 19 | } 20 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image/AbstractImageTemplate.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image; 2 | 3 | import java.awt.Color; 4 | 5 | /** 6 | * 抽像图片模板工具类。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | */ 11 | public abstract class AbstractImageTemplate { 12 | 13 | /** 背景颜色 */ 14 | protected Color backgroundColor = Color.black; 15 | 16 | /** 目标图片品质(取值范围: 0 - 100) */ 17 | protected Integer quality = 50; 18 | 19 | /** 20 | * 设置背景颜色。 21 | * @param backgroundColor 22 | * 背景颜色。 23 | */ 24 | public void setBackgroundColor(Color backgroundColor) { 25 | this.backgroundColor = backgroundColor; 26 | } 27 | 28 | /** 29 | * 设置目标图片品质(取值范围: 0 - 100)。 30 | * @param backgroundColor 31 | * 目标图片品质(取值范围: 0 - 100)。 32 | */ 33 | public void setQuality(Integer quality) { 34 | this.quality = quality; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image/ImageException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 图片异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class ImageException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = -4680588316992658546L; 15 | 16 | public ImageException(String message) { 17 | super(message); 18 | } 19 | 20 | public ImageException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image/ImageInfoException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image; 2 | 3 | 4 | /** 5 | * 图片信息异常。 6 | * 7 | * @author Daniel Li 8 | * @since 18 Jun 2013 9 | */ 10 | public class ImageInfoException extends ImageException { 11 | 12 | private static final long serialVersionUID = 3522360189078014666L; 13 | 14 | public ImageInfoException(String message) { 15 | super(message); 16 | } 17 | 18 | public ImageInfoException(String message, Throwable cause) { 19 | super(message, cause); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image/ImageInfoTemplate.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image; 2 | 3 | import java.io.File; 4 | 5 | import org.danielli.xultimate.context.image.model.ImageInfo; 6 | 7 | /** 8 | * 图片信息模板工具类。 9 | * 10 | * @author Daniel Li 11 | * @since 18 Jun 2013 12 | */ 13 | public interface ImageInfoTemplate { 14 | 15 | /** 16 | * 获取图片信息。 17 | * 18 | * @param imageFile 19 | * 图片文件。 20 | * @return 图片信息。 21 | */ 22 | ImageInfo getImageInfo(File imageFile) throws ImageInfoException; 23 | 24 | /** 25 | * 转换图片。 26 | * 27 | * @param srcImageFile 28 | * 原图片文件。 29 | * @param destImageFile 30 | * 目标图片文件。 31 | */ 32 | void convertImage(File srcImageFile, File destImageFile) throws ImageException; 33 | } 34 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image/im4java/ImageCommandPostProcessor.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image.im4java; 2 | 3 | import org.danielli.xultimate.context.image.ImageException; 4 | import org.im4java.core.IMOperation; 5 | import org.im4java.core.ImageCommand; 6 | 7 | /** 8 | * 图片命令后处理器。 9 | * 10 | * @author Daniel Li 11 | * @since 18 Jun 2013 12 | */ 13 | public interface ImageCommandPostProcessor { 14 | 15 | /** 16 | * 初始化图片命令和操作后,此方法被执行。 17 | */ 18 | void postProcessAfterInitialization(ImageCommand imageCommand, IMOperation operation, Object... params) throws ImageException; 19 | } 20 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image/im4java/support/RunCommandPostProcessor.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image.im4java.support; 2 | 3 | import org.danielli.xultimate.context.image.ImageException; 4 | import org.danielli.xultimate.context.image.im4java.ImageCommandPostProcessor; 5 | import org.im4java.core.IMOperation; 6 | import org.im4java.core.ImageCommand; 7 | 8 | /** 9 | * 默认实现。运行命令后处理器。用于执行图片命令。 10 | * 11 | * @author Daniel Li 12 | * @since 18 Jun 2013 13 | */ 14 | public class RunCommandPostProcessor implements ImageCommandPostProcessor { 15 | 16 | @Override 17 | public void postProcessAfterInitialization(ImageCommand imageCommand, IMOperation operation, Object... params) throws ImageException { 18 | try { 19 | imageCommand.run(operation, params); 20 | } catch (Exception e) { 21 | throw new ImageException(e.getMessage(), e); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image/model/GeometryOperator.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image.model; 2 | 3 | /** 4 | * 几何操作。 5 | * 6 | * @author Daniel Li 7 | * @since JDK 1.7 8 | */ 9 | public enum GeometryOperator { 10 | /** 11 | * 保留宽度或高度中的最小值,宽度与高度比保存。 12 | */ 13 | Minimum(null), 14 | /** 15 | * 保留宽度或高度中的最大值,宽度与高度比保存。 16 | */ 17 | Maximum('^'), 18 | /** 19 | * 保留宽度与高度,忽略原始宽度与高度。 20 | */ 21 | Emphasize('!'), 22 | /** 23 | * 若宽度或高度小于原始宽度或高度,保留宽度或高度中的最小值,并缩小图片,宽度与高度比保存;否则使用原始宽度与高度。 24 | */ 25 | Shrink('>'), 26 | /** 27 | * 若宽度或高度大于原始宽度或高度,保留宽度或高度中的最大值,并放大图片,宽度与高度比保存;否则使用原始宽度与高度。 28 | */ 29 | Enlarge('<'); 30 | 31 | private Character special; 32 | 33 | private GeometryOperator(Character special) { 34 | this.special = special; 35 | } 36 | 37 | public Character getSpecial() { 38 | return special; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image/model/Gravity.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image.model; 2 | 3 | /** 4 | * 方位。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | */ 9 | public enum Gravity { 10 | /** 11 | * 没有。 12 | */ 13 | None, 14 | 15 | 16 | /** 17 | * 西北。 18 | */ 19 | NorthWest, 20 | /** 21 | * 北。 22 | */ 23 | North, 24 | /** 25 | * 东北。 26 | */ 27 | NorthEast, 28 | /** 29 | * 西。 30 | */ 31 | West, 32 | /** 33 | * 中间。 34 | */ 35 | Center, 36 | /** 37 | * 东。 38 | */ 39 | East, 40 | /** 41 | * 西南。 42 | */ 43 | SouthWest, 44 | /** 45 | * 南。 46 | */ 47 | South, 48 | /** 49 | * 东南。 50 | */ 51 | SouthEast; 52 | } 53 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image/model/ImageFormat.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image.model; 2 | 3 | /** 4 | * 图片格式。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | */ 9 | public enum ImageFormat { 10 | JPEG("JPG", "JPEG"), 11 | GIF("GIF"), 12 | BMP("BMP"), 13 | PNG("PNG"); 14 | 15 | private String[] extensions; 16 | 17 | private ImageFormat(String... extensions) { 18 | this.extensions = extensions; 19 | } 20 | 21 | public String[] getExtensions() { 22 | return extensions; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image/model/ImageInfo.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image.model; 2 | 3 | /** 4 | * 图片信息。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | */ 9 | public class ImageInfo { 10 | private ImageSize imageSize; 11 | private ImageFormat imageFormat; 12 | 13 | /** 14 | * 创建图片信息。 15 | * 16 | * @param width 17 | * 图片宽度。 18 | * @param height 19 | * 图片高度。 20 | * @param format 21 | * 图片格式。 22 | */ 23 | public ImageInfo(Integer width, Integer height, ImageFormat imageFormat) { 24 | this.imageSize = new ImageSize(width, height); 25 | this.imageFormat = imageFormat; 26 | } 27 | 28 | public ImageSize getImageSize() { 29 | return imageSize; 30 | } 31 | 32 | public ImageFormat getImageFormat() { 33 | return imageFormat; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image2/AbstractImageTemplate.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image2; 2 | 3 | import java.awt.Color; 4 | 5 | /** 6 | * 抽像图片模板工具类。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | */ 11 | public abstract class AbstractImageTemplate { 12 | 13 | /** 背景颜色 */ 14 | protected Color backgroundColor = Color.black; 15 | 16 | /** 目标图片品质(取值范围: 0 - 100) */ 17 | protected Integer quality = 50; 18 | 19 | /** 20 | * 设置背景颜色。 21 | * @param backgroundColor 22 | * 背景颜色。 23 | */ 24 | public void setBackgroundColor(Color backgroundColor) { 25 | this.backgroundColor = backgroundColor; 26 | } 27 | 28 | /** 29 | * 设置目标图片品质(取值范围: 0 - 100)。 30 | * @param backgroundColor 31 | * 目标图片品质(取值范围: 0 - 100)。 32 | */ 33 | public void setQuality(Integer quality) { 34 | this.quality = quality; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image2/ImageException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image2; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 图片异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class ImageException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = -4680588316992658546L; 15 | 16 | public ImageException(String message) { 17 | super(message); 18 | } 19 | 20 | public ImageException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image2/ImageInfoException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image2; 2 | 3 | 4 | /** 5 | * 图片信息异常。 6 | * 7 | * @author Daniel Li 8 | * @since 18 Jun 2013 9 | */ 10 | public class ImageInfoException extends ImageException { 11 | 12 | private static final long serialVersionUID = 3522360189078014666L; 13 | 14 | public ImageInfoException(String message) { 15 | super(message); 16 | } 17 | 18 | public ImageInfoException(String message, Throwable cause) { 19 | super(message, cause); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image2/ImageInfoTemplate.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image2; 2 | 3 | import org.danielli.xultimate.context.image2.config.DefaultImageResource; 4 | import org.danielli.xultimate.context.image2.config.WrapperImageResource; 5 | 6 | /** 7 | * 图片信息模板工具类。 8 | * 9 | * @author Daniel Li 10 | * @since 18 Jun 2013 11 | */ 12 | public interface ImageInfoTemplate { 13 | 14 | /** 15 | * 转换图片。 16 | * 17 | * @param srcImageResource 18 | * 原图片资源。 19 | * @param destImageResource 20 | * 目标图片资源。 21 | */ 22 | void convertImage(DefaultImageResource srcImageResource, WrapperImageResource destImageResource) throws ImageException; 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image2/config/GeometryOperator.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image2.config; 2 | 3 | /** 4 | * 几何操作。 5 | * 6 | * @author Daniel Li 7 | * @since JDK 1.7 8 | */ 9 | public enum GeometryOperator { 10 | /** 11 | * 保留宽度或高度中的最小值,宽度与高度比保存。 12 | */ 13 | Minimum(null), 14 | /** 15 | * 保留宽度或高度中的最大值,宽度与高度比保存。 16 | */ 17 | Maximum('^'), 18 | /** 19 | * 保留宽度与高度,忽略原始宽度与高度。 20 | */ 21 | Emphasize('!'), 22 | /** 23 | * 若宽度或高度小于原始宽度或高度,保留宽度或高度中的最小值,并缩小图片,宽度与高度比保存;否则使用原始宽度与高度。 24 | */ 25 | Shrink('>'), 26 | /** 27 | * 若宽度或高度大于原始宽度或高度,保留宽度或高度中的最大值,并放大图片,宽度与高度比保存;否则使用原始宽度与高度。 28 | */ 29 | Enlarge('<'); 30 | 31 | private Character special; 32 | 33 | private GeometryOperator(Character special) { 34 | this.special = special; 35 | } 36 | 37 | public Character getSpecial() { 38 | return special; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image2/config/Gravity.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image2.config; 2 | 3 | /** 4 | * 方位。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | */ 9 | public enum Gravity { 10 | /** 11 | * 没有。 12 | */ 13 | None, 14 | 15 | 16 | /** 17 | * 西北。 18 | */ 19 | NorthWest, 20 | /** 21 | * 北。 22 | */ 23 | North, 24 | /** 25 | * 东北。 26 | */ 27 | NorthEast, 28 | /** 29 | * 西。 30 | */ 31 | West, 32 | /** 33 | * 中间。 34 | */ 35 | Center, 36 | /** 37 | * 东。 38 | */ 39 | East, 40 | /** 41 | * 西南。 42 | */ 43 | SouthWest, 44 | /** 45 | * 南。 46 | */ 47 | South, 48 | /** 49 | * 东南。 50 | */ 51 | SouthEast; 52 | } 53 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image2/config/ImageFormat.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image2.config; 2 | 3 | /** 4 | * 图片格式。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | */ 9 | public enum ImageFormat { 10 | JPEG("JPG", "JPEG"), 11 | GIF("GIF"), 12 | BMP("BMP"), 13 | PNG("PNG"); 14 | 15 | private String[] extensions; 16 | 17 | private ImageFormat(String... extensions) { 18 | this.extensions = extensions; 19 | } 20 | 21 | public String[] getExtensions() { 22 | return extensions; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image2/config/ImageInfo.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image2.config; 2 | 3 | /** 4 | * 图片信息。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | */ 9 | public class ImageInfo { 10 | private ImageSize imageSize; 11 | private ImageFormat imageFormat; 12 | 13 | /** 14 | * 创建图片信息。 15 | * 16 | * @param width 17 | * 图片宽度。 18 | * @param height 19 | * 图片高度。 20 | * @param format 21 | * 图片格式。 22 | */ 23 | public ImageInfo(Integer width, Integer height, ImageFormat imageFormat) { 24 | this.imageSize = new ImageSize(width, height); 25 | this.imageFormat = imageFormat; 26 | } 27 | 28 | public ImageSize getImageSize() { 29 | return imageSize; 30 | } 31 | 32 | public ImageFormat getImageFormat() { 33 | return imageFormat; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image2/config/ImageResource.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image2.config; 2 | 3 | import java.awt.image.BufferedImage; 4 | import java.io.File; 5 | 6 | import org.danielli.xultimate.context.image2.ImageInfoException; 7 | 8 | /** 9 | * 图片资源。 10 | * 11 | * @author Daniel Li 12 | * @since 18 Jun 2013 13 | */ 14 | public interface ImageResource { 15 | 16 | /** 17 | * 获取图片文件。 18 | * @return 图片文件。 19 | */ 20 | File getImageFile(); 21 | 22 | /** 23 | * 获取缓冲图片。 24 | * @return 缓冲图片。 25 | */ 26 | BufferedImage getBufferedImage() throws ImageInfoException; 27 | 28 | /** 29 | * 获取图片信息。 30 | * @return 图片信息。 31 | */ 32 | ImageInfo getImageInfo() throws ImageInfoException; 33 | } 34 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/image2/im4java/ImageCommandPostProcessor.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.image2.im4java; 2 | 3 | import org.danielli.xultimate.context.image2.ImageException; 4 | import org.danielli.xultimate.context.image2.config.DefaultImageResource; 5 | import org.danielli.xultimate.context.image2.config.WrapperImageResource; 6 | import org.im4java.core.IMOperation; 7 | import org.im4java.core.ImageCommand; 8 | 9 | /** 10 | * 图片命令后处理器。 11 | * 12 | * @author Daniel Li 13 | * @since 18 Jun 2013 14 | */ 15 | public interface ImageCommandPostProcessor { 16 | 17 | /** 18 | * 初始化图片命令和操作后,此方法被执行。 19 | */ 20 | void postProcessAfterInitialization(ImageCommand imageCommand, IMOperation operation, WrapperImageResource destImageResource, DefaultImageResource... parameterImageResources) throws ImageException; 21 | } 22 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/performance/AbstractStopWatchMonitoringInterceptor.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.performance; 2 | 3 | import org.danielli.xultimate.util.time.stopwatch.support.AbstractStopWatchSummary; 4 | import org.springframework.aop.interceptor.PerformanceMonitorInterceptor; 5 | 6 | /** 7 | * 抽象秒表监测拦截器。 8 | * 9 | *

Uses a {@code StopWatch} for the actual performance measuring. 10 | * 11 | * @author Daniel Li 12 | * @since 18 Jun 2013 13 | * @see PerformanceMonitorInterceptor 14 | */ 15 | public abstract class AbstractStopWatchMonitoringInterceptor extends AbstractMonitoringInterceptor { 16 | 17 | protected AbstractStopWatchSummary stopWatchSummary; 18 | 19 | public void setStopWatchSummary(AbstractStopWatchSummary stopWatchSummary) { 20 | this.stopWatchSummary = stopWatchSummary; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-context/src/main/java/org/danielli/xultimate/context/performance/PerformanceMonitor.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.performance; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Inherited; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * 性能检测注解。 12 | * 13 | * @author Daniel Li 14 | * @since 18 Jun 2013 15 | * @see PerformanceMonitorForEachMethodInterceptor 16 | * @see PerformanceMonitorForOneMethodInterceptor 17 | */ 18 | @Inherited 19 | @Target({ ElementType.METHOD }) 20 | @Retention(RetentionPolicy.RUNTIME) 21 | @Documented 22 | public @interface PerformanceMonitor { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/config/Boss.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.config; 2 | 3 | public class Boss { 4 | private Car car; 5 | 6 | public Car getCar() { 7 | return car; 8 | } 9 | 10 | public void setCar(Car car) { 11 | this.car = car; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/config/Car.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.config; 2 | 3 | public class Car { 4 | private int maxSpeed; 5 | private String brand; 6 | private double price; 7 | public int getMaxSpeed() { 8 | return maxSpeed; 9 | } 10 | public void setMaxSpeed(int maxSpeed) { 11 | this.maxSpeed = maxSpeed; 12 | } 13 | public String getBrand() { 14 | return brand; 15 | } 16 | public void setBrand(String brand) { 17 | this.brand = brand; 18 | } 19 | public double getPrice() { 20 | return price; 21 | } 22 | public void setPrice(double price) { 23 | this.price = price; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/config/CustomCarEditor.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.config; 2 | 3 | import java.beans.PropertyEditorSupport; 4 | 5 | import org.springframework.stereotype.Service; 6 | 7 | @Service("customCarEditor") 8 | public class CustomCarEditor extends PropertyEditorSupport { 9 | 10 | @Override 11 | public void setAsText(String text) throws IllegalArgumentException { 12 | String[] infos = text.split(","); 13 | Car car = new Car(); 14 | car.setBrand(infos[0]); 15 | car.setMaxSpeed(Integer.parseInt(infos[1])); 16 | car.setPrice(Double.parseDouble(infos[2])); 17 | setValue(car); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/config/CustomCardEditorTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.config; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | @ContextConfiguration(locations = { "classpath:/applicationContext-config.xml" }) 14 | public class CustomCardEditorTest { 15 | 16 | @Resource 17 | private Boss boss; 18 | 19 | private static final Logger LOGGER = LoggerFactory.getLogger(CustomCardEditorTest.class); 20 | 21 | @Test 22 | public void test() { 23 | LOGGER.info("Brand:" + boss.getCar().getBrand()); 24 | LOGGER.info("MaxSpeed:" + boss.getCar().getMaxSpeed()); 25 | LOGGER.info("Price:" + boss.getCar().getPrice()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/event/EventTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.event; 2 | 3 | import org.danielli.xultimate.context.util.BeanFactoryContext; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.test.context.ContextConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @ContextConfiguration(locations = { "classpath:/applicationContext-service-event.xml", "classpath:/applicationContext-service-util.xml" }) 11 | public class EventTest { 12 | 13 | @Test 14 | public void testEvent() { 15 | LogEvent logEvent = new LogEvent(BeanFactoryContext.currentApplicationContext(), Thread.currentThread().toString()); 16 | // 为单线程,事件监听器和发布器是同步的调用关系。 17 | // 可通过taskExecutor配置实现异步,SimpleApplicationEventMulticaster 18 | BeanFactoryContext.currentApplicationContext().publishEvent(logEvent); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/event/Log1Listener.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.event; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.ApplicationListener; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * 日志监听器,当使用ApplicationContext.publishEvent(LogEvent)时,监听器起作用。 10 | * @author Daniel Li 11 | * @since 29 July 2012 12 | */ 13 | @Service 14 | public class Log1Listener implements ApplicationListener { 15 | 16 | private static final Logger LOGGER = LoggerFactory.getLogger(Log1Listener.class); 17 | 18 | @Override 19 | public void onApplicationEvent(LogEvent event) { 20 | String message = event.getMessage(); 21 | LOGGER.info("{}:{}", Thread.currentThread(), message); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/event/Log2Listener.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.event; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.ApplicationListener; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * 日志监听器,当使用ApplicationContext.publishEvent(LogEvent)时,监听器起作用。 10 | * @author Daniel Li 11 | * @since 29 July 2012 12 | */ 13 | @Service 14 | public class Log2Listener implements ApplicationListener { 15 | 16 | private static final Logger LOGGER = LoggerFactory.getLogger(Log2Listener.class); 17 | 18 | @Override 19 | public void onApplicationEvent(LogEvent event) { 20 | String message = event.getMessage(); 21 | LOGGER.info("{}:{}", Thread.currentThread(), message); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/event/LogEvent.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.event; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.event.ApplicationContextEvent; 5 | 6 | public class LogEvent extends ApplicationContextEvent { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private String message; 11 | 12 | public LogEvent(ApplicationContext source, String message) { 13 | super(source); 14 | this.message = message; 15 | } 16 | 17 | public String getMessage() { 18 | return message; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/performance/PerformanceMonitorForEachMethodInterceptorTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.performance; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.danielli.xultimate.context.performance.service.TestService; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | @RunWith(SpringJUnit4ClassRunner.class) 12 | @ContextConfiguration(locations = { "classpath:/performance/applicationContext-service-performance-each.xml" }) 13 | public class PerformanceMonitorForEachMethodInterceptorTest { 14 | 15 | @Resource(name = "testService") 16 | private TestService testService; 17 | 18 | @Test 19 | public void test() { 20 | testService.doSomething(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/performance/PerformanceMonitorForOneMethodInterceptorTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.performance; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.danielli.xultimate.context.performance.service.TestService; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | @RunWith(SpringJUnit4ClassRunner.class) 12 | @ContextConfiguration(locations = { "classpath:/performance/applicationContext-service-performance-one.xml" }) 13 | public class PerformanceMonitorForOneMethodInterceptorTest { 14 | 15 | @Resource(name = "testService") 16 | private TestService testService; 17 | 18 | @Test 19 | public void test() { 20 | testService.doSomething(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/performance/biz/TestBiz.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.performance.biz; 2 | 3 | import org.danielli.xultimate.context.performance.PerformanceMonitor; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service("testBiz") 7 | public class TestBiz { 8 | 9 | @PerformanceMonitor 10 | public void doSomething1() { 11 | try { 12 | Thread.sleep(5 * 1000); 13 | } catch (InterruptedException e) { 14 | e.printStackTrace(); 15 | }; 16 | } 17 | 18 | @PerformanceMonitor 19 | public void doSomething2() { 20 | try { 21 | Thread.sleep(3 * 1000); 22 | } catch (InterruptedException e) { 23 | e.printStackTrace(); 24 | }; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/performance/service/TestService.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.performance.service; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.danielli.xultimate.context.performance.PerformanceMonitor; 6 | import org.danielli.xultimate.context.performance.biz.TestBiz; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service("testService") 10 | public class TestService { 11 | 12 | @Resource(name = "testBiz") 13 | private TestBiz testBiz; 14 | 15 | @PerformanceMonitor 16 | public void doSomething() { 17 | try { 18 | Thread.sleep(4 * 1000); 19 | } catch (InterruptedException e) { 20 | e.printStackTrace(); 21 | } 22 | testBiz.doSomething1(); 23 | try { 24 | Thread.sleep(4 * 1000); 25 | } catch (InterruptedException e) { 26 | e.printStackTrace(); 27 | } 28 | testBiz.doSomething2(); 29 | try { 30 | Thread.sleep(4 * 1000); 31 | } catch (InterruptedException e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /xultimate-context/src/test/java/org/danielli/xultimate/context/support/EncryptPropertyPlaceholderConfigurerTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.support; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | @RunWith(SpringJUnit4ClassRunner.class) 12 | @ContextConfiguration(locations = { "classpath*:applicationContext-service-config.xml", "classpath:applicationContext-service-crypto.xml", "classpath:/support/applicationContext-service-support.xml" }) 13 | public class EncryptPropertyPlaceholderConfigurerTest { 14 | 15 | @Value("${test.value}") 16 | private String value; 17 | 18 | private static final Logger LOGGER = LoggerFactory.getLogger(EncryptPropertyPlaceholderConfigurerTest.class); 19 | 20 | @Test 21 | public void test() { 22 | LOGGER.info(value); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-context/src/test/resources/chardet/test.txt: -------------------------------------------------------------------------------- 1 | 我是中国人。 2 | I'm Chinese. -------------------------------------------------------------------------------- /xultimate-context/src/test/resources/i18n/test_en_US.properties: -------------------------------------------------------------------------------- 1 | helloWorld=Hello World! -------------------------------------------------------------------------------- /xultimate-context/src/test/resources/i18n/test_zh_CN.properties: -------------------------------------------------------------------------------- 1 | helloWorld=\u4E16\u754C\u4F60\u597D\uFF01 -------------------------------------------------------------------------------- /xultimate-context/src/test/resources/image/go-home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daniellitoc/xultimate-toolkit/d3224632489626e7ab5a708821f4189c5e6d8764/xultimate-context/src/test/resources/image/go-home.png -------------------------------------------------------------------------------- /xultimate-context/src/test/resources/image/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daniellitoc/xultimate-toolkit/d3224632489626e7ab5a708821f4189c5e6d8764/xultimate-context/src/test/resources/image/test.jpg -------------------------------------------------------------------------------- /xultimate-context/src/test/resources/image2/go-home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daniellitoc/xultimate-toolkit/d3224632489626e7ab5a708821f4189c5e6d8764/xultimate-context/src/test/resources/image2/go-home.png -------------------------------------------------------------------------------- /xultimate-context/src/test/resources/image2/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daniellitoc/xultimate-toolkit/d3224632489626e7ab5a708821f4189c5e6d8764/xultimate-context/src/test/resources/image2/test.jpg -------------------------------------------------------------------------------- /xultimate-context/src/test/resources/support/test.properties: -------------------------------------------------------------------------------- 1 | test.value=dcbe8df70f8da53e3a323ccf7e9ed758 -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/ClassTypeSupporter.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core; 2 | 3 | /** 4 | * 类型支持器。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | */ 9 | public interface ClassTypeSupporter { 10 | 11 | /** 12 | * 是否支持此类型。 13 | * @param classType 类型。 14 | * @return 如果为true,则表示可以,否则为false。 15 | */ 16 | boolean support(Class classType); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/compression/Compressor.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.compression; 2 | 3 | import java.io.OutputStream; 4 | 5 | /** 6 | * 压缩器。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * 11 | * @param 原始源。 12 | * @param 目标源。 13 | */ 14 | public interface Compressor { 15 | 16 | /** 17 | * 压缩。 18 | * 19 | * @param source 原始源。 20 | * @return 目标源。 21 | * @throws CompressorException 压缩异常,在压缩过程中出现的任何异常都会使用{@link CompressorException}封装并抛出。 22 | */ 23 | T compress(S source) throws CompressorException; 24 | 25 | /** 26 | * 包装输出流。 27 | * 28 | * @param sourceInputStream 原始输出流。 29 | * @return 包装后的输出流。 30 | * @throws CompressorException 压缩异常,在包装过程中出现的任何异常都会使用{@link CompressorException}封装并抛出。 31 | */ 32 | OutputStream wrapper(OutputStream sourceOutputStream) throws CompressorException; 33 | } 34 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/compression/CompressorException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.compression; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 压缩异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class CompressorException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = 8862452193888553128L; 15 | 16 | public CompressorException(String message) { 17 | super(message); 18 | } 19 | 20 | public CompressorException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/compression/Decompressor.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.compression; 2 | 3 | import java.io.InputStream; 4 | 5 | /** 6 | * 解压缩器。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * 11 | * @param 原始源。 12 | * @param 目标源。 13 | */ 14 | public interface Decompressor { 15 | 16 | /** 17 | * 解压缩。 18 | * 19 | * @param source 原始源。 20 | * @return 目标源。 21 | * @throws DecompressorException 解压缩异常,在解压缩过程中出现的任何异常都会使用{@link DecompressorException}封装并抛出。 22 | */ 23 | T decompress(S source) throws DecompressorException; 24 | 25 | /** 26 | * 包装输入流。 27 | * 28 | * @param sourceInputStream 原始输入流。 29 | * @return 包装后的输入流。 30 | * @throws DecompressorException 解压缩异常,在包装过程中出现的任何异常都会使用{@link DecompressorException}封装并抛出。 31 | */ 32 | InputStream wrapper(InputStream sourceInputStream) throws DecompressorException; 33 | } 34 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/compression/DecompressorException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.compression; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 解压缩异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class DecompressorException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = 8862452193888553128L; 15 | 16 | public DecompressorException(String message) { 17 | super(message); 18 | } 19 | 20 | public DecompressorException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/io/AbstractObjectInput.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.io; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import com.esotericsoftware.kryo.io.Input; 7 | 8 | /** 9 | * 抽象对象输入流。 10 | * 11 | * @author Daniel Li 12 | * @since 10 May 2014 13 | */ 14 | public abstract class AbstractObjectInput extends Input { 15 | 16 | public AbstractObjectInput (int bufferSize) { 17 | super(bufferSize); 18 | } 19 | 20 | public AbstractObjectInput (byte[] buffer) { 21 | super(buffer); 22 | } 23 | 24 | public AbstractObjectInput (byte[] buffer, int offset, int count) { 25 | super(buffer, offset, count); 26 | } 27 | 28 | public AbstractObjectInput (InputStream inputStream, int bufferSize) { 29 | super(inputStream, bufferSize); 30 | } 31 | 32 | public abstract Object readObject() throws IOException, ClassNotFoundException; 33 | 34 | public abstract T readObject(Class cls) throws IOException, ClassNotFoundException; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/json/JSONException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.json; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * JSON异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class JSONException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = -9198606590046525595L; 15 | 16 | public JSONException(String message) { 17 | super(message); 18 | } 19 | 20 | public JSONException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/json/ValueType.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.json; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | import java.lang.reflect.Type; 5 | 6 | import org.danielli.xultimate.core.json.JSONException; 7 | import org.danielli.xultimate.core.json.ValueType; 8 | import org.danielli.xultimate.util.Assert; 9 | 10 | /** 11 | * 当JSON转换Java类型时,通过此类的范型元素标识转换的类。 12 | * 13 | * @author Daniel Li 14 | * @since 18 Jun 2013 15 | * 16 | * @param 被转换成的类型。 17 | */ 18 | public abstract class ValueType { 19 | /** 范型元素的类型 */ 20 | private Type type; 21 | 22 | public ValueType() { 23 | Type type = this.getClass().getGenericSuperclass(); 24 | if (type instanceof ParameterizedType) { 25 | Type[] parameterizedType = ((ParameterizedType) type).getActualTypeArguments(); 26 | this.type = parameterizedType[0]; 27 | } 28 | Assert.notNull(type, new JSONException("Type has not been set before usage")); 29 | } 30 | 31 | /** 32 | * 获取范型元素的类型。 33 | * 34 | * @return 范型元素的类型。 35 | */ 36 | public final Type getType() { 37 | return this.type; 38 | } 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/json/fastjson/ValueTypeAdapter.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.json.fastjson; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import org.danielli.xultimate.core.json.ValueType; 6 | 7 | import com.alibaba.fastjson.TypeReference; 8 | 9 | /** 10 | * {@link TypeReference}适配器。 11 | * 12 | * @author Daniel Li 13 | * @since 18 Jun 2013 14 | * @see TypeReference 15 | * 16 | * @param 17 | */ 18 | public class ValueTypeAdapter extends TypeReference { 19 | 20 | private ValueType valueType; 21 | 22 | public ValueTypeAdapter(ValueType valueType) { 23 | this.valueType = valueType; 24 | } 25 | 26 | @Override 27 | public Type getType() { 28 | return valueType.getType(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/json/jackson/ValueTypeAdapter.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.json.jackson; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import org.danielli.xultimate.core.json.ValueType; 6 | 7 | import com.fasterxml.jackson.core.type.TypeReference; 8 | 9 | /** 10 | * {@link TypeReference}适配器。 11 | * 12 | * @author Daniel Li 13 | * @since 18 Jun 2013 14 | * @see TypeReference 15 | * 16 | * @param 17 | */ 18 | public class ValueTypeAdapter extends TypeReference { 19 | 20 | private ValueType valueType; 21 | 22 | public ValueTypeAdapter(ValueType valueType) { 23 | this.valueType = valueType; 24 | } 25 | 26 | @Override 27 | public Type getType() { 28 | return valueType.getType(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/serializer/AbstractClassTypeSupporterSerializer.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer; 2 | 3 | import org.danielli.xultimate.core.ClassTypeSupporter; 4 | 5 | public abstract class AbstractClassTypeSupporterSerializer implements ClassTypeSupporterSerializer { 6 | 7 | protected ClassTypeSupporter classTypeSupporter; 8 | 9 | @Override 10 | public boolean support(Class classType) { 11 | return classTypeSupporter.support(classType); 12 | } 13 | 14 | public void setClassTypeSupporter(ClassTypeSupporter classTypeSupporter) { 15 | this.classTypeSupporter = classTypeSupporter; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/serializer/ClassTypeSupporterSerializer.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer; 2 | 3 | import org.danielli.xultimate.core.ClassTypeSupporter; 4 | 5 | public interface ClassTypeSupporterSerializer extends Serializer, Deserializer, ClassTypeSupporter { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/serializer/Deserializer.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer; 2 | 3 | import java.io.InputStream; 4 | 5 | /** 6 | * 反序列化处理器。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | */ 11 | public interface Deserializer { 12 | 13 | /** 14 | * 反序列化。 15 | * 16 | * @param bytes 序列化数据。 17 | * @param clazz 返序列化后的类型。 18 | * @return 类型为clazz的实例。 19 | */ 20 | T deserialize(byte[] bytes, Class clazz) throws DeserializerException; 21 | 22 | /** 23 | * 从输入流中反序列化。 24 | * 25 | * @param inputStream 输入流。 26 | * @param clazz 返序列化后的类型。 27 | * @return 类型为clazz的实例。 28 | */ 29 | T deserialize(InputStream inputStream, Class clazz) throws DeserializerException; 30 | } 31 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/serializer/DeserializerException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 反序列化异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class DeserializerException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = 3488287486491666049L; 15 | 16 | public DeserializerException(String message) { 17 | super(message); 18 | } 19 | 20 | public DeserializerException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/serializer/RpcSerializer.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer; 2 | 3 | 4 | public abstract class RpcSerializer implements ClassTypeSupporterSerializer { 5 | 6 | @Override 7 | public boolean support(Class classType) { 8 | return true; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/serializer/Serializer.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer; 2 | 3 | import java.io.OutputStream; 4 | 5 | /** 6 | * 序列化处理器。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | */ 11 | public interface Serializer { 12 | 13 | /** 14 | * 序列化。 15 | * 16 | * @param source 需要序列化的对像实例。 17 | * @return 序列化后的数据。 18 | */ 19 | byte[] serialize(T source) throws SerializerException; 20 | 21 | /** 22 | * 序列化一个对像到给定的输出流。 23 | * 24 | * @param source 需要序列化的对像实例。 25 | * @param outputStream 输出流。 26 | */ 27 | void serialize(T source, OutputStream outputStream) throws SerializerException; 28 | } 29 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/serializer/SerializerException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 序列化异常。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * @see NestedRuntimeException 11 | */ 12 | public class SerializerException extends NestedRuntimeException { 13 | 14 | private static final long serialVersionUID = 3488287486491666049L; 15 | 16 | public SerializerException(String message) { 17 | super(message); 18 | } 19 | 20 | public SerializerException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/serializer/kryo/KryoGenerator.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer.kryo; 2 | 3 | import com.esotericsoftware.kryo.Kryo; 4 | 5 | /** 6 | * Kryo实例生成器。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | */ 11 | public interface KryoGenerator { 12 | 13 | Kryo generate(); 14 | } 15 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/serializer/kryo/support/KryoContext.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer.kryo.support; 2 | 3 | import com.esotericsoftware.kryo.Kryo; 4 | 5 | public class KryoContext { 6 | 7 | private static final ThreadLocal currentKryo = new ThreadLocal(); 8 | 9 | public static void setCurrentKryo(Kryo kryo) { 10 | if (kryo != null) { 11 | currentKryo.set(kryo); 12 | } 13 | else { 14 | currentKryo.remove(); 15 | } 16 | } 17 | 18 | public static Kryo currentKryo() { 19 | return currentKryo.get(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/serializer/kryo/support/ThreadLocalKryoGenerator.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer.kryo.support; 2 | 3 | import org.danielli.xultimate.core.serializer.kryo.KryoGenerator; 4 | 5 | import com.esotericsoftware.kryo.Kryo; 6 | 7 | public class ThreadLocalKryoGenerator implements KryoGenerator { 8 | 9 | public static final ThreadLocalKryoGenerator INSTANCE = new ThreadLocalKryoGenerator(); 10 | 11 | private KryoGenerator kryoGenerator = DefaultKryoGenerator.INSTANCE; 12 | 13 | private ThreadLocalKryoGenerator() { 14 | } 15 | 16 | @Override 17 | public Kryo generate() { 18 | Kryo currentKryo = KryoContext.currentKryo(); 19 | if (currentKryo == null) { 20 | currentKryo = kryoGenerator.generate(); 21 | KryoContext.setCurrentKryo(currentKryo); 22 | } 23 | return currentKryo; 24 | } 25 | 26 | public KryoGenerator getKryoGenerator() { 27 | return kryoGenerator; 28 | } 29 | 30 | public void setKryoGenerator(KryoGenerator kryoGenerator) { 31 | this.kryoGenerator = kryoGenerator; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/serializer/protostuff/support/ProtobufClassTypeNotSupporter.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer.protostuff.support; 2 | 3 | import java.util.Collection; 4 | import java.util.Date; 5 | import java.util.Map; 6 | 7 | import org.danielli.xultimate.core.support.DefaultClassTypeNotSupporter; 8 | import org.joda.time.DateTime; 9 | 10 | /** 11 | * 序列化性能不太好。 12 | * 13 | * @author Daniel Li 14 | * @since 18 Jun 2013 15 | */ 16 | public class ProtobufClassTypeNotSupporter extends DefaultClassTypeNotSupporter { 17 | 18 | public static final ProtobufClassTypeNotSupporter INSTANCE = new ProtobufClassTypeNotSupporter(); 19 | 20 | private ProtobufClassTypeNotSupporter() { 21 | Class[] notSupportClassTypes = new Class[5]; 22 | notSupportClassTypes[0] = Number.class; 23 | notSupportClassTypes[1] = Date.class; 24 | notSupportClassTypes[2] = DateTime.class; 25 | notSupportClassTypes[3] = Collection.class; 26 | notSupportClassTypes[4] = Map.class; 27 | } 28 | 29 | @Override 30 | public boolean support(Class classType) { 31 | return classType.isArray() ? false : super.support(classType); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/serializer/protostuff/util/LinkedBufferUtils.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer.protostuff.util; 2 | 3 | import com.dyuproject.protostuff.LinkedBuffer; 4 | 5 | /** 6 | * LinkedBuffer工具类。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | */ 11 | public class LinkedBufferUtils { 12 | 13 | private static ThreadLocal currentLinkedBuffer = new ThreadLocal(); 14 | 15 | /** 16 | * 获取LinkedBuffer实例。 17 | * @return LinkedBuffer实例。 18 | */ 19 | public static LinkedBuffer getCurrentLinkedBuffer(int bufferSize) { 20 | LinkedBuffer linkedBuffer = currentLinkedBuffer.get(); 21 | if (linkedBuffer == null) { 22 | linkedBuffer = LinkedBuffer.allocate(bufferSize); 23 | currentLinkedBuffer.set(linkedBuffer); 24 | } 25 | return linkedBuffer; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/support/DefaultClassTypeNotSupporter.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.support; 2 | 3 | import org.danielli.xultimate.core.ClassTypeSupporter; 4 | import org.danielli.xultimate.util.ArrayUtils; 5 | import org.danielli.xultimate.util.reflect.ClassUtils; 6 | 7 | public class DefaultClassTypeNotSupporter implements ClassTypeSupporter{ 8 | 9 | /** 不支持类型列表 */ 10 | protected Class[] notSupportClassTypes; 11 | 12 | @Override 13 | public boolean support(Class classType) { 14 | if (ArrayUtils.isNotEmpty(notSupportClassTypes)) { 15 | for (Class c : notSupportClassTypes) { 16 | if (ClassUtils.isAssignable(c, classType)) { 17 | return false; 18 | } 19 | } 20 | } 21 | return true; 22 | } 23 | 24 | /** 25 | * 设置不支持类型列表。 26 | * @param notSupportClassTypes 不支持类型列表 27 | */ 28 | public void setNotSupportClassTypes(Class[] notSupportClassTypes) { 29 | this.notSupportClassTypes = notSupportClassTypes; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/core/support/DefaultClassTypeSupporter.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.support; 2 | 3 | import org.danielli.xultimate.core.ClassTypeSupporter; 4 | import org.danielli.xultimate.util.ArrayUtils; 5 | import org.danielli.xultimate.util.reflect.ClassUtils; 6 | 7 | public class DefaultClassTypeSupporter implements ClassTypeSupporter { 8 | 9 | /** 支持类型列表 */ 10 | protected Class[] supportClassTypes; 11 | 12 | @Override 13 | public boolean support(Class classType) { 14 | if (ArrayUtils.isNotEmpty(supportClassTypes)) { 15 | for (Class c : supportClassTypes) { 16 | if (ClassUtils.isAssignable(c, classType)) { 17 | return true; 18 | } 19 | } 20 | } 21 | return false; 22 | } 23 | 24 | /** 25 | * 设置支持类型列表。 26 | * @param supportClassTypes 支持类型列表 27 | */ 28 | public void setSupportClassTypes(Class[] supportClassTypes) { 29 | this.supportClassTypes = supportClassTypes; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/util/builder/BuildType.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.builder; 2 | 3 | /** 4 | * 构建类型。 5 | * 6 | * @author Daniel Li 7 | * @since 16 Jun 2013 8 | */ 9 | public enum BuildType { 10 | 11 | /** equals方法 */ 12 | EQUALS, 13 | 14 | /** toString方法 */ 15 | TO_STRING, 16 | 17 | /** hashCode方法 */ 18 | HASH_CODE, 19 | 20 | /** compareTo方法 */ 21 | COMPARE_TO 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/util/builder/Buildable.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.builder; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Inherited; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * 构建标识,用于表示是否支持ToString、HashCode、Equals、CompareTo。 12 | * 13 | * @author Daniel Li 14 | * @since 16 Jun 2013 15 | */ 16 | @Target({ElementType.FIELD, ElementType.TYPE}) 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Inherited 19 | @Documented 20 | public @interface Buildable { 21 | 22 | BuildType[] value() default {}; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/util/collections/MapBuilder.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.collections; 2 | 3 | import java.util.Map; 4 | 5 | import org.apache.commons.lang3.builder.Builder; 6 | 7 | /** 8 | * 创建Map的Builder设计模式。 9 | * 10 | * @author Daniel Li 11 | * @since 16 Jun 2013 12 | * 13 | * @param Map键类型。 14 | * @param Map值类型。 15 | */ 16 | public class MapBuilder implements Builder> { 17 | 18 | private Map map; 19 | 20 | public MapBuilder(Map map) { 21 | this.map = map; 22 | } 23 | 24 | public MapBuilder put(K key, V value) { 25 | map.put(key, value); 26 | return this; 27 | } 28 | 29 | public MapBuilder putAll(Map m) { 30 | map.putAll(m); 31 | return this; 32 | } 33 | 34 | public MapBuilder clear() { 35 | map.clear(); 36 | return this; 37 | } 38 | 39 | public MapBuilder remove(K key) { 40 | map.remove(key); 41 | return this; 42 | } 43 | 44 | @Override 45 | public Map build() { 46 | return map; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/util/crypto/CryptoException.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.crypto; 2 | 3 | import org.springframework.core.NestedRuntimeException; 4 | 5 | /** 6 | * 加密异常类。 7 | * 8 | * @author Daniel Li 9 | * @since 16 Jun 2013 10 | */ 11 | public class CryptoException extends NestedRuntimeException { 12 | 13 | private static final long serialVersionUID = 8862452193888553128L; 14 | 15 | public CryptoException(String message) { 16 | super(message); 17 | } 18 | 19 | public CryptoException(String message, Throwable cause) { 20 | super(message, cause); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/util/exception/ExceptionUtils.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.exception; 2 | 3 | /** 4 | *

Provides utilities for manipulating and examining 5 | * Throwable objects.

6 | * 7 | * @author Daniel Li 8 | * @since 16 Jun 2013 9 | */ 10 | public class ExceptionUtils { 11 | 12 | /** 13 | *

Gets the stack trace from a Throwable as a String.

14 | * 15 | *

The result of this method vary by JDK version as this method 16 | * uses {@link Throwable#printStackTrace(java.io.PrintWriter)}. 17 | * On JDK1.3 and earlier, the cause exception will not be shown 18 | * unless the specified throwable alters printStackTrace.

19 | * 20 | * @param throwable the Throwable to be examined 21 | * @return the stack trace as generated by the exception's 22 | * printStackTrace(PrintWriter) method 23 | */ 24 | public static String getStackTrace(Throwable throwable) { 25 | return org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(throwable); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/util/pinyin/PinyinCallback.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.pinyin; 2 | 3 | /** 4 | * 拼音回调接口。 5 | * 6 | * @author Daniel Li 7 | * @since 16 Jun 2013 8 | */ 9 | public interface PinyinCallback { 10 | 11 | /** 12 | * 某个汉字的拼音处理。 13 | * @param str 处理的字符串。 14 | * @param index ch在str中所处的索引。 15 | * @param ch 指定字符。 16 | * @param mainPinyinStrOfChars 对应字符的拼音表示形式。 17 | * @return 返回指定拼音。 18 | */ 19 | String call(String str, int index, char ch, String[] mainPinyinStrOfChars); 20 | } 21 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/util/thread/ThreadUtils.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.thread; 2 | 3 | public class ThreadUtils { 4 | 5 | /** 6 | * 当前线程等待,直到活跃线程数小于等于activeThreadCount。 7 | * @param activeThreadCount 目标活跃线程数目。 8 | */ 9 | public static void waitUntilLe(int activeThreadCount) { 10 | while (Thread.activeCount() > activeThreadCount) { 11 | try { 12 | Thread.sleep(1 * 1000); 13 | } catch (InterruptedException e) { 14 | return; 15 | } 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/util/time/stopwatch/StopWatchContext.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.time.stopwatch; 2 | 3 | /** 4 | * 秒表上下文。 5 | * 6 | * @author Daniel Li 7 | * @since 16 Jun 2013 8 | */ 9 | public class StopWatchContext { 10 | 11 | private static ThreadLocal stopWatchThreadLocal = new ThreadLocal<>(); 12 | 13 | public static StopWatch get() { 14 | return stopWatchThreadLocal.get(); 15 | } 16 | 17 | public static void remove() { 18 | stopWatchThreadLocal.remove(); 19 | } 20 | 21 | public static void set(StopWatch stopWatch) { 22 | stopWatchThreadLocal.set(stopWatch); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/util/time/stopwatch/StopWatchSummary.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.time.stopwatch; 2 | 3 | /** 4 | * 秒表汇总器。 5 | * 6 | * @author Daniel Li 7 | * @since 17 Jun 2013 8 | */ 9 | public interface StopWatchSummary { 10 | 11 | public String DATE_FORMAT = "yyyy:MM:dd H:mm:ss.SSS"; 12 | 13 | /** 14 | * 汇总指定秒表。 15 | * 16 | * @param stopWatch 秒表。 17 | */ 18 | void summarize(StopWatch stopWatch); 19 | } 20 | -------------------------------------------------------------------------------- /xultimate-core/src/main/java/org/danielli/xultimate/util/time/stopwatch/support/AbstractStopWatchSummary.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.time.stopwatch.support; 2 | 3 | import org.danielli.xultimate.util.time.stopwatch.StopWatch; 4 | import org.danielli.xultimate.util.time.stopwatch.StopWatchSummary; 5 | import org.slf4j.Logger; 6 | 7 | /** 8 | * 抽象秒表汇总器。 9 | * 10 | * @author Daniel Li 11 | * @since 17 Jun 2013 12 | */ 13 | public abstract class AbstractStopWatchSummary implements StopWatchSummary { 14 | 15 | private Logger logger; 16 | 17 | public void setLogger(Logger logger) { 18 | this.logger = logger; 19 | } 20 | 21 | public Logger getLogger() { 22 | return logger; 23 | } 24 | 25 | @Override 26 | public void summarize(StopWatch stopWatch) { 27 | summarize(stopWatch, logger); 28 | } 29 | 30 | public abstract void summarize(StopWatch stopWatch, Logger logger); 31 | } 32 | -------------------------------------------------------------------------------- /xultimate-core/src/test/java/org/danielli/xultimate/PrettyTimeTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate; 2 | 3 | import java.util.Locale; 4 | 5 | import org.joda.time.DateTime; 6 | import org.junit.Test; 7 | import org.ocpsoft.prettytime.PrettyTime; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | public class PrettyTimeTest { 12 | 13 | private static final Logger LOGGER = LoggerFactory.getLogger(PrettyTimeTest.class); 14 | 15 | @Test 16 | public void test() { 17 | PrettyTime p = new PrettyTime(Locale.CHINA); 18 | 19 | LOGGER.info(p.format(new DateTime().toDate())); 20 | //prints: “right now” 21 | 22 | LOGGER.info(p.format(new DateTime().minusMinutes(10).toDate())); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-core/src/test/java/org/danielli/xultimate/SiftingAppenderTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.slf4j.MDC; 8 | 9 | public class SiftingAppenderTest { 10 | 11 | private final String LOGGER_HOST_NAME = "logger.host"; 12 | private final String LOGGER_HOST_VALUE = "127.0.0.1"; 13 | 14 | @Before 15 | public void beforeLogger() { 16 | MDC.put(LOGGER_HOST_NAME, LOGGER_HOST_VALUE); 17 | } 18 | 19 | @Test 20 | public void testLogger() { 21 | Logger logger = LoggerFactory.getLogger(SiftingAppenderTest.class); 22 | for (int i = 0; i < 1; i++) { 23 | logger.info("{}", i); 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /xultimate-core/src/test/java/org/danielli/xultimate/core/serializer/User.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.core.serializer; 2 | 3 | import java.io.Serializable; 4 | 5 | public class User implements Serializable { 6 | 7 | private static final long serialVersionUID = -1738355062692076549L; 8 | 9 | private String name; 10 | 11 | private Integer age; 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | 21 | public Integer getAge() { 22 | return age; 23 | } 24 | 25 | public void setAge(Integer age) { 26 | this.age = age; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /xultimate-core/src/test/java/org/danielli/xultimate/util/builder/Employee.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.builder; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | public class Employee extends Person { 6 | 7 | public Employee(String name, double salary, DateTime hireDay) { 8 | super(name); 9 | this.salary = salary; 10 | this.hireDay = hireDay; 11 | } 12 | 13 | private double salary; 14 | private DateTime hireDay; 15 | 16 | public double getSalary() { 17 | return salary; 18 | } 19 | 20 | public DateTime getHireDay() { 21 | return hireDay; 22 | } 23 | 24 | @Override 25 | public String getDescription() { 26 | return String.format("an employee with a salary of $%.2f", salary); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /xultimate-core/src/test/java/org/danielli/xultimate/util/builder/Manager.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.builder; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | public class Manager extends Employee { 6 | 7 | private double bouns; 8 | 9 | public Manager(String name, double salary, DateTime hireDay, double bouns) { 10 | super(name, salary, hireDay); 11 | this.bouns = bouns; 12 | } 13 | 14 | public double getBouns() { 15 | return bouns; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /xultimate-core/src/test/java/org/danielli/xultimate/util/builder/Person.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.builder; 2 | 3 | @Buildable({BuildType.TO_STRING, BuildType.HASH_CODE, BuildType.EQUALS, BuildType.COMPARE_TO}) 4 | public abstract class Person { 5 | private String name; 6 | 7 | public Person(String name) { 8 | this.name = name; 9 | } 10 | 11 | public abstract String getDescription(); 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /xultimate-core/src/test/java/org/danielli/xultimate/util/math/NumberUtilsTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.math; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class NumberUtilsTest { 7 | 8 | @Test 9 | public void testIsPositiveNumber() { 10 | Assert.assertFalse(NumberUtils.isPositiveNumber(-1L)); 11 | Assert.assertFalse(NumberUtils.isPositiveNumber(-10000000000000000L)); 12 | Assert.assertFalse(NumberUtils.isPositiveNumber(0)); 13 | Assert.assertFalse(NumberUtils.isPositiveNumber(1.6)); 14 | Assert.assertTrue(NumberUtils.isPositiveNumber(1)); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /xultimate-core/src/test/java/org/danielli/xultimate/util/time/ChineseCalendarGBTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.util.time; 2 | 3 | import org.junit.Test; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | public class ChineseCalendarGBTest { 8 | 9 | private static final Logger LOGGER = LoggerFactory.getLogger(ChineseCalendarGBTest.class); 10 | 11 | @Test 12 | public void test() { 13 | ChineseCalendarGB c = new ChineseCalendarGB(); 14 | String cmd = "day"; 15 | int y = 2014; 16 | int m = 2; 17 | int d = 23; 18 | c.setGregorian(y, m, d); 19 | c.computeChineseFields(); 20 | c.computeSolarTerms(); 21 | if (cmd.equalsIgnoreCase("year")) { 22 | String[] t = c.getYearTable(); 23 | for (int i = 0; i < t.length; i++) 24 | LOGGER.info(t[i]); 25 | } else if (cmd.equalsIgnoreCase("month")) { 26 | String[] t = c.getMonthTable(); 27 | for (int i = 0; i < t.length; i++) 28 | LOGGER.info(t[i]); 29 | } else { 30 | LOGGER.info(c.toString()); 31 | LOGGER.info(c.getDateString()); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /xultimate-core/src/test/resources/source: -------------------------------------------------------------------------------- 1 | This is a test text. -------------------------------------------------------------------------------- /xultimate-jdbc/src/main/java/org/danielli/xultimate/jdbc/datasource/lookup/DataSourceContext.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.jdbc.datasource.lookup; 2 | 3 | /** 4 | * DataSource上下文。 5 | * 6 | * @author Daniel Li 7 | * @since 15 Jun 2013 8 | */ 9 | public class DataSourceContext { 10 | 11 | private static final ThreadLocal currentLookupKey = new ThreadLocal(); 12 | 13 | /** 14 | * 设置数据源Key。 15 | * 16 | * @param lookupKey 数据源Key。 17 | * @return 原数据源Key。 18 | */ 19 | public static String setCurrentLookupKey(String lookupKey) { 20 | String oldLookupKey = currentLookupKey.get(); 21 | if (lookupKey != null) { 22 | currentLookupKey.set(lookupKey); 23 | } 24 | else { 25 | currentLookupKey.remove(); 26 | } 27 | return oldLookupKey; 28 | } 29 | 30 | /** 31 | * 获取当前数据源Key。 32 | * 33 | * @return 当前数据源Key。 34 | */ 35 | public static String currentLookupKey() { 36 | return currentLookupKey.get(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/main/java/org/danielli/xultimate/jdbc/datasource/lookup/RoutingDataSource.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.jdbc.datasource.lookup; 2 | 3 | import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; 4 | 5 | /** 6 | * {@link javax.sql.DataSource} implementation that routes {@link #getConnection()} 7 | * calls to one of various target DataSources based on a lookup key. The latter is usually 8 | * (but not necessarily) determined through some thread-bound transaction context. 9 | * 10 | * @author Daniel Li 11 | * @since 15 Jun 2013 12 | * @see #setTargetDataSources 13 | * @see #setDefaultTargetDataSource 14 | * @see #determineCurrentLookupKey() 15 | */ 16 | public class RoutingDataSource extends AbstractRoutingDataSource { 17 | 18 | @Override 19 | protected Object determineCurrentLookupKey() { 20 | return DataSourceContext.currentLookupKey(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/main/java/org/danielli/xultimate/jdbc/support/incrementer/H2SequenceMaxValueIncrementer.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.jdbc.support.incrementer; 2 | 3 | import javax.sql.DataSource; 4 | 5 | /** 6 | * H2序列最大值增长器。 7 | * 8 | * @author Daniel Li 9 | * @since 15 Jun 2013 10 | * @see AbstractSequenceMaxValueIncrementer 11 | */ 12 | public class H2SequenceMaxValueIncrementer extends AbstractSequenceMaxValueIncrementer{ 13 | 14 | /** 15 | * 创建实例。并通过相应的setter方法完成必要设置。 16 | * 17 | * @see #setDataSource 18 | * @see #setIncrementerName 19 | */ 20 | public H2SequenceMaxValueIncrementer() { 21 | } 22 | 23 | /** 24 | * 创建实例。 25 | * 26 | * @param dataSource 使用的数据源。 27 | * @param incrementerName 使用的序列名称。 28 | */ 29 | public H2SequenceMaxValueIncrementer(DataSource dataSource, String incrementerName) { 30 | super(dataSource, incrementerName); 31 | } 32 | 33 | @Override 34 | protected String getSequenceQuery() { 35 | return "select " + getIncrementerName() + ".nextval from dual"; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/main/java/org/danielli/xultimate/jdbc/support/incrementer/OracleSequenceMaxValueIncrementer.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.jdbc.support.incrementer; 2 | 3 | import javax.sql.DataSource; 4 | 5 | /** 6 | * Oracle序列最大值增长器。 7 | * 8 | * @author Daniel Li 9 | * @since 15 Jun 2013 10 | * @see AbstractSequenceMaxValueIncrementer 11 | */ 12 | public class OracleSequenceMaxValueIncrementer extends AbstractSequenceMaxValueIncrementer{ 13 | 14 | /** 15 | * 创建实例。并通过相应的setter方法完成必要设置。 16 | * 17 | * @see #setDataSource 18 | * @see #setIncrementerName 19 | */ 20 | public OracleSequenceMaxValueIncrementer() { 21 | } 22 | 23 | /** 24 | * 创建实例。 25 | * 26 | * @param dataSource 使用的数据源。 27 | * @param incrementerName 使用的序列名称。 28 | */ 29 | public OracleSequenceMaxValueIncrementer(DataSource dataSource, String incrementerName) { 30 | super(dataSource, incrementerName); 31 | } 32 | 33 | 34 | @Override 35 | protected String getSequenceQuery() { 36 | return "select " + getIncrementerName() + ".nextval from dual"; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/main/java/org/danielli/xultimate/jdbc/type/CodeEnum.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.jdbc.type; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 带有Code的枚举类型。 7 | * 8 | * @author Daniel Li 9 | * @since 8 August 2015 10 | */ 11 | public interface CodeEnum> extends Comparable, Serializable { 12 | 13 | int getCode(); 14 | } -------------------------------------------------------------------------------- /xultimate-jdbc/src/main/java/org/danielli/xultimate/jdbc/type/CodeEnums.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.jdbc.type; 2 | 3 | /** 4 | * CodeEnum工具。 5 | * 6 | * @author Daniel Li 7 | * @since 17 August 2015 8 | */ 9 | public class CodeEnums { 10 | 11 | public static E valueOf(Class clazz, int code) { 12 | E[] codeEnums = clazz.getEnumConstants(); 13 | for (E codeEnum : codeEnums) { 14 | if (codeEnum.getCode() == code) { 15 | return codeEnum; 16 | } 17 | } 18 | return null; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/java/org/danielli/xultimate/jdbc/type/StateSetTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.jdbc.type; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.Test; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | public class StateSetTest { 10 | 11 | private static final Logger LOGGER = LoggerFactory.getLogger(StateSetTest.class); 12 | 13 | public enum TestEnum { 14 | v1, v2, v3, v4 15 | } 16 | 17 | @Test 18 | public void test1() { 19 | LOGGER.info("{}", TestEnum.v4); 20 | StateSet set = StateSet.of(TestEnum.class); 21 | set.add(TestEnum.v4); 22 | set.add(TestEnum.v3); 23 | set.remove(TestEnum.v3); 24 | LOGGER.info("{}", set.getValue()); 25 | LOGGER.info("{}", TestEnum.v2); 26 | LOGGER.info("{}", TestEnum.v1); 27 | } 28 | 29 | @Test 30 | public void test2() { 31 | StateSet set = StateSet.of(TestEnum.class); 32 | set.add(TestEnum.v4); 33 | List result = StateSet.getContainStates(set); 34 | int i = 0; 35 | for (Byte b : result) { 36 | LOGGER.info("{}, {}", ++i, b); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/java/org/danielli/xultimate/transaction/ChainedTransactionManagerTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.transaction; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.danielli.xultimate.transaction.service.UserService; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | @RunWith(SpringJUnit4ClassRunner.class) 12 | @ContextConfiguration(locations = { 13 | "classpath:/applicationContext-dao-base.xml", 14 | "classpath:/transaction/applicationContext-service-transaction.xml" 15 | }) 16 | public class ChainedTransactionManagerTest { 17 | 18 | @Resource(name = "userServiceImpl") 19 | private UserService userService; 20 | 21 | @Test 22 | public void test() { 23 | System.out.println("----------------------------------------------------------"); 24 | // userService.testRequired(); 25 | try { 26 | userService.testErrorRequired(); 27 | } catch (Exception e) {} 28 | 29 | System.out.println("----------------------------------------------------------"); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/java/org/danielli/xultimate/transaction/biz/OtherBiz.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.transaction.biz; 2 | 3 | public interface OtherBiz { 4 | 5 | void saveOther(); 6 | 7 | void saveErrorOther(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/java/org/danielli/xultimate/transaction/biz/UserBiz.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.transaction.biz; 2 | 3 | public interface UserBiz { 4 | 5 | void saveUser(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/java/org/danielli/xultimate/transaction/biz/impl/OtherBizImpl.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.transaction.biz.impl; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.danielli.xultimate.jdbc.datasource.lookup.DataSourceContext; 6 | import org.danielli.xultimate.transaction.biz.OtherBiz; 7 | import org.danielli.xultimate.transaction.dao.OtherDAO; 8 | import org.springframework.stereotype.Service; 9 | 10 | @Service("otherBizImpl") 11 | public class OtherBizImpl implements OtherBiz { 12 | 13 | @Resource(name = "otherDAOImpl") 14 | private OtherDAO otherDAO; 15 | 16 | @Override 17 | public void saveOther() { 18 | System.out.println("otherDAO.saveOther(); Before"); 19 | DataSourceContext.setCurrentLookupKey("other"); 20 | otherDAO.saveOther(); 21 | System.out.println("otherDAO.saveOther(); After"); 22 | } 23 | 24 | @Override 25 | public void saveErrorOther() { 26 | System.out.println("otherDAO.saveErrorOther(); Before"); 27 | DataSourceContext.setCurrentLookupKey("other"); 28 | otherDAO.saveErrorOther(); 29 | System.out.println("otherDAO.saveErrorOther(); After"); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/java/org/danielli/xultimate/transaction/biz/impl/UserBizImpl.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.transaction.biz.impl; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.danielli.xultimate.jdbc.datasource.lookup.DataSourceContext; 6 | import org.danielli.xultimate.transaction.biz.UserBiz; 7 | import org.danielli.xultimate.transaction.dao.UserDAO; 8 | import org.springframework.stereotype.Service; 9 | 10 | @Service("userBizImpl") 11 | public class UserBizImpl implements UserBiz { 12 | 13 | @Resource(name = "userDAOImpl") 14 | private UserDAO userDAO; 15 | 16 | @Override 17 | public void saveUser() { 18 | System.out.println("userDAO.saveUser(); Before"); 19 | DataSourceContext.setCurrentLookupKey("user"); 20 | userDAO.saveUser(); 21 | System.out.println("userDAO.saveUser(); After"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/java/org/danielli/xultimate/transaction/dao/OtherDAO.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.transaction.dao; 2 | 3 | public interface OtherDAO { 4 | 5 | void saveOther(); 6 | 7 | void saveErrorOther(); 8 | } 9 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/java/org/danielli/xultimate/transaction/dao/UserDAO.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.transaction.dao; 2 | 3 | public interface UserDAO { 4 | 5 | public void saveUser(); 6 | } 7 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/java/org/danielli/xultimate/transaction/dao/impl/OtherDAOImpl.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.transaction.dao.impl; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.danielli.xultimate.transaction.dao.OtherDAO; 6 | import org.springframework.jdbc.core.JdbcTemplate; 7 | import org.springframework.stereotype.Repository; 8 | import org.springframework.transaction.annotation.Propagation; 9 | import org.springframework.transaction.annotation.Transactional; 10 | 11 | @Repository("otherDAOImpl") 12 | public class OtherDAOImpl implements OtherDAO { 13 | 14 | @Resource(name = "routingJdbcTemplate") 15 | private JdbcTemplate jdbcTemplate; 16 | 17 | @Override 18 | @Transactional(value = "chainTransactionManager", propagation = Propagation.REQUIRED) 19 | public void saveOther() { 20 | System.out.println("Save Other"); 21 | jdbcTemplate.update("INSERT INTO `other` values (1, 'Daniel Li')"); 22 | } 23 | 24 | @Override 25 | @Transactional(value = "chainTransactionManager", propagation = Propagation.REQUIRED) 26 | public void saveErrorOther() { 27 | throw new RuntimeException(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/java/org/danielli/xultimate/transaction/dao/impl/UserDAOImpl.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.transaction.dao.impl; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.danielli.xultimate.transaction.dao.UserDAO; 6 | import org.springframework.jdbc.core.JdbcTemplate; 7 | import org.springframework.stereotype.Repository; 8 | import org.springframework.transaction.annotation.Propagation; 9 | import org.springframework.transaction.annotation.Transactional; 10 | 11 | @Repository("userDAOImpl") 12 | public class UserDAOImpl implements UserDAO { 13 | 14 | @Resource(name = "routingJdbcTemplate") 15 | private JdbcTemplate jdbcTemplate; 16 | 17 | @Override 18 | @Transactional(value = "chainTransactionManager", propagation = Propagation.REQUIRED) 19 | public void saveUser() { 20 | System.out.println("Save User"); 21 | jdbcTemplate.update("INSERT INTO `user` values (1, 'Daniel Li')"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/java/org/danielli/xultimate/transaction/service/UserService.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.transaction.service; 2 | 3 | public interface UserService { 4 | 5 | 6 | public void testRequired(); 7 | 8 | public void testErrorRequired(); 9 | } 10 | -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/resources/primaryKey/databases.properties: -------------------------------------------------------------------------------- 1 | datasource.primaryKey.1.jdbc.driver=com.mysql.jdbc.Driver 2 | datasource.primaryKey.1.jdbc.url=jdbc:mysql://127.0.0.1:3306/primary_key_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&failOverReadOnly=false 3 | datasource.primaryKey.1.jdbc.username=3684f43fb94f83604ce73c25f930288e09b05fdfb6b8a3b731b8fe56f42332ea 4 | datasource.primaryKey.1.jdbc.password=3684f43fb94f83604ce73c25f930288e09b05fdfb6b8a3b731b8fe56f42332ea 5 | datasource.primaryKey.1.pool.maxActive=20 6 | datasource.primaryKey.1.pool.minIdle=1 7 | 8 | datasource.primaryKey.2.jdbc.driver=com.mysql.jdbc.Driver 9 | datasource.primaryKey.2.jdbc.url=jdbc:mysql://127.0.0.1:3306/primary_key_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&failOverReadOnly=false 10 | datasource.primaryKey.2.jdbc.username=3684f43fb94f83604ce73c25f930288e09b05fdfb6b8a3b731b8fe56f42332ea 11 | datasource.primaryKey.2.jdbc.password=3684f43fb94f83604ce73c25f930288e09b05fdfb6b8a3b731b8fe56f42332ea 12 | datasource.primaryKey.2.pool.maxActive=20 13 | datasource.primaryKey.2.pool.minIdle=1 -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/resources/primaryKey/primary_key_1_destroy.sql: -------------------------------------------------------------------------------- 1 | drop table primary_key_table_1; -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/resources/primaryKey/primary_key_1_init.sql: -------------------------------------------------------------------------------- 1 | create table primary_key_table_1 ( 2 | next_id int 3 | ) ENGINE = MyISAM; 4 | 5 | insert into primary_key_table_1 values (0); -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/resources/primaryKey/primary_key_2_destroy.sql: -------------------------------------------------------------------------------- 1 | drop table primary_key_table_2; -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/resources/primaryKey/primary_key_2_init.sql: -------------------------------------------------------------------------------- 1 | create table primary_key_table_2 ( 2 | next_id int 3 | ) ENGINE = MyISAM; 4 | 5 | insert into primary_key_table_2 values (1); -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/resources/transaction/other_destroy.sql: -------------------------------------------------------------------------------- 1 | drop table `other`; -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/resources/transaction/other_init.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE if not exists `other` ( 2 | `id` bigint(20) NOT NULL, 3 | `name` varchar(255) DEFAULT NULL, 4 | PRIMARY KEY (`id`) 5 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/resources/transaction/user_destroy.sql: -------------------------------------------------------------------------------- 1 | drop table `user`; -------------------------------------------------------------------------------- /xultimate-jdbc/src/test/resources/transaction/user_init.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE if not exists `user` ( 2 | `id` bigint(20) NOT NULL, 3 | `name` varchar(255) DEFAULT NULL, 4 | PRIMARY KEY (`id`) 5 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -------------------------------------------------------------------------------- /xultimate-orm/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.danielli.xultimate 8 | xultimate-toolkit 9 | 1.0.0-SNAPSHOT 10 | 11 | 12 | xultimate-orm 13 | pom 14 | 15 | The X-Ultimate Toolkit ORM 16 | The X-Ultimate Toolkit orm project. 17 | https://github.com/daniellitoc/xultimate-toolkit/tree/master/xultimate-orm 18 | 19 | xultimate-hibernate 20 | xultimate-mybatis 21 | 22 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/main/java/org/danielli/xultimate/orm/jpa/GenericDAO.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | import org.danielli.xultimate.orm.jpa.id.IDEntity; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.data.domain.Sort; 10 | import org.springframework.data.jpa.domain.Specification; 11 | import org.springframework.data.jpa.repository.JpaRepository; 12 | 13 | /** 14 | * 通用数据访问接口。 15 | * 16 | * @author Daniel Li 17 | * @since 18 Jun 2013 18 | * 19 | * @param 操作对象类型。 20 | * @param 操作对象主键类型。 21 | */ 22 | public interface GenericDAO, ID extends Serializable> extends JpaRepository { 23 | 24 | List findAll(Specification spec); 25 | 26 | List findAll(Specification spec, Sort sort); 27 | 28 | Page findAll(Specification spec, Pageable pageable); 29 | } 30 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/main/java/org/danielli/xultimate/orm/jpa/config/ProxyInitializer.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.config; 2 | 3 | /** 4 | * 代理初始化器。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | */ 9 | public interface ProxyInitializer { 10 | 11 | void initialize(Object proxy); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/main/java/org/danielli/xultimate/orm/jpa/config/SessionCallback.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.config; 2 | 3 | import org.hibernate.Session; 4 | 5 | /** 6 | * Session回调。 7 | * 8 | * @author Daniel Li 9 | * @since 19 Jun 2013 10 | */ 11 | public interface SessionCallback { 12 | 13 | /** 14 | * 回调实现。 15 | * 16 | * @param session 会话。 17 | */ 18 | void doInSession(Session session); 19 | } 20 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/main/java/org/danielli/xultimate/orm/jpa/config/support/HibernateProxyInitializer.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.config.support; 2 | 3 | import org.danielli.xultimate.orm.jpa.config.ProxyInitializer; 4 | import org.hibernate.Hibernate; 5 | 6 | /** 7 | * 代理初始化器,Hibernate实现。 8 | * 9 | * @author Daniel Li 10 | * @since 18 Jun 2013 11 | */ 12 | public class HibernateProxyInitializer implements ProxyInitializer { 13 | 14 | @Override 15 | public void initialize(Object proxy) { 16 | Hibernate.initialize(proxy); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/main/java/org/danielli/xultimate/orm/jpa/ds/LogicalOperator.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.ds; 2 | 3 | import javax.persistence.criteria.CriteriaBuilder; 4 | import javax.persistence.criteria.Predicate; 5 | 6 | /** 7 | * 动态查询的逻辑符操作器。 8 | * 9 | * @author Daniel Li 10 | * @since 18 Jun 2013 11 | */ 12 | public enum LogicalOperator { 13 | OR { 14 | @Override 15 | public Predicate getPredicate(Predicate predicate, CriteriaBuilder builder) { 16 | return builder.or(predicate); 17 | } 18 | }, 19 | AND { 20 | @Override 21 | public Predicate getPredicate(Predicate predicate, CriteriaBuilder builder) { 22 | return builder.and(predicate); 23 | } 24 | }, 25 | NOT { 26 | @Override 27 | public Predicate getPredicate(Predicate predicate, CriteriaBuilder builder) { 28 | return builder.not(predicate); 29 | } 30 | }; 31 | 32 | public abstract Predicate getPredicate(Predicate predicate, CriteriaBuilder builder); 33 | } 34 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/main/java/org/danielli/xultimate/orm/jpa/ds/Value.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.ds; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 动态查询的值。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * 11 | * @param 值。 12 | */ 13 | public interface Value extends Serializable { 14 | 15 | T getValue(); 16 | } 17 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/main/java/org/danielli/xultimate/orm/jpa/ds/support/GenericValue.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.ds.support; 2 | 3 | import org.danielli.xultimate.orm.jpa.ds.Value; 4 | 5 | public class GenericValue implements Value { 6 | private static final long serialVersionUID = 8776418271286892897L; 7 | 8 | private T value; 9 | 10 | @Override 11 | public T getValue() { 12 | return value; 13 | } 14 | 15 | public void setValue(T value) { 16 | this.value = value; 17 | } 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/main/java/org/danielli/xultimate/orm/jpa/ds/support/Pair.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.ds.support; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Pair implements Serializable { 6 | 7 | private static final long serialVersionUID = 211613925559016612L; 8 | 9 | private T first; 10 | 11 | private T second; 12 | 13 | public T getFirst() { 14 | return first; 15 | } 16 | 17 | public void setFirst(T first) { 18 | this.first = first; 19 | } 20 | 21 | public T getSecond() { 22 | return second; 23 | } 24 | 25 | public void setSecond(T second) { 26 | this.second = second; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/main/java/org/danielli/xultimate/orm/jpa/id/NormsEntity.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.id; 2 | 3 | import javax.persistence.Cacheable; 4 | import javax.persistence.EntityListeners; 5 | import javax.persistence.MappedSuperclass; 6 | 7 | /** 8 | * 权重。 9 | * 10 | * @author Daniel Li 11 | * @since 18 Jun 2013 12 | */ 13 | @MappedSuperclass 14 | @Cacheable(true) 15 | @EntityListeners({ NormsListener.class }) 16 | public abstract class NormsEntity extends DateEntity { 17 | 18 | private static final long serialVersionUID = -6174042248508311497L; 19 | 20 | private Float boost; 21 | 22 | public Float getBoost() { 23 | return boost; 24 | } 25 | 26 | public void setBoost(Float boost) { 27 | this.boost = boost; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/main/java/org/danielli/xultimate/orm/jpa/id/NormsListener.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.id; 2 | 3 | import javax.persistence.PrePersist; 4 | 5 | /** 6 | * 权重监听器。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | */ 11 | public class NormsListener { 12 | 13 | @PrePersist 14 | public void prePersist(NormsEntity norms) { 15 | if (norms.getBoost() == null) { 16 | norms.setBoost(0.0F); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/main/java/org/danielli/xultimate/orm/jpa/id/VersionEntity.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.id; 2 | 3 | import javax.persistence.Cacheable; 4 | import javax.persistence.Column; 5 | import javax.persistence.MappedSuperclass; 6 | import javax.persistence.Version; 7 | 8 | /** 9 | * 版本实体,包含version属性。 10 | * 11 | * @author Daniel Li 12 | * @since 18 Jun 2013 13 | */ 14 | @MappedSuperclass 15 | @Cacheable(true) 16 | public abstract class VersionEntity extends IDEntity { 17 | private static final long serialVersionUID = 479107963083635365L; 18 | 19 | protected Long version; // 版本号 20 | 21 | @Version 22 | @Column(name = "entity_version") 23 | public Long getVersion() { 24 | return version; 25 | } 26 | 27 | public void setVersion(Long version) { 28 | this.version = version; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/test/java/org/danielli/xultimate/orm/jpa/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa; 2 | 3 | import javax.persistence.Cacheable; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | import javax.persistence.MappedSuperclass; 8 | 9 | import org.danielli.xultimate.orm.jpa.id.NormsEntity; 10 | 11 | @MappedSuperclass 12 | @Cacheable(true) 13 | public class BaseEntity extends NormsEntity { 14 | 15 | private static final long serialVersionUID = 1298348676340359002L; 16 | 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.AUTO) 19 | @Override 20 | public Long getId() { 21 | return super.getId(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/test/java/org/danielli/xultimate/orm/jpa/area/biz/AreaBiz.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.area.biz; 2 | 3 | import org.danielli.xultimate.orm.jpa.GenericBiz; 4 | import org.danielli.xultimate.orm.jpa.area.domain.Area; 5 | 6 | public interface AreaBiz extends GenericBiz { 7 | 8 | void execCustomMethod(Area area); 9 | } 10 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/test/java/org/danielli/xultimate/orm/jpa/area/biz/impl/AreaBizImpl.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.area.biz.impl; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.danielli.xultimate.orm.jpa.DefaultGenericBiz; 6 | import org.danielli.xultimate.orm.jpa.GenericDAO; 7 | import org.danielli.xultimate.orm.jpa.area.biz.AreaBiz; 8 | import org.danielli.xultimate.orm.jpa.area.dao.AreaDAO; 9 | import org.danielli.xultimate.orm.jpa.area.domain.Area; 10 | import org.springframework.stereotype.Service; 11 | 12 | @Service("areaBizImpl") 13 | public class AreaBizImpl extends DefaultGenericBiz implements AreaBiz { 14 | 15 | @Resource(name = "areaDAO") 16 | private AreaDAO areaDAO; 17 | 18 | @Override 19 | @Resource(name = "areaDAO") 20 | public void setGenericDAO(GenericDAO genericDAO) { 21 | super.setGenericDAO(genericDAO); 22 | } 23 | 24 | @Override 25 | public void execCustomMethod(Area area) { 26 | areaDAO.execCustomMethod(area); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/test/java/org/danielli/xultimate/orm/jpa/area/dao/AreaDAO.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.area.dao; 2 | 3 | import java.util.List; 4 | 5 | import org.danielli.xultimate.orm.jpa.GenericDAO; 6 | import org.danielli.xultimate.orm.jpa.area.domain.Area; 7 | import org.springframework.data.domain.Pageable; 8 | import org.springframework.data.jpa.repository.Query; 9 | import org.springframework.data.repository.query.Param; 10 | 11 | public interface AreaDAO extends GenericDAO, AreaDAOExt { 12 | 13 | List findByName(String name); 14 | 15 | @Query("FROM Area WHERE name = :name") 16 | List findByQuery(@Param("name") String name, Pageable pageable); 17 | 18 | } -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/test/java/org/danielli/xultimate/orm/jpa/area/dao/AreaDAOExt.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.area.dao; 2 | 3 | import org.danielli.xultimate.orm.jpa.area.domain.Area; 4 | 5 | public interface AreaDAOExt { 6 | 7 | public void execCustomMethod(Area area); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/test/java/org/danielli/xultimate/orm/jpa/area/dao/AreaDAOImpl.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.area.dao; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.danielli.xultimate.orm.jpa.area.domain.Area; 6 | import org.hibernate.SessionFactory; 7 | import org.springframework.stereotype.Repository; 8 | 9 | /** 10 | * 此注解在Spring Data JPA中,只能由jpa:repositories解析,并且通过定义为areaRepositoryImpl,也会被忽略,使用areaDAOImpl 11 | */ 12 | @Repository("areaDAOImpl") 13 | public class AreaDAOImpl implements AreaDAOExt { 14 | 15 | @Resource(name = "sessionFactory") 16 | private SessionFactory sessionFactory; 17 | 18 | @Override 19 | public void execCustomMethod(Area area) { 20 | System.out.println("This is a custom Method"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/test/java/org/danielli/xultimate/orm/jpa/area/domain/AreaEntityListener.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.jpa.area.domain; 2 | 3 | import javax.persistence.PostPersist; 4 | import javax.persistence.PostUpdate; 5 | import javax.persistence.PreUpdate; 6 | 7 | public class AreaEntityListener { 8 | 9 | @PostPersist 10 | private void test2(Area area) { 11 | System.out.println("postPersist"); 12 | area.setName("北京2"); 13 | area.setDisplayName(area.getName()); 14 | } 15 | 16 | @PreUpdate 17 | private void test3(Area area) { 18 | // 前置处理应用与改变属性。 19 | System.out.println("preUpdate"); 20 | area.setName("北京3"); 21 | area.setDisplayName(area.getName()); 22 | } 23 | 24 | @PostUpdate 25 | private void test4(Area area) { 26 | // 后处理改变属性无法同步到数据库。 27 | System.out.println("postUpdate"); 28 | area.setName("北京4"); 29 | area.setDisplayName(area.getName()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-hibernate/src/test/resources/databases.properties: -------------------------------------------------------------------------------- 1 | #------------ MySQL ------------ 2 | datasource.ormDb.jdbc.driver=com.mysql.jdbc.Driver 3 | datasource.ormDb.jdbc.url=jdbc:mysql://127.0.0.1:3306/orm_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull 4 | datasource.ormDb.jdbc.username=64c15dd4a9f5523d71dde127e8e8db96 5 | datasource.ormDb.jdbc.password=64c15dd4a9f5523d71dde127e8e8db96 6 | datasource.ormDb.pool.maxActive=20 7 | datasource.ormDb.pool.minIdle=10 8 | 9 | #------------ Oracle ------------ 10 | #datasource.ormDb.jdbc.driver=oracle.jdbc.driver.OracleDriver 11 | #datasource.ormDb.jdbc.url=jdbc:oracle:thin:@localhost:1521:orm_db 12 | #datasource.ormDb.jdbc.username=64c15dd4a9f5523d71dde127e8e8db96 13 | #datasource.ormDb.jdbc.password=64c15dd4a9f5523d71dde127e8e8db96 14 | #datasource.ormDb.pool.maxActive=20 15 | #datasource.ormDb.pool.minIdle=10 -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/main/java/org/danielli/xultimate/orm/mybatis/MyBatisRepository.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * MyBatis Repository标识。 10 | * 11 | * @author Daniel Li 12 | * @since 15 Jun 2013 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target(ElementType.TYPE) 16 | public @interface MyBatisRepository { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/main/java/org/danielli/xultimate/orm/mybatis/ds/ComparsionOperator.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.ds; 2 | 3 | /** 4 | * 动态查询的比较符操作器。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | */ 9 | public enum ComparsionOperator { 10 | EQ, 11 | NOT_EQ, 12 | LIKE, 13 | NOT_LIKE, 14 | GT, 15 | LT, 16 | GE, 17 | LE, 18 | IN, 19 | BETWEEN; 20 | } 21 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/main/java/org/danielli/xultimate/orm/mybatis/ds/LogicalOperator.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.ds; 2 | 3 | /** 4 | * 动态查询的逻辑符操作器。 5 | * 6 | * @author Daniel Li 7 | * @since 18 Jun 2013 8 | */ 9 | public enum LogicalOperator { 10 | OR, 11 | AND, 12 | NOT; 13 | } 14 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/main/java/org/danielli/xultimate/orm/mybatis/ds/Value.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.ds; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 动态查询的值。 7 | * 8 | * @author Daniel Li 9 | * @since 18 Jun 2013 10 | * 11 | * @param 值。 12 | */ 13 | public interface Value extends Serializable { 14 | T getValue(); 15 | } 16 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/main/java/org/danielli/xultimate/orm/mybatis/ds/support/GenericValue.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.ds.support; 2 | 3 | import org.danielli.xultimate.orm.mybatis.ds.Value; 4 | 5 | public class GenericValue implements Value { 6 | private static final long serialVersionUID = 8776418271286892897L; 7 | 8 | private T value; 9 | 10 | @Override 11 | public T getValue() { 12 | return value; 13 | } 14 | 15 | public void setValue(T value) { 16 | this.value = value; 17 | } 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/main/java/org/danielli/xultimate/orm/mybatis/ds/support/Pair.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.ds.support; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Pair implements Serializable { 6 | private static final long serialVersionUID = 211613925559016612L; 7 | 8 | private T first; 9 | 10 | private T second; 11 | 12 | public T getFirst() { 13 | return first; 14 | } 15 | 16 | public void setFirst(T first) { 17 | this.first = first; 18 | } 19 | 20 | public T getSecond() { 21 | return second; 22 | } 23 | 24 | public void setSecond(T second) { 25 | this.second = second; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/test/java/org/danielli/xultimate/orm/mybatis/area/biz/AreaBiz.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.area.biz; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.danielli.xultimate.orm.mybatis.ds.Item; 7 | import org.danielli.xultimate.orm.mybatis.po.Area; 8 | 9 | public interface AreaBiz { 10 | 11 | void save(Area entity); 12 | 13 | void update(Area entity); 14 | 15 | void delete(Area entity); 16 | 17 | Long findIdByName(String name); 18 | 19 | Map findIdAndNameMap(); 20 | 21 | Map findOneMap(Long id); 22 | 23 | Area findOne(Long id); 24 | 25 | List findAll(); 26 | 27 | Long count(); 28 | 29 | List findByItems(List> items); 30 | } 31 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/test/java/org/danielli/xultimate/orm/mybatis/area/dao/AreaDAO.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.area.dao; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.apache.ibatis.annotations.MapKey; 7 | import org.apache.ibatis.annotations.Select; 8 | import org.danielli.xultimate.orm.mybatis.MyBatisRepository; 9 | import org.danielli.xultimate.orm.mybatis.ds.Item; 10 | import org.danielli.xultimate.orm.mybatis.po.Area; 11 | 12 | @MyBatisRepository 13 | public interface AreaDAO { 14 | 15 | int save(Area entity); 16 | 17 | int update(Area entity); 18 | 19 | int delete(Area entity); 20 | 21 | Long findIdByName(String name); 22 | 23 | @MapKey("id") 24 | Map findIdAndNameMap(); 25 | 26 | Map findOneMap(Long id); 27 | 28 | Area findOne(Long id); 29 | 30 | List findAll(); 31 | 32 | @Select("select count(id) from ULTIMATE_AREA") 33 | Long count(); 34 | 35 | List findByItems(List> items); 36 | } 37 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/test/java/org/danielli/xultimate/orm/mybatis/area/service/AreaService.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.area.service; 2 | 3 | import java.util.List; 4 | 5 | import org.danielli.xultimate.orm.mybatis.ds.Item; 6 | import org.danielli.xultimate.orm.mybatis.po.Area; 7 | 8 | public interface AreaService { 9 | 10 | void save(Area entity); 11 | 12 | void update(Area entity); 13 | 14 | void delete(Area entity); 15 | 16 | Area findOne(Long id); 17 | 18 | List findAll(); 19 | 20 | public void testRollback(Area area); 21 | 22 | void noSupportTransaction(Area area); 23 | 24 | List findByItems(List> items); 25 | 26 | 27 | List findAllByReadOnly(); 28 | List findAllByNotSupport(); 29 | List findAllByTransaction(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/test/java/org/danielli/xultimate/orm/mybatis/po/e/Sex.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.po.e; 2 | 3 | public enum Sex { 4 | FEMALE, MALE 5 | } 6 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/test/java/org/danielli/xultimate/orm/mybatis/po/e/TestEnum.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.po.e; 2 | 3 | public enum TestEnum { 4 | CAN_READ, CAN_WRITE, CAN_EXECUTE 5 | } 6 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/test/java/org/danielli/xultimate/orm/mybatis/type/biz/TestPoBiz.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.type.biz; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.List; 5 | 6 | import org.danielli.xultimate.jdbc.type.StateSet; 7 | import org.danielli.xultimate.orm.mybatis.po.TestPo; 8 | import org.danielli.xultimate.orm.mybatis.po.e.TestEnum; 9 | 10 | public interface TestPoBiz { 11 | 12 | int save(TestPo testPo); 13 | 14 | List findByParentId(Long parentId); 15 | 16 | List findBetweenMonty(BigDecimal startMoney, BigDecimal endMoney); 17 | 18 | List findByMessage(String message); 19 | 20 | List findByIsLock(Boolean isLock); 21 | 22 | List findByStateSet(StateSet stateSet); 23 | 24 | List findByStateSets(List stateSets); 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/test/java/org/danielli/xultimate/orm/mybatis/type/dao/TestPoDAO.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.type.dao; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.List; 5 | 6 | import org.apache.ibatis.annotations.Param; 7 | import org.danielli.xultimate.jdbc.type.StateSet; 8 | import org.danielli.xultimate.orm.mybatis.MyBatisRepository; 9 | import org.danielli.xultimate.orm.mybatis.po.TestPo; 10 | import org.danielli.xultimate.orm.mybatis.po.e.TestEnum; 11 | 12 | @MyBatisRepository 13 | public interface TestPoDAO { 14 | 15 | int save(TestPo testPo); 16 | 17 | List findByParentId(Long parentId); 18 | 19 | List findBetweenMonty(BigDecimal startMoney, BigDecimal endMoney); 20 | 21 | List findByMessage(String message); 22 | 23 | List findByIsLock(@Param("isLock") Boolean isLock); 24 | 25 | List findByStateSet(@Param("stateSet") StateSet stateSet); 26 | 27 | List findByStateSets(List stateSets); 28 | } 29 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/test/java/org/danielli/xultimate/orm/mybatis/type/service/TestPoService.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.orm.mybatis.type.service; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.List; 5 | 6 | import org.danielli.xultimate.jdbc.type.StateSet; 7 | import org.danielli.xultimate.orm.mybatis.po.TestPo; 8 | import org.danielli.xultimate.orm.mybatis.po.e.TestEnum; 9 | 10 | public interface TestPoService { 11 | 12 | int save(TestPo testPo); 13 | 14 | List findByParentId(Long parentId); 15 | 16 | List findBetweenMonty(BigDecimal startMoney, BigDecimal endMoney); 17 | 18 | List findByMessage(String message); 19 | 20 | List findByIsLock(Boolean isLock); 21 | 22 | List findByStateSet(StateSet stateSet); 23 | 24 | List findByStateSets(List stateSets); 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-orm/xultimate-mybatis/src/test/resources/databases.properties: -------------------------------------------------------------------------------- 1 | #------------ MySQL ------------ 2 | datasource.ormDb.jdbc.driver=com.mysql.jdbc.Driver 3 | datasource.ormDb.jdbc.url=jdbc:mysql://127.0.0.1:3306/orm_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull 4 | datasource.ormDb.jdbc.username=64c15dd4a9f5523d71dde127e8e8db96 5 | datasource.ormDb.jdbc.password=64c15dd4a9f5523d71dde127e8e8db96 6 | datasource.ormDb.pool.maxActive=20 7 | datasource.ormDb.pool.minIdle=10 8 | 9 | #------------ Oracle ------------ 10 | #datasource.ormDb.jdbc.driver=oracle.jdbc.driver.OracleDriver 11 | #datasource.ormDb.jdbc.url=jdbc:oracle:thin:@localhost:1521:orm_db 12 | #datasource.ormDb.jdbc.username=64c15dd4a9f5523d71dde127e8e8db96 13 | #datasource.ormDb.jdbc.password=64c15dd4a9f5523d71dde127e8e8db96 14 | #datasource.ormDb.pool.maxActive=20 15 | #datasource.ormDb.pool.minIdle=10 -------------------------------------------------------------------------------- /xultimate-shard/src/main/java/org/danielli/xultimate/shard/Action.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.shard; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 执行操作。 7 | * 8 | * @author Daniel Li 9 | * @since 15 Jun 2013 10 | */ 11 | public interface Action { 12 | 13 | /** 14 | * 执行方法。 15 | * 16 | * @param elements 被执行元素列表。 17 | */ 18 | void execute(List elements); 19 | } 20 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/java/org/danielli/xultimate/shard/Filter.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.shard; 2 | 3 | 4 | /** 5 | * 过滤器。 6 | * 7 | * @author Daniel Li 8 | * @since 15 Jun 2013 9 | * 10 | * @param 原类型。 11 | * @param 处理后的类型。 12 | */ 13 | public interface Filter { 14 | 15 | /** 16 | * 过滤。 17 | * @param source 原实例。 18 | * @return 处理后的实例。 19 | */ 20 | T doFilter(S source); 21 | } 22 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/java/org/danielli/xultimate/shard/Operator.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.shard; 2 | 3 | /** 4 | * 操作器。 5 | * 6 | * @author Daniel Li 7 | * @since 15 Jun 2013 8 | * 9 | * @param 操作元素类型。 10 | */ 11 | public interface Operator { 12 | 13 | /** 14 | * 操作方法。 15 | * 16 | * @param element1 第一个元素。 17 | * @param element2 第二个元素。 18 | * @return 结果元素。 19 | */ 20 | E operate(E element1, E element2); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/java/org/danielli/xultimate/shard/mybatis/biz/PartitionedTableIntervalBiz.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.shard.mybatis.biz; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | 8 | /** 9 | * 分区表的数据划分区间Biz。 10 | * 11 | * @author Daniel Li 12 | * @since 15 Jun 2013 13 | */ 14 | public interface PartitionedTableIntervalBiz { 15 | 16 | /** 17 | * 获取分区表的数据划分区间信息列表。 18 | * @param virtualTableIntervalIdList 虚拟表区间ID列表。 19 | * @return 分区表的数据划分区间信息列表。 20 | */ 21 | List> findInfosByVirtualTableIdAndVirtualSocketIdSet(Long virtualTableId, Set virtualSocketIdSet); 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/java/org/danielli/xultimate/shard/mybatis/biz/VirtualSocketBindRecordBiz.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.shard.mybatis.biz; 2 | 3 | import java.util.List; 4 | 5 | import org.danielli.xultimate.shard.po.VirtualSocketBindRecord; 6 | 7 | /** 8 | * 虚拟表的数据划分区间绑定记录Biz。 9 | * 10 | * @author Daniel Li 11 | * @since 15 Jun 2013 12 | */ 13 | public interface VirtualSocketBindRecordBiz { 14 | 15 | /** 16 | * 获取虚拟表的数据划分区间绑定记录列表。 17 | * @param virtualTableIntervalIdList 虚拟表区间ID列表。 18 | * @return 虚拟表的数据划分区间绑定记录列表。 19 | */ 20 | List findByVirtualTableIntervalIdList(List virtualTableIntervalIdList); 21 | } 22 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/java/org/danielli/xultimate/shard/mybatis/biz/VirtualTableBiz.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.shard.mybatis.biz; 2 | 3 | import org.danielli.xultimate.shard.po.VirtualTable; 4 | 5 | /** 6 | * 虚拟表Biz。 7 | * 8 | * @author Daniel Li 9 | * @since 15 Jun 2013 10 | */ 11 | public interface VirtualTableBiz { 12 | 13 | /** 14 | * 获取虚拟表。 15 | * @param virtualDatabaseName 虚拟数据库名称。 16 | * @param name 虚拟表的名称。 17 | * @return 虚拟表。 18 | */ 19 | VirtualTable findOneByVirtualDatabaseNameAndName(String virtualDatabaseName, String name); 20 | } 21 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/java/org/danielli/xultimate/shard/mybatis/biz/VirtualTableIntervalBiz.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.shard.mybatis.biz; 2 | 3 | import java.util.List; 4 | 5 | import org.danielli.xultimate.shard.po.VirtualTableInterval; 6 | 7 | /** 8 | * 虚拟表的数据划分区间Biz。 9 | * 10 | * @author Daniel Li 11 | * @since 15 Jun 2013 12 | */ 13 | public interface VirtualTableIntervalBiz { 14 | 15 | /** 16 | * 获取虚拟表的数据划分区间列表。 17 | * @param virtualTableId 虚拟表ID。 18 | * @return 虚拟表的数据划分区间列表。 19 | */ 20 | List findByVirtualTableId(Long virtualTableId); 21 | 22 | /** 23 | * 更新是否可用。 24 | * @param id 虚拟表的数据划分区间ID。 25 | * @param available 是否可用。 26 | */ 27 | void updateAvailableById(Long id, boolean available); 28 | 29 | /** 30 | * 获取虚拟表的数据划分区间列表。 31 | * @param virtualDatabaseName 虚拟数据库名称。 32 | * @param virtualTableName 虚拟表的名称。 33 | * @return 虚拟表的数据划分区间列表。 34 | */ 35 | List findByVirtualDatabaseNameAndVirtualTableName(String virtualDatabaseName, String virtualTableName); 36 | } 37 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/java/org/danielli/xultimate/shard/mybatis/dao/PartitionedTableIntervalDAO.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.shard.mybatis.dao; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | import org.danielli.xultimate.orm.mybatis.MyBatisRepository; 8 | 9 | 10 | /** 11 | * 分区表的数据划分区间DAO。 12 | * 13 | * @author Daniel Li 14 | * @since 15 Jun 2013 15 | */ 16 | @MyBatisRepository 17 | public interface PartitionedTableIntervalDAO { 18 | 19 | /** 20 | * 获取分区表的数据划分区间信息列表。 21 | * @param virtualTableIntervalIdList 虚拟表区间ID列表。 22 | * @return 分区表的数据划分区间信息列表。 23 | */ 24 | List> findInfosByVirtualTableIdAndVirtualSocketIdSet(Long virtualTableId, Set virtualSocketIdSet); 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/java/org/danielli/xultimate/shard/mybatis/dao/VirtualSocketBindRecordDAO.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.shard.mybatis.dao; 2 | 3 | import java.util.List; 4 | 5 | import org.danielli.xultimate.orm.mybatis.MyBatisRepository; 6 | import org.danielli.xultimate.shard.po.VirtualSocketBindRecord; 7 | 8 | /** 9 | * 虚拟表的数据划分区间绑定记录DAO。 10 | * 11 | * @author Daniel Li 12 | * @since 15 Jun 2013 13 | */ 14 | @MyBatisRepository 15 | public interface VirtualSocketBindRecordDAO { 16 | 17 | /** 18 | * 获取虚拟表的数据划分区间绑定记录列表。 19 | * @param virtualTableIntervalIdList 虚拟表区间ID列表。 20 | * @return 虚拟表的数据划分区间绑定记录列表。 21 | */ 22 | List findByVirtualTableIntervalIdList(List virtualTableIntervalIdList); 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/java/org/danielli/xultimate/shard/mybatis/dao/VirtualTableDAO.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.shard.mybatis.dao; 2 | 3 | import org.danielli.xultimate.orm.mybatis.MyBatisRepository; 4 | import org.danielli.xultimate.shard.po.VirtualTable; 5 | 6 | /** 7 | * 虚拟表DAO。 8 | * 9 | * @author Daniel Li 10 | * @since 15 Jun 2013 11 | */ 12 | @MyBatisRepository 13 | public interface VirtualTableDAO { 14 | 15 | /** 16 | * 获取虚拟表。 17 | * @param virtualDatabaseName 虚拟数据库名称。 18 | * @param name 虚拟表的名称。 19 | * @return 虚拟表。 20 | */ 21 | VirtualTable findOneByVirtualDatabaseNameAndName(String virtualDatabaseName, String name); 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/java/org/danielli/xultimate/shard/po/VirtualDatabase.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.shard.po; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | /** 7 | * 虚拟数据库。 8 | * 9 | * @author Daniel Li 10 | * @since 15 Jun 2013 11 | */ 12 | public class VirtualDatabase implements Serializable { 13 | private static final long serialVersionUID = 2222557352100341183L; 14 | /** 标识 */ 15 | private Long id; 16 | /** 虚拟数据库的名称 */ 17 | private String name; 18 | /** 创建时间 */ 19 | private Date createTime; 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Long id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public Date getCreateTime() { 38 | return createTime; 39 | } 40 | 41 | public void setCreateTime(Date createTime) { 42 | this.createTime = createTime; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/java/org/danielli/xultimate/shard/po/VirtualSocket.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.shard.po; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | /** 7 | * 虚拟Socket。 8 | * 9 | * @author Daniel Li 10 | * @since 15 Jun 2013 11 | */ 12 | public class VirtualSocket implements Serializable { 13 | private static final long serialVersionUID = -430452214732789530L; 14 | 15 | /** 标识 */ 16 | private Long id; 17 | /** 虚拟Socket地址,包含了IP和端口 */ 18 | private String address; 19 | /** 创建时间 */ 20 | private Date createTime; 21 | 22 | public Long getId() { 23 | return id; 24 | } 25 | 26 | public void setId(Long id) { 27 | this.id = id; 28 | } 29 | 30 | public String getAddress() { 31 | return address; 32 | } 33 | 34 | public void setAddress(String address) { 35 | this.address = address; 36 | } 37 | 38 | public Date getCreateTime() { 39 | return createTime; 40 | } 41 | 42 | public void setCreateTime(Date createTime) { 43 | this.createTime = createTime; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/resources/mybatis/PartitionedTableDAO.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SELECT PT.id, PT.virtual_table_id, PT.virtual_socket_id, PT.shard_id, PT.create_time FROM XULTIMATE_PARTITIONED_TABLE PT 6 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/resources/mybatis/VirtualSocketDAO.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SELECT VS.id, VS.address, VS.create_time FROM XULTIMATE_VIRTUAL_SOCKET VS 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /xultimate-shard/src/main/resources/mybatis/VirtualTableDAO.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SELECT VT.id, VT.name, VT.virtual_database_id, VT.create_time FROM XULTIMATE_VIRTUAL_TABLE VT 6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /xultimate-shard/src/test/resources/primaryKey/databases.properties: -------------------------------------------------------------------------------- 1 | datasource.primaryKey.1.jdbc.driver=com.mysql.jdbc.Driver 2 | datasource.primaryKey.1.jdbc.url=jdbc:mysql://127.0.0.1:3306/primary_key_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull 3 | datasource.primaryKey.1.jdbc.username=3684f43fb94f83604ce73c25f930288e09b05fdfb6b8a3b731b8fe56f42332ea 4 | datasource.primaryKey.1.jdbc.password=3684f43fb94f83604ce73c25f930288e09b05fdfb6b8a3b731b8fe56f42332ea 5 | datasource.primaryKey.1.pool.maxActive=20 6 | datasource.primaryKey.1.pool.minIdle=10 -------------------------------------------------------------------------------- /xultimate-shard/src/test/resources/primaryKey/primary_key_1_destroy.sql: -------------------------------------------------------------------------------- 1 | drop table primary_key_table_1; -------------------------------------------------------------------------------- /xultimate-shard/src/test/resources/primaryKey/primary_key_1_init.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS `primary_key_table_1` ( 2 | next_id int 3 | ) ENGINE = MyISAM; 4 | 5 | insert into primary_key_table_1 values (0); -------------------------------------------------------------------------------- /xultimate-shard/src/test/resources/shard/databases.properties: -------------------------------------------------------------------------------- 1 | datasource.shard.jdbc.driver=com.mysql.jdbc.Driver 2 | datasource.shard.jdbc.url=jdbc:mysql://127.0.0.1:3306/shard_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull 3 | datasource.shard.jdbc.username=dfd37e84cfe838f2cfe87657f83a89ff 4 | datasource.shard.jdbc.password=dfd37e84cfe838f2cfe87657f83a89ff 5 | datasource.shard.pool.maxActive=20 6 | datasource.shard.pool.minIdle=10 -------------------------------------------------------------------------------- /xultimate-test/src/main/java/org/danielli/xultimate/test/vo/User.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.vo; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | import javax.validation.constraints.NotNull; 7 | import javax.validation.constraints.Pattern; 8 | 9 | import org.springframework.format.annotation.DateTimeFormat; 10 | 11 | public class User implements Serializable { 12 | 13 | private static final long serialVersionUID = -1517649455741479617L; 14 | 15 | private Long id; 16 | 17 | @NotNull 18 | @Pattern(regexp = "\\w{4,30}") 19 | private String name; 20 | 21 | @DateTimeFormat(pattern = "yyyy-MM-dd") 22 | private Date birthday; 23 | 24 | public Long getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Long id) { 29 | this.id = id; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public Date getBirthday() { 41 | return birthday; 42 | } 43 | 44 | public void setBirthday(Date birthday) { 45 | this.birthday = birthday; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /xultimate-test/src/main/java/org/danielli/xultimate/test/web/converter/UserConverter.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.web.converter; 2 | 3 | import org.danielli.xultimate.test.vo.User; 4 | import org.danielli.xultimate.util.StringUtils; 5 | import org.danielli.xultimate.util.math.NumberUtils; 6 | import org.springframework.core.convert.converter.Converter; 7 | 8 | public class UserConverter implements Converter { 9 | 10 | @Override 11 | public User convert(String source) { 12 | User user = new User(); 13 | if (StringUtils.isNotBlank(source)) { 14 | String[] items = StringUtils.split(source, "|"); 15 | user.setName(items[0]); 16 | user.setId(NumberUtils.createLong(items[1])); 17 | } 18 | return user; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /xultimate-test/src/main/resources/shell/mysql/analyze.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 来源:《高性能MySQL》 3 | # This script converts SHOW GLOBAL STATUS into a tabulated format, one line per sample in the input, with the metrics divided by the time elapsed between samples. 4 | awk ' 5 | BEGIN { 6 | printf "#ts\t date\t time load QPS"; 7 | fmt = " %.2f"; 8 | } 9 | /^TS/ { # The timestamp lines begin with TS. 10 | ts = substr($2, 1, index($2, ".") - 1); 11 | load = NF - 2; 12 | diff = ts - prev_ts; 13 | prev_ts = ts; 14 | printf "\n%s %s %s %s", ts, $3, $4, substr($load, 1, length($load) - 1); 15 | } 16 | /Queries/ { 17 | printf fmt, ($2-Queries)/diff; 18 | Queries=$2 19 | } 20 | END { 21 | printf "\n" 22 | } 23 | 24 | ' "$@" 25 | -------------------------------------------------------------------------------- /xultimate-test/src/main/resources/shell/mysql/collect.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 来源:《高性能MySQL》 3 | INTERVAL=5 4 | PREFIX=$INTERVAL-sec-status 5 | RUNFILE=/tmp/collect.sh.running 6 | USER=$2 7 | read -s -p "请输入密码:" PASSWORD 8 | printf "\n" 9 | HOST=$1 10 | mysql -e 'show global variables' --host=$HOST --user=$USER --password=$PASSWORD >> mysql-variables 11 | while test -e $RUNFILE; do 12 | file=$(date +%F_%I) 13 | sleep=$(date +%s.%N | awk "{print $INTERVAL - (\$1 % $INTERVAL)}") 14 | sleep $sleep 15 | ts="$(date +"TS %s.%N %F %T")" 16 | loadavg="$(uptime)" 17 | echo "$ts $loadavg" >> $PREFIX-${file}-status 18 | mysql -e 'show global status' --host=$HOST --user=$USER --password=$PASSWORD >> $PREFIX-${file}-status & 19 | echo "$ts $loadavg" >> $PREFIX-${file}-innodbstatus 20 | mysql -e 'show engine innodb status\G' --host=$HOST --user=$USER --password=$PASSWORD >> $PREFIX-${file}-innodbstatus & 21 | echo "$ts $loadavg" >> $PREFIX-${file}-processlist 22 | mysql -e 'show full processlist\G' --host=$HOST --user=$USER --password=$PASSWORD >> $PREFIX-${file}-processlist & 23 | echo $ts 24 | 25 | done 26 | echo Exiting because $RUNFILE does not exist. 27 | -------------------------------------------------------------------------------- /xultimate-test/src/main/resources/test_zh_CN.properties: -------------------------------------------------------------------------------- 1 | required.msg=\u6D88\u606F\u5FC5\u987B\u5B58\u5728 2 | typeMismatch=\u7C7B\u578B\u8F6C\u6362\u5931\u8D25 3 | typeMismatch.long=\u6570\u5B57\u7C7B\u578BLong\u8F6C\u5316\u5931\u8D25 4 | typeMismatch.int=\u6570\u5B57\u7C7B\u578BInteger\u8F6C\u6362\u5931\u8D25 5 | typeMismatch.user.birthday=\u7528\u6237\u751F\u65E5\u8F6C\u6362\u5931\u8D25 6 | Pattern.user.name=\u540D\u5B57\u4E0D\u7B26\u5408\u8981\u6C42 7 | NotNull.user.name=\u6027\u80FD\u4E0D\u80FD\u4E3A\u7A7A\u3002 8 | required.user.name=\u4F60\u4E3A\u7A7A\u4E86 9 | Exists.user.name=\u4F60\u5B58\u5728\u4E86 10 | 11 | 12 | 13 | 14 | analysis.tprofiler.empty=\u6587\u4EF6\u4E0D\u80FD\u4E3A\u7A7A 15 | analysis.mysql.empty=\u6587\u4EF6\u4E0D\u80FD\u4E3A\u7A7A 16 | -------------------------------------------------------------------------------- /xultimate-test/src/main/webapp/WEB-INF/template/error/throwable.httl: -------------------------------------------------------------------------------- 1 | <%@page import="org.danielli.xultimate.util.exception.ExceptionUtils"%> 2 | <%@ page isErrorPage="true" import="java.io.*" contentType="text/plain"%> 3 | 4 | Message: 5 | <%=exception.getMessage()%> 6 | 7 | StackTrace: 8 | <% 9 | StringWriter stringWriter = new StringWriter(); 10 | PrintWriter printWriter = new PrintWriter(stringWriter); 11 | exception.printStackTrace(printWriter); 12 | out.println(stringWriter); 13 | printWriter.close(); 14 | stringWriter.close(); 15 | %> -------------------------------------------------------------------------------- /xultimate-test/src/main/webapp/WEB-INF/template/httl/error.httl: -------------------------------------------------------------------------------- 1 | 2 | ${exception} -------------------------------------------------------------------------------- /xultimate-test/src/main/webapp/WEB-INF/template/httl/param1.httl: -------------------------------------------------------------------------------- 1 | 2 | ${message} -------------------------------------------------------------------------------- /xultimate-test/src/main/webapp/WEB-INF/template/httl/param2.httl: -------------------------------------------------------------------------------- 1 | 2 | ${user.id}, ${user.name} -------------------------------------------------------------------------------- /xultimate-test/src/main/webapp/WEB-INF/template/httl/param2_error.httl: -------------------------------------------------------------------------------- 1 | This is param2_error Page. 2 | -------------------------------------------------------------------------------- /xultimate-test/src/main/webapp/WEB-INF/template/httl/test1.httl: -------------------------------------------------------------------------------- 1 | 2 | ${text} -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/custom/ErrorTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.custom; 2 | 3 | public class ErrorTest { 4 | 5 | public static void main(String[] args) { 6 | try { 7 | testError(); 8 | } catch (Error e) { 9 | e.printStackTrace(); 10 | } 11 | } 12 | 13 | public static void testError() { 14 | throw new OutOfMemoryError(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/custom/IntegerDecodeTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.custom; 2 | 3 | public class IntegerDecodeTest { 4 | 5 | public static void main(String[] args) { 6 | Integer integer = Integer.decode("08"); 7 | System.out.println(integer); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/custom/RuntimeConstantPoolOOMTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.custom; 2 | 3 | public class RuntimeConstantPoolOOMTest { 4 | 5 | public static void main(String[] args) { 6 | // "I'm"和"Daniel Li"在之前都没出现过,现在都在常量池中指向了对象的引用。 7 | String abc1 = new StringBuilder("I'm ").append("Daniel Li").toString(); 8 | abc1.intern(); // "I'm Daniel Li"之前也没出现过,现在常量池中指向了abc1的引用。 9 | String abc2 = "I'm Daniel Li"; // "I'm Daniel Li"之前出现过,现在常量池中指向了abc1的引用。 10 | System.out.println(abc1 == abc2); // true 11 | 12 | String val2 = "I'm not Daniel Li"; // "I'm not Daniel Li"之前没出现过,现在常量池中指向了val2的引用。 13 | // "not Daniel Li"在之前都没出现过,现在都在常量池中指向了对象的引用。 14 | String val1 = new StringBuilder("I'm ").append("not Daniel Li").toString(); 15 | System.out.println(val1.intern() == val1); // false。"I'm not Daniel Li"之前出现过,val1.intern()只想的是val2。 16 | System.out.println(val1.intern() == val2); // true 17 | System.out.println(val2 == val1); // false 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/custom/audition/Count.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.custom.audition; 2 | 3 | /** 4 | * 有一个整数n,写一个函数f(n),返回0到n之间出现的"1"的个数。比如f(13)=6,现在f(1)=1,找出小于11111111111的所有满足f(n)=n的n。 5 | */ 6 | public class Count { 7 | public static int calcOneCount(int n) { 8 | int number = 0; 9 | if (n > 9) { 10 | if (n % 10 == 1) { 11 | number++; 12 | } 13 | number += calcOneCount(n / 10); 14 | } else if (n == 1) { 15 | number++; 16 | } 17 | return number; 18 | } 19 | public static int calcTotalCount(int n) { 20 | int number = 0; 21 | for (int i = 0; i <= n; i++) { 22 | number += calcOneCount(i); 23 | } 24 | return number; 25 | } 26 | 27 | public static void main(String[] args) { 28 | System.out.println(calcTotalCount(10000)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/custom/audition/ThreadIncDec.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.custom.audition; 2 | 3 | /** 4 | * 设计4个线程,其中两个线程每次增加1,另外两个线程每次减少1。 5 | */ 6 | public class ThreadIncDec { 7 | private int j; 8 | 9 | private synchronized void inc() { 10 | j++; 11 | System.out.println(Thread.currentThread().getName() + "-inc:" + j); 12 | } 13 | 14 | private synchronized void dec() { 15 | j--; 16 | System.out.println(Thread.currentThread().getName() + "-dec:" + j); 17 | } 18 | 19 | class Inc implements Runnable { 20 | public void run() { 21 | for (int i = 0; i < 100; i++) { 22 | inc(); 23 | } 24 | } 25 | } 26 | 27 | class Dec implements Runnable { 28 | public void run() { 29 | for (int i = 0; i < 100; i++) { 30 | dec(); 31 | } 32 | } 33 | } 34 | 35 | public static void main(String[] args) { 36 | ThreadIncDec incDec = new ThreadIncDec(); 37 | Inc inc = incDec.new Inc(); 38 | Dec dec = incDec.new Dec(); 39 | for (int i = 0; i < 2; i++) { 40 | Thread t = new Thread(inc); 41 | t.start(); 42 | t = new Thread(dec); 43 | t.start(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/custom/cglib/Action.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.custom.cglib; 2 | 3 | public interface Action { 4 | 5 | void execute(); 6 | } 7 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/custom/cglib/CglibClass.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.custom.cglib; 2 | 3 | import net.sf.cglib.core.DebuggingClassWriter; 4 | import net.sf.cglib.proxy.Enhancer; 5 | 6 | import org.danielli.xultimate.test.custom.cglib.callback.DefaultActionMethodInterceptor; 7 | import org.danielli.xultimate.test.custom.cglib.support.DefaultAction; 8 | import org.danielli.xultimate.util.ArrayUtils; 9 | 10 | public class CglibClass { 11 | 12 | public static void main(String[] args) { 13 | System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "/tmp"); 14 | DefaultActionMethodInterceptor interceptor = new DefaultActionMethodInterceptor(); 15 | Enhancer enhancer = new Enhancer(); 16 | enhancer.setCallbacks(ArrayUtils.toArray(interceptor)); 17 | enhancer.setSuperclass(DefaultAction.class); 18 | enhancer.setUseCache(true); 19 | enhancer.create(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/custom/cglib/CglibInterface.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.custom.cglib; 2 | 3 | import net.sf.cglib.core.DebuggingClassWriter; 4 | import net.sf.cglib.proxy.Enhancer; 5 | 6 | import org.danielli.xultimate.test.custom.cglib.callback.DefaultActionInvocationHandler; 7 | import org.danielli.xultimate.util.ArrayUtils; 8 | 9 | public class CglibInterface { 10 | 11 | @SuppressWarnings("unchecked") 12 | public static void main(String[] args) { 13 | System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "/tmp"); 14 | DefaultActionInvocationHandler handler = new DefaultActionInvocationHandler(); 15 | Enhancer enhancer = new Enhancer(); 16 | enhancer.setCallbacks(ArrayUtils.toArray(handler)); 17 | enhancer.setInterfaces(ArrayUtils.toArray(Action.class)); 18 | enhancer.setUseCache(true); 19 | enhancer.create(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/custom/cglib/callback/DefaultActionInvocationHandler.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.custom.cglib.callback; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import net.sf.cglib.proxy.InvocationHandler; 6 | 7 | import org.danielli.xultimate.test.custom.cglib.support.DefaultAction; 8 | 9 | public class DefaultActionInvocationHandler implements InvocationHandler { 10 | 11 | private DefaultAction defaultAction = new DefaultAction(); 12 | 13 | @Override 14 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 15 | System.out.println("DefaultActionInvocationHandler.invoke.before()"); 16 | Object result = method.invoke(defaultAction, args); 17 | System.out.println("DefaultActionInvocationHandler.invoke.after()"); 18 | return result; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/custom/cglib/callback/DefaultActionMethodInterceptor.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.custom.cglib.callback; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import net.sf.cglib.proxy.MethodInterceptor; 6 | import net.sf.cglib.proxy.MethodProxy; 7 | 8 | public class DefaultActionMethodInterceptor implements MethodInterceptor { 9 | 10 | @Override 11 | public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { 12 | System.out.println("DefaultActionMethodInterceptor.intercept.before()"); 13 | Object result = proxy.invokeSuper(obj, args); 14 | System.out.println("DefaultActionMethodInterceptor.intercept.after()"); 15 | return result; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/custom/cglib/support/DefaultAction.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.custom.cglib.support; 2 | 3 | import org.danielli.xultimate.test.custom.cglib.Action; 4 | 5 | public class DefaultAction implements Action { 6 | 7 | @Override 8 | public void execute() { 9 | System.out.println("DefaultAction.execute()"); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/io/aio/Client.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.io.aio; 2 | 3 | import java.io.IOException; 4 | import java.net.InetSocketAddress; 5 | import java.nio.ByteBuffer; 6 | import java.nio.channels.AsynchronousSocketChannel; 7 | import java.util.Date; 8 | import java.util.concurrent.ExecutionException; 9 | import java.util.concurrent.Future; 10 | 11 | import org.danielli.xultimate.core.serializer.java.util.SerializerUtils; 12 | 13 | public class Client { 14 | 15 | public static void main(String[] args) throws IOException, InterruptedException, ExecutionException { 16 | AsynchronousSocketChannel socketChannel = AsynchronousSocketChannel.open(); 17 | socketChannel.connect(new InetSocketAddress("localhost", 9999)).get(); 18 | ByteBuffer buffer = ByteBuffer.allocate(8); 19 | Future integerFuture = socketChannel.read(buffer); 20 | System.out.println("等待信息接收完成"); 21 | Integer integer = integerFuture.get(); 22 | System.out.println("信息接收完成,接受到用" + integer + "个字节"); 23 | System.out.println(new Date(SerializerUtils.decodeLong(buffer.array()))); 24 | socketChannel.close(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/io/nio/Client.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.io.nio; 2 | 3 | import java.io.IOException; 4 | import java.net.InetSocketAddress; 5 | import java.nio.ByteBuffer; 6 | import java.nio.channels.SocketChannel; 7 | import java.util.Date; 8 | import java.util.concurrent.ExecutionException; 9 | 10 | import org.danielli.xultimate.core.serializer.java.util.SerializerUtils; 11 | 12 | public class Client { 13 | 14 | public static void main(String[] args) throws IOException, InterruptedException, ExecutionException { 15 | SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress("localhost", 9999)); 16 | ByteBuffer buffer = ByteBuffer.allocate(8); 17 | socketChannel.read(buffer); 18 | System.out.println(new Date(SerializerUtils.decodeLong(buffer.array()))); 19 | socketChannel.close(); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter2/DirectMemoryOOM.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter2; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.Method; 5 | 6 | /** 7 | * VM Args: -Xmx20m -XX:MaxDirectMemorySize=10m 8 | * 9 | * @author Daniel Li 10 | */ 11 | public class DirectMemoryOOM { 12 | private static final int _1MB = 1024 * 1024; 13 | 14 | public static void main(String[] args) throws Throwable { 15 | Field unsafeField = DirectMemoryOOM.class.getClassLoader().loadClass("sun.misc.Unsafe").getDeclaredFields()[0]; 16 | unsafeField.setAccessible(true); 17 | Object unsafe = unsafeField.get(null); 18 | Method unsafeMethod = unsafe.getClass().getDeclaredMethod("allocateMemory", long.class); 19 | int i = 0; 20 | while (true) { 21 | System.out.println(++i); 22 | unsafeMethod.invoke(unsafe, _1MB); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter2/HeapOOM.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter2; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * VM Args: -Xms20m -Xmx20m 8 | * 9 | * @author Daniel Li 10 | */ 11 | public class HeapOOM { 12 | public static void main(String[] args) { 13 | List list = new ArrayList(); 14 | 15 | while (true) { 16 | list.add(new OOMObject()); 17 | } 18 | } 19 | 20 | static class OOMObject { 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter2/JavaMethodAreaOOM.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter2; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import net.sf.cglib.proxy.Enhancer; 6 | import net.sf.cglib.proxy.MethodInterceptor; 7 | import net.sf.cglib.proxy.MethodProxy; 8 | 9 | /** 10 | * VM Args: -XX:PermSize=10m -XX:MaxPerrmSize=10m 11 | * 12 | * @author Daniel Li 13 | */ 14 | public class JavaMethodAreaOOM { 15 | public static void main(String[] args) { 16 | while (true) { 17 | Enhancer enhancer = new Enhancer(); 18 | enhancer.setSuperclass(OOMObject.class); 19 | enhancer.setUseCache(false); 20 | enhancer.setCallback(new MethodInterceptor() { 21 | 22 | @Override 23 | public Object intercept(Object obj, Method method, 24 | Object[] args, MethodProxy proxy) throws Throwable { 25 | return proxy.invokeSuper(obj, args); 26 | } 27 | 28 | }); 29 | enhancer.create(); 30 | } 31 | } 32 | 33 | static class OOMObject { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter2/JavaVMStackOOM.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter2; 2 | 3 | /** 4 | * VM Args: -Xss2m 5 | * 6 | * @author Daniel Li 7 | */ 8 | public class JavaVMStackOOM { 9 | private void dontStop() { 10 | while (true) { 11 | 12 | } 13 | } 14 | 15 | public void stackLeakByThread() { 16 | while (true) { 17 | Thread thread = new Thread(new Runnable() { 18 | 19 | @Override 20 | public void run() { 21 | dontStop(); 22 | } 23 | }); 24 | thread.start(); 25 | } 26 | } 27 | 28 | public static void main(String[] args) { 29 | JavaVMStackOOM oom = new JavaVMStackOOM(); 30 | oom.stackLeakByThread(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter2/JavaVMStackSOF.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter2; 2 | 3 | /** 4 | * VM Args: -Xss128k 5 | * 6 | * @author Daniel Li 7 | */ 8 | public class JavaVMStackSOF { 9 | private int stackLength = 1; 10 | 11 | public void stackLeak() { 12 | // long tmp1 = 1; 13 | // long tmp2 = 1; 14 | // long tmp3 = 1; 15 | // long tmp4 = 1; 16 | // long tmp5 = 1; 17 | // long tmp6 = 1; 18 | // long tmp7 = 1; 19 | // long tmp8 = 1; 20 | // long tmp9 = 1; 21 | stackLength++; 22 | stackLeak(); 23 | } 24 | 25 | public static void main(String[] args) { 26 | JavaVMStackSOF oom = new JavaVMStackSOF(); 27 | try { 28 | oom.stackLeak(); 29 | } catch (Throwable e) { 30 | System.out.println("stack length: " + oom.stackLength); 31 | throw e; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter2/RuntimeConstantPoolOOM.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter2; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * VM Args: -XX:PermSize=5m -XX:MaxPermSize=5m 8 | * 9 | * JDK 1.7中不会出现这个问题,String.intern()返回的是首次出现的实例引用。见 10 | * 11 | * @author Daniel Li 12 | */ 13 | public class RuntimeConstantPoolOOM { 14 | public static void main(String[] args) { 15 | List list = new ArrayList(); 16 | int i = 0; 17 | while (true) { 18 | list.add(String.valueOf(i++).intern()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter2/RuntimeConstantPoolOOM1.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter2; 2 | 3 | public class RuntimeConstantPoolOOM1 { 4 | 5 | public static void main(String[] args) { 6 | String str1 = new StringBuilder("计算机").append("软件").toString(); 7 | System.out.println(str1.intern() == str1); 8 | 9 | String str2 = new StringBuilder("ja").append("va").toString(); 10 | System.out.println(str2.intern() == str2); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter3/FinalizeEscapeGC.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter3; 2 | 3 | /** 4 | * VM Args: -XX:+UseSerialGC 5 | * 6 | * @author Daniel Li 7 | */ 8 | public class FinalizeEscapeGC { 9 | public static FinalizeEscapeGC SAVE_HOOK = null; 10 | 11 | public void isAlive() { 12 | System.out.println("yes, I am still alive"); 13 | } 14 | 15 | @Override 16 | protected void finalize() throws Throwable { 17 | super.finalize(); 18 | System.out.println("finalize method executed!"); 19 | FinalizeEscapeGC.SAVE_HOOK = this; 20 | } 21 | 22 | public static void main(String[] args) throws InterruptedException { 23 | SAVE_HOOK = new FinalizeEscapeGC(); 24 | 25 | SAVE_HOOK = null; 26 | System.gc(); 27 | 28 | Thread.sleep(500); 29 | if (SAVE_HOOK != null) { 30 | SAVE_HOOK.isAlive(); 31 | } else { 32 | System.out.println("No, I am dead :("); 33 | } 34 | 35 | SAVE_HOOK = null; 36 | System.gc(); 37 | 38 | Thread.sleep(500); 39 | if (SAVE_HOOK != null) { 40 | SAVE_HOOK.isAlive(); 41 | } else { 42 | System.out.println("No, I am dead :("); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter3/GCSample1.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter3; 2 | 3 | 4 | /** 5 | * VM Args: -XX:+UseSerialGC -Xms20m -Xmx20m -Xmn10m -XX:SurvivorRatio=8 -XX:+PrintGCDetails 6 | * 7 | * @author Daniel Li 8 | */ 9 | public class GCSample1 { 10 | 11 | private static final int _1MB = 1024 * 1024; 12 | 13 | @SuppressWarnings("unused") 14 | public static void testAllocation() { 15 | byte[] allocation1, allocation2, allocation3, allocation4; 16 | allocation1 = new byte[2 * _1MB]; 17 | allocation2 = new byte[2 * _1MB]; 18 | allocation3 = new byte[2 * _1MB]; 19 | allocation4 = new byte[4 * _1MB]; 20 | } 21 | 22 | public static void main(String[] args) { 23 | testAllocation(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter3/GCSample2.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter3; 2 | 3 | /** 4 | * VM Args: -XX:+UseSerialGC -Xms20m -Xmx20m -Xmn10m -XX:SurvivorRatio=8 -XX:+PrintGCDetails -XX:PretenureSizeThreshold=3145728 5 | * 6 | * @author Daniel Li 7 | */ 8 | public class GCSample2 { 9 | 10 | private static final int _1MB = 1024 * 1024; 11 | 12 | @SuppressWarnings("unused") 13 | public static void testPretenureSizeThreshold() { 14 | byte[] allocation; 15 | allocation = new byte[4 * _1MB]; 16 | } 17 | 18 | public static void main(String[] args) { 19 | testPretenureSizeThreshold(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter3/GCSample3.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter3; 2 | 3 | /** 4 | * VM Args: -XX:+UseSerialGC -Xms20m -Xmx20m -Xmn10m -XX:SurvivorRatio=8 -XX:+PrintGCDetails -XX:MaxTenuringThreshold=1 5 | * 6 | * @author Daniel Li 7 | */ 8 | public class GCSample3 { 9 | 10 | private static final int _1MB = 1024 * 1024; 11 | 12 | @SuppressWarnings("unused") 13 | public static void testTenuringThreshold() { 14 | byte[] allocation1, allocation2, allocation3; 15 | allocation1 = new byte[_1MB / 4]; 16 | allocation2 = new byte[4 * _1MB]; 17 | allocation3 = new byte[4 * _1MB]; 18 | allocation3 = null; 19 | allocation3 = new byte[4 * _1MB]; 20 | } 21 | 22 | public static void main(String[] args) { 23 | testTenuringThreshold(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter3/GCSample4.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter3; 2 | 3 | /** 4 | * VM Args: -XX:+UseSerialGC -Xms20m -Xmx20m -Xmn10m -XX:SurvivorRatio=8 -XX:+PrintGCDetails -XX:MaxTenuringThreshold=15 5 | * 6 | * @author Daniel Li 7 | */ 8 | public class GCSample4 { 9 | 10 | private static final int _1MB = 1024 * 1024; 11 | 12 | @SuppressWarnings("unused") 13 | public static void testTenuringThreshold2() { 14 | byte[] allocation1, allocation2, allocation3, allocation4; 15 | allocation1 = new byte[_1MB / 4]; 16 | allocation2 = new byte[_1MB / 4]; 17 | allocation3 = new byte[4 * _1MB]; 18 | allocation4 = new byte[4 * _1MB]; 19 | allocation4 = null; 20 | allocation4 = new byte[4 * _1MB]; 21 | } 22 | 23 | public static void main(String[] args) { 24 | testTenuringThreshold2(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter3/GCSample5.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter3; 2 | 3 | /** 4 | * VM Args: -XX:+UseSerialGC -Xms20m -Xmx20m -Xmn10m -XX:SurvivorRatio=8 -XX:+PrintGCDetails -XX:+HandlePromotionFailure 5 | * 6 | * @author Daniel Li 7 | */ 8 | public class GCSample5 { 9 | 10 | private static final int _1MB = 1024 * 1024; 11 | 12 | @SuppressWarnings("unused") 13 | public static void testHandlePromotion() { 14 | byte[] allocation1, allocation2, allocation3, allocation4, allocation5, allocation6, allocation7; 15 | allocation1 = new byte[2 * _1MB ]; 16 | allocation2 = new byte[2 * _1MB ]; 17 | allocation3 = new byte[2 * _1MB ]; 18 | allocation1 = null; 19 | allocation4 = new byte[2 * _1MB ]; 20 | allocation5 = new byte[2 * _1MB ]; 21 | allocation6 = new byte[2 * _1MB ]; 22 | allocation4 = null; 23 | allocation5 = null; 24 | allocation6 = null; 25 | allocation7 = new byte[2 * _1MB ]; 26 | } 27 | 28 | public static void main(String[] args) { 29 | testHandlePromotion(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter3/ReferenceCountingGC.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter3; 2 | 3 | /** 4 | * VM Args: -XX:+UseSerialGC -XX:+PrintGCDetails 5 | * 6 | * @author Daniel Li 7 | */ 8 | public class ReferenceCountingGC { 9 | 10 | public Object instance = null; 11 | 12 | private static final int _1MB = 1024 * 1024; 13 | 14 | @SuppressWarnings("unused") 15 | private byte[] bigSize = new byte[2 * _1MB]; 16 | 17 | public static void testGC() { 18 | ReferenceCountingGC objA = new ReferenceCountingGC(); 19 | ReferenceCountingGC objB = new ReferenceCountingGC(); 20 | objA.instance = objB; 21 | objB.instance = objA; 22 | 23 | objA = null; 24 | objB = null; 25 | System.gc(); 26 | } 27 | 28 | public static void main(String[] args) { 29 | testGC(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter4/JConsoleSample1.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter4; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class JConsoleSample1 { 7 | static class OOMObject { 8 | public byte[] placeholder = new byte[64 * 1024]; 9 | } 10 | 11 | public static void fillHeap(int num) throws InterruptedException { 12 | List list = new ArrayList(); 13 | for (int i = 0; i < num; i++) { 14 | Thread.sleep(50); 15 | list.add(new OOMObject()); 16 | } 17 | System.gc(); 18 | } 19 | 20 | public static void main(String[] args) throws InterruptedException { 21 | fillHeap(1000); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter4/JConsoleSample3.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter4; 2 | 3 | public class JConsoleSample3 { 4 | static class SynAddRunable implements Runnable { 5 | int a, b; 6 | 7 | public SynAddRunable(int a, int b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public void run() { 14 | synchronized (Integer.valueOf(a)) { 15 | synchronized (Integer.valueOf(b)) { 16 | System.out.println(a + b); 17 | } 18 | } 19 | 20 | } 21 | } 22 | 23 | public static void main(String[] args) { 24 | for (int i = 0; i < 10; i++) { 25 | new Thread(new SynAddRunable(1, 2)).start(); 26 | new Thread(new SynAddRunable(2, 1)).start(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/jvm/chapter8/ClassLoaderTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.jvm.chapter8; 2 | 3 | public class ClassLoaderTest { 4 | public static void main(String[] args) { 5 | ClassLoader loader = Thread.currentThread().getContextClassLoader(); 6 | System.out.println("current loader: " + loader); 7 | System.out.println("parent loader: " + loader.getParent()); 8 | System.out.println("grandparent loader: " + loader.getParent().getParent()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/thread/VolatileCase.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.thread; 2 | 3 | /** 4 | * 测试volatile关键字 5 | */ 6 | public class VolatileCase { 7 | // 去除volatile关键字后,会导致修改后无法生效。 8 | private volatile boolean again = true; 9 | 10 | public void setAgain(boolean setAgain) { 11 | this.again = setAgain; 12 | System.out.println(this.again); 13 | } 14 | 15 | public void doWork() { 16 | while (again) { 17 | } 18 | System.out.println(System.currentTimeMillis()); 19 | } 20 | 21 | public static void main(String[] args) { 22 | final VolatileCase vo = new VolatileCase(); 23 | for (int i = 0; i < 10; i++) { 24 | Thread thread1 = new Thread(new Runnable() { 25 | @Override 26 | public void run() { 27 | vo.doWork(); 28 | } 29 | }); 30 | thread1.start(); 31 | } 32 | Thread thread2 = new Thread(new Runnable() { 33 | @Override 34 | public void run() { 35 | vo.setAgain(false); 36 | } 37 | }); 38 | thread2.start(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/thread/disruptor/LongEvent.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.thread.disruptor; 2 | 3 | /** 4 | * 取自{@link https://github.com/LMAX-Exchange/disruptor/wiki} 5 | */ 6 | public class LongEvent { 7 | 8 | private long value; 9 | 10 | public void set(long value) { 11 | this.value = value; 12 | } 13 | 14 | public long getValue() { 15 | return value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/thread/disruptor/LongEventFactory.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.thread.disruptor; 2 | 3 | import com.lmax.disruptor.EventFactory; 4 | 5 | /** 6 | * 取自{@link https://github.com/LMAX-Exchange/disruptor/wiki} 7 | */ 8 | public class LongEventFactory implements EventFactory { 9 | 10 | public LongEvent newInstance() { 11 | return new LongEvent(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/thread/disruptor/LongEventHandler.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.thread.disruptor; 2 | 3 | import com.lmax.disruptor.EventHandler; 4 | 5 | /** 6 | * 取自{@link https://github.com/LMAX-Exchange/disruptor/wiki} 7 | */ 8 | public class LongEventHandler implements EventHandler { 9 | 10 | public void onEvent(LongEvent event, long sequence, boolean endOfBatch) { 11 | System.out.println("Event: " + event.getValue()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/thread/disruptor/LongEventProducer.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.thread.disruptor; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | import com.lmax.disruptor.RingBuffer; 6 | 7 | /** 8 | * 取自{@link https://github.com/LMAX-Exchange/disruptor/wiki} 9 | */ 10 | public class LongEventProducer { 11 | 12 | private final RingBuffer ringBuffer; 13 | 14 | public LongEventProducer(RingBuffer ringBuffer) { 15 | this.ringBuffer = ringBuffer; 16 | } 17 | 18 | public void onData(ByteBuffer bb) { 19 | long sequence = ringBuffer.next(); // Grab the next sequence 20 | try { 21 | LongEvent event = ringBuffer.get(sequence); // Get the entry in the Disruptor for the sequence 22 | event.set(bb.getLong(0)); // Fill with data 23 | } finally { 24 | ringBuffer.publish(sequence); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/thread/disruptor/LongEventProducerWithTranslator.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.thread.disruptor; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | import com.lmax.disruptor.EventTranslatorOneArg; 6 | import com.lmax.disruptor.RingBuffer; 7 | 8 | /** 9 | * 取自{@link https://github.com/LMAX-Exchange/disruptor/wiki} 10 | */ 11 | public class LongEventProducerWithTranslator { 12 | private final RingBuffer ringBuffer; 13 | 14 | public LongEventProducerWithTranslator(RingBuffer ringBuffer) { 15 | this.ringBuffer = ringBuffer; 16 | } 17 | 18 | private static final EventTranslatorOneArg TRANSLATOR = new EventTranslatorOneArg() { 19 | public void translateTo(LongEvent event, long sequence, ByteBuffer bb) { 20 | event.set(bb.getLong(0)); 21 | } 22 | }; 23 | 24 | public void onData(ByteBuffer bb) { 25 | ringBuffer.publishEvent(TRANSLATOR, bb); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/test/thread/linkedhashmap/ConcurrentLinkedHashMapTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.test.thread.linkedhashmap; 2 | 3 | import java.util.concurrent.ConcurrentMap; 4 | 5 | import org.junit.Test; 6 | 7 | import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; 8 | import com.googlecode.concurrentlinkedhashmap.EvictionListener; 9 | import com.googlecode.concurrentlinkedhashmap.Weighers; 10 | 11 | public class ConcurrentLinkedHashMapTest { 12 | 13 | @Test 14 | public void test() { 15 | EvictionListener listener = new EvictionListener() { 16 | @Override 17 | public void onEviction(Integer key, Integer value) { 18 | System.out.println("Evicted key=" + key + ", value=" + value); 19 | } 20 | }; 21 | 22 | ConcurrentMap cache = new ConcurrentLinkedHashMap.Builder() 23 | .maximumWeightedCapacity(2).listener(listener) 24 | .weigher(Weighers.singleton()).build(); 25 | cache.put(1, 1); 26 | cache.put(2, 2); 27 | cache.put(3, 3); 28 | System.out.println(cache.get(1));// null 已经失效了 29 | System.out.println(cache.get(2)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/testexample/junit/GroupTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.testexample.junit; 2 | 3 | import org.danielli.xultimate.testexample.junit.support.ConstructorTest; 4 | import org.danielli.xultimate.testexample.junit.support.ExampleTest; 5 | import org.danielli.xultimate.testexample.junit.support.ExceptionTest; 6 | import org.junit.runner.RunWith; 7 | import org.junit.runners.Suite; 8 | import org.junit.runners.Suite.SuiteClasses; 9 | 10 | @RunWith(Suite.class) 11 | @SuiteClasses({ ExampleTest.class, ExceptionTest.class, ConstructorTest.class }) 12 | public class GroupTest { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/testexample/junit/support/ConstructorTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.testexample.junit.support; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collection; 5 | 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.junit.runners.Parameterized; 10 | import org.junit.runners.Parameterized.Parameters; 11 | 12 | @RunWith(Parameterized.class) 13 | public class ConstructorTest { 14 | 15 | private String v1; 16 | 17 | private String v2; 18 | 19 | public ConstructorTest(String v1, String v2) { 20 | this.v1 = v1; 21 | this.v2 = v2; 22 | } 23 | 24 | @Parameters 25 | public static Collection getParameters() { 26 | String[][] constructors = { 27 | { "test1", "test1" }, 28 | { "test2", "test2" } 29 | }; 30 | return Arrays.asList(constructors); 31 | } 32 | 33 | @Test(timeout = 10) // 十秒内必须完成 34 | public void testEquals() { 35 | Assert.assertEquals(v1, v2); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/testexample/junit/support/ExceptionTest.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.testexample.junit.support; 2 | 3 | import org.junit.After; 4 | import org.junit.AfterClass; 5 | import org.junit.Assert; 6 | import org.junit.Before; 7 | import org.junit.BeforeClass; 8 | import org.junit.Test; 9 | 10 | public class ExceptionTest { 11 | 12 | private static String v1; 13 | 14 | private String v2; 15 | 16 | @BeforeClass // 只执行一次 17 | public static void init() { 18 | v1 = null; 19 | } 20 | 21 | @Before // 可以出现多个,测试方法运行前会执行一次。 22 | public void v2Init() { 23 | v2 = "v2"; 24 | } 25 | 26 | @AfterClass // 只执行一次,且一定会执行 27 | public static void destory() { 28 | v1 = null; 29 | } 30 | 31 | @After // 可以出现多个,测试方法运行后会执行一次,且一定会执行。 32 | public void v2Destory() { 33 | v2 = null; 34 | } 35 | 36 | @Test(expected = NullPointerException.class) 37 | public void testException() { 38 | Assert.assertEquals(v1.concat("v1"), "v1"); 39 | } 40 | 41 | @Test 42 | public void testV2() { 43 | Assert.assertEquals(v2, "v2"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/testexample/mock/support/User.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.testexample.mock.support; 2 | 3 | public class User { 4 | 5 | private String username; 6 | 7 | public User() { 8 | 9 | } 10 | 11 | public User(String username) { 12 | this.username = username; 13 | } 14 | 15 | public String getUsername() { 16 | return username; 17 | } 18 | 19 | public void setUsername(String username) { 20 | this.username = username; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/testexample/mock/support/UserService.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.testexample.mock.support; 2 | 3 | public interface UserService { 4 | 5 | User getByUsername(String username); 6 | 7 | void deleteByUsername(String username); 8 | } 9 | -------------------------------------------------------------------------------- /xultimate-test/src/test/java/org/danielli/xultimate/testexample/mock/support/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.testexample.mock.support; 2 | 3 | import org.danielli.xultimate.util.ArrayUtils; 4 | 5 | public class UserServiceImpl implements UserService { 6 | 7 | private String[] existsUsernames = { "daniellitoc", "danielli", "daniel" }; 8 | 9 | @Override 10 | public User getByUsername(String username) { 11 | boolean result = ArrayUtils.contains(existsUsernames, username); 12 | if (result) { 13 | return new User(username); 14 | } else { 15 | return null; 16 | } 17 | } 18 | 19 | @Override 20 | public void deleteByUsername(String username) { 21 | ArrayUtils.removeElement(existsUsernames, username); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xultimate-web/src/main/java/org/danielli/xultimate/context/config/StringToFileArrayPropertyEditor.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.context.config; 2 | 3 | import java.beans.PropertyEditorSupport; 4 | import java.io.File; 5 | 6 | import org.apache.commons.lang3.ArrayUtils; 7 | import org.danielli.xultimate.util.io.ResourceUtils; 8 | import org.springframework.core.io.Resource; 9 | 10 | public class StringToFileArrayPropertyEditor extends PropertyEditorSupport { 11 | 12 | @Override 13 | public void setAsText(String text) throws IllegalArgumentException { 14 | try { 15 | Resource[] resources = ResourceUtils.getResources(text); 16 | if (ArrayUtils.isNotEmpty(resources)) { 17 | File[] files = new File[resources.length]; 18 | for (int i = 0; i < files.length; i++) { 19 | files[i] = resources[i].getFile(); 20 | } 21 | setValue(files); 22 | } 23 | } catch (Exception e) { 24 | throw new IllegalArgumentException(e.getMessage(), e); 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /xultimate-web/src/main/java/org/danielli/xultimate/web/context/response/GzipResponseStream.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.web.context.response; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | import javax.servlet.ServletOutputStream; 7 | import javax.servlet.WriteListener; 8 | 9 | /** 10 | * Gzip响应流。 11 | * 12 | * @author Daniel Li 13 | * @since 15 Jun 2013 14 | */ 15 | public class GzipResponseStream extends ServletOutputStream { 16 | 17 | private OutputStream outputStream; 18 | 19 | public GzipResponseStream(OutputStream outputStream) { 20 | this.outputStream = outputStream; 21 | } 22 | 23 | public void write(int b) throws IOException { 24 | outputStream.write(b); 25 | } 26 | 27 | public void write(byte[] b) throws IOException { 28 | outputStream.write(b); 29 | } 30 | 31 | public void write(byte[] b, int off, int len) throws IOException { 32 | outputStream.write(b, off, len); 33 | } 34 | 35 | @Override 36 | public boolean isReady() { 37 | return false; 38 | } 39 | 40 | @Override 41 | public void setWriteListener(WriteListener arg0) { 42 | } 43 | } -------------------------------------------------------------------------------- /xultimate-web/src/main/java/org/danielli/xultimate/web/util/PasswordCallback.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.web.util; 2 | 3 | /** 4 | * 密码回调类。 5 | * 6 | * @author Daniel Li 7 | * @since 15 Jun 2013 8 | */ 9 | public interface PasswordCallback { 10 | 11 | /** 12 | * 通过用户名获取密码。 13 | * 14 | * @param userName 用户名。 15 | * @return 密码。 16 | */ 17 | String getPassword(String userName); 18 | } 19 | -------------------------------------------------------------------------------- /xultimate-web/src/main/java/org/danielli/xultimate/web/util/PropertyCallback.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.web.util; 2 | 3 | 4 | /** 5 | * 属性值回调类。 6 | * 7 | * @author Daniel Li 8 | * @since 15 Jun 2013 9 | * @see WebUtils#setProperty(javax.servlet.ServletContext, String, String, String, SetPropertyCallback) 10 | */ 11 | public interface PropertyCallback { 12 | 13 | /** 14 | * 获取属性值。 15 | * 16 | * @param key 与属性值对应的属性键。 17 | * @return 属性值。 18 | */ 19 | String get(String key); 20 | 21 | /** 22 | * 设置属性值。 23 | * 24 | * @param key 属性键。 25 | * @param value 属性值。 26 | */ 27 | void set(String key, String value); 28 | 29 | /** 30 | * 删除属性值。 31 | * 32 | * @param key 被删除的属性键。 33 | */ 34 | void remove(String key); 35 | } 36 | -------------------------------------------------------------------------------- /xultimate-web/src/test/resources/cookie.properties: -------------------------------------------------------------------------------- 1 | cookie.domain=localhost 2 | cookie.defaultPath=/ 3 | cookie.secure=false 4 | cookie.httpOnly=false; 5 | 6 | -------------------------------------------------------------------------------- /xultimate-webmvc/src/main/java/org/danielli/xultimate/web/servlet/view/httl/HttlViewResolver.java: -------------------------------------------------------------------------------- 1 | package org.danielli.xultimate.web.servlet.view.httl; 2 | 3 | import httl.web.WebEngine; 4 | 5 | import java.util.Map; 6 | import java.util.Properties; 7 | 8 | /** 9 | * HTTL视图解析器。 10 | * 11 | * @author Daniel Li 12 | * @since 15 Jun 2013 13 | * @see WebEngine 14 | * @see httl.web.springmvc.HttlViewResolver 15 | */ 16 | public class HttlViewResolver extends httl.web.springmvc.HttlViewResolver { 17 | 18 | private Properties httlProperties; 19 | 20 | public void setHttlProperties(Properties httlProperties) { 21 | this.httlProperties = httlProperties; 22 | } 23 | 24 | @Override 25 | public void afterPropertiesSet() throws Exception { 26 | if (httlProperties != null) { 27 | for (Map.Entry entry : httlProperties.entrySet()) { 28 | WebEngine.setProperty((String) entry.getKey(), (String) entry.getValue()); 29 | } 30 | } 31 | super.afterPropertiesSet(); 32 | } 33 | } 34 | --------------------------------------------------------------------------------